blob: 4e7a864513010756d4d086bb10412b0038f5c74c [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
Per Åstrandc823bcf2021-01-12 13:11:13 +010030#ifdef __cplusplus
31namespace EthosU {
32#endif
33
Kristofer Jonssonb74492c2020-09-10 13:26:01 +020034/** Maximum number of IFM/OFM buffers per inference */
35#define ETHOSU_CORE_BUFFER_MAX 16
36
Per Åstrandf7e407a2020-10-23 21:25:05 +020037/** Maximum number of PMU counters to be returned for inference */
38#define ETHOSU_CORE_PMU_MAX 4
39
Jonny Svärd7c24c772021-01-14 19:53:17 +010040#define ETHOSU_CORE_MSG_MAGIC 0x41457631
41#define ETHOSU_CORE_MSG_VERSION_MAJOR 0
42#define ETHOSU_CORE_MSG_VERSION_MINOR 2
43#define ETHOSU_CORE_MSG_VERSION_PATCH 0
44
Kristofer Jonsson116a6352020-08-20 17:25:23 +020045/**
46 * enum ethosu_core_msg_type - Message types
47 *
48 * Types for the messages sent between the host and the core subsystem.
49 */
50enum ethosu_core_msg_type {
Jonny Svärd7c24c772021-01-14 19:53:17 +010051 ETHOSU_CORE_MSG_ERR = 1,
52 ETHOSU_CORE_MSG_PING,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020053 ETHOSU_CORE_MSG_PONG,
54 ETHOSU_CORE_MSG_INFERENCE_REQ,
55 ETHOSU_CORE_MSG_INFERENCE_RSP,
Jonny Svärd7c24c772021-01-14 19:53:17 +010056 ETHOSU_CORE_MSG_VERSION_REQ,
57 ETHOSU_CORE_MSG_VERSION_RSP,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020058 ETHOSU_CORE_MSG_MAX
59};
60
61/**
62 * struct ethosu_core_msg - Message header
63 */
64struct ethosu_core_msg {
Jonny Svärd7c24c772021-01-14 19:53:17 +010065 uint32_t magic;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020066 uint32_t type;
67 uint32_t length;
68};
69
70/**
71 * struct ethosu_core_queue_header - Message queue header
72 */
73struct ethosu_core_queue_header {
74 uint32_t size;
75 uint32_t read;
76 uint32_t write;
77};
78
79/**
80 * struct ethosu_core_queue - Message queue
81 *
82 * Dynamically sized message queue.
83 */
84struct ethosu_core_queue {
85 struct ethosu_core_queue_header header;
86 uint8_t data[];
87};
88
89enum ethosu_core_status {
90 ETHOSU_CORE_STATUS_OK,
91 ETHOSU_CORE_STATUS_ERROR
92};
93
94struct ethosu_core_buffer {
95 uint32_t ptr;
96 uint32_t size;
97};
98
99struct ethosu_core_inference_req {
100 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200101 uint32_t ifm_count;
102 struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX];
103 uint32_t ofm_count;
104 struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200105 struct ethosu_core_buffer network;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200106 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
107 uint32_t pmu_cycle_counter_enable;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200108};
109
110struct ethosu_core_inference_rsp {
111 uint64_t user_arg;
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200112 uint32_t ofm_count;
113 uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX];
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200114 uint32_t status;
Per Åstrandf7e407a2020-10-23 21:25:05 +0200115 uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX];
116 uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX];
117 uint32_t pmu_cycle_counter_enable;
118 uint64_t pmu_cycle_counter_count;
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200119};
120
Jonny Svärd7c24c772021-01-14 19:53:17 +0100121/**
122 * struct ethosu_core_msg_verson - Message protocol version
123 */
124struct ethosu_core_msg_version {
125 uint8_t major;
126 uint8_t minor;
127 uint8_t patch;
128 uint8_t _reserved;
129};
130
131/**
132 * enum ethosu_core_msg_err_type - Error types
133 */
134enum ethosu_core_msg_err_type {
135 ETHOSU_CORE_MSG_ERR_GENERIC = 0,
136 ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE,
137 ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD,
138 ETHOSU_CORE_MSG_ERR_INVALID_SIZE,
139 ETHOSU_CORE_MSG_ERR_INVALID_MAGIC,
140 ETHOSU_CORE_MSG_ERR_MAX
141};
142
143/**
144 * struct ethosu_core_msg_err - Error message struct
145 */
146struct ethosu_core_msg_err {
147 uint32_t type; /* optional use of extra error code */
148 char msg[128];
149};
Per Åstrandc823bcf2021-01-12 13:11:13 +0100150#ifdef __cplusplus
151} /*namespace EthosU */
152#endif
Jonny Svärd7c24c772021-01-14 19:53:17 +0100153
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200154#endif