blob: 4089932c8c1e5e4cf80eacf06868eaa947b53721 [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;
78};
79
80struct ethosu_version
81{
82 struct ethosu_version_id id;
83 struct ethosu_version_config cfg;
84};
85
Anton Moberg0a614292021-03-24 14:08:22 +010086enum ethosu_request_clients
87{
88 ETHOSU_PMU_REQUEST = 0,
89 ETHOSU_INFERENCE_REQUEST = 1,
90};
91
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020092/******************************************************************************
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020093 * Variables
94 ******************************************************************************/
95
96extern struct ethosu_driver ethosu_drv;
97
98/******************************************************************************
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020099 * Prototypes
100 ******************************************************************************/
101
102/**
103 * Initialize the Ethos-U driver.
104 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100105int ethosu_init_v4(struct ethosu_driver *drv,
106 const void *base_address,
Per Åstrande6498f02020-11-09 15:33:12 +0100107 const void *fast_memory,
108 const size_t fast_memory_size,
109 uint32_t secure_enable,
110 uint32_t privilege_enable);
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200111
Per Åstrand849cf692020-11-24 07:39:55 +0100112#define ethosu_init(base_address) ethosu_init_v3(base_address, NULL, 0, 0, 0)
Per Åstrande6498f02020-11-09 15:33:12 +0100113#define ethosu_init_v2(base_address, fast_memory, fast_memory_size) \
Per Åstrand849cf692020-11-24 07:39:55 +0100114 ethosu_init_v3(base_address, fast_memory, fast_memory_size, 0, 0)
Anton Moberg61da4d32020-12-22 16:00:31 +0100115#define ethosu_init_v3(base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable) \
116 ethosu_init_v4(&ethosu_drv, base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200117
118/**
119 * Get Ethos-U version.
120 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100121int ethosu_get_version_v2(struct ethosu_driver *drv, struct ethosu_version *version);
122
123#define ethosu_get_version(version) ethosu_get_version_v2(&ethosu_drv, version)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200124
125/**
126 * Invoke Vela command stream.
127 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100128int ethosu_invoke_v3(struct ethosu_driver *drv,
129 const void *custom_data_ptr,
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200130 const int custom_data_size,
131 const uint64_t *base_addr,
132 const size_t *base_addr_size,
133 const int num_base_addr);
134
135#define ethosu_invoke(custom_data_ptr, custom_data_size, base_addr, num_base_addr) \
136 ethosu_invoke_v2(custom_data_ptr, custom_data_size, base_addr, NULL, num_base_addr)
137
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200138/**
139 * Abort Ethos-U inference.
140 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100141void ethosu_abort_v2(struct ethosu_driver *drv);
142
143#define ethosu_abort(void) ethosu_abort_v2(&ethosu_drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200144
Per Åstrand25d78c02020-04-21 14:19:44 +0200145/**
146 * Interrupt handler do be called on IRQ from Ethos-U
147 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100148void ethosu_irq_handler_v2(struct ethosu_driver *drv);
149
150#define ethosu_irq_handler(void) ethosu_irq_handler_v2(&ethosu_drv)
Per Åstrand25d78c02020-04-21 14:19:44 +0200151
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100152/**
153 * Set Ethos-U power mode.
154 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100155void ethosu_set_power_mode_v2(struct ethosu_driver *drv, bool always_on);
156
157#define ethosu_set_power_mode(always_on) ethosu_set_power_mode_v2(&ethosu_drv, always_on)
158
159/**
160 * Register a driver for multiNPU usage
161 */
162int ethosu_register_driver(struct ethosu_driver *drv);
163
164/**
165 * Deregister a driver from multiNPU usage
166 */
167int ethosu_deregister_driver(struct ethosu_driver *drv);
168
169/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100170 * Reserves a driver to execute inference with
Anton Moberg61da4d32020-12-22 16:00:31 +0100171 */
172struct ethosu_driver *ethosu_reserve_driver(void);
173
174/**
175 * Change driver status to available
176 */
177void ethosu_release_driver(struct ethosu_driver *drv);
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100178
Anton Mobergdf386e02021-02-02 11:26:48 +0100179/**
Anton Moberg0a614292021-03-24 14:08:22 +0100180 * Set clock and power request bits
181 */
182enum ethosu_error_codes set_clock_and_power_request(struct ethosu_driver *drv,
183 enum ethosu_request_clients client,
184 enum ethosu_clock_q_request clock_request,
185 enum ethosu_power_q_request power_request);
186
187/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100188 * Static inline for backwards-compatibility
189 */
190static inline int ethosu_invoke_v2(const void *custom_data_ptr,
191 const int custom_data_size,
192 const uint64_t *base_addr,
193 const size_t *base_addr_size,
194 const int num_base_addr)
195{
196 struct ethosu_driver *drv = ethosu_reserve_driver();
197 int result = ethosu_invoke_v3(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr);
198 ethosu_release_driver(drv);
199 return result;
200}
201
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200202#ifdef __cplusplus
203}
204#endif
Kristofer Jonsson3c439172020-08-05 09:38:40 +0200205
206#endif // ETHOSU_DRIVER_H