blob: 07370ca01f224b9ce0390943a2356d1a08369383 [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
Per Åstrandf7e407a2020-10-23 21:25:05 +020047 * @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 * @pmu_event_config: PMU event configuration
57 * @pmu_event_count: PMU event count after inference
58 * @pmu_cycle_counter_enable: PMU cycle counter config
59 * @pmu_cycle_counter_count: PMU cycle counter count after inference
Kristofer Jonsson116a6352020-08-20 17:25:23 +020060 */
61struct ethosu_inference {
62 struct ethosu_device *edev;
63 struct file *file;
64 struct kref kref;
65 wait_queue_head_t waitq;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020066 uint32_t ifm_count;
67 struct ethosu_buffer *ifm[ETHOSU_FD_MAX];
68 uint32_t ofm_count;
69 struct ethosu_buffer *ofm[ETHOSU_FD_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +020070 struct ethosu_network *net;
71 bool pending;
72 enum ethosu_uapi_status status;
Per Åstrandf7e407a2020-10-23 21:25:05 +020073 uint8_t pmu_event_config[ETHOSU_PMU_EVENT_MAX];
74 uint32_t pmu_event_count[ETHOSU_PMU_EVENT_MAX];
75 uint32_t pmu_cycle_counter_enable;
76 uint64_t pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020077 struct list_head list;
78};
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 */
91int ethosu_inference_create(struct ethosu_device *edev,
92 struct ethosu_network *net,
93 struct ethosu_uapi_inference_create *uapi);
94
95/**
96 * ethosu_inference_get_from_fd() - Get inference handle from fd
97 *
98 * This function must be called from a user space context.
99 *
100 * Return: Pointer on success, else ERR_PTR.
101 */
102struct ethosu_inference *ethosu_inference_get_from_fd(int fd);
103
104/**
105 * ethosu_inference_get() - Get inference
106 */
107void ethosu_inference_get(struct ethosu_inference *inf);
108
109/**
110 * ethosu_inference_put() - Put inference
111 */
112void ethosu_inference_put(struct ethosu_inference *inf);
113
114/**
115 * ethosu_inference_rsp() - Handle inference response
116 */
117void ethosu_inference_rsp(struct ethosu_device *edev,
118 struct ethosu_core_inference_rsp *rsp);
119
120#endif /* ETHOSU_INFERENCE_H */