blob: 16f0a2543f67f1db42236ea94a054cf854725b93 [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;
Bhavik Pateldae5be02020-06-18 15:25:15 +020052};
53
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020054struct ethosu_version_id
55{
56 // Ethos-U id
57 uint8_t version_status;
58 uint8_t version_minor;
59 uint8_t version_major;
60 uint8_t product_major;
61 uint8_t arch_patch_rev;
62 uint8_t arch_minor_rev;
63 uint8_t arch_major_rev;
64
65 // Driver Version
66 uint8_t driver_patch_rev;
67 uint8_t driver_minor_rev;
68 uint8_t driver_major_rev;
69};
70
71struct ethosu_version_config
72{
73 uint8_t macs_per_cc;
74 uint8_t cmd_stream_version;
75 uint8_t shram_size;
76};
77
78struct ethosu_version
79{
80 struct ethosu_version_id id;
81 struct ethosu_version_config cfg;
82};
83
84/******************************************************************************
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020085 * Variables
86 ******************************************************************************/
87
88extern struct ethosu_driver ethosu_drv;
89
90/******************************************************************************
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020091 * Prototypes
92 ******************************************************************************/
93
94/**
95 * Initialize the Ethos-U driver.
96 */
Anton Moberg61da4d32020-12-22 16:00:31 +010097int ethosu_init_v4(struct ethosu_driver *drv,
98 const void *base_address,
Per Åstrande6498f02020-11-09 15:33:12 +010099 const void *fast_memory,
100 const size_t fast_memory_size,
101 uint32_t secure_enable,
102 uint32_t privilege_enable);
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200103
Per Åstrand849cf692020-11-24 07:39:55 +0100104#define ethosu_init(base_address) ethosu_init_v3(base_address, NULL, 0, 0, 0)
Per Åstrande6498f02020-11-09 15:33:12 +0100105#define ethosu_init_v2(base_address, fast_memory, fast_memory_size) \
Per Åstrand849cf692020-11-24 07:39:55 +0100106 ethosu_init_v3(base_address, fast_memory, fast_memory_size, 0, 0)
Anton Moberg61da4d32020-12-22 16:00:31 +0100107#define ethosu_init_v3(base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable) \
108 ethosu_init_v4(&ethosu_drv, base_address, fast_memory, fast_memory_size, secure_enable, privilege_enable)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200109
110/**
111 * Get Ethos-U version.
112 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100113int ethosu_get_version_v2(struct ethosu_driver *drv, struct ethosu_version *version);
114
115#define ethosu_get_version(version) ethosu_get_version_v2(&ethosu_drv, version)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200116
117/**
118 * Invoke Vela command stream.
119 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100120int ethosu_invoke_v3(struct ethosu_driver *drv,
121 const void *custom_data_ptr,
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200122 const int custom_data_size,
123 const uint64_t *base_addr,
124 const size_t *base_addr_size,
125 const int num_base_addr);
126
127#define ethosu_invoke(custom_data_ptr, custom_data_size, base_addr, num_base_addr) \
128 ethosu_invoke_v2(custom_data_ptr, custom_data_size, base_addr, NULL, num_base_addr)
129
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200130/**
131 * Abort Ethos-U inference.
132 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100133void ethosu_abort_v2(struct ethosu_driver *drv);
134
135#define ethosu_abort(void) ethosu_abort_v2(&ethosu_drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200136
Per Åstrand25d78c02020-04-21 14:19:44 +0200137/**
138 * Interrupt handler do be called on IRQ from Ethos-U
139 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100140void ethosu_irq_handler_v2(struct ethosu_driver *drv);
141
142#define ethosu_irq_handler(void) ethosu_irq_handler_v2(&ethosu_drv)
Per Åstrand25d78c02020-04-21 14:19:44 +0200143
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100144/**
145 * Set Ethos-U power mode.
146 */
Anton Moberg61da4d32020-12-22 16:00:31 +0100147void ethosu_set_power_mode_v2(struct ethosu_driver *drv, bool always_on);
148
149#define ethosu_set_power_mode(always_on) ethosu_set_power_mode_v2(&ethosu_drv, always_on)
150
151/**
152 * Register a driver for multiNPU usage
153 */
154int ethosu_register_driver(struct ethosu_driver *drv);
155
156/**
157 * Deregister a driver from multiNPU usage
158 */
159int ethosu_deregister_driver(struct ethosu_driver *drv);
160
161/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100162 * Reserves a driver to execute inference with
Anton Moberg61da4d32020-12-22 16:00:31 +0100163 */
164struct ethosu_driver *ethosu_reserve_driver(void);
165
166/**
167 * Change driver status to available
168 */
169void ethosu_release_driver(struct ethosu_driver *drv);
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100170
Anton Mobergdf386e02021-02-02 11:26:48 +0100171/**
172 * Static inline for backwards-compatibility
173 */
174static inline int ethosu_invoke_v2(const void *custom_data_ptr,
175 const int custom_data_size,
176 const uint64_t *base_addr,
177 const size_t *base_addr_size,
178 const int num_base_addr)
179{
180 struct ethosu_driver *drv = ethosu_reserve_driver();
181 int result = ethosu_invoke_v3(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr);
182 ethosu_release_driver(drv);
183 return result;
184}
185
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200186#ifdef __cplusplus
187}
188#endif
Kristofer Jonsson3c439172020-08-05 09:38:40 +0200189
190#endif // ETHOSU_DRIVER_H