blob: d47b6769a25204098de29531989185af7db8f784 [file] [log] [blame]
Kristofer Jonsson49bdee82020-04-06 13:21:21 +02001/*
2 * Copyright (c) 2019-2020 Arm Limited. All rights reserved.
3 *
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;
Bhavik Pateldae5be02020-06-18 15:25:15 +020048};
49
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020050struct ethosu_version_id
51{
52 // Ethos-U id
53 uint8_t version_status;
54 uint8_t version_minor;
55 uint8_t version_major;
56 uint8_t product_major;
57 uint8_t arch_patch_rev;
58 uint8_t arch_minor_rev;
59 uint8_t arch_major_rev;
60
61 // Driver Version
62 uint8_t driver_patch_rev;
63 uint8_t driver_minor_rev;
64 uint8_t driver_major_rev;
65};
66
67struct ethosu_version_config
68{
69 uint8_t macs_per_cc;
70 uint8_t cmd_stream_version;
71 uint8_t shram_size;
72};
73
74struct ethosu_version
75{
76 struct ethosu_version_id id;
77 struct ethosu_version_config cfg;
78};
79
80/******************************************************************************
Kristofer Jonsson4dc73dc2020-10-16 12:33:47 +020081 * Variables
82 ******************************************************************************/
83
84extern struct ethosu_driver ethosu_drv;
85
86/******************************************************************************
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020087 * Prototypes
88 ******************************************************************************/
89
90/**
91 * Initialize the Ethos-U driver.
92 */
Per Åstrande6498f02020-11-09 15:33:12 +010093int ethosu_init_v3(const void *base_address,
94 const void *fast_memory,
95 const size_t fast_memory_size,
96 uint32_t secure_enable,
97 uint32_t privilege_enable);
Kristofer Jonsson2b201c32020-09-02 16:42:43 +020098
Per Åstrand849cf692020-11-24 07:39:55 +010099#define ethosu_init(base_address) ethosu_init_v3(base_address, NULL, 0, 0, 0)
Per Åstrande6498f02020-11-09 15:33:12 +0100100#define ethosu_init_v2(base_address, fast_memory, fast_memory_size) \
Per Åstrand849cf692020-11-24 07:39:55 +0100101 ethosu_init_v3(base_address, fast_memory, fast_memory_size, 0, 0)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200102
103/**
104 * Get Ethos-U version.
105 */
106int ethosu_get_version(struct ethosu_version *version);
107
108/**
109 * Invoke Vela command stream.
110 */
Kristofer Jonsson2b201c32020-09-02 16:42:43 +0200111int ethosu_invoke_v2(const void *custom_data_ptr,
112 const int custom_data_size,
113 const uint64_t *base_addr,
114 const size_t *base_addr_size,
115 const int num_base_addr);
116
117#define ethosu_invoke(custom_data_ptr, custom_data_size, base_addr, num_base_addr) \
118 ethosu_invoke_v2(custom_data_ptr, custom_data_size, base_addr, NULL, num_base_addr)
119
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200120/**
121 * Abort Ethos-U inference.
122 */
123void ethosu_abort(void);
124
Per Åstrand25d78c02020-04-21 14:19:44 +0200125/**
126 * Interrupt handler do be called on IRQ from Ethos-U
127 */
128void ethosu_irq_handler(void);
129
Anton Moberg8d65b6f2020-12-21 09:37:18 +0100130/**
131 * Set Ethos-U power mode.
132 */
133void ethosu_set_power_mode(bool);
134
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200135#ifdef __cplusplus
136}
137#endif
Kristofer Jonsson3c439172020-08-05 09:38:40 +0200138
139#endif // ETHOSU_DRIVER_H