blob: c0d8461e128caf7383ca6cd2023a7cd2ea3e1e63 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
2 * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
3 *
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#ifndef ETHOSU_INFERENCE_H
22#define ETHOSU_INFERENCE_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
27
28#include "uapi/ethosu.h"
29
30#include <linux/kref.h>
31#include <linux/types.h>
32#include <linux/wait.h>
33
34/****************************************************************************
35 * Types
36 ****************************************************************************/
37
38struct ethosu_buffer;
39struct ethosu_core_inference_rsp;
40struct ethosu_device;
41struct ethosu_network;
42struct ethosu_uapi_inference_create;
43struct file;
44
45/**
46 * struct ethosu_inference - Inference struct
47 * @edev: Arm Ethos-U device
48 * @file: File handle
49 * @kref: Reference counter
50 * @waitq: Wait queue
51 * @ifm: Pointer to IFM buffer
52 * @ofm: Pointer to OFM buffer
53 * @net: Pointer to network
54 * @pending: Pending response from the firmware
55 * @status: Inference status
56 */
57struct ethosu_inference {
58 struct ethosu_device *edev;
59 struct file *file;
60 struct kref kref;
61 wait_queue_head_t waitq;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020062 uint32_t ifm_count;
63 struct ethosu_buffer *ifm[ETHOSU_FD_MAX];
64 uint32_t ofm_count;
65 struct ethosu_buffer *ofm[ETHOSU_FD_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +020066 struct ethosu_network *net;
67 bool pending;
68 enum ethosu_uapi_status status;
69 struct list_head list;
70};
71
72/****************************************************************************
73 * Functions
74 ****************************************************************************/
75
76/**
77 * ethosu_inference_create() - Create inference
78 *
79 * This function must be called in the context of a user space process.
80 *
81 * Return: fd on success, else error code.
82 */
83int ethosu_inference_create(struct ethosu_device *edev,
84 struct ethosu_network *net,
85 struct ethosu_uapi_inference_create *uapi);
86
87/**
88 * ethosu_inference_get_from_fd() - Get inference handle from fd
89 *
90 * This function must be called from a user space context.
91 *
92 * Return: Pointer on success, else ERR_PTR.
93 */
94struct ethosu_inference *ethosu_inference_get_from_fd(int fd);
95
96/**
97 * ethosu_inference_get() - Get inference
98 */
99void ethosu_inference_get(struct ethosu_inference *inf);
100
101/**
102 * ethosu_inference_put() - Put inference
103 */
104void ethosu_inference_put(struct ethosu_inference *inf);
105
106/**
107 * ethosu_inference_rsp() - Handle inference response
108 */
109void ethosu_inference_rsp(struct ethosu_device *edev,
110 struct ethosu_core_inference_rsp *rsp);
111
112#endif /* ETHOSU_INFERENCE_H */