1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2016 Intel Corporation. All rights reserved. 4 * 5 * Author: Yan Wang <yan.wang@linux.intel.com> 6 */ 7 8 #ifndef __SOF_TRACE_DMA_TRACE_H__ 9 #define __SOF_TRACE_DMA_TRACE_H__ 10 11 #include <sof/lib/dma.h> 12 #include <rtos/task.h> 13 #include <rtos/sof.h> 14 #include <rtos/spinlock.h> 15 #include <ipc/trace.h> 16 #include <stdint.h> 17 18 struct ipc_msg; 19 struct sof; 20 21 struct dma_trace_buf { 22 void *w_ptr; /* buffer write pointer */ 23 void *r_ptr; /* buffer read position */ 24 void *addr; /* buffer base address */ 25 void *end_addr; /* buffer end address */ 26 uint32_t size; /* size of buffer in bytes */ 27 uint32_t avail; /* bytes available to read */ 28 }; 29 30 struct dma_trace_data { 31 struct dma_sg_config config; 32 struct dma_trace_buf dmatb; 33 #if CONFIG_DMA_GW 34 struct dma_sg_config gw_config; 35 #endif 36 struct dma_copy dc; 37 struct sof_ipc_dma_trace_posn posn; 38 struct ipc_msg *msg; 39 uint32_t host_size; 40 struct task dmat_work; 41 uint32_t enabled; 42 uint32_t copy_in_progress; 43 uint32_t stream_tag; 44 uint32_t active_stream_tag; 45 uint32_t dma_copy_align; /* Minimal chunk of data possible to be 46 * copied by dma connected to host 47 */ 48 uint32_t dropped_entries; /* amount of dropped entries */ 49 struct k_spinlock lock; /* dma trace lock */ 50 uint64_t time_delta; /* difference between the host time */ 51 }; 52 53 int dma_trace_init_early(struct sof *sof); 54 int dma_trace_init_complete(struct dma_trace_data *d); 55 int dma_trace_host_buffer(struct dma_trace_data *d, 56 struct dma_sg_elem_array *elem_array, 57 uint32_t host_size); 58 int dma_trace_enable(struct dma_trace_data *d); 59 void dma_trace_disable(struct dma_trace_data *d); 60 void dma_trace_flush(void *destination); 61 void dma_trace_on(void); 62 void dma_trace_off(void); 63 64 void dtrace_event(const char *e, uint32_t size); 65 void dtrace_event_atomic(const char *e, uint32_t length); 66 dma_trace_initialized(const struct dma_trace_data * d)67static inline bool dma_trace_initialized(const struct dma_trace_data *d) 68 { 69 return d && d->dmatb.addr; 70 } 71 dma_trace_data_get(void)72static inline struct dma_trace_data *dma_trace_data_get(void) 73 { 74 return sof_get()->dmat; 75 } 76 dtrace_calc_buf_margin(struct dma_trace_buf * buffer)77static inline uint32_t dtrace_calc_buf_margin(struct dma_trace_buf *buffer) 78 { 79 return (char *)buffer->end_addr - (char *)buffer->w_ptr; 80 } 81 82 #endif /* __SOF_TRACE_DMA_TRACE_H__ */ 83