blob: 5a3b860535b2980e18087ac7cb7cfcf37dcb6650 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonssond779a082023-01-04 17:09:47 +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#ifndef ETHOSU_INFERENCE_H
22#define ETHOSU_INFERENCE_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
27
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010028#include "ethosu_mailbox.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020029#include "uapi/ethosu.h"
30
31#include <linux/kref.h>
32#include <linux/types.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020033
34/****************************************************************************
35 * Types
36 ****************************************************************************/
37
38struct ethosu_buffer;
Kristofer Jonssond779a082023-01-04 17:09:47 +010039struct ethosu_core_msg_inference_rsp;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020040struct 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
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010051 * @done: Wait condition is done
Per Åstrandf7e407a2020-10-23 21:25:05 +020052 * @ifm: Pointer to IFM buffer
53 * @ofm: Pointer to OFM buffer
54 * @net: Pointer to network
Per Åstrandf7e407a2020-10-23 21:25:05 +020055 * @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
Davide Grohmann7e8f5082022-03-23 12:48:45 +010060 * @msg: Mailbox message
Kristofer Jonsson116a6352020-08-20 17:25:23 +020061 */
62struct ethosu_inference {
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010063 struct ethosu_device *edev;
64 struct file *file;
65 struct kref kref;
66 wait_queue_head_t waitq;
67 bool done;
68 uint32_t ifm_count;
69 struct ethosu_buffer *ifm[ETHOSU_FD_MAX];
70 uint32_t ofm_count;
71 struct ethosu_buffer *ofm[ETHOSU_FD_MAX];
72 struct ethosu_network *net;
73 enum ethosu_uapi_status status;
74 uint8_t pmu_event_config[ETHOSU_PMU_EVENT_MAX];
75 uint32_t pmu_event_count[ETHOSU_PMU_EVENT_MAX];
76 uint32_t pmu_cycle_counter_enable;
77 uint64_t pmu_cycle_counter_count;
78 struct ethosu_mailbox_msg msg;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020079};
80
81/****************************************************************************
82 * Functions
83 ****************************************************************************/
84
85/**
86 * ethosu_inference_create() - Create inference
87 *
88 * This function must be called in the context of a user space process.
89 *
90 * Return: fd on success, else error code.
91 */
92int ethosu_inference_create(struct ethosu_device *edev,
93 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 */
120void ethosu_inference_rsp(struct ethosu_device *edev,
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 */