Skip to content

Commit 4c424c7

Browse files
lyakhkv2019i
authored andcommitted
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 <guennadi.liakhovetski@linux.intel.com>
1 parent 340f1d0 commit 4c424c7

6 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/include/sof/debug/gdb/gdb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
void gdb_handle_exception(void);
3939
void gdb_debug_info(unsigned char *str);
4040
void gdb_init_debug_exception(void);
41-
void gdb_init(void);
4241

4342
#endif /* CONFIG_GDB_DEBUG */
4443

44+
void gdb_init(void);
45+
4546
#endif /* __SOF_DEBUG_GDB_GDB_H__ */

src/include/sof/ipc/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,7 @@ void ipc_msg_reply(struct sof_ipc_reply *reply);
247247
*/
248248
void ipc_complete_cmd(struct ipc *ipc);
249249

250+
/* GDB stub: should enter GDB after completing the IPC processing */
251+
extern bool ipc_enter_gdb;
252+
250253
#endif /* __SOF_DRIVERS_IPC_H__ */

src/include/sof/ipc/driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ int ipc_platform_poll_is_host_ready(void);
112112
*/
113113
int ipc_platform_poll_tx_host_msg(struct ipc_msg *msg);
114114

115+
/**
116+
* \brief wait for host acknowledgment to an IPC message
117+
*/
118+
void ipc_platform_wait_ack(struct ipc *ipc);
119+
115120
#endif

src/ipc/ipc-common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sof/audio/component_ext.h>
1010
#include <sof/audio/pipeline.h>
1111
#include <sof/common.h>
12+
#include <sof/debug/gdb/gdb.h>
1213
#include <rtos/idc.h>
1314
#include <rtos/symbol.h>
1415
#include <sof/ipc/topology.h>
@@ -361,6 +362,13 @@ void ipc_complete_cmd(struct ipc *ipc)
361362
ipc_platform_complete_cmd(ipc);
362363
}
363364

365+
bool ipc_enter_gdb;
366+
367+
__attribute__((weak)) void ipc_platform_wait_ack(struct ipc *ipc)
368+
{
369+
k_msleep(1);
370+
}
371+
364372
static void ipc_complete_task(void *data)
365373
{
366374
struct ipc *ipc = data;
@@ -370,6 +378,13 @@ static void ipc_complete_task(void *data)
370378
ipc->task_mask &= ~IPC_TASK_INLINE;
371379
ipc_complete_cmd(ipc);
372380
k_spin_unlock(&ipc->lock, key);
381+
#if CONFIG_GDBSTUB
382+
if (ipc_enter_gdb) {
383+
ipc_enter_gdb = false;
384+
ipc_platform_wait_ack(ipc);
385+
gdb_init();
386+
}
387+
#endif
373388
}
374389

375390
static enum task_state ipc_do_cmd(void *data)

src/ipc/ipc-zephyr.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <autoconf.h>
1313

14+
#include <zephyr/kernel.h>
15+
1416
#include <intel_adsp_ipc.h>
1517
#include <sof/ipc/common.h>
1618

@@ -309,3 +311,23 @@ int platform_ipc_init(struct ipc *ipc)
309311

310312
return 0;
311313
}
314+
315+
static bool ipc_wait_complete(const struct device *dev, void *arg)
316+
{
317+
k_sem_give(arg);
318+
return false;
319+
}
320+
321+
void ipc_platform_wait_ack(struct ipc *ipc)
322+
{
323+
static struct k_sem ipc_wait_sem;
324+
325+
k_sem_init(&ipc_wait_sem, 0, 1);
326+
327+
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, ipc_wait_complete, &ipc_wait_sem);
328+
329+
if (k_sem_take(&ipc_wait_sem, Z_TIMEOUT_MS(10)) == -EAGAIN)
330+
tr_err(&ipc_tr, "Timeout waiting for host ack!");
331+
332+
intel_adsp_ipc_set_done_handler(INTEL_ADSP_IPC_HOST_DEV, NULL, NULL);
333+
}

src/ipc/ipc3/handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ static int ipc_glb_gdb_debug(uint32_t header)
973973
(void) header;
974974

975975
#if CONFIG_GDBSTUB
976-
gdb_init();
976+
ipc_enter_gdb = true;
977977
return 0;
978978
// TODO: remove old GDB stub?
979979
#elif CONFIG_GDB_DEBUG

0 commit comments

Comments
 (0)