blob: 8bdfb8a7257d7e2b285b676576c0f6268ef00bee [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olssond4ad9e52024-02-07 11:22:26 +01002 * SPDX-FileCopyrightText: Copyright 2020, 2022-2024 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#ifndef ETHOSU_INFERENCE_H
21#define ETHOSU_INFERENCE_H
22
23/****************************************************************************
24 * Includes
25 ****************************************************************************/
26
Mikael Olssond4ad9e52024-02-07 11:22:26 +010027#include <rpmsg/ethosu_rpmsg_mailbox.h>
28#include <uapi/ethosu.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020029
30#include <linux/kref.h>
31#include <linux/types.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020032
33/****************************************************************************
34 * Types
35 ****************************************************************************/
36
37struct ethosu_buffer;
Kristofer Jonssond779a082023-01-04 17:09:47 +010038struct ethosu_core_msg_inference_rsp;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020039struct ethosu_network;
40struct ethosu_uapi_inference_create;
41struct file;
42
43/**
44 * struct ethosu_inference - Inference struct
Per Åstrandf7e407a2020-10-23 21:25:05 +020045 * @edev: Arm Ethos-U device
46 * @file: File handle
47 * @kref: Reference counter
48 * @waitq: Wait queue
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010049 * @done: Wait condition is done
Per Åstrandf7e407a2020-10-23 21:25:05 +020050 * @ifm: Pointer to IFM buffer
51 * @ofm: Pointer to OFM buffer
52 * @net: Pointer to network
Per Åstrandf7e407a2020-10-23 21:25:05 +020053 * @status: Inference status
54 * @pmu_event_config: PMU event configuration
55 * @pmu_event_count: PMU event count after inference
56 * @pmu_cycle_counter_enable: PMU cycle counter config
57 * @pmu_cycle_counter_count: PMU cycle counter count after inference
Davide Grohmann7e8f5082022-03-23 12:48:45 +010058 * @msg: Mailbox message
Kristofer Jonsson116a6352020-08-20 17:25:23 +020059 */
60struct ethosu_inference {
Kristofer Jonssonec477042023-01-20 13:38:13 +010061 struct device *dev;
62 struct ethosu_mailbox *mailbox;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010063 struct file *file;
64 struct kref kref;
65 wait_queue_head_t waitq;
66 bool done;
67 uint32_t ifm_count;
68 struct ethosu_buffer *ifm[ETHOSU_FD_MAX];
69 uint32_t ofm_count;
70 struct ethosu_buffer *ofm[ETHOSU_FD_MAX];
71 struct ethosu_network *net;
72 enum ethosu_uapi_status status;
73 uint8_t pmu_event_config[ETHOSU_PMU_EVENT_MAX];
Mikael Olssone87446c2023-12-15 17:17:06 +010074 uint64_t pmu_event_count[ETHOSU_PMU_EVENT_MAX];
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010075 uint32_t pmu_cycle_counter_enable;
76 uint64_t pmu_cycle_counter_count;
77 struct ethosu_mailbox_msg msg;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020078};
79
80/****************************************************************************
81 * Functions
82 ****************************************************************************/
83
84/**
85 * ethosu_inference_create() - Create inference
86 *
87 * This function must be called in the context of a user space process.
88 *
89 * Return: fd on success, else error code.
90 */
Kristofer Jonssonec477042023-01-20 13:38:13 +010091int ethosu_inference_create(struct device *dev,
92 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020093 struct ethosu_network *net,
94 struct ethosu_uapi_inference_create *uapi);
95
96/**
97 * ethosu_inference_get_from_fd() - Get inference handle from fd
98 *
99 * This function must be called from a user space context.
100 *
101 * Return: Pointer on success, else ERR_PTR.
102 */
103struct ethosu_inference *ethosu_inference_get_from_fd(int fd);
104
105/**
106 * ethosu_inference_get() - Get inference
107 */
108void ethosu_inference_get(struct ethosu_inference *inf);
109
110/**
111 * ethosu_inference_put() - Put inference
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100112 *
113 * Return: 1 if object was removed, else 0.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200114 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100115int ethosu_inference_put(struct ethosu_inference *inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200116
117/**
118 * ethosu_inference_rsp() - Handle inference response
119 */
Kristofer Jonssonec477042023-01-20 13:38:13 +0100120void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
Kristofer Jonssond779a082023-01-04 17:09:47 +0100121 int msg_id,
122 struct ethosu_core_msg_inference_rsp *rsp);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200123
124#endif /* ETHOSU_INFERENCE_H */