blob: bc382364c3501facdc00318a094a6b2c03847343 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonssonb42bc0b2023-01-04 17:09:28 +01002 * Copyright 2020,2022-2023 Arm Limited and/or its affiliates
Kristofer Jonsson116a6352020-08-20 17:25:23 +02003 *
4 * This program is free software and is provided to you under the terms of the
5 * GNU General Public License version 2 as published by the Free Software
6 * Foundation, and any use by you of this program is subject to the terms
7 * of such GNU licence.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * SPDX-License-Identifier: GPL-2.0-only
19 */
20
21/****************************************************************************
22 * Includes
23 ****************************************************************************/
24
25#include "ethosu_inference.h"
26
27#include "ethosu_buffer.h"
Kristofer Jonssond779a082023-01-04 17:09:47 +010028#include "ethosu_core_rpmsg.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020029#include "ethosu_device.h"
30#include "ethosu_network.h"
Davide Grohmann7e8f5082022-03-23 12:48:45 +010031#include "ethosu_cancel_inference.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020032
33#include <linux/anon_inodes.h>
34#include <linux/file.h>
35#include <linux/fs.h>
36#include <linux/poll.h>
37
38/****************************************************************************
39 * Variables
40 ****************************************************************************/
41
42static int ethosu_inference_release(struct inode *inode,
43 struct file *file);
44
45static unsigned int ethosu_inference_poll(struct file *file,
46 poll_table *wait);
47
48static long ethosu_inference_ioctl(struct file *file,
49 unsigned int cmd,
50 unsigned long arg);
51
52static const struct file_operations ethosu_inference_fops = {
53 .release = &ethosu_inference_release,
54 .poll = &ethosu_inference_poll,
55 .unlocked_ioctl = &ethosu_inference_ioctl,
56#ifdef CONFIG_COMPAT
57 .compat_ioctl = &ethosu_inference_ioctl,
58#endif
59};
60
61/****************************************************************************
62 * Functions
63 ****************************************************************************/
64
65static const char *status_to_string(const enum ethosu_uapi_status status)
66{
67 switch (status) {
68 case ETHOSU_UAPI_STATUS_OK: {
69 return "Ok";
70 }
71 case ETHOSU_UAPI_STATUS_ERROR: {
72 return "Error";
73 }
Davide Grohmann82d22582022-04-25 12:52:38 +020074 case ETHOSU_UAPI_STATUS_RUNNING: {
75 return "Running";
76 }
77 case ETHOSU_UAPI_STATUS_REJECTED: {
78 return "Rejected";
79 }
Davide Grohmann7e8f5082022-03-23 12:48:45 +010080 case ETHOSU_UAPI_STATUS_ABORTED: {
81 return "Aborted";
82 }
83 case ETHOSU_UAPI_STATUS_ABORTING: {
84 return "Aborting";
85 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +020086 default: {
87 return "Unknown";
88 }
89 }
90}
91
92static int ethosu_inference_send(struct ethosu_inference *inf)
93{
Kristofer Jonssonec477042023-01-20 13:38:13 +010094 struct device *dev = inf->dev;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020095 int ret;
96
Kristofer Jonsson116a6352020-08-20 17:25:23 +020097 inf->status = ETHOSU_UAPI_STATUS_ERROR;
98
Kristofer Jonssonec477042023-01-20 13:38:13 +010099 ret = ethosu_mailbox_inference(inf->mailbox, &inf->msg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200100 inf->ifm_count, inf->ifm,
101 inf->ofm_count, inf->ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200102 inf->net->buf,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100103 inf->net->index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200104 inf->pmu_event_config,
105 ETHOSU_PMU_EVENT_MAX,
106 inf->pmu_cycle_counter_enable);
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200107 if (ret) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100108 dev_warn(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200109 "Failed to send inference request. inf=0x%pK, ret=%d",
110 inf, ret);
111
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200112 return ret;
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200113 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200114
Davide Grohmann82d22582022-04-25 12:52:38 +0200115 inf->status = ETHOSU_UAPI_STATUS_RUNNING;
116
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200117 ethosu_inference_get(inf);
118
119 return 0;
120}
121
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100122static void ethosu_inference_fail(struct ethosu_mailbox_msg *msg)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200123{
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100124 struct ethosu_inference *inf =
125 container_of(msg, typeof(*inf), msg);
126 int ret;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200127
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100128 if (inf->done)
129 return;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200130
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100131 /* Decrement reference count if inference was pending reponse */
132 ret = ethosu_inference_put(inf);
133 if (ret)
134 return;
135
136 /* Set status accordingly to the inference state */
137 inf->status = inf->status == ETHOSU_UAPI_STATUS_ABORTING ?
138 ETHOSU_UAPI_STATUS_ABORTED :
139 ETHOSU_UAPI_STATUS_ERROR;
140 /* Mark it done and wake up the waiting process */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100141 inf->done = true;
142 wake_up_interruptible(&inf->waitq);
143}
144
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200145static bool ethosu_inference_verify(struct file *file)
146{
147 return file->f_op == &ethosu_inference_fops;
148}
149
150static void ethosu_inference_kref_destroy(struct kref *kref)
151{
152 struct ethosu_inference *inf =
153 container_of(kref, struct ethosu_inference, kref);
Kristofer Jonssonec477042023-01-20 13:38:13 +0100154 struct device *dev = inf->dev;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200155
Kristofer Jonssonec477042023-01-20 13:38:13 +0100156 dev_info(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200157 "Inference destroy. inf=0x%pK, status=%d, ifm_count=%u, ofm_count=%u",
158 inf, inf->status, inf->ifm_count, inf->ofm_count);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200159
Kristofer Jonssonec477042023-01-20 13:38:13 +0100160 ethosu_mailbox_deregister(inf->mailbox, &inf->msg);
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200161
162 while (inf->ifm_count-- > 0)
163 ethosu_buffer_put(inf->ifm[inf->ifm_count]);
164
165 while (inf->ofm_count-- > 0)
166 ethosu_buffer_put(inf->ofm[inf->ofm_count]);
167
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200168 ethosu_network_put(inf->net);
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
Kristofer Jonssonec477042023-01-20 13:38:13 +0100178 dev_info(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200179 "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 Jonssonec477042023-01-20 13:38:13 +0100216 dev_info(dev,
Kristofer Jonsson53fd03d2022-06-21 16:58:45 +0200217 "Inference ioctl: file=0x%pK, inf=0x%pK, cmd=0x%x, arg=%lu",
218 file, inf, cmd, arg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200219
220 switch (cmd) {
221 case ETHOSU_IOCTL_INFERENCE_STATUS: {
Per Åstrandf7e407a2020-10-23 21:25:05 +0200222 struct ethosu_uapi_result_status uapi;
223 int i;
224
225 uapi.status = inf->status;
226
227 for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) {
228 uapi.pmu_config.events[i] =
229 inf->pmu_event_config[i];
230 uapi.pmu_count.events[i] =
231 inf->pmu_event_count[i];
232 }
233
234 uapi.pmu_config.cycle_count = inf->pmu_cycle_counter_enable;
235 uapi.pmu_count.cycle_count = inf->pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200236
Kristofer Jonssonec477042023-01-20 13:38:13 +0100237 dev_info(dev,
Kristofer Jonsson53fd03d2022-06-21 16:58:45 +0200238 "Inference ioctl: Inference status. status=%s (%d)\n",
Per Åstrandf7e407a2020-10-23 21:25:05 +0200239 status_to_string(uapi.status), uapi.status);
240
241 ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
242
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200243 break;
244 }
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100245 case ETHOSU_IOCTL_INFERENCE_CANCEL: {
246 struct ethosu_uapi_cancel_inference_status uapi;
247
Kristofer Jonssonec477042023-01-20 13:38:13 +0100248 dev_info(dev,
Kristofer Jonsson53fd03d2022-06-21 16:58:45 +0200249 "Inference ioctl: Cancel Inference. Handle=%p\n",
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100250 inf);
251
Kristofer Jonssonec477042023-01-20 13:38:13 +0100252 ret = ethosu_cancel_inference_request(dev, inf->mailbox, inf,
253 &uapi);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100254 if (ret)
255 break;
256
257 ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
258
259 break;
260 }
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200261 default: {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100262 dev_err(dev, "Invalid ioctl. cmd=%u, arg=%lu\n",
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200263 cmd, arg);
264 break;
265 }
266 }
267
Kristofer Jonssonec477042023-01-20 13:38:13 +0100268 device_unlock(dev);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200269
270 return ret;
271}
272
Kristofer Jonssonec477042023-01-20 13:38:13 +0100273int ethosu_inference_create(struct device *dev,
274 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200275 struct ethosu_network *net,
276 struct ethosu_uapi_inference_create *uapi)
277{
278 struct ethosu_inference *inf;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200279 uint32_t i;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200280 int fd;
281 int ret = -ENOMEM;
282
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200283 if (uapi->ifm_count > ETHOSU_FD_MAX ||
284 uapi->ofm_count > ETHOSU_FD_MAX) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100285 dev_warn(dev,
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200286 "Too many IFM and/or OFM buffers for inference. ifm_count=%u, ofm_count=%u",
287 uapi->ifm_count, uapi->ofm_count);
288
289 return -EFAULT;
290 }
291
Kristofer Jonssonec477042023-01-20 13:38:13 +0100292 inf = devm_kzalloc(dev, sizeof(*inf), GFP_KERNEL);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200293 if (!inf)
294 return -ENOMEM;
295
Kristofer Jonssonec477042023-01-20 13:38:13 +0100296 inf->dev = dev;
297 inf->mailbox = mailbox;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200298 inf->net = net;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100299 inf->done = false;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200300 inf->status = ETHOSU_UAPI_STATUS_ERROR;
301 kref_init(&inf->kref);
302 init_waitqueue_head(&inf->waitq);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100303 inf->msg.fail = ethosu_inference_fail;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200304
Davide Grohmann32660f92022-04-27 16:49:07 +0200305 /* Add inference to pending list */
Kristofer Jonssonec477042023-01-20 13:38:13 +0100306 ret = ethosu_mailbox_register(mailbox, &inf->msg);
Davide Grohmann32660f92022-04-27 16:49:07 +0200307 if (ret < 0)
308 goto kfree;
309
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200310 /* Get pointer to IFM buffers */
311 for (i = 0; i < uapi->ifm_count; i++) {
312 inf->ifm[i] = ethosu_buffer_get_from_fd(uapi->ifm_fd[i]);
313 if (IS_ERR(inf->ifm[i])) {
314 ret = PTR_ERR(inf->ifm[i]);
315 goto put_ifm;
316 }
317
318 inf->ifm_count++;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200319 }
320
321 /* Get pointer to OFM buffer */
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200322 for (i = 0; i < uapi->ofm_count; i++) {
323 inf->ofm[i] = ethosu_buffer_get_from_fd(uapi->ofm_fd[i]);
324 if (IS_ERR(inf->ofm[i])) {
325 ret = PTR_ERR(inf->ofm[i]);
326 goto put_ofm;
327 }
328
329 inf->ofm_count++;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200330 }
331
Per Åstrandf7e407a2020-10-23 21:25:05 +0200332 /* Configure PMU and cycle counter */
Kristofer Jonssonec477042023-01-20 13:38:13 +0100333 dev_info(dev,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200334 "Configuring events for PMU. events=[%u, %u, %u, %u]\n",
335 uapi->pmu_config.events[0], uapi->pmu_config.events[1],
336 uapi->pmu_config.events[2], uapi->pmu_config.events[3]);
337
338 /* Configure events and reset count for all events */
339 for (i = 0; i < ETHOSU_PMU_EVENT_MAX; i++) {
340 inf->pmu_event_config[i] = uapi->pmu_config.events[i];
341 inf->pmu_event_count[i] = 0;
342 }
343
344 if (uapi->pmu_config.cycle_count)
Kristofer Jonssonec477042023-01-20 13:38:13 +0100345 dev_info(dev, "Enabling cycle counter\n");
Per Åstrandf7e407a2020-10-23 21:25:05 +0200346
347 /* Configure cycle counter and reset any previous count */
348 inf->pmu_cycle_counter_enable = uapi->pmu_config.cycle_count;
349 inf->pmu_cycle_counter_count = 0;
350
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200351 /* Increment network reference count */
352 ethosu_network_get(net);
353
Kristofer Jonsson2d69b8b2022-06-30 15:34:52 +0200354 /* Send inference request to Arm Ethos-U subsystem */
355 ret = ethosu_inference_send(inf);
356 if (ret)
357 goto put_net;
358
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200359 /* Create file descriptor */
360 ret = fd = anon_inode_getfd("ethosu-inference", &ethosu_inference_fops,
361 inf, O_RDWR | O_CLOEXEC);
362 if (ret < 0)
363 goto put_net;
364
365 /* Store pointer to file structure */
366 inf->file = fget(ret);
367 fput(inf->file);
368
Kristofer Jonssonec477042023-01-20 13:38:13 +0100369 dev_info(dev,
Kristofer Jonsson53fd03d2022-06-21 16:58:45 +0200370 "Inference create. file=0x%pK, fd=%d, inf=0x%p, net=0x%pK, msg.id=0x%x",
371 inf->file, fd, inf, inf->net, inf->msg.id);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200372
373 return fd;
374
375put_net:
376 ethosu_network_put(inf->net);
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200377
378put_ofm:
379 while (inf->ofm_count-- > 0)
380 ethosu_buffer_put(inf->ofm[inf->ofm_count]);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200381
382put_ifm:
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200383 while (inf->ifm_count-- > 0)
384 ethosu_buffer_put(inf->ifm[inf->ifm_count]);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200385
Davide Grohmann32660f92022-04-27 16:49:07 +0200386kfree:
Kristofer Jonssonec477042023-01-20 13:38:13 +0100387 devm_kfree(dev, inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200388
389 return ret;
390}
391
392struct ethosu_inference *ethosu_inference_get_from_fd(int fd)
393{
394 struct ethosu_inference *inf;
395 struct file *file;
396
397 file = fget(fd);
398 if (!file)
399 return ERR_PTR(-EINVAL);
400
401 if (!ethosu_inference_verify(file)) {
402 fput(file);
403
404 return ERR_PTR(-EINVAL);
405 }
406
407 inf = file->private_data;
408 ethosu_inference_get(inf);
409 fput(file);
410
411 return inf;
412}
413
414void ethosu_inference_get(struct ethosu_inference *inf)
415{
416 kref_get(&inf->kref);
417}
418
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100419int ethosu_inference_put(struct ethosu_inference *inf)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200420{
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100421 return kref_put(&inf->kref, &ethosu_inference_kref_destroy);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200422}
423
Kristofer Jonssonec477042023-01-20 13:38:13 +0100424void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
Kristofer Jonssond779a082023-01-04 17:09:47 +0100425 int msg_id,
426 struct ethosu_core_msg_inference_rsp *rsp)
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200427{
Kristofer Jonssonec477042023-01-20 13:38:13 +0100428 struct device *dev = mailbox->dev;
Davide Grohmann32660f92022-04-27 16:49:07 +0200429 struct ethosu_mailbox_msg *msg;
430 struct ethosu_inference *inf;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200431 int ret;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200432 int i;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200433
Mikael Olsson09965b02023-06-13 12:17:04 +0200434 msg = ethosu_mailbox_find(mailbox, msg_id,
435 ETHOSU_CORE_MSG_INFERENCE_REQ);
Davide Grohmann32660f92022-04-27 16:49:07 +0200436 if (IS_ERR(msg)) {
Kristofer Jonssonec477042023-01-20 13:38:13 +0100437 dev_warn(dev,
Mikael Olsson09965b02023-06-13 12:17:04 +0200438 "Id for inference msg not found. Id=0x%x: %ld\n",
439 msg_id, PTR_ERR(msg));
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200440
441 return;
442 }
443
Davide Grohmann32660f92022-04-27 16:49:07 +0200444 inf = container_of(msg, typeof(*inf), msg);
445
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200446 if (rsp->status == ETHOSU_CORE_STATUS_OK &&
447 inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX) {
448 uint32_t i;
449
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200450 inf->status = ETHOSU_UAPI_STATUS_OK;
451
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200452 for (i = 0; i < inf->ofm_count; i++) {
453 struct ethosu_buffer *ofm = inf->ofm[i];
454
455 ret = ethosu_buffer_resize(
456 ofm, ofm->size + rsp->ofm_size[i],
457 ofm->offset);
458 if (ret)
459 inf->status = ETHOSU_UAPI_STATUS_ERROR;
460 }
Davide Grohmann82d22582022-04-25 12:52:38 +0200461 } else if (rsp->status == ETHOSU_CORE_STATUS_REJECTED) {
462 inf->status = ETHOSU_UAPI_STATUS_REJECTED;
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100463 } else if (rsp->status == ETHOSU_CORE_STATUS_ABORTED) {
464 inf->status = ETHOSU_UAPI_STATUS_ABORTED;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200465 } else {
466 inf->status = ETHOSU_UAPI_STATUS_ERROR;
467 }
468
Davide Grohmann82d22582022-04-25 12:52:38 +0200469 if (inf->status == ETHOSU_UAPI_STATUS_OK) {
470 for (i = 0; i < ETHOSU_CORE_PMU_MAX; i++) {
471 inf->pmu_event_config[i] = rsp->pmu_event_config[i];
472 inf->pmu_event_count[i] = rsp->pmu_event_count[i];
473 }
474
475 inf->pmu_cycle_counter_enable = rsp->pmu_cycle_counter_enable;
476 inf->pmu_cycle_counter_count = rsp->pmu_cycle_counter_count;
477
Kristofer Jonssonec477042023-01-20 13:38:13 +0100478 dev_info(dev,
Davide Grohmann82d22582022-04-25 12:52:38 +0200479 "PMU events. config=[%u, %u, %u, %u], count=[%u, %u, %u, %u]\n",
480 inf->pmu_event_config[0], inf->pmu_event_config[1],
481 inf->pmu_event_config[2], inf->pmu_event_config[3],
482 inf->pmu_event_count[0], inf->pmu_event_count[1],
483 inf->pmu_event_count[2], inf->pmu_event_count[3]);
484
Kristofer Jonssonec477042023-01-20 13:38:13 +0100485 dev_info(dev,
Davide Grohmann82d22582022-04-25 12:52:38 +0200486 "PMU cycle counter. enable=%u, count=%llu\n",
487 inf->pmu_cycle_counter_enable,
488 inf->pmu_cycle_counter_count);
Per Åstrandf7e407a2020-10-23 21:25:05 +0200489 }
490
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100491 inf->done = true;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200492 wake_up_interruptible(&inf->waitq);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200493 ethosu_inference_put(inf);
494}