Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 1 | /* |
| 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 Jonsson | 3c43917 | 2020-08-05 09:38:40 +0200 | [diff] [blame] | 19 | #ifndef ETHOSU_DRIVER_H |
| 20 | #define ETHOSU_DRIVER_H |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 21 | |
| 22 | /****************************************************************************** |
| 23 | * Includes |
| 24 | ******************************************************************************/ |
| 25 | |
Bhavik Patel | dae5be0 | 2020-06-18 15:25:15 +0200 | [diff] [blame] | 26 | #include "ethosu_device.h" |
| 27 | |
| 28 | #include <stdbool.h> |
Kristofer Jonsson | 2b201c3 | 2020-09-02 16:42:43 +0200 | [diff] [blame] | 29 | #include <stddef.h> |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 30 | #include <stdint.h> |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | /****************************************************************************** |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 37 | * Types |
| 38 | ******************************************************************************/ |
| 39 | |
Bhavik Patel | dae5be0 | 2020-06-18 15:25:15 +0200 | [diff] [blame] | 40 | struct ethosu_driver |
| 41 | { |
| 42 | struct ethosu_device dev; |
| 43 | bool abort_inference; |
Kristofer Jonsson | 2b201c3 | 2020-09-02 16:42:43 +0200 | [diff] [blame] | 44 | uint64_t fast_memory; |
| 45 | size_t fast_memory_size; |
Bhavik Patel | 5f8dad1 | 2020-09-30 09:06:52 +0200 | [diff] [blame] | 46 | bool status_error; |
Bhavik Patel | dae5be0 | 2020-06-18 15:25:15 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 49 | struct ethosu_version_id |
| 50 | { |
| 51 | // Ethos-U id |
| 52 | uint8_t version_status; |
| 53 | uint8_t version_minor; |
| 54 | uint8_t version_major; |
| 55 | uint8_t product_major; |
| 56 | uint8_t arch_patch_rev; |
| 57 | uint8_t arch_minor_rev; |
| 58 | uint8_t arch_major_rev; |
| 59 | |
| 60 | // Driver Version |
| 61 | uint8_t driver_patch_rev; |
| 62 | uint8_t driver_minor_rev; |
| 63 | uint8_t driver_major_rev; |
| 64 | }; |
| 65 | |
| 66 | struct ethosu_version_config |
| 67 | { |
| 68 | uint8_t macs_per_cc; |
| 69 | uint8_t cmd_stream_version; |
| 70 | uint8_t shram_size; |
| 71 | }; |
| 72 | |
| 73 | struct ethosu_version |
| 74 | { |
| 75 | struct ethosu_version_id id; |
| 76 | struct ethosu_version_config cfg; |
| 77 | }; |
| 78 | |
| 79 | /****************************************************************************** |
Kristofer Jonsson | 4dc73dc | 2020-10-16 12:33:47 +0200 | [diff] [blame] | 80 | * Variables |
| 81 | ******************************************************************************/ |
| 82 | |
| 83 | extern struct ethosu_driver ethosu_drv; |
| 84 | |
| 85 | /****************************************************************************** |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 86 | * Prototypes |
| 87 | ******************************************************************************/ |
| 88 | |
| 89 | /** |
| 90 | * Initialize the Ethos-U driver. |
| 91 | */ |
Per Åstrand | e6498f0 | 2020-11-09 15:33:12 +0100 | [diff] [blame] | 92 | int ethosu_init_v3(const void *base_address, |
| 93 | const void *fast_memory, |
| 94 | const size_t fast_memory_size, |
| 95 | uint32_t secure_enable, |
| 96 | uint32_t privilege_enable); |
Kristofer Jonsson | 2b201c3 | 2020-09-02 16:42:43 +0200 | [diff] [blame] | 97 | |
Per Åstrand | e6498f0 | 2020-11-09 15:33:12 +0100 | [diff] [blame] | 98 | #define ethosu_init(base_address) ethosu_init_v3(base_address, NULL, 0, 1, 1) |
| 99 | #define ethosu_init_v2(base_address, fast_memory, fast_memory_size) \ |
| 100 | ethosu_init_v3(base_address, fast_memory, fast_memory_size, 1, 1) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Get Ethos-U version. |
| 104 | */ |
| 105 | int ethosu_get_version(struct ethosu_version *version); |
| 106 | |
| 107 | /** |
| 108 | * Invoke Vela command stream. |
| 109 | */ |
Kristofer Jonsson | 2b201c3 | 2020-09-02 16:42:43 +0200 | [diff] [blame] | 110 | int ethosu_invoke_v2(const void *custom_data_ptr, |
| 111 | const int custom_data_size, |
| 112 | const uint64_t *base_addr, |
| 113 | const size_t *base_addr_size, |
| 114 | const int num_base_addr); |
| 115 | |
| 116 | #define ethosu_invoke(custom_data_ptr, custom_data_size, base_addr, num_base_addr) \ |
| 117 | ethosu_invoke_v2(custom_data_ptr, custom_data_size, base_addr, NULL, num_base_addr) |
| 118 | |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 119 | /** |
| 120 | * Abort Ethos-U inference. |
| 121 | */ |
| 122 | void ethosu_abort(void); |
| 123 | |
Per Åstrand | 25d78c0 | 2020-04-21 14:19:44 +0200 | [diff] [blame] | 124 | /** |
| 125 | * Interrupt handler do be called on IRQ from Ethos-U |
| 126 | */ |
| 127 | void ethosu_irq_handler(void); |
| 128 | |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 129 | #ifdef __cplusplus |
| 130 | } |
| 131 | #endif |
Kristofer Jonsson | 3c43917 | 2020-08-05 09:38:40 +0200 | [diff] [blame] | 132 | |
| 133 | #endif // ETHOSU_DRIVER_H |