aboutsummaryrefslogtreecommitdiff
path: root/kernel/ethosu_inference.c
diff options
context:
space:
mode:
authorDavide Grohmann <davide.grohmann@arm.com>2022-04-27 16:49:07 +0200
committerDavide Grohmann <davide.grohmann@arm.com>2022-05-23 15:42:30 +0200
commit32660f9ff9608dc595f4bdf3944a3ceb37d67a79 (patch)
treec57eaef314cc0600c2df6de9426c15709f42bccf /kernel/ethosu_inference.c
parentb9248a425e7f72d240d11852c72c44bae4d38bac (diff)
downloadethos-u-linux-driver-stack-32660f9ff9608dc595f4bdf3944a3ceb37d67a79.tar.gz
Use ids for identifying messages sent to EthosU firmware
Avoid to use pointers to kernel memory as identify messages, prior this change, if memory is reused that can lead to unexpected conflicts. Remove ref counting from capabilities and network_info since memory is freed in only one place. Finally, extract the capabilities code in its own files. Change-Id: I9ab7257f3ab85fa3347be65b3739e0daf9b5a441
Diffstat (limited to 'kernel/ethosu_inference.c')
-rw-r--r--kernel/ethosu_inference.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/kernel/ethosu_inference.c b/kernel/ethosu_inference.c
index 0599b53..55cabc3 100644
--- a/kernel/ethosu_inference.c
+++ b/kernel/ethosu_inference.c
@@ -95,7 +95,7 @@ static int ethosu_inference_send(struct ethosu_inference *inf)
inf->status = ETHOSU_UAPI_STATUS_ERROR;
- ret = ethosu_mailbox_inference(&inf->edev->mailbox, inf,
+ ret = ethosu_mailbox_inference(&inf->edev->mailbox, &inf->msg,
inf->ifm_count, inf->ifm,
inf->ofm_count, inf->ofm,
inf->net->buf,
@@ -180,7 +180,7 @@ static void ethosu_inference_kref_destroy(struct kref *kref)
"Inference destroy. handle=0x%pK, status=%d\n",
inf, inf->status);
- list_del(&inf->msg.list);
+ ethosu_mailbox_deregister(&inf->edev->mailbox, &inf->msg);
while (inf->ifm_count-- > 0)
ethosu_buffer_put(inf->ifm[inf->ifm_count]);
@@ -307,6 +307,11 @@ int ethosu_inference_create(struct ethosu_device *edev,
inf->msg.fail = ethosu_inference_fail;
inf->msg.resend = ethosu_inference_resend;
+ /* Add inference to pending list */
+ ret = ethosu_mailbox_register(&edev->mailbox, &inf->msg);
+ if (ret < 0)
+ goto kfree;
+
/* Get pointer to IFM buffers */
for (i = 0; i < uapi->ifm_count; i++) {
inf->ifm[i] = ethosu_buffer_get_from_fd(uapi->ifm_fd[i]);
@@ -361,14 +366,13 @@ int ethosu_inference_create(struct ethosu_device *edev,
inf->file = fget(ret);
fput(inf->file);
- /* Add inference to pending list */
- list_add(&inf->msg.list, &edev->mailbox.pending_list);
-
/* Send inference request to Arm Ethos-U subsystem */
- (void)ethosu_inference_send(inf);
+ ret = ethosu_inference_send(inf);
+ if (ret)
+ goto put_net;
- dev_info(edev->dev, "Inference create. handle=0x%pK, fd=%d",
- inf, fd);
+ dev_info(edev->dev, "Inference create. Id=%d, handle=0x%p, fd=%d",
+ inf->msg.id, inf, fd);
return fd;
@@ -383,6 +387,7 @@ put_ifm:
while (inf->ifm_count-- > 0)
ethosu_buffer_put(inf->ifm[inf->ifm_count]);
+kfree:
devm_kfree(edev->dev, inf);
return ret;
@@ -423,20 +428,23 @@ int ethosu_inference_put(struct ethosu_inference *inf)
void ethosu_inference_rsp(struct ethosu_device *edev,
struct ethosu_core_inference_rsp *rsp)
{
- struct ethosu_inference *inf =
- (struct ethosu_inference *)rsp->user_arg;
+ int id = (int)rsp->user_arg;
+ struct ethosu_mailbox_msg *msg;
+ struct ethosu_inference *inf;
int ret;
int i;
- ret = ethosu_mailbox_find(&edev->mailbox, &inf->msg);
- if (ret) {
+ msg = ethosu_mailbox_find(&edev->mailbox, id);
+ if (IS_ERR(msg)) {
dev_warn(edev->dev,
- "Handle not found in inference list. handle=0x%p\n",
- rsp);
+ "Id for inference msg not found. Id=%d\n",
+ id);
return;
}
+ inf = container_of(msg, typeof(*inf), msg);
+
if (rsp->status == ETHOSU_CORE_STATUS_OK &&
inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX) {
uint32_t i;