blob: b985e7512c9dadf116fb05ff5fae3c01186808d4 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Ledion Dajaedd25502023-10-17 09:15:32 +02002 * SPDX-FileCopyrightText: Copyright 2020,2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
3 * SPDX-License-Identifier: GPL-2.0-only
Kristofer Jonsson116a6352020-08-20 17:25:23 +02004 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, you can access it online at
17 * http://www.gnu.org/licenses/gpl-2.0.html.
Kristofer Jonsson116a6352020-08-20 17:25:23 +020018 */
19
20/****************************************************************************
21 * Includes
22 ****************************************************************************/
23
24#include "ethosu_inference.h"
25
26#include "ethosu_buffer.h"
Kristofer Jonssond779a082023-01-04 17:09:47 +010027#include "ethosu_core_rpmsg.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020028#include "ethosu_device.h"
29#include "ethosu_network.h"
Davide Grohmann7e8f5082022-03-23 12:48:45 +010030#include "ethosu_cancel_inference.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020031
32#include <linux/anon_inodes.h>
33#include <linux/file.h>
34#include <linux/fs.h>
35#include <linux/poll.h>
36
37/****************************************************************************
38 * Variables
39 ****************************************************************************/
40
41static int ethosu_inference_release(struct inode *inode,
42 struct file *file);
43
44static unsigned int ethosu_inference_poll(struct file *file,
45 poll_table *wait);
46
47static long ethosu_inference_ioctl(struct file *file,
48 unsigned int cmd,
49 unsigned long arg);
50
51static const struct file_operations ethosu_inference_fops = {
52 .release = &ethosu_inference_release,
53 .poll = &ethosu_inference_poll,
54 .unlocked_ioctl = &ethosu_inference_ioctl,
55#ifdef CONFIG_COMPAT
56 .compat_ioctl = &ethosu_inference_ioctl,
57#endif
58};
59
60/****************************************************************************
61 * Functions
62 ****************************************************************************/
63
64static const char *status_to_string(const enum ethosu_uapi_status status)
65{
66 switch (status) {
67 case ETHOSU_UAPI_STATUS_OK: {
68 return "Ok";
69 }
70 case ETHOSU_UAPI_STATUS_ERROR: {
71 return "Error";
72 }
Davide Grohmann82d22582022-04-25 12:52:38 +020073 case ETHOSU_UAPI_STATUS_RUNNING: {
74 return "Running";
75 }
76 case ETHOSU_UAPI_STATUS_REJECTED: {
77 return "Rejected";
78 }
Davide Grohmann7e8f5082022-03-23 12:48:45 +010079 case ETHOSU_UAPI_STATUS_ABORTED: {
80 return "Aborted";
81 }
82 case ETHOSU_UAPI_STATUS_ABORTING: {
83 return "Aborting";
84 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +020085 default: {
86 return "Unknown";
87 }
88 }
89}
90
91static int ethosu_inference_send(struct ethosu_inference *inf)
92{
Kristofer Jonssonec477042023-01-20 13:38:13 +010093 struct device *dev = inf->dev;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020094 int ret;
95
Kristofer Jonsson116a6352020-08-20 17:25:23 +020096 inf->status = ETHOSU_UAPI_STATUS_ERROR;
97
Kristofer Jonssonec477042023-01-20 13:38:13 +010098 ret = ethosu_mailbox_inference(inf->mailbox, &inf->msg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020099 inf->ifm_count, inf->ifm,
100 inf->ofm_count, inf->ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200101 inf->net->buf,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100102 inf->net->index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200103 inf->pmu_event_config,
104 ETHOSU_PMU_EVENT_MAX,
105 inf->pmu_cycle_counter_enable);
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200106 if (ret) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100107 dev_warn(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200108 "Failed to send inference request. inf=0x%pK, ret=%d",
109 inf, ret);
110
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200111 return ret;
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200112 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200113
Davide Grohmann82d22582022-04-25 12:52:38 +0200114 inf->status = ETHOSU_UAPI_STATUS_RUNNING;
115
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200116 ethosu_inference_get(inf);
117
118 return 0;
119}
120
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100121static void ethosu_inference_fail(struct ethosu_mailbox_msg *msg)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200122{
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100123 struct ethosu_inference *inf =
124 container_of(msg, typeof(*inf), msg);
125 int ret;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200126
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100127 if (inf->done)
128 return;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200129
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100130 /* Decrement reference count if inference was pending reponse */
131 ret = ethosu_inference_put(inf);
132 if (ret)
133 return;
134
135 /* Set status accordingly to the inference state */
136 inf->status = inf->status == ETHOSU_UAPI_STATUS_ABORTING ?
137 ETHOSU_UAPI_STATUS_ABORTED :
138 ETHOSU_UAPI_STATUS_ERROR;
139 /* Mark it done and wake up the waiting process */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100140 inf->done = true;
141 wake_up_interruptible(&inf->waitq);
142}
143
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200144static bool ethosu_inference_verify(struct file *file)
145{
146 return file->f_op == &ethosu_inference_fops;
147}
148
149static void ethosu_inference_kref_destroy(struct kref *kref)
150{
151 struct ethosu_inference *inf =
152 container_of(kref, struct ethosu_inference, kref);
Kristofer Jonssonec477042023-01-20 13:38:13 +0100153 struct device *dev = inf->dev;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200154
Ledion Dajaedd25502023-10-17 09:15:32 +0200155 dev_dbg(dev,
156 "Inference destroy. inf=0x%pK, status=%d, ifm_count=%u, ofm_count=%u",
157 inf, inf->status, inf->ifm_count, inf->ofm_count);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200158
Kristofer Jonssonec477042023-01-20 13:38:13 +0100159 ethosu_mailbox_deregister(inf->mailbox, &inf->msg);
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200160
161 while (inf->ifm_count-- > 0)
162 ethosu_buffer_put(inf->ifm[inf->ifm_count]);
163
164 while (inf->ofm_count-- > 0)
165 ethosu_buffer_put(inf->ofm[inf->ofm_count]);
166
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200167 ethosu_network_put(inf->net);
Mikael Olsson1182f382023-08-10 13:25:44 +0200168 memset(inf, 0, sizeof(*inf));
Kristofer Jonssonec477042023-01-20 13:38:13 +0100169 devm_kfree(dev, inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200170}
171
172static int ethosu_inference_release(struct inode *inode,
173 struct file *file)
174{
175 struct ethosu_inference *inf = file->private_data;
Kristofer Jonssonec477042023-01-20 13:38:13 +0100176 struct device *dev = inf->dev;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200177
Ledion Dajaedd25502023-10-17 09:15:32 +0200178 dev_dbg(dev,
179 "Inference release. file=0x%pK, inf=0x%pK",
180 file, inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200181
Mikael Olsson529cfad2023-06-14 17:14:14 +0200182 device_lock(dev);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200183 ethosu_inference_put(inf);
Mikael Olsson529cfad2023-06-14 17:14:14 +0200184 device_unlock(dev);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200185
186 return 0;
187}
188
189static unsigned int ethosu_inference_poll(struct file *file,
190 poll_table *wait)
191{
192 struct ethosu_inference *inf = file->private_data;
193 int ret = 0;
194
195 poll_wait(file, &inf->waitq, wait);
196
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100197 if (inf->done)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200198 ret |= POLLIN;
199
200 return ret;
201}
202
203static long ethosu_inference_ioctl(struct file *file,
204 unsigned int cmd,
205 unsigned long arg)
206{
207 struct ethosu_inference *inf = file->private_data;
Kristofer Jonssonec477042023-01-20 13:38:13 +0100208 struct device *dev = inf->dev;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200209 void __user *udata = (void __user *)arg;
210 int ret;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200211
Kristofer Jonssonec477042023-01-20 13:38:13 +0100212 ret = device_lock_interruptible(dev);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200213 if (ret)
214 return ret;
215
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200216 switch (cmd) {
217 case ETHOSU_IOCTL_INFERENCE_STATUS: {
Mikael Olssonec902232023-08-24 13:28:19 +0200218 struct ethosu_uapi_result_status uapi = { 0 };
Per Åstrandf7e407a2020-10-23 21:25:05 +0200219 int i;
220
221 uapi.status = inf->status;
222
223 for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) {
224 uapi.pmu_config.events[i] =
225 inf->pmu_event_config[i];
226 uapi.pmu_count.events[i] =
227 inf->pmu_event_count[i];
228 }
229
230 uapi.pmu_config.cycle_count = inf->pmu_cycle_counter_enable;
231 uapi.pmu_count.cycle_count = inf->pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200232
Ledion Dajaedd25502023-10-17 09:15:32 +0200233 dev_dbg(dev,
234 "Inference ioctl: Inference status. status=%s (%d)\n",
235 status_to_string(uapi.status), uapi.status);
Per Åstrandf7e407a2020-10-23 21:25:05 +0200236
237 ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
238
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200239 break;
240 }
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100241 case ETHOSU_IOCTL_INFERENCE_CANCEL: {
Mikael Olssonec902232023-08-24 13:28:19 +0200242 struct ethosu_uapi_cancel_inference_status uapi = { 0 };
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100243
Ledion Dajaedd25502023-10-17 09:15:32 +0200244 dev_dbg(dev,
245 "Inference ioctl: Cancel Inference. Handle=%p\n",
246 inf);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100247
Kristofer Jonssonec477042023-01-20 13:38:13 +0100248 ret = ethosu_cancel_inference_request(dev, inf->mailbox, inf,
249 &uapi);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100250 if (ret)
251 break;
252
253 ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
254
255 break;
256 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200257 default: {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100258 dev_err(dev, "Invalid ioctl. cmd=%u, arg=%lu\n",
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200259 cmd, arg);
Mikael Olsson891156d2023-08-24 13:20:31 +0200260 ret = -ENOIOCTLCMD;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200261 break;
262 }
263 }
264
Kristofer Jonssonec477042023-01-20 13:38:13 +0100265 device_unlock(dev);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200266
267 return ret;
268}
269
Kristofer Jonssonec477042023-01-20 13:38:13 +0100270int ethosu_inference_create(struct device *dev,
271 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200272 struct ethosu_network *net,
273 struct ethosu_uapi_inference_create *uapi)
274{
275 struct ethosu_inference *inf;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200276 uint32_t i;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200277 int fd;
278 int ret = -ENOMEM;
279
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200280 if (uapi->ifm_count > ETHOSU_FD_MAX ||
281 uapi->ofm_count > ETHOSU_FD_MAX) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100282 dev_warn(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200283 "Too many IFM and/or OFM buffers for inference. ifm_count=%u, ofm_count=%u",
284 uapi->ifm_count, uapi->ofm_count);
285
286 return -EFAULT;
287 }
288
Kristofer Jonssonec477042023-01-20 13:38:13 +0100289 inf = devm_kzalloc(dev, sizeof(*inf), GFP_KERNEL);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200290 if (!inf)
291 return -ENOMEM;
292
Kristofer Jonssonec477042023-01-20 13:38:13 +0100293 inf->dev = dev;
294 inf->mailbox = mailbox;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200295 inf->net = net;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100296 inf->done = false;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200297 inf->status = ETHOSU_UAPI_STATUS_ERROR;
298 kref_init(&inf->kref);
299 init_waitqueue_head(&inf->waitq);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100300 inf->msg.fail = ethosu_inference_fail;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200301
Davide Grohmann32660f92022-04-27 16:49:07 +0200302 /* Add inference to pending list */
Kristofer Jonssonec477042023-01-20 13:38:13 +0100303 ret = ethosu_mailbox_register(mailbox, &inf->msg);
Davide Grohmann32660f92022-04-27 16:49:07 +0200304 if (ret < 0)
305 goto kfree;
306
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200307 /* Get pointer to IFM buffers */
308 for (i = 0; i < uapi->ifm_count; i++) {
309 inf->ifm[i] = ethosu_buffer_get_from_fd(uapi->ifm_fd[i]);
310 if (IS_ERR(inf->ifm[i])) {
311 ret = PTR_ERR(inf->ifm[i]);
312 goto put_ifm;
313 }
314
315 inf->ifm_count++;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200316 }
317
318 /* Get pointer to OFM buffer */
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200319 for (i = 0; i < uapi->ofm_count; i++) {
320 inf->ofm[i] = ethosu_buffer_get_from_fd(uapi->ofm_fd[i]);
321 if (IS_ERR(inf->ofm[i])) {
322 ret = PTR_ERR(inf->ofm[i]);
323 goto put_ofm;
324 }
325
326 inf->ofm_count++;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200327 }
328
Per Åstrandf7e407a2020-10-23 21:25:05 +0200329 /* Configure PMU and cycle counter */
Ledion Dajaedd25502023-10-17 09:15:32 +0200330 dev_dbg(dev,
331 "Configuring events for PMU. events=[%u, %u, %u, %u]\n",
332 uapi->pmu_config.events[0], uapi->pmu_config.events[1],
333 uapi->pmu_config.events[2], uapi->pmu_config.events[3]);
Per Åstrandf7e407a2020-10-23 21:25:05 +0200334
335 /* Configure events and reset count for all events */
336 for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) {
337 inf->pmu_event_config[i] = uapi->pmu_config.events[i];
338 inf->pmu_event_count[i] = 0;
339 }
340
Per Åstrandf7e407a2020-10-23 21:25:05 +0200341 /* Configure cycle counter and reset any previous count */
342 inf->pmu_cycle_counter_enable = uapi->pmu_config.cycle_count;
343 inf->pmu_cycle_counter_count = 0;
344
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200345 /* Increment network reference count */
346 ethosu_network_get(net);
347
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200348 /* Send inference request to Arm Ethos-U subsystem */
349 ret = ethosu_inference_send(inf);
350 if (ret)
351 goto put_net;
352
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200353 /* Create file descriptor */
354 ret = fd = anon_inode_getfd("ethosu-inference", &ethosu_inference_fops,
355 inf, O_RDWR | O_CLOEXEC);
356 if (ret < 0)
357 goto put_net;
358
359 /* Store pointer to file structure */
360 inf->file = fget(ret);
361 fput(inf->file);
362
Ledion Dajaedd25502023-10-17 09:15:32 +0200363 dev_dbg(dev,
364 "Inference create. file=0x%pK, fd=%d, inf=0x%p, net=0x%pK, msg.id=0x%x",
365 inf->file, fd, inf, inf->net, inf->msg.id);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200366
367 return fd;
368
369put_net:
370 ethosu_network_put(inf->net);
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200371
372put_ofm:
373 while (inf->ofm_count-- > 0)
374 ethosu_buffer_put(inf->ofm[inf->ofm_count]);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200375
376put_ifm:
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200377 while (inf->ifm_count-- > 0)
378 ethosu_buffer_put(inf->ifm[inf->ifm_count]);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200379
Mikael Olsson27fe8e02023-08-23 10:43:08 +0200380 ethosu_mailbox_deregister(mailbox, &inf->msg);
381
Davide Grohmann32660f92022-04-27 16:49:07 +0200382kfree:
Mikael Olsson1182f382023-08-10 13:25:44 +0200383 memset(inf, 0, sizeof(*inf));
Kristofer Jonssonec477042023-01-20 13:38:13 +0100384 devm_kfree(dev, inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200385
386 return ret;
387}
388
389struct ethosu_inference *ethosu_inference_get_from_fd(int fd)
390{
391 struct ethosu_inference *inf;
392 struct file *file;
393
394 file = fget(fd);
395 if (!file)
396 return ERR_PTR(-EINVAL);
397
398 if (!ethosu_inference_verify(file)) {
399 fput(file);
400
401 return ERR_PTR(-EINVAL);
402 }
403
404 inf = file->private_data;
405 ethosu_inference_get(inf);
406 fput(file);
407
408 return inf;
409}
410
411void ethosu_inference_get(struct ethosu_inference *inf)
412{
413 kref_get(&inf->kref);
414}
415
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100416int ethosu_inference_put(struct ethosu_inference *inf)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200417{
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100418 return kref_put(&inf->kref, &ethosu_inference_kref_destroy);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200419}
420
Kristofer Jonssonec477042023-01-20 13:38:13 +0100421void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
Kristofer Jonssond779a082023-01-04 17:09:47 +0100422 int msg_id,
423 struct ethosu_core_msg_inference_rsp *rsp)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200424{
Kristofer Jonssonec477042023-01-20 13:38:13 +0100425 struct device *dev = mailbox->dev;
Davide Grohmann32660f92022-04-27 16:49:07 +0200426 struct ethosu_mailbox_msg *msg;
427 struct ethosu_inference *inf;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200428 int i;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200429
Mikael Olsson09965b02023-06-13 12:17:04 +0200430 msg = ethosu_mailbox_find(mailbox, msg_id,
431 ETHOSU_CORE_MSG_INFERENCE_REQ);
Davide Grohmann32660f92022-04-27 16:49:07 +0200432 if (IS_ERR(msg)) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100433 dev_warn(dev,
Mikael Olsson09965b02023-06-13 12:17:04 +0200434 "Id for inference msg not found. Id=0x%x: %ld\n",
435 msg_id, PTR_ERR(msg));
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200436
437 return;
438 }
439
Davide Grohmann32660f92022-04-27 16:49:07 +0200440 inf = container_of(msg, typeof(*inf), msg);
441
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200442 if (rsp->status == ETHOSU_CORE_STATUS_OK &&
Mikael Olsson07545152023-10-17 13:05:38 +0200443 inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200444 inf->status = ETHOSU_UAPI_STATUS_OK;
Mikael Olsson07545152023-10-17 13:05:38 +0200445 else if (rsp->status == ETHOSU_CORE_STATUS_REJECTED)
Davide Grohmann82d22582022-04-25 12:52:38 +0200446 inf->status = ETHOSU_UAPI_STATUS_REJECTED;
Mikael Olsson07545152023-10-17 13:05:38 +0200447 else if (rsp->status == ETHOSU_CORE_STATUS_ABORTED)
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100448 inf->status = ETHOSU_UAPI_STATUS_ABORTED;
Mikael Olsson07545152023-10-17 13:05:38 +0200449 else
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200450 inf->status = ETHOSU_UAPI_STATUS_ERROR;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200451
Davide Grohmann82d22582022-04-25 12:52:38 +0200452 if (inf->status == ETHOSU_UAPI_STATUS_OK) {
453 for (i = 0; i < ETHOSU_CORE_PMU_MAX; i++) {
454 inf->pmu_event_config[i] = rsp->pmu_event_config[i];
455 inf->pmu_event_count[i] = rsp->pmu_event_count[i];
456 }
457
458 inf->pmu_cycle_counter_enable = rsp->pmu_cycle_counter_enable;
459 inf->pmu_cycle_counter_count = rsp->pmu_cycle_counter_count;
460
Ledion Dajaedd25502023-10-17 09:15:32 +0200461 dev_dbg(dev,
462 "PMU events. config=[%u, %u, %u, %u], count=[%u, %u, %u, %u]\n",
463 inf->pmu_event_config[0], inf->pmu_event_config[1],
464 inf->pmu_event_config[2], inf->pmu_event_config[3],
465 inf->pmu_event_count[0], inf->pmu_event_count[1],
466 inf->pmu_event_count[2], inf->pmu_event_count[3]);
Davide Grohmann82d22582022-04-25 12:52:38 +0200467
Ledion Dajaedd25502023-10-17 09:15:32 +0200468 if (inf->pmu_cycle_counter_enable)
469 dev_dbg(dev,
470 "PMU cycle counter: count=%llu\n",
471 inf->pmu_cycle_counter_count);
Per Åstrandf7e407a2020-10-23 21:25:05 +0200472 }
473
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100474 inf->done = true;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200475 wake_up_interruptible(&inf->waitq);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200476 ethosu_inference_put(inf);
477}