blob: 96822e08ac431433d42129404e1a9f5fb841b068 [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
Anton Mobergdfed5fd2021-03-11 14:41:11 +01002 * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02003 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Kristofer Jonsson3c439172020-08-05 09:38:40 +020019#ifndef ETHOSU_DRIVER_H
20#define ETHOSU_DRIVER_H
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020021
22/******************************************************************************
23 * Includes
24 ******************************************************************************/
25
Bhavik Pateldae5be02020-06-18 15:25:15 +020026#include "ethosu_device.h"
27
28#include <stdbool.h>
Kristofer Jonsson2b201c32020-09-02 16:42:43 +020029#include <stddef.h>
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020030#include <stdint.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/******************************************************************************
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020037 * Types
38 ******************************************************************************/
39
Bhavik Pateldae5be02020-06-18 15:25:15 +020040struct ethosu_driver
41{
42 struct ethosu_device dev;
43 bool abort_inference;
Kristofer Jonsson2b201c32020-09-02 16:42:43 +020044 uint64_t fast_memory;
45 size_t fast_memory_size;
Bhavik Patel5f8dad12020-09-30 09:06:52 +020046 bool status_error;
Anton Moberg8d65b6f2020-12-21 09:37:18 +010047 bool dev_power_always_on;
Anton Moberg61da4d32020-12-22 16:00:31 +010048 struct ethosu_driver *next;
49 bool reserved;
Anton Mobergdfed5fd2021-03-11 14:41:11 +010050 volatile bool irq_triggered;
51 void *semaphore;
Anton Moberg0a614292021-03-24 14:08:22 +010052 uint8_t clock_request;
53 uint8_t power_request;
Bhavik Pateldae5be02020-06-18 15:25:15 +020054};
55
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020056struct ethosu_version_id
57{
58 // Ethos-U id
59 uint8_t version_status;
60 uint8_t version_minor;
61 uint8_t version_major;
62 uint8_t product_major;
63 uint8_t arch_patch_rev;
64 uint8_t arch_minor_rev;
65 uint8_t arch_major_rev;
66
67 // Driver Version
68 uint8_t driver_patch_rev;
69 uint8_t driver_minor_rev;
70 uint8_t driver_major_rev;
71};
72
73struct ethosu_version_config
74{
75 uint8_t macs_per_cc;
76 uint8_t cmd_stream_version;
77 uint8_t shram_size;
Anton Mobergb8bcf132021-03-29 10:02:25 +020078 uint8_t custom_dma;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020079};
80
81struct ethosu_version
82{
83 struct ethosu_version_id id;
84 struct ethosu_version_config cfg;
85};
86
Anton Moberg0a614292021-03-24 14:08:22 +010087enum ethosu_request_clients
88{
89 ETHOSU_PMU_REQUEST = 0,
90 ETHOSU_INFERENCE_REQUEST = 1,
91};
92
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020093/******************************************************************************
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020094 * Variables
95 ******************************************************************************/
96
97extern struct ethosu_driver ethosu_drv;
98
99/******************************************************************************
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200100 * Prototypes
101 ******************************************************************************/
102
103/**
104 * Initialize the Ethos-U driver.
105 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100106int ethosu_init_v4(struct ethosu_driver *drv,
107 const void *base_address,
Per Åstrande6498f02020-11-09 15:33:12 +0100108 const void *fast_memory,
109 const size_t fast_memory_size,
110 uint32_t secure_enable,
111 uint32_t privilege_enable);
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200112
Per Åstrand849cf692020-11-24 07:39:55 +0100113#define ethosu_init(base_address) ethosu_init_v3(base_address, NULL, 0, 0, 0)
Per Åstrande6498f02020-11-09 15:33:12 +0100114#define ethosu_init_v2(base_address, fast_memory, fast_memory_size) \
Per Åstrand849cf692020-11-24 07:39:55 +0100115 ethosu_init_v3(base_address, fast_memory, fast_memory_size, 0, 0)
Anton Moberg61da4d32020-12-22 16:00:31 +0100116#define ethosu_init_v3(base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable) \
117 ethosu_init_v4(&ethosu_drv, base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200118
119/**
120 * Get Ethos-U version.
121 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100122int ethosu_get_version_v2(struct ethosu_driver *drv, struct ethosu_version *version);
123
124#define ethosu_get_version(version) ethosu_get_version_v2(&ethosu_drv, version)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200125
126/**
127 * Invoke Vela command stream.
128 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100129int ethosu_invoke_v3(struct ethosu_driver *drv,
130 const void *custom_data_ptr,
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200131 const int custom_data_size,
132 const uint64_t *base_addr,
133 const size_t *base_addr_size,
134 const int num_base_addr);
135
136#define ethosu_invoke(custom_data_ptr, custom_data_size, base_addr, num_base_addr) \
137 ethosu_invoke_v2(custom_data_ptr, custom_data_size, base_addr, NULL, num_base_addr)
138
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200139/**
140 * Abort Ethos-U inference.
141 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100142void ethosu_abort_v2(struct ethosu_driver *drv);
143
144#define ethosu_abort(void) ethosu_abort_v2(&ethosu_drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200145
Per Åstrand25d78c02020-04-21 14:19:44 +0200146/**
147 * Interrupt handler do be called on IRQ from Ethos-U
148 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100149void ethosu_irq_handler_v2(struct ethosu_driver *drv);
150
151#define ethosu_irq_handler(void) ethosu_irq_handler_v2(&ethosu_drv)
Per Åstrand25d78c02020-04-21 14:19:44 +0200152
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100153/**
154 * Set Ethos-U power mode.
155 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100156void ethosu_set_power_mode_v2(struct ethosu_driver *drv, bool always_on);
157
158#define ethosu_set_power_mode(always_on) ethosu_set_power_mode_v2(&ethosu_drv, always_on)
159
160/**
161 * Register a driver for multiNPU usage
162 */
163int ethosu_register_driver(struct ethosu_driver *drv);
164
165/**
166 * Deregister a driver from multiNPU usage
167 */
168int ethosu_deregister_driver(struct ethosu_driver *drv);
169
170/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100171 * Reserves a driver to execute inference with
Anton Moberg61da4d32020-12-22 16:00:31 +0100172 */
173struct ethosu_driver *ethosu_reserve_driver(void);
174
175/**
176 * Change driver status to available
177 */
178void ethosu_release_driver(struct ethosu_driver *drv);
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100179
Anton Mobergdf386e02021-02-02 11:26:48 +0100180/**
Anton Moberg0a614292021-03-24 14:08:22 +0100181 * Set clock and power request bits
182 */
183enum ethosu_error_codes set_clock_and_power_request(struct ethosu_driver *drv,
184 enum ethosu_request_clients client,
185 enum ethosu_clock_q_request clock_request,
186 enum ethosu_power_q_request power_request);
187
188/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100189 * Static inline for backwards-compatibility
190 */
191static inline int ethosu_invoke_v2(const void *custom_data_ptr,
192 const int custom_data_size,
193 const uint64_t *base_addr,
194 const size_t *base_addr_size,
195 const int num_base_addr)
196{
197 struct ethosu_driver *drv = ethosu_reserve_driver();
198 int result = ethosu_invoke_v3(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr);
199 ethosu_release_driver(drv);
200 return result;
201}
202
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200203#ifdef __cplusplus
204}
205#endif
Kristofer Jonsson3c439172020-08-05 09:38:40 +0200206
207#endif // ETHOSU_DRIVER_H