blob: 9fa0a4a6fbd229cb46fbd4ac5ef593bba315d2e3 [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_network;
41struct ethosu_uapi_inference_create;
42struct file;
43
44/**
45 * struct ethosu_inference - Inference struct
Per Åstrandf7e407a2020-10-23 21:25:05 +020046 * @edev: Arm Ethos-U device
47 * @file: File handle
48 * @kref: Reference counter
49 * @waitq: Wait queue
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010050 * @done: Wait condition is done
Per Åstrandf7e407a2020-10-23 21:25:05 +020051 * @ifm: Pointer to IFM buffer
52 * @ofm: Pointer to OFM buffer
53 * @net: Pointer to network
Per Åstrandf7e407a2020-10-23 21:25:05 +020054 * @status: Inference status
55 * @pmu_event_config: PMU event configuration
56 * @pmu_event_count: PMU event count after inference
57 * @pmu_cycle_counter_enable: PMU cycle counter config
58 * @pmu_cycle_counter_count: PMU cycle counter count after inference
Davide Grohmann7e8f5082022-03-23 12:48:45 +010059 * @msg: Mailbox message
Kristofer Jonsson116a6352020-08-20 17:25:23 +020060 */
61struct ethosu_inference {
Kristofer Jonssonec477042023-01-20 13:38:13 +010062 struct device *dev;
63 struct ethosu_mailbox *mailbox;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010064 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 */
Kristofer Jonssonec477042023-01-20 13:38:13 +010092int ethosu_inference_create(struct device *dev,
93 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020094 struct ethosu_network *net,
95 struct ethosu_uapi_inference_create *uapi);
96
97/**
98 * ethosu_inference_get_from_fd() - Get inference handle from fd
99 *
100 * This function must be called from a user space context.
101 *
102 * Return: Pointer on success, else ERR_PTR.
103 */
104struct ethosu_inference *ethosu_inference_get_from_fd(int fd);
105
106/**
107 * ethosu_inference_get() - Get inference
108 */
109void ethosu_inference_get(struct ethosu_inference *inf);
110
111/**
112 * ethosu_inference_put() - Put inference
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100113 *
114 * Return: 1 if object was removed, else 0.
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200115 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100116int ethosu_inference_put(struct ethosu_inference *inf);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200117
118/**
119 * ethosu_inference_rsp() - Handle inference response
120 */
Kristofer Jonssonec477042023-01-20 13:38:13 +0100121void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
Kristofer Jonssond779a082023-01-04 17:09:47 +0100122 int msg_id,
123 struct ethosu_core_msg_inference_rsp *rsp);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200124
125#endif /* ETHOSU_INFERENCE_H */