From 90a4f5274510ea8d6303f0b4dfa5589bb44d032e Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Wed, 18 Sep 2024 19:35:30 +0300 Subject: [PATCH 1/4] soc: intel_adsp: tools: cavstool.py: argsparse code to separate function Do not force argsparse code to all modules importing cavstool.py. The commit moves argparse code into a separate function, and calls it from 'if __name__ == "__main__":'. Also adds the argsparse call to to acetool.py that shares cavstool code with the argument parsing. Signed-off-by: Jyri Sarha --- soc/intel/intel_adsp/tools/acetool.py | 1 + soc/intel/intel_adsp/tools/cavstool.py | 42 ++++++++++++++------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/soc/intel/intel_adsp/tools/acetool.py b/soc/intel/intel_adsp/tools/acetool.py index 5424e2a68ae817..a1202f47577b28 100755 --- a/soc/intel/intel_adsp/tools/acetool.py +++ b/soc/intel/intel_adsp/tools/acetool.py @@ -6,6 +6,7 @@ import cavstool if __name__ == "__main__": + cavstool.args_parse() try: asyncio.run(cavstool.main()) except KeyboardInterrupt: diff --git a/soc/intel/intel_adsp/tools/cavstool.py b/soc/intel/intel_adsp/tools/cavstool.py index e250730910f1d4..6b0dda07561380 100755 --- a/soc/intel/intel_adsp/tools/cavstool.py +++ b/soc/intel/intel_adsp/tools/cavstool.py @@ -962,28 +962,30 @@ async def main(): if not args.log_only: handle_ipc() - -ap = argparse.ArgumentParser(description="DSP loader/logger tool", allow_abbrev=False) -ap.add_argument("-q", "--quiet", action="store_true", - help="No loader output, just DSP logging") -ap.add_argument("-v", "--verbose", action="store_true", - help="More loader output, DEBUG logging level") -ap.add_argument("-l", "--log-only", action="store_true", - help="Don't load firmware, just show log output") -ap.add_argument("-p", "--shell-pty", action="store_true", - help="Create a Zephyr shell pty if enabled in firmware") -ap.add_argument("-n", "--no-history", action="store_true", - help="No current log buffer at start, just new output") -ap.add_argument("fw_file", nargs="?", help="Firmware file") - -args = ap.parse_args() - -if args.quiet: - log.setLevel(logging.WARN) -elif args.verbose: - log.setLevel(logging.DEBUG) +def args_parse(): + global args + ap = argparse.ArgumentParser(description="DSP loader/logger tool", allow_abbrev=False) + ap.add_argument("-q", "--quiet", action="store_true", + help="No loader output, just DSP logging") + ap.add_argument("-v", "--verbose", action="store_true", + help="More loader output, DEBUG logging level") + ap.add_argument("-l", "--log-only", action="store_true", + help="Don't load firmware, just show log output") + ap.add_argument("-p", "--shell-pty", action="store_true", + help="Create a Zephyr shell pty if enabled in firmware") + ap.add_argument("-n", "--no-history", action="store_true", + help="No current log buffer at start, just new output") + ap.add_argument("fw_file", nargs="?", help="Firmware file") + + args = ap.parse_args() + + if args.quiet: + log.setLevel(logging.WARN) + elif args.verbose: + log.setLevel(logging.DEBUG) if __name__ == "__main__": + args_parse() try: asyncio.run(main()) except KeyboardInterrupt: From f066c06c30caf739ba138060414054acc5e2e3ae Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Thu, 19 Sep 2024 19:22:19 +0300 Subject: [PATCH 2/4] soc: intel_adsp: tools: cavstool.py: Make map_regs() shareable map_reg() depends on args global variable for knowing it should load a new firmware or just stand by for logging or Zephyr shell. The map_regs() code is the very first step to access the DSP memory, it nees to be shareable if the code is to be accessed from another python module. Signed-off-by: Jyri Sarha --- soc/intel/intel_adsp/tools/cavstool.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/soc/intel/intel_adsp/tools/cavstool.py b/soc/intel/intel_adsp/tools/cavstool.py index 6b0dda07561380..2b008b98b7c3f2 100755 --- a/soc/intel/intel_adsp/tools/cavstool.py +++ b/soc/intel/intel_adsp/tools/cavstool.py @@ -210,7 +210,7 @@ def adsp_mem_window_config(): return (base, stride) -def map_regs(): +def map_regs(log_only): p = runx(f"grep -iEl 'PCI_CLASS=40(10|38)0' /sys/bus/pci/devices/*/uevent") pcidir = os.path.dirname(p) @@ -226,7 +226,7 @@ def map_regs(): if os.path.exists(f"{pcidir}/driver"): mod = os.path.basename(os.readlink(f"{pcidir}/driver/module")) found_msg = f"Existing driver \"{mod}\" found" - if args.log_only: + if log_only: log.info(found_msg) else: log.warning(found_msg + ", unloading module") @@ -920,7 +920,7 @@ async def main(): global hda, sd, dsp, hda_ostream_id, hda_streams try: - (hda, sd, dsp, hda_ostream_id) = map_regs() + (hda, sd, dsp, hda_ostream_id) = map_regs(args.log_only) except Exception as e: log.error("Could not map device in sysfs; run as root?") log.error(e) From 40c7a6768e843b0f028fa44169d5eef4c836dc6c Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Thu, 19 Sep 2024 12:11:28 +0300 Subject: [PATCH 3/4] soc: intel_adsp: tools: cavstool: Fix fw_is_alive() and wait_fw_entered() The fw_is_alive() depends on 'dsp' global variable which is assigned from map_regs() return value. To make fw_is_alive() and wait_fw_entered(), that calls fw_is_alive(), callable from another module, the 'dsp' variable needs to be passed as an argument. Signed-off-by: Jyri Sarha --- soc/intel/intel_adsp/tools/cavstool.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/soc/intel/intel_adsp/tools/cavstool.py b/soc/intel/intel_adsp/tools/cavstool.py index 2b008b98b7c3f2..9718ef894b9901 100755 --- a/soc/intel/intel_adsp/tools/cavstool.py +++ b/soc/intel/intel_adsp/tools/cavstool.py @@ -482,7 +482,7 @@ def load_firmware(fw_file): log.info(f"Starting DMA, FW_STATUS = 0x{dsp.SRAM_FW_STATUS:x}") sd.CTL |= 2 # START flag - wait_fw_entered() + wait_fw_entered(dsp, timeout_s=None) # Turn DMA off and reset the stream. Clearing START first is a # noop per the spec, but absolutely required for stability. @@ -604,7 +604,7 @@ def load_firmware_ace(fw_file): log.info(f"Starting DMA, FW_STATUS = 0x{dsp.ROM_STATUS:x}") sd.CTL |= 2 # START flag - wait_fw_entered() + wait_fw_entered(dsp, timeout_s=None) # Turn DMA off and reset the stream. Clearing START first is a # noop per the spec, but absolutely required for stability. @@ -618,17 +618,17 @@ def load_firmware_ace(fw_file): sd.CTL |= 1 log.info(f"ACE firmware load complete") -def fw_is_alive(): +def fw_is_alive(dsp): return dsp.ROM_STATUS & ((1 << 28) - 1) == 5 # "FW_ENTERED" -def wait_fw_entered(timeout_s=2): +def wait_fw_entered(dsp, timeout_s): log.info("Waiting %s for firmware handoff, ROM_STATUS = 0x%x", "forever" if timeout_s is None else f"{timeout_s} seconds", dsp.ROM_STATUS) hertz = 100 attempts = None if timeout_s is None else timeout_s * hertz while True: - alive = fw_is_alive() + alive = fw_is_alive(dsp) if alive: break if attempts is not None: @@ -875,10 +875,10 @@ def ipc_command(data, ext_data): sys.stdout.flush() else: log.warning(f"cavstool: Unrecognized IPC command 0x{data:x} ext 0x{ext_data:x}") - if not fw_is_alive(): + if not fw_is_alive(dsp): if args.log_only: log.info("DSP power seems off") - wait_fw_entered(timeout_s=None) + wait_fw_entered(dsp, timeout_s=None) else: log.warning("DSP power seems off?!") time.sleep(2) # potential spam reduction @@ -929,7 +929,7 @@ async def main(): log.info(f"Detected cAVS 1.8+ hardware") if args.log_only: - wait_fw_entered(timeout_s=None) + wait_fw_entered(dsp, timeout_s=None) else: if not args.fw_file: log.error("Firmware file argument missing") From c3e70823f47ca3a0aff55a619440018aadb950b1 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Thu, 19 Sep 2024 20:28:01 +0300 Subject: [PATCH 4/4] soc: intel_adsp: tools: cavstool.py: Add debug_slot_offset() Add debug_slot_offset() function for getting a debug slot offset by the slot number. Signed-off-by: Jyri Sarha --- soc/intel/intel_adsp/tools/cavstool.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/intel/intel_adsp/tools/cavstool.py b/soc/intel/intel_adsp/tools/cavstool.py index 9718ef894b9901..874bd1de6faa5e 100755 --- a/soc/intel/intel_adsp/tools/cavstool.py +++ b/soc/intel/intel_adsp/tools/cavstool.py @@ -745,6 +745,9 @@ def debug_offset(): ( base, stride ) = adsp_mem_window_config() return base + stride * 2 +def debug_slot_offset(num): + return debug_offset() + DEBUG_SLOT_SIZE * (1 + num) + def shell_base_offset(): return debug_offset() + DEBUG_SLOT_SIZE * (1 + DEBUG_SLOT_SHELL)