Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. |
| 3 | * |
| 4 | * This program is free software and is provided to you under the terms of the |
| 5 | * GNU General Public License version 2 as published by the Free Software |
| 6 | * Foundation, and any use by you of this program is subject to the terms |
| 7 | * of such GNU licence. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, you can access it online at |
| 16 | * http://www.gnu.org/licenses/gpl-2.0.html. |
| 17 | * |
| 18 | * SPDX-License-Identifier: GPL-2.0-only |
| 19 | */ |
| 20 | |
| 21 | #ifndef ETHOSU_CORE_INTERFACE_H |
| 22 | #define ETHOSU_CORE_INTERFACE_H |
| 23 | |
| 24 | #ifdef __KERNEL__ |
| 25 | #include <linux/types.h> |
| 26 | #else |
| 27 | #include <stdint.h> |
| 28 | #endif |
| 29 | |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 30 | /** Maximum number of IFM/OFM buffers per inference */ |
| 31 | #define ETHOSU_CORE_BUFFER_MAX 16 |
| 32 | |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 33 | /** Maximum number of PMU counters to be returned for inference */ |
| 34 | #define ETHOSU_CORE_PMU_MAX 4 |
| 35 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame^] | 36 | #define ETHOSU_CORE_MSG_MAGIC 0x41457631 |
| 37 | #define ETHOSU_CORE_MSG_VERSION_MAJOR 0 |
| 38 | #define ETHOSU_CORE_MSG_VERSION_MINOR 2 |
| 39 | #define ETHOSU_CORE_MSG_VERSION_PATCH 0 |
| 40 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 41 | /** |
| 42 | * enum ethosu_core_msg_type - Message types |
| 43 | * |
| 44 | * Types for the messages sent between the host and the core subsystem. |
| 45 | */ |
| 46 | enum ethosu_core_msg_type { |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame^] | 47 | ETHOSU_CORE_MSG_ERR = 1, |
| 48 | ETHOSU_CORE_MSG_PING, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 49 | ETHOSU_CORE_MSG_PONG, |
| 50 | ETHOSU_CORE_MSG_INFERENCE_REQ, |
| 51 | ETHOSU_CORE_MSG_INFERENCE_RSP, |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame^] | 52 | ETHOSU_CORE_MSG_VERSION_REQ, |
| 53 | ETHOSU_CORE_MSG_VERSION_RSP, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 54 | ETHOSU_CORE_MSG_MAX |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * struct ethosu_core_msg - Message header |
| 59 | */ |
| 60 | struct ethosu_core_msg { |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame^] | 61 | uint32_t magic; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 62 | uint32_t type; |
| 63 | uint32_t length; |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct ethosu_core_queue_header - Message queue header |
| 68 | */ |
| 69 | struct ethosu_core_queue_header { |
| 70 | uint32_t size; |
| 71 | uint32_t read; |
| 72 | uint32_t write; |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * struct ethosu_core_queue - Message queue |
| 77 | * |
| 78 | * Dynamically sized message queue. |
| 79 | */ |
| 80 | struct ethosu_core_queue { |
| 81 | struct ethosu_core_queue_header header; |
| 82 | uint8_t data[]; |
| 83 | }; |
| 84 | |
| 85 | enum ethosu_core_status { |
| 86 | ETHOSU_CORE_STATUS_OK, |
| 87 | ETHOSU_CORE_STATUS_ERROR |
| 88 | }; |
| 89 | |
| 90 | struct ethosu_core_buffer { |
| 91 | uint32_t ptr; |
| 92 | uint32_t size; |
| 93 | }; |
| 94 | |
| 95 | struct ethosu_core_inference_req { |
| 96 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 97 | uint32_t ifm_count; |
| 98 | struct ethosu_core_buffer ifm[ETHOSU_CORE_BUFFER_MAX]; |
| 99 | uint32_t ofm_count; |
| 100 | struct ethosu_core_buffer ofm[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 101 | struct ethosu_core_buffer network; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 102 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 103 | uint32_t pmu_cycle_counter_enable; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct ethosu_core_inference_rsp { |
| 107 | uint64_t user_arg; |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 108 | uint32_t ofm_count; |
| 109 | uint32_t ofm_size[ETHOSU_CORE_BUFFER_MAX]; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 110 | uint32_t status; |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 111 | uint8_t pmu_event_config[ETHOSU_CORE_PMU_MAX]; |
| 112 | uint32_t pmu_event_count[ETHOSU_CORE_PMU_MAX]; |
| 113 | uint32_t pmu_cycle_counter_enable; |
| 114 | uint64_t pmu_cycle_counter_count; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame^] | 117 | /** |
| 118 | * struct ethosu_core_msg_verson - Message protocol version |
| 119 | */ |
| 120 | struct ethosu_core_msg_version { |
| 121 | uint8_t major; |
| 122 | uint8_t minor; |
| 123 | uint8_t patch; |
| 124 | uint8_t _reserved; |
| 125 | }; |
| 126 | |
| 127 | /** |
| 128 | * enum ethosu_core_msg_err_type - Error types |
| 129 | */ |
| 130 | enum ethosu_core_msg_err_type { |
| 131 | ETHOSU_CORE_MSG_ERR_GENERIC = 0, |
| 132 | ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, |
| 133 | ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, |
| 134 | ETHOSU_CORE_MSG_ERR_INVALID_SIZE, |
| 135 | ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, |
| 136 | ETHOSU_CORE_MSG_ERR_MAX |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * struct ethosu_core_msg_err - Error message struct |
| 141 | */ |
| 142 | struct ethosu_core_msg_err { |
| 143 | uint32_t type; /* optional use of extra error code */ |
| 144 | char msg[128]; |
| 145 | }; |
| 146 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 147 | #endif |