From c0a6906f54d2854278454e8576b76851b24d1115 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 12 May 2025 12:13:38 +0200 Subject: [PATCH 1/5] IPC4: add a GDB entry command Add an IPC4 message type to instruct the firmware to enter the GDB stub. Signed-off-by: Guennadi Liakhovetski --- src/include/ipc4/header.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/include/ipc4/header.h b/src/include/ipc4/header.h index 5abef50342b0..a9bb5676e71f 100644 --- a/src/include/ipc4/header.h +++ b/src/include/ipc4/header.h @@ -88,9 +88,11 @@ enum ipc4_message_type { /**< Notification (FW to SW driver) */ SOF_IPC4_GLB_NOTIFICATION = 27, /* GAP HERE- DO NOT USE - size 3 (28 .. 30) */ + /**< Enter GDB stub to wait for commands in memory window */ + SOF_IPC4_GLB_ENTER_GDB = 31, /**< Maximum message number */ - SOF_IPC4_GLB_MAX_IXC_MESSAGE_TYPE = 31 + SOF_IPC4_GLB_MAX_IXC_MESSAGE_TYPE = 32 }; /** From f3d77c55fa3a5f44bbfe7aa2364adbcfdec05deb Mon Sep 17 00:00:00 2001 From: Noah Klayman Date: Fri, 12 Aug 2022 16:11:03 +0000 Subject: [PATCH 2/5] debug: enter Zephyr GDB stub on ipc_glb_gdb_debug command Need to decide if old XTOS GDB stub should be removed and add support for IPC4. Signed-off-by: Noah Klayman --- src/ipc/ipc3/handler.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index 5e58c8ba9443..8bc6a8d06fc2 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -969,10 +969,14 @@ static int ipc_glb_trace_message(uint32_t header) static int ipc_glb_gdb_debug(uint32_t header) { - /* no furher information needs to be extracted form header */ + /* no further information needs to be extracted from header */ (void) header; -#if CONFIG_GDB_DEBUG +#if CONFIG_GDBSTUB + gdb_init(); + return 0; +// TODO: remove old GDB stub? +#elif CONFIG_GDB_DEBUG gdb_init_debug_exception(); gdb_init(); /* TODO: this asm should be in arch/include/debug/debug.h From 86421f62673915f4d67cd48d1ba6fd23ed2e8917 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 12 May 2025 12:45:31 +0200 Subject: [PATCH 3/5] ipc: gdb: initialise GDB after IPC completion To avoid timed out IPC on the host side, enter the GDB stub only after replying to the IPC. Signed-off-by: Guennadi Liakhovetski --- src/include/sof/debug/gdb/gdb.h | 3 ++- src/include/sof/ipc/common.h | 3 +++ src/include/sof/ipc/driver.h | 5 +++++ src/ipc/ipc-common.c | 15 +++++++++++++++ src/ipc/ipc-zephyr.c | 22 ++++++++++++++++++++++ src/ipc/ipc3/handler.c | 2 +- 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/include/sof/debug/gdb/gdb.h b/src/include/sof/debug/gdb/gdb.h index c27e60e64290..338b97b27541 100644 --- a/src/include/sof/debug/gdb/gdb.h +++ b/src/include/sof/debug/gdb/gdb.h @@ -38,8 +38,9 @@ void gdb_handle_exception(void); void gdb_debug_info(unsigned char *str); void gdb_init_debug_exception(void); -void gdb_init(void); #endif /* CONFIG_GDB_DEBUG */ +void gdb_init(void); + #endif /* __SOF_DEBUG_GDB_GDB_H__ */ diff --git a/src/include/sof/ipc/common.h b/src/include/sof/ipc/common.h index f9cec480d61c..e46fc10b9521 100644 --- a/src/include/sof/ipc/common.h +++ b/src/include/sof/ipc/common.h @@ -247,4 +247,7 @@ void ipc_msg_reply(struct sof_ipc_reply *reply); */ void ipc_complete_cmd(struct ipc *ipc); +/* GDB stub: should enter GDB after completing the IPC processing */ +extern bool ipc_enter_gdb; + #endif /* __SOF_DRIVERS_IPC_H__ */ diff --git a/src/include/sof/ipc/driver.h b/src/include/sof/ipc/driver.h index 348300a5a6ff..9b6506a7c1e8 100644 --- a/src/include/sof/ipc/driver.h +++ b/src/include/sof/ipc/driver.h @@ -112,4 +112,9 @@ int ipc_platform_poll_is_host_ready(void); */ int ipc_platform_poll_tx_host_msg(struct ipc_msg *msg); +/** + * \brief wait for host acknowledgment to an IPC message + */ +void ipc_platform_wait_ack(struct ipc *ipc); + #endif diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index 4811d366a7ab..9a07b6b8b715 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -361,6 +362,13 @@ void ipc_complete_cmd(struct ipc *ipc) ipc_platform_complete_cmd(ipc); } +bool ipc_enter_gdb; + +__attribute__((weak)) void ipc_platform_wait_ack(struct ipc *ipc) +{ + k_msleep(1); +} + static void ipc_complete_task(void *data) { struct ipc *ipc = data; @@ -370,6 +378,13 @@ static void ipc_complete_task(void *data) ipc->task_mask &= ~IPC_TASK_INLINE; ipc_complete_cmd(ipc); k_spin_unlock(&ipc->lock, key); +#if CONFIG_GDBSTUB + if (ipc_enter_gdb) { + ipc_enter_gdb = false; + ipc_platform_wait_ack(ipc); + gdb_init(); + } +#endif } static enum task_state ipc_do_cmd(void *data) diff --git a/src/ipc/ipc-zephyr.c b/src/ipc/ipc-zephyr.c index 83763c6b3828..460089414cf7 100644 --- a/src/ipc/ipc-zephyr.c +++ b/src/ipc/ipc-zephyr.c @@ -11,6 +11,8 @@ #include +#include + #include #include @@ -309,3 +311,23 @@ int platform_ipc_init(struct ipc *ipc) return 0; } + +static bool ipc_wait_complete(const struct device *dev, void *arg) +{ + k_sem_give(arg); + return false; +} + +void ipc_platform_wait_ack(struct ipc *ipc) +{ + static struct k_sem ipc_wait_sem; + + k_sem_init(&ipc_wait_sem, 0, 1); + + intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_wait_complete, &ipc_wait_sem); + + if (k_sem_take(&ipc_wait_sem, Z_TIMEOUT_MS(10)) == -EAGAIN) + tr_err(&ipc_tr, "Timeout waiting for host ack!"); + + intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL); +} diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index 8bc6a8d06fc2..196368e1e7eb 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -973,7 +973,7 @@ static int ipc_glb_gdb_debug(uint32_t header) (void) header; #if CONFIG_GDBSTUB - gdb_init(); + ipc_enter_gdb = true; return 0; // TODO: remove old GDB stub? #elif CONFIG_GDB_DEBUG From a96173cba6c96f27fedc010ca862ebff675f1533 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 12 May 2025 12:52:17 +0200 Subject: [PATCH 4/5] ipc4: add support for GDB Add suppoprt for the new IPC4 GDB enter message. Signed-off-by: Guennadi Liakhovetski --- src/ipc/ipc4/handler.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ipc/ipc4/handler.c b/src/ipc/ipc4/handler.c index 16156a29b6db..097f3e313d74 100644 --- a/src/ipc/ipc4/handler.c +++ b/src/ipc/ipc4/handler.c @@ -817,6 +817,16 @@ __cold static int ipc4_process_ipcgtw_cmd(struct ipc4_message_request *ipc4) #endif } +static int ipc_glb_gdb_debug(struct ipc4_message_request *ipc4) +{ +#if CONFIG_GDBSTUB + ipc_enter_gdb = true; + return IPC4_SUCCESS; +#else + return IPC4_UNAVAILABLE; +#endif +} + static int ipc4_process_glb_message(struct ipc4_message_request *ipc4) { uint32_t type; @@ -881,6 +891,10 @@ static int ipc4_process_glb_message(struct ipc4_message_request *ipc4) ret = ipc4_process_ipcgtw_cmd(ipc4); break; + case SOF_IPC4_GLB_ENTER_GDB: + ret = ipc_glb_gdb_debug(ipc4); + break; + default: ipc_cmd_err(&ipc_tr, "unsupported ipc message type %d", type); ret = IPC4_UNAVAILABLE; From 5f5dab670c2e13e25dc956309b2b92ab40067305 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 12 May 2025 13:01:07 +0200 Subject: [PATCH 5/5] debug: gdb: enable GDB stub in debug builds By default enable the GDB stub when building the debug configuration. Signed-off-by: Guennadi Liakhovetski --- app/debug_overlay.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/debug_overlay.conf b/app/debug_overlay.conf index d020447ef02d..650b3c09f7f2 100644 --- a/app/debug_overlay.conf +++ b/app/debug_overlay.conf @@ -17,3 +17,8 @@ CONFIG_DAI_VERBOSE_GLITCH_WARNINGS=y # CONFIG_SPIN_LOCK_TIME_LIMIT=50000 CONFIG_COLD_STORE_EXECUTE_DEBUG=y + +# GDB stub + +CONFIG_GDBSTUB=y +CONFIG_GDBSTUB_ENTER_IMMEDIATELY=n