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 <sof/schedule/task.h> 13 #include <sof/sof.h> 14 #include <sof/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 struct dma_copy dc; 34 struct sof_ipc_dma_trace_posn posn; 35 struct ipc_msg *msg; 36 uint32_t old_host_offset; /**< Last posn.offset sent to host */ 37 uint32_t host_size; 38 struct task dmat_work; 39 uint32_t enabled; 40 uint32_t copy_in_progress; 41 uint32_t stream_tag; 42 uint32_t dma_copy_align; /**< Minimal chunk of data possible to be 43 * copied by dma connected to host 44 */ 45 uint32_t dropped_entries; /* amount of dropped entries */ 46 spinlock_t lock; /* dma trace lock */ 47 }; 48 49 int dma_trace_init_early(struct sof *sof); 50 int dma_trace_init_complete(struct dma_trace_data *d); 51 int dma_trace_host_buffer(struct dma_trace_data *d, 52 struct dma_sg_elem_array *elem_array, 53 uint32_t host_size); 54 int dma_trace_enable(struct dma_trace_data *d); 55 void dma_trace_flush(void *destination); 56 void dma_trace_on(void); 57 void dma_trace_off(void); 58 59 void dtrace_event(const char *e, uint32_t size); 60 void dtrace_event_atomic(const char *e, uint32_t length); 61 dma_trace_initialized(const struct dma_trace_data * d)62static inline bool dma_trace_initialized(const struct dma_trace_data *d) 63 { 64 return d && d->dmatb.addr; 65 } 66 dma_trace_data_get(void)67static inline struct dma_trace_data *dma_trace_data_get(void) 68 { 69 return sof_get()->dmat; 70 } 71 dtrace_calc_buf_margin(struct dma_trace_buf * buffer)72static inline uint32_t dtrace_calc_buf_margin(struct dma_trace_buf *buffer) 73 { 74 return (char *)buffer->end_addr - (char *)buffer->w_ptr; 75 } 76 77 #endif /* __SOF_TRACE_DMA_TRACE_H__ */ 78