blob: dcd929728cc899305c19ea3420c56bd3e4f50a4f [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
19#pragma once
20
21/******************************************************************************
22 * Includes
23 ******************************************************************************/
24
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/******************************************************************************
32 * Defines
33 ******************************************************************************/
34
35#define ETHOSU_DRIVER_VERSION_MAJOR 0 ///< Driver major version
Douglas Trohaf6a85da2020-05-11 11:45:28 +020036#define ETHOSU_DRIVER_VERSION_MINOR 16 ///< Driver minor version
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020037#define ETHOSU_DRIVER_VERSION_PATCH 0 ///< Driver patch version
38#define ETHOSU_DRIVER_BASEP_INDEXES 8 ///< Number of base pointer indexes
39
40/******************************************************************************
41 * Types
42 ******************************************************************************/
43
44enum ethosu_error_codes
45{
46 ETHOSU_SUCCESS = 0, ///< Success
47 ETHOSU_GENERIC_FAILURE = -1, ///< Generic failure
48 ETHOSU_INVALID_PARAM = -2 ///< Invalid parameter
49};
50
51struct ethosu_id
52{
53 uint32_t version_status; ///< Version status
54 uint32_t version_minor; ///< Version minor
55 uint32_t version_major; ///< Version major
56 uint32_t product_major; ///< Product major
57 uint32_t arch_patch_rev; ///< Architecture version patch
58 uint32_t arch_minor_rev; ///< Architecture version minor
59 uint32_t arch_major_rev; ///< Architecture version major
60};
61
62struct ethosu_config
63{
64 struct
65 {
66 uint32_t macs_per_cc; ///< MACs per clock cycle
67 uint32_t cmd_stream_version; ///< NPU command stream version
68 uint32_t shram_size; ///< SHRAM size
69 };
70};
71
72/**
73 * Memory type parameter for set_regioncfg_reg:
74 * Counter{0,1}: Outstanding transactions for
75 * AXI port 0 for memory type/region a=0,b=1
76 * Counter{2,3}: Outstanding transactions for
77 * AXI port 1 for memory type/region a=2,b=3
78 */
79enum ethosu_memory_type
80{
81 ETHOSU_AXI0_OUTSTANDING_COUNTER0 = 0, ///< NPU axi0_outstanding_counter0
82 ETHOSU_AXI0_OUTSTANDING_COUNTER1 = 1, ///< NPU axi0_outstanding_counter1
83 ETHOSU_AXI1_OUTSTANDING_COUNTER2 = 2, ///< NPU axi1_outstanding_counter2
84 ETHOSU_AXI1_OUTSTANDING_COUNTER3 = 3 ///< NPU axi1_outstanding_counter3
85};
86
87enum ethosu_axi_limit_beats
88{
89 ETHOSU_AXI_LIMIT_64_BYTES = 0, ///< NPU AXI limit 64 byte burst split alignment.
90 ETHOSU_AXI_LIMIT_128_BYTES = 1, ///< NPU AXI limit 128 byte burst split alignment.
91 ETHOSU_AXI_LIMIT_256_BYTES = 2 ///< NPU AXI limit 256 byte burst split alignment.
92};
93
94enum ethosu_axi_limit_mem_type
95{
96 ETHOSU_MEM_TYPE_DEVICE_NON_BUFFERABLE = 0,
97 ETHOSU_MEM_TYPE_DEVICE_BUFFERABLE = 1,
98 ETHOSU_MEM_TYPE_NORMAL_NON_CACHEABLE_NON_BUFFERABLE = 2,
99 ETHOSU_MEM_TYPE_NORMAL_NON_CACHEABLE_BUFFERABLE = 3,
100 ETHOSU_MEM_TYPE_WRITE_THROUGH_NO_ALLOCATE = 4,
101 ETHOSU_MEM_TYPE_WRITE_THROUGH_READ_ALLOCATE = 5,
102 ETHOSU_MEM_TYPE_WRITE_THROUGH_WRITE_ALLOCATE = 6,
103 ETHOSU_MEM_TYPE_WRITE_THROUGH_READ_AND_WRITE_ALLOCATE = 7,
104 ETHOSU_MEM_TYPE_WRITE_BACK_NO_ALLOCATE = 8,
105 ETHOSU_MEM_TYPE_WRITE_BACK_READ_ALLOCATE = 9,
106 ETHOSU_MEM_TYPE_WRITE_BACK_WRITE_ALLOCATE = 10,
107 ETHOSU_MEM_TYPE_WRITE_BACK_READ_AND_WRITE_ALLOCATE = 11
108};
109
110enum ethosu_clock_q_request
111{
112 ETHOSU_CLOCK_Q_DISABLE = 0, ///< Disble NPU signal ready for clock off.
113 ETHOSU_CLOCK_Q_ENABLE = 1 ///< Enable NPU signal ready for clock off when stop+idle state reached.
114};
115
116enum ethosu_power_q_request
117{
118 ETHOSU_POWER_Q_DISABLE = 0, ///< Disble NPU signal ready for power off.
119 ETHOSU_POWER_Q_ENABLE = 1 ///< Enable NPU signal ready for power off when stop+idle state reached.
120};
121
122/******************************************************************************
123 * Prototypes
124 ******************************************************************************/
125
126/**
127 * Initialize the device.
128 */
129enum ethosu_error_codes ethosu_dev_init(void);
130
131/**
132 * Get device id.
133 */
134enum ethosu_error_codes ethosu_get_id(struct ethosu_id *id);
135
136/**
137 * Get device configuration.
138 */
139enum ethosu_error_codes ethosu_get_config(struct ethosu_config *config);
140
141/**
142 * Execute a given command stream on NPU.
143 * \param[in] cmd_stream_ptr Pointer to the command stream
144 * \param[in] cms_length Command stream length
145 * \param[in] base_addr Pointer to array of base addresses
146 * - 0: weight tensor
147 * - 1: scratch tensor
148 * - All input tensors
149 * - All output tensors
150 * \param[in] num_base_addr Number of base addresses.
151 * \return \ref ethosu_error_codes
152 */
153enum ethosu_error_codes ethosu_run_command_stream(const uint8_t *cmd_stream_ptr,
154 uint32_t cms_length,
155 const uint64_t *base_addr,
156 int num_base_addr);
157
158/**
159 * Check if IRQ is raised.
160 * \param[out] irq_status Pointer to IRQ status
161 * - 0 IRQ not raised
162 * - 1 IRQ raised
163 * \return \ref ethosu_error_codes
164 */
165enum ethosu_error_codes ethosu_is_irq_raised(uint8_t *irq_status);
166
167/**
168 * Clear IRQ status.
169 * \return \ref ethosu_error_codes
170 */
171enum ethosu_error_codes ethosu_clear_irq_status(void);
172
173/**
174 * Get the 16 bit status mask.
175 * \param[out] irq_status_mask Pointer to the status mask.
176 * The lower 16 bits of status reg are returned.
177 * bit0: state
178 * bit1: irq_raised
179 * bit2: bus_status
180 * bit3: reset_status
181 * bit4: cmd_parse_error
182 * bit5: cmd_end_reached
183 * bit6: pmu_irq_raised
184 * bit7-15: reserved
185 * \return \ref ethosu_error_codes
186 */
187enum ethosu_error_codes ethosu_get_status_mask(uint16_t *status_mask);
188
189/**
190 * Get the 16 bit IRQ history mask.
191 * \param[out] irq_history_mask Pointer to the IRQ history mask.
192 * \return \ref ethosu_error_codes
193 */
194enum ethosu_error_codes ethosu_get_irq_history_mask(uint16_t *irq_history_mask);
195
196/**
197 * Clear the given bits in the
198 * IRQ history mask.
199 * \param[in] irq_history_clear_mask 16 bit mask indicating which bits to
200 * clear in the IRQ history mask.
201 * \return \ref ethosu_error_codes
202 */
203enum ethosu_error_codes ethosu_clear_irq_history_mask(uint16_t irq_history_clear_mask);
204
205/**
206 * Perform a NPU soft reset.
207 * \return \ref ethosu_error_codes
208 */
209enum ethosu_error_codes ethosu_soft_reset(void);
210
211/**
212 * Wait for reset ready.
213 * \return \ref ethosu_error_codes
214 */
215enum ethosu_error_codes ethosu_wait_for_reset(void);
216
217/**
218 * Read and return the content of a given NPU APB
219 * register range.
220 * \param[in] start_address Start address.
221 * \param[in] num_reg Number of registers to read.
222 * \param[out] reg_p Pointer to a output area, allocated by the
223 * caller, where the register content shall be
224 * written.
225 * \return \ref ethosu_error_codes
226 */
227enum ethosu_error_codes ethosu_read_apb_reg(uint32_t start_address, uint16_t num_reg, uint32_t *reg_p);
228
229/**
230 * Set qconfig register. I.e.
231 * AXI configuration for the command stream.
232 * \param[in] memory_type Memory_type to use for command stream:
233 * enum ethosu_memory_type.
234 * \return \ref ethosu_error_codes
235 */
236enum ethosu_error_codes ethosu_set_qconfig(enum ethosu_memory_type memory_type);
237
238/**
239 * Set register REGIONCFG.
240 * Base pointer configuration.
241 * Bits[2*k+1:2*k] give the memory type for BASEP[k].
242 * \param[in] region Region field to set: 0 - 7.
243 * \param[in] memory_type Memory_type to use for region: enum ethosu_memory_type.
244 * \return \ref ethosu_error_codes
245 */
246enum ethosu_error_codes ethosu_set_regioncfg(uint8_t region, enum ethosu_memory_type memory_type);
247
248/**
249 * Set AXI limit parameters for port 0 counter 0.
250 * \param[in] max_beats Burst split alignment, \ref ethosu_axi_limit_beats.
251 * \param[in] memtype Cache policy \ref ethosu_axi_limit_mem_type
252 * \param[in] max_reads Maximum number of outstanding reads.
253 * \param[in] max_writes Maximum number of outstanding writes.
254 * \return \ref ethosu_error_codes
255 */
256enum ethosu_error_codes ethosu_set_axi_limit0(enum ethosu_axi_limit_beats max_beats,
257 enum ethosu_axi_limit_mem_type memtype,
258 uint8_t max_reads,
259 uint8_t max_writes);
260/**
261 * Set AXI limit parameters for port 0 counter 1.
262 * \param[in] max_beats Burst split alignment, \ref ethosu_axi_limit_beats.
263 * \param[in] memtype Cache policy \ref ethosu_axi_limit_mem_type
264 * \param[in] max_reads Maximum number of outstanding reads.
265 * \param[in] max_writes Maximum number of outstanding writes.
266 * \return \ref ethosu_error_codes
267 */
268enum ethosu_error_codes ethosu_set_axi_limit1(enum ethosu_axi_limit_beats max_beats,
269 enum ethosu_axi_limit_mem_type memtype,
270 uint8_t max_reads,
271 uint8_t max_writes);
272/**
273 * Set AXI limit parameters for port 1 counter 2.
274 * \param[in] max_beats Burst split alignment, \ref ethosu_axi_limit_beats.
275 * \param[in] memtype Cache policy \ref ethosu_axi_limit_mem_type
276 * \param[in] max_reads Maximum number of outstanding reads.
277 * \param[in] max_writes Maximum number of outstanding writes.
278 * \return \ref ethosu_error_codes
279 */
280enum ethosu_error_codes ethosu_set_axi_limit2(enum ethosu_axi_limit_beats max_beats,
281 enum ethosu_axi_limit_mem_type memtype,
282 uint8_t max_reads,
283 uint8_t max_writes);
284/**
285 * Set AXI limit parameters for port 1 counter 3.
286 * \param[in] max_beats Burst split alignment, \ref ethosu_axi_limit_beats.
287 * \param[in] memtype Cache policy \ref ethosu_axi_limit_mem_type
288 * \param[in] max_reads Maximum number of outstanding reads.
289 * \param[in] max_writes Maximum number of outstanding writes.
290 * \return \ref ethosu_error_codes
291 */
292enum ethosu_error_codes ethosu_set_axi_limit3(enum ethosu_axi_limit_beats max_beats,
293 enum ethosu_axi_limit_mem_type memtype,
294 uint8_t max_reads,
295 uint8_t max_writes);
296
297/**
298 * Get current command stream queue read position.
299 * \param[out] qread Pointer to queue read.
300 * \return \ref ethosu_error_codes
301 */
302enum ethosu_error_codes ethosu_get_qread(uint32_t *qread);
303
304/**
305 * Get revision of NPU
306 * \param[out] revision Pointer to revision read.
307 * \return \ref ethosu_error_codes
308 */
309enum ethosu_error_codes ethosu_get_revision(uint32_t *revision);
310
311/**
312 * Issue run command for the currently programmed
313 * command stream, starting at current queue read
314 * position.
315 * \return \ref ethosu_error_codes
316 */
317enum ethosu_error_codes ethosu_set_command_run(void);
318
319/**
320 * Dump a 1KB section of SHRAM.
321 * \param[in] section Section offset to 1KB section in SHRAM.
322 * \param[out] shram_p Pointer to a output area, allocated by the
323 * caller, where the SHRAM content shall be
324 * written.
325 * \return \ref ethosu_error_codes
326 */
327enum ethosu_error_codes ethosu_get_shram_data(int section, uint32_t *shram_p);
328
329/**
330 * Set clock and power q request enable bits.
331 * \param[in] clock_q Clock q ENABLE/DISABLE \ref clock_q_request.
332 * \param[in] power_q Power q ENABLE/DISABLE \ref power_q_request.
333 * \return \ref ethosu_error_codes
334 */
335enum ethosu_error_codes ethosu_set_clock_and_power(enum ethosu_clock_q_request clock_q,
336 enum ethosu_power_q_request power_q);
337
338#ifdef __cplusplus
339}
340#endif