From 6e2cf6920bd5c62095e26e6751d3169a07c34b5c Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Thu, 19 Dec 2019 14:41:05 +0100 Subject: [PATCH] trace: add trace to sof main context Adds pointer to generic trace data to sof main context. Also changes access to the trace data to go only through sof context. Signed-off-by: Tomasz Lauda --- src/include/sof/sof.h | 4 ++++ src/include/sof/trace/trace.h | 13 +++++++++++++ src/trace/trace.c | 27 +++++++++++---------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/include/sof/sof.h b/src/include/sof/sof.h index 53b025f9d..dc82d50f1 100644 --- a/src/include/sof/sof.h +++ b/src/include/sof/sof.h @@ -15,6 +15,7 @@ struct dma_trace_data; struct ipc; struct sa; +struct trace; /** * \brief General firmware context. @@ -37,6 +38,9 @@ struct sof { /* DMA for Trace*/ struct dma_trace_data *dmat; + /* generic trace structure */ + struct trace *trace; + __aligned(PLATFORM_DCACHE_ALIGN) int alignment[0]; } __aligned(PLATFORM_DCACHE_ALIGN); diff --git a/src/include/sof/trace/trace.h b/src/include/sof/trace/trace.h index a8b31d430..01c86a951 100644 --- a/src/include/sof/trace/trace.h +++ b/src/include/sof/trace/trace.h @@ -19,6 +19,8 @@ #include #endif #include +#include +#include #include #include #include @@ -28,6 +30,12 @@ struct sof; +struct trace { + uint32_t pos ; /* trace position */ + uint32_t enable; + spinlock_t *lock; /* locking mechanism */ +}; + /* bootloader trace values */ #define TRACE_BOOT_LDR_ENTRY 0x100 #define TRACE_BOOT_LDR_HPSRAM 0x110 @@ -171,6 +179,11 @@ void trace_on(void); void trace_off(void); void trace_init(struct sof *sof); +static inline struct trace *trace_get(void) +{ + return sof_get()->trace; +} + #define trace_unused(class, id_0, id_1, format, ...) \ UNUSED(id_0, id_1, ##__VA_ARGS__) diff --git a/src/trace/trace.c b/src/trace/trace.c index 0c1cc037c..e2169e33b 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -21,14 +22,6 @@ #include #include -struct trace { - uint32_t pos ; /* trace position */ - uint32_t enable; - spinlock_t *lock; /* locking mechanism */ -}; - -static struct trace *trace; - /* calculates total message size, both header and payload in bytes */ #define MESSAGE_SIZE(args_num) \ (sizeof(struct log_entry_header) + args_num * sizeof(uint32_t)) @@ -61,6 +54,7 @@ static void put_header(uint32_t *dst, uint32_t id_0, uint32_t id_1, static void mtrace_event(const char *data, uint32_t length) { + struct trace *trace = trace_get(); volatile char *t; uint32_t i, available; @@ -101,6 +95,7 @@ META_IF_ELSE(is_atomic)(_atomic)() \ ), arg_count) \ { \ uint32_t dt[MESSAGE_SIZE_DWORDS(arg_count)]; \ + struct trace *trace = trace_get(); \ META_IF_ELSE(is_mbox) \ ( \ META_IF_ELSE(is_atomic)()(unsigned long flags;) \ @@ -200,7 +195,7 @@ void trace_flush(void) volatile uint64_t *t; /* get mailbox position */ - t = (volatile uint64_t *)(MAILBOX_TRACE_BASE + trace->pos); + t = (volatile uint64_t *)(MAILBOX_TRACE_BASE + trace_get()->pos); /* flush dma trace messages */ dma_trace_flush((void *)t); @@ -208,13 +203,13 @@ void trace_flush(void) void trace_on(void) { - trace->enable = 1; + trace_get()->enable = 1; dma_trace_on(); } void trace_off(void) { - trace->enable = 0; + trace_get()->enable = 0; dma_trace_off(); } @@ -222,11 +217,11 @@ void trace_init(struct sof *sof) { dma_trace_init_early(sof); - trace = rzalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_SHARED, SOF_MEM_CAPS_RAM, - sizeof(*trace)); - trace->enable = 1; - trace->pos = 0; - spinlock_init(&trace->lock); + sof->trace = rzalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_SHARED, + SOF_MEM_CAPS_RAM, sizeof(*sof->trace)); + sof->trace->enable = 1; + sof->trace->pos = 0; + spinlock_init(&sof->trace->lock); bzero((void *)MAILBOX_TRACE_BASE, MAILBOX_TRACE_SIZE); dcache_writeback_invalidate_region((void *)MAILBOX_TRACE_BASE,