blob: f47d3f286c520dfe41ca86dd1cb5f1487ac348e7 [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#include "ethosu_driver.h"
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020020#include "ethosu_common.h"
Bhavik Pateldae5be02020-06-18 15:25:15 +020021#include "ethosu_config.h"
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020022#include "ethosu_device.h"
Per Åstrand25d78c02020-04-21 14:19:44 +020023
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020024#include <assert.h>
Per Åstrand25d78c02020-04-21 14:19:44 +020025#include <cmsis_compiler.h>
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020026#include <stdbool.h>
Bhavik Patelbf7ae632020-06-11 21:00:16 +020027#include <stddef.h>
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020028#include <stdint.h>
29#include <stdio.h>
30#include <stdlib.h>
31
Bhavik Patel5da40922020-07-15 10:06:43 +020032struct ethosu_driver ethosu_drv = {.dev = {.base_address = NULL,
33 .restore_pmu_config = false,
34 .pmccntr = 0,
35 .pmu_evcntr = {0, 0, 0, 0},
36 .pmu_evtypr = {0, 0, 0, 0}},
37 .abort_inference = false};
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020038
39// IRQ
40static volatile bool irq_triggered = false;
41#if defined(CPU_CORTEX_M3) || defined(CPU_CORTEX_M4) || defined(CPU_CORTEX_M7) || defined(CPU_CORTEX_M33) || \
42 defined(CPU_CORTEX_M55)
Per Åstrand25d78c02020-04-21 14:19:44 +020043void ethosu_irq_handler(void)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020044{
45 uint8_t irq_raised = 0;
Kristofer Jonsson125429a2020-08-20 16:52:23 +020046
47 LOG_DEBUG("Interrupt. status=0x%08x, qread=%d\n",
48 ethosu_read_reg(&ethosu_drv.dev, NPU_REG_STATUS),
49 ethosu_read_reg(&ethosu_drv.dev, NPU_REG_QREAD));
50
51 // Verify that interrupt has been raised
Bhavik Pateldae5be02020-06-18 15:25:15 +020052 (void)ethosu_is_irq_raised(&ethosu_drv.dev, &irq_raised);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020053 ASSERT(irq_raised == 1);
54 irq_triggered = true;
Kristofer Jonsson125429a2020-08-20 16:52:23 +020055
56 // Clear interrupt
Bhavik Pateldae5be02020-06-18 15:25:15 +020057 (void)ethosu_clear_irq_status(&ethosu_drv.dev);
Kristofer Jonsson125429a2020-08-20 16:52:23 +020058
59 // Verify that interrupt has been successfully cleard
Bhavik Pateldae5be02020-06-18 15:25:15 +020060 (void)ethosu_is_irq_raised(&ethosu_drv.dev, &irq_raised);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020061 ASSERT(irq_raised == 0);
62}
63
Bhavik Pateldae5be02020-06-18 15:25:15 +020064static inline void wait_for_irq(struct ethosu_driver *drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020065{
66 while (1)
67 {
68 __disable_irq();
Bhavik Pateldae5be02020-06-18 15:25:15 +020069 if (irq_triggered || drv->abort_inference)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020070 {
71 __enable_irq();
72 break;
73 }
74
Per Åstrand25d78c02020-04-21 14:19:44 +020075 __WFI();
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020076
77 __enable_irq();
78 }
79}
80#else
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020081// Just polling the status register
Bhavik Pateldae5be02020-06-18 15:25:15 +020082static inline void wait_for_irq(struct ethosu_driver *drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020083{
84 uint8_t irq_raised = 0;
85
86 for (int i = 0; i < 5000; ++i)
87 {
Bhavik Pateldae5be02020-06-18 15:25:15 +020088 (void)ethosu_is_irq_raised(&drv->dev, &irq_raised);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +020089 if (1 == irq_raised)
90 {
91 break;
92 }
93 }
94 ASSERT(1 == irq_raised);
95
96 irq_triggered = true;
97}
98#endif
99
100#define MACS_PER_CYCLE_LOG2_MASK 0x000F
101#define SHRAM_SIZE_MASK 0xFF00
102#define SHRAM_SIZE_RIGHT_SHIFT 8
103#define BYTES_IN_32_BITS 4
104#define CUSTOM_OPTION_LENGTH_32_BIT_WORD 1
105#define DRIVER_ACTION_LENGTH_32_BIT_WORD 1
106#define OPTIMIZER_CONFIG_LENGTH_32_BIT_WORD 2
107#define ETHOSU_FOURCC ('1' << 24 | 'P' << 16 | 'O' << 8 | 'C') // "Custom Operator Payload 1"
108#define APB_START_ADDR_MASK 0x0FFF
109#define APB_NUM_REG_BIT_SHIFT 12
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200110#define BYTES_1KB 1024
Bhavik Patel790ef362020-06-03 10:05:28 +0200111#define PRODUCT_MAJOR_ETHOSU55 (4)
Bhavik Patelbf7ae632020-06-11 21:00:16 +0200112#define MASK_16_BYTE_ALIGN (0xF)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200113
114// Driver actions
115enum DRIVER_ACTION_e
116{
117 RESERVED = 0,
118 OPTIMIZER_CONFIG = 1,
119 COMMAND_STREAM = 2,
120 READ_APB_REG = 3,
121 DUMP_SHRAM = 4,
122 NOP = 5,
123};
124
125// Custom data struct
126struct custom_data_s
127{
128 union
129 {
130 // Driver action data
131 struct
132 {
133 // Driver action command (valid values in DRIVER_ACTION_e)
134 uint8_t driver_action_command;
135 // reserved
136 uint8_t reserved;
137 // Driver action data
138 union
139 {
140 struct
141 { // DA_CMD_OPT_CFG
142 uint16_t rel_nbr : 4;
143 uint16_t patch_nbr : 4;
144 uint16_t opt_cfg_reserved : 8;
145 };
146 struct
147 { // DA_CMD_CMSTRM
148 uint16_t length;
149 };
150 struct
151 { // DA_CMD_READAPB
152 uint16_t start_address : 12;
153 uint16_t nbr_reg_minus1 : 4;
154 };
155 uint16_t driver_action_data;
156 };
157 };
158 uint32_t word;
159 };
160};
161
162// optimizer config struct
163struct opt_cfg_s
164{
165 struct custom_data_s da_data;
166 union
167 {
168 struct
169 {
170 uint32_t macs_per_cc : 4;
171 uint32_t cmd_stream_version : 4;
172 uint32_t shram_size : 8;
173 uint32_t reserved1 : 16;
174 };
175 uint32_t npu_cfg;
176 };
177 union
178 {
179 struct
180 {
181 uint32_t version_status : 4;
182 uint32_t version_minor : 4;
183 uint32_t version_major : 4;
184 uint32_t product_major : 4;
185 uint32_t arch_patch_rev : 4;
186 uint32_t arch_minor_rev : 8;
187 uint32_t arch_major_rev : 4;
188 };
189 uint32_t ethosu_id;
190 };
191};
192
Bhavik Pateldae5be02020-06-18 15:25:15 +0200193static int handle_optimizer_config(struct ethosu_driver *drv, struct opt_cfg_s *opt_cfg_p);
194static int handle_command_stream(struct ethosu_driver *drv,
195 const uint8_t *cmd_stream,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200196 const int cms_length,
197 const uint64_t *base_addr,
198 const int num_base_addr);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200199static int read_apb_reg(struct ethosu_driver *drv, uint16_t);
200static int dump_shram(struct ethosu_driver *drv);
201static void dump_npu_register(struct ethosu_driver *drv, int npu_reg, int npu_reg_end);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200202static void dump_command_stream(const uint32_t *cmd_stream, const int cms_length, int qread);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200203static void npu_axi_init(struct ethosu_driver *drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200204
Bhavik Pateldae5be02020-06-18 15:25:15 +0200205int ethosu_init(const void *base_address)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200206{
207 int return_code = 0;
Bhavik Pateldae5be02020-06-18 15:25:15 +0200208
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200209 LOG_INFO("ethosu_init calling NPU embed driver ethosu_dev_init\n");
210
Bhavik Pateldae5be02020-06-18 15:25:15 +0200211 if (ETHOSU_SUCCESS != ethosu_dev_init(&ethosu_drv.dev, base_address))
212 {
213 LOG_ERR("Failed in ethosu_dev_init");
214 return -1;
215 }
216
217 if (ETHOSU_SUCCESS != ethosu_set_clock_and_power(&ethosu_drv.dev, ETHOSU_CLOCK_Q_DISABLE, ETHOSU_POWER_Q_DISABLE))
Bhavik Patele645fed2020-06-12 14:46:47 +0200218 {
219 LOG_ERR("Failed to disable clock-q & power-q for Ethos-U\n");
220 return -1;
221 }
222
Bhavik Pateldae5be02020-06-18 15:25:15 +0200223 ethosu_soft_reset(&ethosu_drv.dev);
Kristofer Jonssondaa0d202020-05-12 12:23:16 +0200224
Bhavik Pateldae5be02020-06-18 15:25:15 +0200225 if (ETHOSU_SUCCESS != ethosu_wait_for_reset(&ethosu_drv.dev))
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200226 {
227 LOG_ERR("Failed reset of Ethos-U\n");
228 return -1;
229 }
230
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200231 return return_code;
232}
233
234int ethosu_get_version(struct ethosu_version *version)
235{
236 int return_code = 0;
237
238 if (NULL != version)
239 {
240 struct ethosu_id id;
241 struct ethosu_config cfg;
Bhavik Pateldae5be02020-06-18 15:25:15 +0200242 (void)ethosu_get_id(&ethosu_drv.dev, &id);
243 (void)ethosu_get_config(&ethosu_drv.dev, &cfg);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200244
245 version->id.version_status = id.version_status;
246 version->id.version_minor = id.version_minor;
247 version->id.version_major = id.version_major;
248 version->id.product_major = id.product_major;
249 version->id.arch_patch_rev = id.arch_patch_rev;
250 version->id.arch_minor_rev = id.arch_minor_rev;
251 version->id.arch_major_rev = id.arch_major_rev;
252 version->id.driver_patch_rev = ETHOSU_DRIVER_VERSION_PATCH;
253 version->id.driver_minor_rev = ETHOSU_DRIVER_VERSION_MINOR;
254 version->id.driver_major_rev = ETHOSU_DRIVER_VERSION_MAJOR;
255 version->cfg.macs_per_cc = cfg.macs_per_cc;
256 version->cfg.cmd_stream_version = cfg.cmd_stream_version;
257 version->cfg.shram_size = cfg.shram_size;
258 }
259 else
260 {
261 return_code = -1;
262 }
263
264 return return_code;
265}
266
267int ethosu_invoke(const void *custom_data_ptr,
268 const int custom_data_size,
269 const uint64_t *base_addr,
270 const int num_base_addr)
271{
272 struct custom_data_s *data_start_ptr = (struct custom_data_s *)custom_data_ptr;
273 int return_code = 0;
274
275 LOG_INFO("ethosu_invoke\n");
276
277 // First word in custom_data_ptr should contain "Custom Operator Payload 1"
278 if (data_start_ptr->word != ETHOSU_FOURCC)
279 {
280 LOG_ERR("Custom Operator Payload: %x is not correct, expected %x\n", data_start_ptr->word, ETHOSU_FOURCC);
281 return -1;
282 }
283 data_start_ptr += CUSTOM_OPTION_LENGTH_32_BIT_WORD;
284 struct custom_data_s *data_ptr = data_start_ptr;
285
286 if ((custom_data_size % BYTES_IN_32_BITS) != 0)
287 {
288 LOG_ERR("ethosu_invoke ERROR custom_data_size=0x%x not a multiple of 4\n", custom_data_size);
289 return -1;
290 }
291 int custom_data_32bit_size = (custom_data_size / BYTES_IN_32_BITS - CUSTOM_OPTION_LENGTH_32_BIT_WORD);
292
Kristofer Jonsson125429a2020-08-20 16:52:23 +0200293 ethosu_soft_reset(&ethosu_drv.dev);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200294 ethosu_set_clock_and_power(&ethosu_drv.dev, ETHOSU_CLOCK_Q_ENABLE, ETHOSU_POWER_Q_DISABLE);
Bhavik Patel5da40922020-07-15 10:06:43 +0200295 ethosu_restore_pmu_config(&ethosu_drv.dev);
Kristofer Jonsson125429a2020-08-20 16:52:23 +0200296
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200297 while (data_ptr < (data_start_ptr + custom_data_32bit_size))
298 {
Bhavik Patele645fed2020-06-12 14:46:47 +0200299 int ret = 0;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200300 switch (data_ptr->driver_action_command)
301 {
302 case OPTIMIZER_CONFIG:
303 LOG_INFO("ethosu_invoke OPTIMIZER_CONFIG\n");
304 struct opt_cfg_s *opt_cfg_p = (struct opt_cfg_s *)data_ptr;
305
Bhavik Pateldae5be02020-06-18 15:25:15 +0200306 ret = handle_optimizer_config(&ethosu_drv, opt_cfg_p);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200307 data_ptr += DRIVER_ACTION_LENGTH_32_BIT_WORD + OPTIMIZER_CONFIG_LENGTH_32_BIT_WORD;
308 break;
309 case COMMAND_STREAM:
310 LOG_INFO("ethosu_invoke COMMAND_STREAM\n");
311 void *command_stream = (uint8_t *)(data_ptr) + sizeof(struct custom_data_s);
312 int cms_length = (data_ptr->reserved << 16) | data_ptr->length;
313
Bhavik Pateldae5be02020-06-18 15:25:15 +0200314 ethosu_drv.abort_inference = false;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200315 // It is safe to clear this flag without atomic, because npu is not running.
316 irq_triggered = false;
317
Bhavik Pateldae5be02020-06-18 15:25:15 +0200318 ret = handle_command_stream(&ethosu_drv, command_stream, cms_length, base_addr, num_base_addr);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200319
Bhavik Pateldae5be02020-06-18 15:25:15 +0200320 if (return_code == -1 && ethosu_drv.abort_inference)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200321 {
322 uint32_t qread = 0;
Bhavik Pateldae5be02020-06-18 15:25:15 +0200323 ethosu_get_qread(&ethosu_drv.dev, &qread);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200324 LOG_ERR("NPU timeout\n");
325 dump_command_stream(command_stream, cms_length, qread);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200326 dump_npu_register(&ethosu_drv, 0x200, 0x2BF);
327 dump_npu_register(&ethosu_drv, 0x800, 0xB3F);
328 dump_shram(&ethosu_drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200329 }
330
331 data_ptr += DRIVER_ACTION_LENGTH_32_BIT_WORD + cms_length;
332 break;
333 case READ_APB_REG:
334 LOG_INFO("ethosu_invoke READ_APB_REG\n");
Bhavik Pateldae5be02020-06-18 15:25:15 +0200335 ret = read_apb_reg(&ethosu_drv, data_ptr->driver_action_data);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200336 data_ptr += DRIVER_ACTION_LENGTH_32_BIT_WORD;
337 break;
338 case DUMP_SHRAM:
339 LOG_INFO("ethosu_invoke DUMP_SHRAM\n");
Bhavik Pateldae5be02020-06-18 15:25:15 +0200340 ret = dump_shram(&ethosu_drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200341 data_ptr += DRIVER_ACTION_LENGTH_32_BIT_WORD;
342 break;
343 case NOP:
344 LOG_INFO("ethosu_invoke NOP\n");
345 data_ptr += DRIVER_ACTION_LENGTH_32_BIT_WORD;
346 break;
347 default:
348 LOG_ERR("ethosu_invoke UNSUPPORTED driver_action_command %d \n", data_ptr->driver_action_command);
Bhavik Patele645fed2020-06-12 14:46:47 +0200349 ret = -1;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200350 break;
351 }
Bhavik Patele645fed2020-06-12 14:46:47 +0200352 if (ret != 0)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200353 {
Bhavik Patele645fed2020-06-12 14:46:47 +0200354 return_code = -1;
355 break;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200356 }
357 }
Bhavik Patel5da40922020-07-15 10:06:43 +0200358 ethosu_save_pmu_config(&ethosu_drv.dev);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200359 ethosu_set_clock_and_power(&ethosu_drv.dev, ETHOSU_CLOCK_Q_ENABLE, ETHOSU_POWER_Q_ENABLE);
Bhavik Patele645fed2020-06-12 14:46:47 +0200360 return return_code;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200361}
362
363void ethosu_abort(void)
364{
Bhavik Pateldae5be02020-06-18 15:25:15 +0200365 ethosu_drv.abort_inference = true;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200366}
367
Bhavik Pateldae5be02020-06-18 15:25:15 +0200368static int handle_optimizer_config(struct ethosu_driver *drv, struct opt_cfg_s *opt_cfg_p)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200369{
370 struct ethosu_config cfg;
371 struct ethosu_id id;
372 int return_code = 0;
373
374 LOG_INFO("handle_optimizer_config:\n");
375 LOG_INFO("Optimizer release nbr: %d patch: %d\n", opt_cfg_p->da_data.rel_nbr, opt_cfg_p->da_data.patch_nbr);
376 LOG_INFO("Optimizer config cmd_stream_version: %d macs_per_cc: %d shram_size: %d\n",
377 opt_cfg_p->cmd_stream_version,
378 opt_cfg_p->macs_per_cc,
379 opt_cfg_p->shram_size);
380 LOG_INFO("Optimizer config Ethos-U version: %d.%d.%d\n",
381 opt_cfg_p->arch_major_rev,
382 opt_cfg_p->arch_minor_rev,
383 opt_cfg_p->arch_patch_rev);
384
Bhavik Pateldae5be02020-06-18 15:25:15 +0200385 (void)ethosu_get_config(&drv->dev, &cfg);
386 (void)ethosu_get_id(&drv->dev, &id);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200387 LOG_INFO("Ethos-U config cmd_stream_version: %d macs_per_cc: %d shram_size: %d\n",
388 cfg.cmd_stream_version,
389 cfg.macs_per_cc,
390 cfg.shram_size);
391 LOG_INFO("Ethos-U version: %d.%d.%d\n", id.arch_major_rev, id.arch_minor_rev, id.arch_patch_rev);
392
393 if ((cfg.macs_per_cc != opt_cfg_p->macs_per_cc) || (cfg.shram_size != opt_cfg_p->shram_size) ||
394 (cfg.cmd_stream_version != opt_cfg_p->cmd_stream_version))
395 {
396 if (cfg.macs_per_cc != opt_cfg_p->macs_per_cc)
397 {
398 LOG_ERR("NPU config mismatch: npu.macs_per_cc=%d optimizer.macs_per_cc=%d\n",
399 cfg.macs_per_cc,
400 opt_cfg_p->macs_per_cc);
401 }
402 if (cfg.shram_size != opt_cfg_p->shram_size)
403 {
404 LOG_ERR("NPU config mismatch: npu.shram_size=%d optimizer.shram_size=%d\n",
405 cfg.shram_size,
406 opt_cfg_p->shram_size);
407 }
408 if (cfg.cmd_stream_version != opt_cfg_p->cmd_stream_version)
409 {
410 LOG_ERR("NPU config mismatch: npu.cmd_stream_version=%d optimizer.cmd_stream_version=%d\n",
411 cfg.cmd_stream_version,
412 opt_cfg_p->cmd_stream_version);
413 }
414 return_code = -1;
415 }
416
Bhavik Patel790ef362020-06-03 10:05:28 +0200417 if ((id.product_major == PRODUCT_MAJOR_ETHOSU55) &&
Douglas Troha60d50ae2020-06-15 12:48:10 +0200418 ((id.arch_major_rev != opt_cfg_p->arch_major_rev) || (id.arch_minor_rev != opt_cfg_p->arch_minor_rev)))
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200419 {
Bhavik Patel790ef362020-06-03 10:05:28 +0200420 LOG_ERR("NPU arch mismatch: npu.arch=%d.%d.%d optimizer.arch=%d.%d.%d\n",
421 id.arch_major_rev,
422 id.arch_minor_rev,
423 id.arch_patch_rev,
424 opt_cfg_p->arch_major_rev,
425 opt_cfg_p->arch_minor_rev,
426 opt_cfg_p->arch_patch_rev);
427 return_code = -1;
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200428 }
429
430#if !defined(LOG_ENABLED)
431 UNUSED(opt_cfg_p);
432#endif
433 return return_code;
434}
435
Bhavik Pateldae5be02020-06-18 15:25:15 +0200436static void npu_axi_init(struct ethosu_driver *drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200437{
Bhavik Pateldae5be02020-06-18 15:25:15 +0200438 ethosu_set_qconfig(&drv->dev, NPU_QCONFIG);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200439
Bhavik Pateldae5be02020-06-18 15:25:15 +0200440 ethosu_set_regioncfg(&drv->dev, 0, NPU_REGIONCFG_0);
441 ethosu_set_regioncfg(&drv->dev, 1, NPU_REGIONCFG_1);
442 ethosu_set_regioncfg(&drv->dev, 2, NPU_REGIONCFG_2);
443 ethosu_set_regioncfg(&drv->dev, 3, NPU_REGIONCFG_3);
444 ethosu_set_regioncfg(&drv->dev, 4, NPU_REGIONCFG_4);
445 ethosu_set_regioncfg(&drv->dev, 5, NPU_REGIONCFG_5);
446 ethosu_set_regioncfg(&drv->dev, 6, NPU_REGIONCFG_6);
447 ethosu_set_regioncfg(&drv->dev, 7, NPU_REGIONCFG_7);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200448
Bhavik Pateldae5be02020-06-18 15:25:15 +0200449 (void)ethosu_set_axi_limit0(&drv->dev,
450 AXI_LIMIT0_MAX_BEATS_BYTES,
Bhavik Patel790ef362020-06-03 10:05:28 +0200451 AXI_LIMIT0_MEM_TYPE,
452 AXI_LIMIT0_MAX_OUTSTANDING_READS,
453 AXI_LIMIT0_MAX_OUTSTANDING_WRITES);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200454 (void)ethosu_set_axi_limit1(&drv->dev,
455 AXI_LIMIT1_MAX_BEATS_BYTES,
Bhavik Patel790ef362020-06-03 10:05:28 +0200456 AXI_LIMIT1_MEM_TYPE,
457 AXI_LIMIT1_MAX_OUTSTANDING_READS,
458 AXI_LIMIT1_MAX_OUTSTANDING_WRITES);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200459 (void)ethosu_set_axi_limit2(&drv->dev,
460 AXI_LIMIT2_MAX_BEATS_BYTES,
Bhavik Patel790ef362020-06-03 10:05:28 +0200461 AXI_LIMIT2_MEM_TYPE,
462 AXI_LIMIT2_MAX_OUTSTANDING_READS,
463 AXI_LIMIT2_MAX_OUTSTANDING_WRITES);
Bhavik Pateldae5be02020-06-18 15:25:15 +0200464 (void)ethosu_set_axi_limit3(&drv->dev,
465 AXI_LIMIT3_MAX_BEATS_BYTES,
Bhavik Patel790ef362020-06-03 10:05:28 +0200466 AXI_LIMIT3_MEM_TYPE,
467 AXI_LIMIT3_MAX_OUTSTANDING_READS,
468 AXI_LIMIT3_MAX_OUTSTANDING_WRITES);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200469}
470
Bhavik Pateldae5be02020-06-18 15:25:15 +0200471static int handle_command_stream(struct ethosu_driver *drv,
472 const uint8_t *cmd_stream,
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200473 const int cms_length,
474 const uint64_t *base_addr,
475 const int num_base_addr)
476{
477 uint32_t qread = 0;
478 uint32_t cms_bytes = cms_length * BYTES_IN_32_BITS;
Kristofer Jonsson125429a2020-08-20 16:52:23 +0200479 LOG_INFO("handle_command_stream: cmd_stream=%p, cms_length %d\n", cmd_stream, cms_length);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200480
Bhavik Patelbf7ae632020-06-11 21:00:16 +0200481 if (0 != ((ptrdiff_t)cmd_stream & MASK_16_BYTE_ALIGN))
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200482 {
Bhavik Patelbf7ae632020-06-11 21:00:16 +0200483 LOG_ERR("Error: Command stream addr %p not aligned to 16 bytes\n", cmd_stream);
484 return -1;
485 }
486
487 bool base_addr_invalid = false;
488 for (int i = 0; i < num_base_addr; i++)
489 {
490 if (0 != (base_addr[i] & MASK_16_BYTE_ALIGN))
491 {
492 LOG_ERR("Error: Base addr %d: %p not aligned to 16 bytes\n", i, (void *)(base_addr[i]));
493 base_addr_invalid = true;
494 }
495 }
496 if (base_addr_invalid)
497 {
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200498 return -1;
499 }
Bhavik Pateldae5be02020-06-18 15:25:15 +0200500 npu_axi_init(drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200501
Bhavik Pateldae5be02020-06-18 15:25:15 +0200502 if (ETHOSU_SUCCESS != ethosu_run_command_stream(&drv->dev, cmd_stream, cms_bytes, base_addr, num_base_addr))
Bhavik Patel790ef362020-06-03 10:05:28 +0200503 {
504 return -1;
505 }
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200506
Bhavik Pateldae5be02020-06-18 15:25:15 +0200507 wait_for_irq(drv);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200508
Bhavik Pateldae5be02020-06-18 15:25:15 +0200509 (void)ethosu_get_qread(&drv->dev, &qread);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200510 if (qread != cms_bytes)
511 {
512 LOG_ERR("Failure: IRQ received but qread (%d) not at end of stream (%d).\n", qread, cms_bytes);
513 return -1;
514 }
515
516 // TODO Power off
517 return 0;
518}
519
Bhavik Pateldae5be02020-06-18 15:25:15 +0200520static int read_apb_reg(struct ethosu_driver *drv, uint16_t da_data)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200521{
522 uint32_t *reg_p;
523 uint32_t start_address = (uint32_t)(da_data & APB_START_ADDR_MASK);
524 uint16_t num_reg = (da_data >> APB_NUM_REG_BIT_SHIFT) + 1;
525
526 reg_p = (uint32_t *)malloc(num_reg * sizeof(uint32_t));
527 if (reg_p == NULL)
528 {
529 LOG_INFO("read_apb_reg, Error! memory not allocated.");
530 return -1;
531 }
532
Bhavik Pateldae5be02020-06-18 15:25:15 +0200533 if (ETHOSU_SUCCESS == ethosu_read_apb_reg(&drv->dev, start_address, num_reg, reg_p))
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200534 {
535 for (int i = 0; i < num_reg; i++)
536 {
537 LOG_INFO("NPU_REG ADDR 0x%04x = 0x%08x\n", (start_address + (i * BYTES_IN_32_BITS)), reg_p[i]);
538 }
539 }
540 else
541 {
542 free(reg_p);
543 return -1;
544 }
545
546 free(reg_p);
547 return 0;
548}
549
Bhavik Pateldae5be02020-06-18 15:25:15 +0200550static int dump_shram(struct ethosu_driver *drv)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200551{
552 struct ethosu_config cfg;
553 uint32_t *shram_p;
Bhavik Pateldae5be02020-06-18 15:25:15 +0200554 (void)ethosu_get_config(&drv->dev, &cfg);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200555
556 LOG_INFO("dump_shram size = %d KB\n", cfg.shram_size);
557
558 shram_p = (uint32_t *)malloc(BYTES_1KB);
559 if (shram_p == NULL)
560 {
561 LOG_ERR("read_shram, Error! memory not allocated.");
562 return -1;
563 }
564
565 for (uint32_t i = 0; i < cfg.shram_size; i++)
566 {
Bhavik Pateldae5be02020-06-18 15:25:15 +0200567 ethosu_get_shram_data(&drv->dev, i, (uint32_t *)shram_p);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200568 // Output 1KB of SHRAM
569 LOG_INFO("***SHRAM SECTION %d***\n", i);
570 for (int j = 0; j < (BYTES_1KB / BYTES_IN_32_BITS); j++)
571 {
572 LOG_INFO("[0x%04x] %x\n", (i * 1024 + j * 4), shram_p[j]);
573 }
574 }
575 free(shram_p);
576
577 return 0;
578}
579
580typedef struct
581{
582 int number;
583 const char *name;
584} name_lookup_t;
585
586static const name_lookup_t npu_reg_name_tbl[] = {
587 {0x200, "KERNEL_X"},
588 {0x204, "KERNEL_Y"},
589 {0x208, "KERNEL_W_M1"},
590 {0x20C, "KERNEL_H_M1"},
591 {0x210, "OFM_CBLK_WIDTH_M1"},
592 {0x214, "OFM_CBLK_HEIGHT_M1"},
593 {0x218, "OFM_CBLK_DEPTH_M1"},
594 {0x21c, "IFM_CBLK_DEPTH_M1"},
595 {0x220, "OFM_X"},
596 {0x224, "OFM_Y"},
597 {0x228, "OFM_Z"},
598 {0x22C, "IFM_Z"},
599 {0x230, "PAD_TOP"},
600 {0x234, "PAD_LEFT"},
601 {0x238, "IFM_CBLK_WIDTH"},
602 {0x23C, "IFM_CBLK_HEIGHT"},
603 {0x240, "DMA_IFM_SRC"},
604 {0x244, "DMA_IFM_SRC_HI"},
605 {0x248, "DMA_IFM_DST"},
606 {0x24c, "DMA_OFM_SRC"},
607 {0x250, "DMA_OFM_DST"},
608 {0x254, "DMA_OFM_DST_HI"},
609 {0x258, "DMA_WEIGHT_SRC"},
610 {0x25c, "DMA_WEIGHT_SRC_HI"},
611 {0x260, "DMA_CMD_SRC"},
612 {0x264, "DMA_CMD_SRC_HI"},
613 {0x268, "DMA_CMD_SIZE"},
614 {0x26c, "DMA_M2M_SRC"},
615 {0x270, "DMA_M2M_SRC_HI"},
616 {0x274, "DMA_M2M_DST"},
617 {0x278, "DMA_M2M_DST_HI"},
618 {0x27c, "CURRENT_QREAD"},
619 {0x280, "DMA_SCALE_SRC"},
620 {0x284, "DMA_SCALE_SRC_HI"},
621 {0x2BC, "CURRENT_CMD"},
622 {0x800, "IFM_PAD_TOP"},
623 {0x804, "IFM_PAD_LEFT"},
624 {0x808, "IFM_PAD_RIGHT"},
625 {0x80C, "IFM_PAD_BOTTOM"},
626 {0x810, "IFM_DEPTH_M1"},
627 {0x814, "IFM_PRECISION"},
628 {0x81C, "IFM_UPSCALE"},
629 {0x824, "IFM_ZERO_POINT"},
630 {0x828, "IFM_WIDTH0_M1"},
631 {0x82C, "IFM_HEIGHT0_M1"},
632 {0x830, "IFM_HEIGHT1_M1"},
633 {0x834, "IFM_IB_END"},
634 {0x83C, "IFM_REGION"},
635 {0x844, "OFM_WIDTH_M1"},
636 {0x848, "OFM_HEIGHT_M1"},
637 {0x84C, "OFM_DEPTH_M1"},
638 {0x850, "OFM_PRECISION"},
639 {0x854, "OFM_BLK_WIDTH_M1"},
640 {0x858, "OFM_BLK_HEIGHT_M1"},
641 {0x85C, "OFM_BLK_DEPTH_M1"},
642 {0x860, "OFM_ZERO_POINT"},
643 {0x868, "OFM_WIDTH0_M1"},
644 {0x86C, "OFM_HEIGHT0_M1"},
645 {0x870, "OFM_HEIGHT1_M1"},
646 {0x87C, "OFM_REGION"},
647 {0x880, "KERNEL_WIDTH_M1"},
648 {0x884, "KERNEL_HEIGHT_M1"},
649 {0x888, "KERNEL_STRIDE"},
650 {0x88C, "PARALLEL_MODE"},
651 {0x890, "ACC_FORMAT"},
652 {0x894, "ACTIVATION"},
653 {0x898, "ACTIVATION_MIN"},
654 {0x89C, "ACTIVATION_MAX"},
655 {0x8A0, "WEIGHT_REGION"},
656 {0x8A4, "SCALE_REGION"},
657 {0x8B4, "AB_START"},
658 {0x8BC, "BLOCKDEP"},
659 {0x8C0, "DMA0_SRC_REGION"},
660 {0x8C4, "DMA0_DST_REGION"},
661 {0x8C8, "DMA0_SIZE0"},
662 {0x8CC, "DMA0_SIZE1"},
663 {0x900, "IFM2_BROADCAST"},
664 {0x904, "IFM2_SCALAR"},
665 {0x924, "IFM2_ZERO_POINT"},
666 {0x928, "IFM2_WIDTH0_M1"},
667 {0x92C, "IFM2_HEIGHT0_M1"},
668 {0x930, "IFM2_HEIGHT1_M1"},
669 {0x934, "IFM2_IB_START"},
670 {0x93C, "IFM2_REGION"},
671 {0xA00, "IFM_BASE0"},
672 {0xA04, "IFM_BASE0_HI"},
673 {0xA08, "IFM_BASE1"},
674 {0xA0C, "IFM_BASE1_HI"},
675 {0xA10, "IFM_BASE2"},
676 {0xA14, "IFM_BASE2_HI"},
677 {0xA18, "IFM_BASE3"},
678 {0xA1C, "IFM_BASE3_HI"},
679 {0xA20, "IFM_STRIDE_X"},
680 {0xA24, "IFM_STRIDE_X_HI"},
681 {0xA28, "IFM_STRIDE_Y"},
682 {0xA2C, "IFM_STRIDE_Y_HI"},
683 {0xA30, "IFM_STRIDE_C"},
684 {0xA34, "IFM_STRIDE_C_HI"},
685 {0xA40, "OFM_BASE0"},
686 {0xA44, "OFM_BASE0_HI"},
687 {0xA48, "OFM_BASE1"},
688 {0xA4C, "OFM_BASE1_HI"},
689 {0xA50, "OFM_BASE2"},
690 {0xA54, "OFM_BASE2_HI"},
691 {0xA58, "OFM_BASE3"},
692 {0xA5C, "OFM_BASE3_HI"},
693 {0xA60, "OFM_STRIDE_X"},
694 {0xA64, "OFM_STRIDE_X_HI"},
695 {0xA68, "OFM_STRIDE_Y"},
696 {0xA6C, "OFM_STRIDE_Y_HI"},
697 {0xA70, "OFM_STRIDE_C"},
698 {0xA74, "OFM_STRIDE_C_HI"},
699 {0xA80, "WEIGHT_BASE"},
700 {0xA84, "WEIGHT_BASE_HI"},
701 {0xA88, "WEIGHT_LENGTH"},
702 {0xA8C, "WEIGHT_LENGTH_HI"},
703 {0xA90, "SCALE_BASE"},
704 {0xA94, "SCALE_BASE_HI"},
705 {0xA98, "SCALE_LENGTH"},
706 {0xAA0, "OFM_SCALE"},
707 {0xAA4, "OFM_SCALE_SHIFT"},
708 {0xAA8, "OPA_SCALE "},
709 {0xAB0, "OPB_SCALE"},
710 {0xAC0, "DMA0_SRC"},
711 {0xAC4, "DMA0_SRC_HI"},
712 {0xAC8, "DMA0_DST"},
713 {0xACC, "DMA0_DST_HI"},
714 {0xAD0, "DMA0_LEN"},
715 {0xAD4, "DMA0_LEN_HI"},
716 {0xAD8, "DMA0_SKIP0"},
717 {0xADC, "DMA0_SKIP0_HI"},
718 {0xAE0, "DMA0_SKIP1"},
719 {0xAE4, "DMA0_SKIP1_HI"},
720 {0xB00, "IFM2_BASE0"},
721 {0xB04, "IFM2_BASE0_HI"},
722 {0xB08, "IFM2_BASE1"},
723 {0xB0C, "IFM2_BASE1_HI"},
724 {0xB10, "IFM2_BASE2"},
725 {0xB14, "IFM2_BASE2_HI"},
726 {0xB18, "IFM2_BASE3"},
727 {0xB1C, "IFM2_BASE3_HI"},
728 {0xB20, "IFM2_STRIDE_X"},
729 {0xB24, "IFM2_STRIDE_X_HI"},
730 {0xB28, "IFM2_STRIDE_Y"},
731 {0xB2C, "IFM2_STRIDE_Y_HI"},
732 {0xB30, "IFM2_STRIDE_C"},
733 {0xB34, "IFM2_STRIDE_C_HI"},
734 {0xB40, "WEIGHT1_BASE"},
735 {0xB44, "WEIGHT1_BASE_HI"},
736 {0xB48, "WEIGHT1_LENGTH"},
737 {0xB4C, "WEIGHT1_LENGTH_HI"},
738 {0xB50, "SCALE1_BASE"},
739 {0xB54, "SCALE1_BASE_HI"},
740 {0xB58, "SCALE1_LENGTH"},
741};
742
743static const char *lookup_name(const name_lookup_t *lookup_table, int lookup_table_count, int find)
744{
745 int n;
746 for (n = 0; n < lookup_table_count; n++)
747 {
748 if (lookup_table[n].number == find)
749 {
750 return lookup_table[n].name;
751 }
752 }
753 // Not found
754 return 0;
755}
756
Bhavik Pateldae5be02020-06-18 15:25:15 +0200757static void dump_npu_register(struct ethosu_driver *drv, int npu_reg, int npu_reg_end)
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200758{
759 unsigned int reg_val;
760 const char *reg_name;
761 int npu_reg_name_tbl_count = sizeof(npu_reg_name_tbl) / sizeof(npu_reg_name_tbl[0]);
762
763 LOG_INFO("dump_register %X - %X\n", npu_reg, npu_reg_end);
764 for (; npu_reg <= npu_reg_end; npu_reg += sizeof(int))
765 {
Bhavik Pateldae5be02020-06-18 15:25:15 +0200766 reg_val = ethosu_read_reg(&drv->dev, npu_reg);
Kristofer Jonsson49bdee82020-04-06 13:21:21 +0200767 reg_name = lookup_name(npu_reg_name_tbl, npu_reg_name_tbl_count, npu_reg);
768 LOG_INFO("[0x%.4X] 0x%.8X\t%s\n", npu_reg, reg_val, (reg_name) ? reg_name : "");
769 }
770}
771
772static const name_lookup_t cmd0_name_tbl[] = {
773 {0x000, "NPU_OP_STOP"},
774 {0x001, "NPU_OP_IRQ"},
775 {0x002, "NPU_OP_CONV"},
776 {0x003, "NPU_OP_DEPTHWISE"},
777 {0x004, "NPU_OP_VECTOR_PROD"},
778 {0x005, "NPU_OP_POOL"},
779 {0x006, "NPU_OP_ELEMENTWISE"},
780 {0x010, "NPU_OP_DMA_START"},
781 {0x011, "NPU_OP_DMA_WAIT"},
782 {0x012, "NPU_OP_KERNEL_WAIT"},
783 {0x100, "NPU_SET_IFM_PAD_TOP"},
784 {0x101, "NPU_SET_IFM_PAD_LEFT"},
785 {0x102, "NPU_SET_IFM_PAD_RIGHT"},
786 {0x103, "NPU_SET_IFM_PAD_BOTTOM"},
787 {0x104, "NPU_SET_IFM_DEPTH_M1"},
788 {0x105, "NPU_SET_IFM_PRECISION"},
789 {0x107, "NPU_SET_IFM_UPSCALE"},
790 {0x109, "NPU_SET_IFM_ZERO_POINT"},
791 {0x10A, "NPU_SET_IFM_WIDTH0_M1"},
792 {0x10B, "NPU_SET_IFM_HEIGHT0_M1"},
793 {0x10C, "NPU_SET_IFM_HEIGHT1_M1"},
794 {0x10D, "NPU_SET_IFM_IB_END"},
795 {0x10F, "NPU_SET_IFM_REGION"},
796 {0x110, "NPU_SET_OFM_BATCH_SIZE_M1"},
797 {0x111, "NPU_SET_OFM_WIDTH_M1"},
798 {0x112, "NPU_SET_OFM_HEIGHT_M1"},
799 {0x113, "NPU_SET_OFM_DEPTH_M1"},
800 {0x114, "NPU_SET_OFM_PRECISION"},
801 {0x115, "NPU_SET_OFM_BLK_WIDTH_M1"},
802 {0x116, "NPU_SET_OFM_BLK_HEIGHT_M1"},
803 {0x117, "NPU_SET_OFM_BLK_DEPTH_M1"},
804 {0x118, "NPU_SET_OFM_ZERO_POINT"},
805 {0x11A, "NPU_SET_OFM_WIDTH0_M1"},
806 {0x11B, "NPU_SET_OFM_HEIGHT0_M1"},
807 {0x11C, "NPU_SET_OFM_HEIGHT1_M1"},
808 {0x11F, "NPU_SET_OFM_REGION"},
809 {0x120, "NPU_SET_KERNEL_WIDTH_M1"},
810 {0x121, "NPU_SET_KERNEL_HEIGHT_M1"},
811 {0x122, "NPU_SET_KERNEL_STRIDE"},
812 {0x124, "NPU_SET_ACC_FORMAT"},
813 {0x125, "NPU_SET_ACTIVATION"},
814 {0x126, "NPU_SET_ACTIVATION_MIN"},
815 {0x127, "NPU_SET_ACTIVATION_MAX"},
816 {0x128, "NPU_SET_WEIGHT_REGION"},
817 {0x129, "NPU_SET_SCALE_REGION"},
818 {0x12D, "NPU_SET_AB_START"},
819 {0x12F, "NPU_SET_BLOCKDEP"},
820 {0x130, "NPU_SET_DMA0_SRC_REGION"},
821 {0x131, "NPU_SET_DMA0_DST_REGION"},
822 {0x180, "NPU_SET_IFM2_BROADCAST"},
823 {0x181, "NPU_SET_IFM2_SCALAR"},
824 {0x185, "NPU_SET_IFM2_PRECISION"},
825 {0x189, "NPU_SET_IFM2_ZERO_POINT"},
826 {0x18A, "NPU_SET_IFM2_WIDTH0_M1"},
827 {0x18B, "NPU_SET_IFM2_HEIGHT0_M1"},
828 {0x18C, "NPU_SET_IFM2_HEIGHT1_M1"},
829 {0x18D, "NPU_SET_IFM2_IB_START"},
830 {0x18F, "NPU_SET_IFM2_REGION"},
831};
832
833static const name_lookup_t cmd1_name_tbl[] = {
834 {0x000, "NPU_SET_IFM_BASE0"}, {0x001, "NPU_SET_IFM_BASE1"}, {0x002, "NPU_SET_IFM_BASE2"},
835 {0x003, "NPU_SET_IFM_BASE3"}, {0x004, "NPU_SET_IFM_STRIDE_X"}, {0x005, "NPU_SET_IFM_STRIDE_Y"},
836 {0x006, "NPU_SET_IFM_STRIDE_C"}, {0x007, "NPU_SET_IFM_STRIDE_N"}, {0x010, "NPU_SET_OFM_BASE0"},
837 {0x011, "NPU_SET_OFM_BASE1"}, {0x012, "NPU_SET_OFM_BASE2"}, {0x013, "NPU_SET_OFM_BASE3"},
838 {0x014, "NPU_SET_OFM_STRIDE_X"}, {0x015, "NPU_SET_OFM_STRIDE_Y"}, {0x016, "NPU_SET_OFM_STRIDE_C"},
839 {0x017, "NPU_SET_OFM_STRIDE_N"}, {0x020, "NPU_SET_WEIGHT_BASE"}, {0x021, "NPU_SET_WEIGHT_LENGTH"},
840 {0x022, "NPU_SET_SCALE_BASE"}, {0x023, "NPU_SET_SCALE_LENGTH"}, {0x024, "NPU_SET_OFM_SCALE"},
841 {0x025, "NPU_SET_OPA_SCALE"}, {0x026, "NPU_SET_OPB_SCALE"}, {0x030, "NPU_SET_DMA0_SRC"},
842 {0x031, "NPU_SET_DMA0_DST"}, {0x032, "NPU_SET_DMA0_LEN"}, {0x080, "NPU_SET_IFM2_BASE0"},
843 {0x081, "NPU_SET_IFM2_BASE1"}, {0x082, "NPU_SET_IFM2_BASE2"}, {0x083, "NPU_SET_IFM2_BASE3"},
844 {0x084, "NPU_SET_IFM2_STRIDE_X"}, {0x085, "NPU_SET_IFM2_STRIDE_Y"}, {0x086, "NPU_SET_IFM2_STRIDE_C"},
845};
846
847static void dump_command_stream(const uint32_t *cmd_stream, const int cms_length, int qread)
848{
849 int n;
850 int offset;
851 uint32_t cmd_val;
852 const uint8_t *cmd_ptr;
853 const char *cmd_name;
854 int cmd0_name_tbl_count = sizeof(cmd0_name_tbl) / sizeof(cmd0_name_tbl[0]);
855 int cmd1_name_tbl_count = sizeof(cmd1_name_tbl) / sizeof(cmd1_name_tbl[0]);
856
857 LOG_INFO("dump_command_stream cmd_stream = 0x%8p cms_length = %d\n", cmd_stream, cms_length);
858 for (n = 0; n < cms_length; n++)
859 {
860 // Offset
861 offset = n * sizeof(int);
862 LOG_INFO("[%.4d] ", offset);
863 // Command
864 cmd_ptr = (const uint8_t *)&cmd_stream[n];
865 LOG_INFO("0x%.2X 0x%.2X 0x%.2X 0x%.2X ", cmd_ptr[0], cmd_ptr[1], cmd_ptr[2], cmd_ptr[3]);
866 // Command name and payload
867 if (cmd_stream[n] & 0x4000)
868 {
869 cmd_name = lookup_name(cmd1_name_tbl, cmd1_name_tbl_count, cmd_stream[n] & 0x3FF);
870 n++;
871 cmd_val = cmd_stream[n];
872 cmd_ptr = (const uint8_t *)&cmd_stream[n];
873 LOG_INFO("0x%.2X 0x%.2X 0x%.2X 0x%.2X ", cmd_ptr[0], cmd_ptr[1], cmd_ptr[2], cmd_ptr[3]);
874 }
875 else
876 {
877 cmd_val = cmd_stream[n] >> 16;
878 cmd_name = lookup_name(cmd0_name_tbl, cmd0_name_tbl_count, cmd_stream[n] & 0x3FF);
879 }
880 if (cmd_name)
881 {
882 LOG_INFO("\t%s 0x%.8X", cmd_name, cmd_val);
883 }
884 if (offset == qread)
885 {
886 LOG_INFO(" <<== QREAD\n");
887 }
888 else
889 {
890 LOG_INFO("\n");
891 }
892 }
893}