aboutsummaryrefslogtreecommitdiff
path: root/kernel/ethosu_inference.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/ethosu_inference.c')
-rw-r--r--kernel/ethosu_inference.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/kernel/ethosu_inference.c b/kernel/ethosu_inference.c
index 4f56126..6befd3a 100644
--- a/kernel/ethosu_inference.c
+++ b/kernel/ethosu_inference.c
@@ -91,11 +91,12 @@ static const char *status_to_string(const enum ethosu_uapi_status status)
static int ethosu_inference_send(struct ethosu_inference *inf)
{
+ struct device *dev = inf->dev;
int ret;
inf->status = ETHOSU_UAPI_STATUS_ERROR;
- ret = ethosu_mailbox_inference(&inf->edev->mailbox, &inf->msg,
+ ret = ethosu_mailbox_inference(inf->mailbox, &inf->msg,
inf->ifm_count, inf->ifm,
inf->ofm_count, inf->ofm,
inf->net->buf,
@@ -104,7 +105,7 @@ static int ethosu_inference_send(struct ethosu_inference *inf)
ETHOSU_PMU_EVENT_MAX,
inf->pmu_cycle_counter_enable);
if (ret) {
- dev_warn(inf->edev->dev,
+ dev_warn(dev,
"Failed to send inference request. inf=0x%pK, ret=%d",
inf, ret);
@@ -150,12 +151,13 @@ static void ethosu_inference_kref_destroy(struct kref *kref)
{
struct ethosu_inference *inf =
container_of(kref, struct ethosu_inference, kref);
+ struct device *dev = inf->dev;
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Inference destroy. inf=0x%pK, status=%d, ifm_count=%u, ofm_count=%u",
inf, inf->status, inf->ifm_count, inf->ofm_count);
- ethosu_mailbox_deregister(&inf->edev->mailbox, &inf->msg);
+ ethosu_mailbox_deregister(inf->mailbox, &inf->msg);
while (inf->ifm_count-- > 0)
ethosu_buffer_put(inf->ifm[inf->ifm_count]);
@@ -164,15 +166,16 @@ static void ethosu_inference_kref_destroy(struct kref *kref)
ethosu_buffer_put(inf->ofm[inf->ofm_count]);
ethosu_network_put(inf->net);
- devm_kfree(inf->edev->dev, inf);
+ devm_kfree(dev, inf);
}
static int ethosu_inference_release(struct inode *inode,
struct file *file)
{
struct ethosu_inference *inf = file->private_data;
+ struct device *dev = inf->dev;
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Inference release. file=0x%pK, inf=0x%pK",
file, inf);
@@ -200,14 +203,15 @@ static long ethosu_inference_ioctl(struct file *file,
unsigned long arg)
{
struct ethosu_inference *inf = file->private_data;
+ struct device *dev = inf->dev;
void __user *udata = (void __user *)arg;
int ret;
- ret = mutex_lock_interruptible(&inf->edev->mutex);
+ ret = device_lock_interruptible(dev);
if (ret)
return ret;
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Inference ioctl: file=0x%pK, inf=0x%pK, cmd=0x%x, arg=%lu",
file, inf, cmd, arg);
@@ -228,7 +232,7 @@ static long ethosu_inference_ioctl(struct file *file,
uapi.pmu_config.cycle_count = inf->pmu_cycle_counter_enable;
uapi.pmu_count.cycle_count = inf->pmu_cycle_counter_count;
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Inference ioctl: Inference status. status=%s (%d)\n",
status_to_string(uapi.status), uapi.status);
@@ -239,11 +243,12 @@ static long ethosu_inference_ioctl(struct file *file,
case ETHOSU_IOCTL_INFERENCE_CANCEL: {
struct ethosu_uapi_cancel_inference_status uapi;
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Inference ioctl: Cancel Inference. Handle=%p\n",
inf);
- ret = ethosu_cancel_inference_request(inf, &uapi);
+ ret = ethosu_cancel_inference_request(dev, inf->mailbox, inf,
+ &uapi);
if (ret)
break;
@@ -252,18 +257,19 @@ static long ethosu_inference_ioctl(struct file *file,
break;
}
default: {
- dev_err(inf->edev->dev, "Invalid ioctl. cmd=%u, arg=%lu\n",
+ dev_err(dev, "Invalid ioctl. cmd=%u, arg=%lu\n",
cmd, arg);
break;
}
}
- mutex_unlock(&inf->edev->mutex);
+ device_unlock(dev);
return ret;
}
-int ethosu_inference_create(struct ethosu_device *edev,
+int ethosu_inference_create(struct device *dev,
+ struct ethosu_mailbox *mailbox,
struct ethosu_network *net,
struct ethosu_uapi_inference_create *uapi)
{
@@ -274,18 +280,19 @@ int ethosu_inference_create(struct ethosu_device *edev,
if (uapi->ifm_count > ETHOSU_FD_MAX ||
uapi->ofm_count > ETHOSU_FD_MAX) {
- dev_warn(edev->dev,
+ dev_warn(dev,
"Too many IFM and/or OFM buffers for inference. ifm_count=%u, ofm_count=%u",
uapi->ifm_count, uapi->ofm_count);
return -EFAULT;
}
- inf = devm_kzalloc(edev->dev, sizeof(*inf), GFP_KERNEL);
+ inf = devm_kzalloc(dev, sizeof(*inf), GFP_KERNEL);
if (!inf)
return -ENOMEM;
- inf->edev = edev;
+ inf->dev = dev;
+ inf->mailbox = mailbox;
inf->net = net;
inf->done = false;
inf->status = ETHOSU_UAPI_STATUS_ERROR;
@@ -294,7 +301,7 @@ int ethosu_inference_create(struct ethosu_device *edev,
inf->msg.fail = ethosu_inference_fail;
/* Add inference to pending list */
- ret = ethosu_mailbox_register(&edev->mailbox, &inf->msg);
+ ret = ethosu_mailbox_register(mailbox, &inf->msg);
if (ret < 0)
goto kfree;
@@ -321,7 +328,7 @@ int ethosu_inference_create(struct ethosu_device *edev,
}
/* Configure PMU and cycle counter */
- dev_info(inf->edev->dev,
+ dev_info(dev,
"Configuring events for PMU. events=[%u, %u, %u, %u]\n",
uapi->pmu_config.events[0], uapi->pmu_config.events[1],
uapi->pmu_config.events[2], uapi->pmu_config.events[3]);
@@ -333,7 +340,7 @@ int ethosu_inference_create(struct ethosu_device *edev,
}
if (uapi->pmu_config.cycle_count)
- dev_info(inf->edev->dev, "Enabling cycle counter\n");
+ dev_info(dev, "Enabling cycle counter\n");
/* Configure cycle counter and reset any previous count */
inf->pmu_cycle_counter_enable = uapi->pmu_config.cycle_count;
@@ -357,7 +364,7 @@ int ethosu_inference_create(struct ethosu_device *edev,
inf->file = fget(ret);
fput(inf->file);
- dev_info(edev->dev,
+ dev_info(dev,
"Inference create. file=0x%pK, fd=%d, inf=0x%p, net=0x%pK, msg.id=0x%x",
inf->file, fd, inf, inf->net, inf->msg.id);
@@ -375,7 +382,7 @@ put_ifm:
ethosu_buffer_put(inf->ifm[inf->ifm_count]);
kfree:
- devm_kfree(edev->dev, inf);
+ devm_kfree(dev, inf);
return ret;
}
@@ -412,18 +419,19 @@ int ethosu_inference_put(struct ethosu_inference *inf)
return kref_put(&inf->kref, &ethosu_inference_kref_destroy);
}
-void ethosu_inference_rsp(struct ethosu_device *edev,
+void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
int msg_id,
struct ethosu_core_msg_inference_rsp *rsp)
{
+ struct device *dev = mailbox->dev;
struct ethosu_mailbox_msg *msg;
struct ethosu_inference *inf;
int ret;
int i;
- msg = ethosu_mailbox_find(&edev->mailbox, msg_id);
+ msg = ethosu_mailbox_find(mailbox, msg_id);
if (IS_ERR(msg)) {
- dev_warn(edev->dev,
+ dev_warn(dev,
"Id for inference msg not found. Id=%d\n",
msg_id);
@@ -464,14 +472,14 @@ void ethosu_inference_rsp(struct ethosu_device *edev,
inf->pmu_cycle_counter_enable = rsp->pmu_cycle_counter_enable;
inf->pmu_cycle_counter_count = rsp->pmu_cycle_counter_count;
- dev_info(edev->dev,
+ dev_info(dev,
"PMU events. config=[%u, %u, %u, %u], count=[%u, %u, %u, %u]\n",
inf->pmu_event_config[0], inf->pmu_event_config[1],
inf->pmu_event_config[2], inf->pmu_event_config[3],
inf->pmu_event_count[0], inf->pmu_event_count[1],
inf->pmu_event_count[2], inf->pmu_event_count[3]);
- dev_info(edev->dev,
+ dev_info(dev,
"PMU cycle counter. enable=%u, count=%llu\n",
inf->pmu_cycle_counter_enable,
inf->pmu_cycle_counter_count);