Skip to content

Commit 3209bc1

Browse files
edersondisouzacarlescufi
authored andcommitted
soc/xtensa/intel_adsp/tools: Make cavstool.py DSP resetting more stable
When using more than one core on cavs25, some hangs were made "persistent", as it seems not all cores were being properly reset, thus compromising tests - if a test hangs for any reason, subsequent tests that were not restrict to a single CPU would also fail. This patch mitigates these issues by two changes: - Closely mimics SOF Linux driver way of loading the firmware. So, explicit stall and reset (and "unstall" and "unreset") of cores, with appropriate checks that states have been reached; - More generous sleep before resetting the stream. Also, the status of ADSPCS (Audio DSP Control and Status) register is logged more thoroughly to aid debugging in case new issues arise. Signed-off-by: Ederson de Souza <[email protected]>
1 parent f875d02 commit 3209bc1

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

soc/xtensa/intel_adsp/tools/cavstool.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
INBOX_OFFSET = (512 + (1 * 128)) * 1024
4747
WINSTREAM_OFFSET = (512 + (3 * 128)) * 1024
4848

49+
# ADSPCS bits
50+
CRST = 0
51+
CSTALL = 8
52+
SPA = 16
53+
CPA = 24
54+
4955
class HDAStream:
5056
# creates an hda stream with at 2 buffers of buf_len
5157
def __init__(self, stream_id: int):
@@ -355,6 +361,14 @@ def __getattr__(self, name):
355361
def runx(cmd):
356362
return subprocess.check_output(cmd, shell=True).decode().rstrip()
357363

364+
def mask(bit):
365+
if cavs25:
366+
return 0b1 << bit
367+
if cavs18:
368+
return 0b1111 << bit
369+
if cavs15:
370+
return 0b11 << bit
371+
358372
def load_firmware(fw_file):
359373
try:
360374
fw_bytes = open(fw_file, "rb").read()
@@ -377,9 +391,14 @@ def load_firmware(fw_file):
377391
hda.GCTL = 1
378392
while not hda.GCTL & 1: pass
379393

380-
log.info("Powering down DSP cores")
381-
dsp.ADSPCS = 0xffff
382-
while dsp.ADSPCS & 0xff000000: pass
394+
log.info(f"Stalling and Resetting DSP cores, ADSPCS = 0x{dsp.ADSPCS:x}")
395+
dsp.ADSPCS |= mask(CSTALL)
396+
dsp.ADSPCS |= mask(CRST)
397+
while (dsp.ADSPCS & mask(CRST)) == 0: pass
398+
399+
log.info(f"Powering down DSP cores, ADSPCS = 0x{dsp.ADSPCS:x}")
400+
dsp.ADSPCS &= ~mask(SPA)
401+
while dsp.ADSPCS & mask(CPA): pass
383402

384403
log.info(f"Configuring HDA stream {hda_ostream_id} to transfer firmware image")
385404
(buf_list_addr, num_bufs) = setup_dma_mem(fw_bytes)
@@ -403,18 +422,25 @@ def load_firmware(fw_file):
403422

404423
# Start DSP. Host needs to provide power to all cores on 1.5
405424
# (which also starts them) and 1.8 (merely gates power, DSP also
406-
# has to set PWRCTL). The bits for cores other than 0 are ignored
407-
# on 2.5 where the DSP has full control.
425+
# has to set PWRCTL). On 2.5 where the DSP has full control,
426+
# and only core 0 is set.
408427
log.info(f"Starting DSP, ADSPCS = 0x{dsp.ADSPCS:x}")
409-
dsp.ADSPCS = 0xff0000 if not cavs25 else 0x01fefe
410-
while (dsp.ADSPCS & 0x1000000) == 0: pass
428+
dsp.ADSPCS = mask(SPA)
429+
while (dsp.ADSPCS & mask(CPA)) == 0: pass
430+
431+
log.info(f"Unresetting DSP cores, ADSPCS = 0x{dsp.ADSPCS:x}")
432+
dsp.ADSPCS &= ~mask(CRST)
433+
while (dsp.ADSPCS & 1) != 0: pass
434+
435+
log.info(f"Running DSP cores, ADSPCS = 0x{dsp.ADSPCS:x}")
436+
dsp.ADSPCS &= ~mask(CSTALL)
411437

412-
# Wait for the ROM to boot and signal it's ready. This short
438+
# Wait for the ROM to boot and signal it's ready. This not so short
413439
# sleep seems to be needed; if we're banging on the memory window
414440
# during initial boot (before/while the window control registers
415441
# are configured?) the DSP hardware will hang fairly reliably.
416-
log.info("Wait for ROM startup")
417-
time.sleep(0.1)
442+
log.info(f"Wait for ROM startup, ADSPCS = 0x{dsp.ADSPCS:x}")
443+
time.sleep(1)
418444
while (dsp.SRAM_FW_STATUS >> 24) != 5: pass
419445

420446
# Send the DSP an IPC message to tell the device how to boot.
@@ -443,7 +469,7 @@ def load_firmware(fw_file):
443469
# chromebook) putting the two writes next each other also hangs
444470
# the DSP!
445471
sd.CTL &= ~2 # clear START
446-
time.sleep(0.1)
472+
time.sleep(1)
447473
sd.CTL |= 1
448474
log.info(f"cAVS firmware load complete")
449475

tests/boards/intel_adsp/hda/src/dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <zephyr/drivers/dma.h>
1010
#include "tests.h"
1111

12-
#define IPC_TIMEOUT K_MSEC(500)
12+
#define IPC_TIMEOUT K_MSEC(1500)
1313
#define DMA_BUF_SIZE 256
1414
#define TRANSFER_SIZE 256
1515
#define TRANSFER_COUNT 8

tests/boards/intel_adsp/hda/src/smoke.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define HDA_REGBLOCK_SIZE DT_PROP_BY_IDX(DT_NODELABEL(hda_host_out), reg, 1)
1616
#include <cavs_hda.h>
1717

18-
#define IPC_TIMEOUT K_MSEC(500)
18+
#define IPC_TIMEOUT K_MSEC(1500)
1919
#define STREAM_ID 3U
2020
#define HDA_BUF_SIZE 256
2121
#define TRANSFER_COUNT 8

tests/boards/intel_adsp/hda_log/src/logger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <zephyr/logging/log.h>
1818
LOG_MODULE_REGISTER(hda_test, LOG_LEVEL_DBG);
1919

20-
#define IPC_TIMEOUT K_MSEC(500)
20+
#define IPC_TIMEOUT K_MSEC(1500)
2121

2222
void hda_log_hook(uint32_t written)
2323
{

0 commit comments

Comments
 (0)