blob: a3a21e08c7acad8f8930abee97bc1ae3a5a81515 [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_CORE_INTERFACE_H
22#define ETHOSU_CORE_INTERFACE_H
23
24#ifdef __KERNEL__
25#include <linux/types.h>
26#else
27#include <stdint.h>
28#endif
29
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020030/** Maximum number of IFM/OFM buffers per inference */
31#define ETHOSU_CORE_BUFFER_MAX 16
32
Per Åstrandf7e407a2020-10-23 21:25:05 +020033/** Maximum number of PMU counters to be returned for inference */
34#define ETHOSU_CORE_PMU_MAX 4
35
Jonny Svärd7c24c772021-01-14 19:53:17 +010036#define ETHOSU_CORE_MSG_MAGIC 0x41457631
37#define ETHOSU_CORE_MSG_VERSION_MAJOR 0
38#define ETHOSU_CORE_MSG_VERSION_MINOR 2
39#define ETHOSU_CORE_MSG_VERSION_PATCH 0
40
Kristofer Jonsson116a6352020-08-20 17:25:23 +020041/**
42 * enum ethosu_core_msg_type - Message types
43 *
44 * Types for the messages sent between the host and the core subsystem.
45 */
46enum ethosu_core_msg_type {
Jonny Svärd7c24c772021-01-14 19:53:17 +010047 ETHOSU_CORE_MSG_ERR = 1,
48 ETHOSU_CORE_MSG_PING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020049 ETHOSU_CORE_MSG_PONG,
50 ETHOSU_CORE_MSG_INFERENCE_REQ,
51 ETHOSU_CORE_MSG_INFERENCE_RSP,
Jonny Svärd7c24c772021-01-14 19:53:17 +010052 ETHOSU_CORE_MSG_VERSION_REQ,
53 ETHOSU_CORE_MSG_VERSION_RSP,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020054 ETHOSU_CORE_MSG_MAX
55};
56
57/**
58 * struct ethosu_core_msg - Message header
59 */
60struct ethosu_core_msg {
Jonny Svärd7c24c772021-01-14 19:53:17 +010061 uint32_t magic;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062 uint32_t type;
63 uint32_t length;
64};
65
66/**
67 * struct ethosu_core_queue_header - Message queue header
68 */
69struct ethosu_core_queue_header {
70 uint32_t size;
71 uint32_t read;
72 uint32_t write;
73};
74
75/**
76 * struct ethosu_core_queue - Message queue
77 *
78 * Dynamically sized message queue.
79 */
80struct ethosu_core_queue {
81 struct ethosu_core_queue_header header;
82 uint8_t data[];
83};
84
85enum ethosu_core_status {
86 ETHOSU_CORE_STATUS_OK,
87 ETHOSU_CORE_STATUS_ERROR
88};
89
90struct ethosu_core_buffer {
91 uint32_t ptr;
92 uint32_t size;
93};
94
95struct ethosu_core_inference_req {
96 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020097 uint32_t ifm_count;
98 struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX];
99 uint32_t ofm_count;
100 struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200101 struct ethosu_core_buffer network;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200102 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
103 uint32_t pmu_cycle_counter_enable;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200104};
105
106struct ethosu_core_inference_rsp {
107 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200108 uint32_t ofm_count;
109 uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200110 uint32_t status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200111 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
112 uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX];
113 uint32_t pmu_cycle_counter_enable;
114 uint64_t pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200115};
116
Jonny Svärd7c24c772021-01-14 19:53:17 +0100117/**
118 * struct ethosu_core_msg_verson - Message protocol version
119 */
120struct ethosu_core_msg_version {
121 uint8_t major;
122 uint8_t minor;
123 uint8_t patch;
124 uint8_t _reserved;
125};
126
127/**
128 * enum ethosu_core_msg_err_type - Error types
129 */
130enum ethosu_core_msg_err_type {
131 ETHOSU_CORE_MSG_ERR_GENERIC = 0,
132 ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE,
133 ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD,
134 ETHOSU_CORE_MSG_ERR_INVALID_SIZE,
135 ETHOSU_CORE_MSG_ERR_INVALID_MAGIC,
136 ETHOSU_CORE_MSG_ERR_MAX
137};
138
139/**
140 * struct ethosu_core_msg_err - Error message struct
141 */
142struct ethosu_core_msg_err {
143 uint32_t type; /* optional use of extra error code */
144 char msg[128];
145};
146
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200147#endif