blob: e492f915438341dffbfa4bf3336f398a70d86fd6 [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 Mobergeffc7aa2021-05-03 09:25:06 +0200106int ethosu_init(struct ethosu_driver *drv,
107 const void *base_address,
108 const void *fast_memory,
109 const size_t fast_memory_size,
110 uint32_t secure_enable,
111 uint32_t privilege_enable);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200112
113/**
114 * Get Ethos-U version.
115 */
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200116int ethosu_get_version(struct ethosu_driver *drv, struct ethosu_version *version);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200117
118/**
119 * Invoke Vela command stream.
120 */
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200121int ethosu_invoke(struct ethosu_driver *drv,
122 const void *custom_data_ptr,
123 const int custom_data_size,
124 const uint64_t *base_addr,
125 const size_t *base_addr_size,
126 const int num_base_addr);
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200127
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200128/**
129 * Abort Ethos-U inference.
130 */
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200131void ethosu_abort(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200132
Per Åstrand25d78c02020-04-21 14:19:44 +0200133/**
134 * Interrupt handler do be called on IRQ from Ethos-U
135 */
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200136void ethosu_irq_handler(struct ethosu_driver *drv);
Per Åstrand25d78c02020-04-21 14:19:44 +0200137
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100138/**
139 * Set Ethos-U power mode.
140 */
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200141void ethosu_set_power_mode(struct ethosu_driver *drv, bool always_on);
Anton Moberg61da4d32020-12-22 16:00:31 +0100142
143/**
144 * Register a driver for multiNPU usage
145 */
146int ethosu_register_driver(struct ethosu_driver *drv);
147
148/**
149 * Deregister a driver from multiNPU usage
150 */
151int ethosu_deregister_driver(struct ethosu_driver *drv);
152
153/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100154 * Reserves a driver to execute inference with
Anton Moberg61da4d32020-12-22 16:00:31 +0100155 */
156struct ethosu_driver *ethosu_reserve_driver(void);
157
158/**
159 * Change driver status to available
160 */
161void ethosu_release_driver(struct ethosu_driver *drv);
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100162
Anton Mobergdf386e02021-02-02 11:26:48 +0100163/**
Anton Moberg0a614292021-03-24 14:08:22 +0100164 * Set clock and power request bits
165 */
166enum ethosu_error_codes set_clock_and_power_request(struct ethosu_driver *drv,
167 enum ethosu_request_clients client,
168 enum ethosu_clock_q_request clock_request,
169 enum ethosu_power_q_request power_request);
170
171/**
Anton Mobergdf386e02021-02-02 11:26:48 +0100172 * 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();
Anton Mobergeffc7aa2021-05-03 09:25:06 +0200181 int result = ethosu_invoke(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr);
Anton Mobergdf386e02021-02-02 11:26:48 +0100182 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