Sound Open Firmware
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
4 *
5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6 * Keyon Jie <yang.jie@linux.intel.com>
7 */
8
15#ifndef __SOF_DEBUG_DEBUG_H__
16#define __SOF_DEBUG_DEBUG_H__
17
18#include <sof/common.h>
19#include <rtos/panic.h>
20#include <rtos/cache.h>
21#include <sof/lib/cpu.h>
22#include <rtos/sof.h>
23#include <rtos/string.h>
24#include <ipc/info.h>
25#include <ipc/trace.h>
26
27#include <stddef.h>
28#include <stdint.h>
29
30#ifndef RELATIVE_FILE
31#error "This file requires RELATIVE_FILE to be defined. " \
32 "Add it to CMake's target with sof_append_relative_path_definitions."
33#endif
34
35#if CONFIG_DEBUG
36
37#include <sof/lib/mailbox.h>
38
40#define DEBUG_SET_FW_READY_FLAGS SOF_IPC_INFO_BUILD
41
43#define dbg() \
44 do { \
45 volatile uint32_t *__m = (uint32_t *)mailbox_get_debug_base(); \
46 *(__m++) = (RELATIVE_FILE[0] << 24) + \
47 (RELATIVE_FILE[1] << 16) + \
48 (RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
49 *(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
50 (__func__[2] << 8) + (__func__[3]); \
51 *__m = __LINE__; \
52 } while (0)
53
55#define dbg_at(__x) \
56 do { \
57 volatile uint32_t *__m = \
58 (uint32_t *)mailbox_get_debug_base() + __x; \
59 *(__m++) = (RELATIVE_FILE[0] << 24) + \
60 (RELATIVE_FILE[1] << 16) + \
61 (RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
62 *(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
63 (__func__[2] << 8) + (__func__[3]); \
64 *__m = __LINE__; \
65 } while (0)
66
68#define dbg_val(__v) \
69 do { \
70 volatile uint32_t *__m = \
71 (volatile uint32_t *)mailbox_get_debug_base(); \
72 *__m = __v; \
73 } while (0)
74
76#define dbg_val_at(__v, __x) \
77 do { \
78 volatile uint32_t *__m = \
79 (volatile uint32_t *)mailbox_get_debug_base() + __x; \
80 *__m = __v; \
81 } while (0)
82
84#define dump(addr, count) \
85 do { \
86 volatile uint32_t *__m = (uint32_t *)mailbox_get_debug_base(); \
87 volatile uint32_t *__a = (uint32_t *)addr; \
88 volatile int __c = count; \
89 while (__c--) \
90 *(__m++) = *(__a++); \
91 } while (0)
92
94#define dump_at(addr, count, offset) \
95 do { \
96 volatile uint32_t *__m = \
97 (uint32_t *)mailbox_get_debug_base() + offset; \
98 volatile uint32_t *__a = (uint32_t *)addr; \
99 volatile int __c = count; \
100 while (__c--) \
101 *(__m++) = *(__a++); \
102 } while (0)
103
105#define dump_object(__o) \
106 do { \
107 dbg(); \
108 dump(&__o, sizeof(__o) >> 2); \
109 } while (0)
110
112#define dump_object_ptr(__o) \
113 do { \
114 dbg(); \
115 dump(__o, sizeof(*(__o)) >> 2); \
116 } while (0)
117
119#define dump_object_ptr_at(__o, __at) \
120 do { \
121 dbg(); \
122 dump_at(__o, sizeof(*(__o)) >> 2, __at);\
123 } while (0)
124
125#else
126
127#define DEBUG_SET_FW_READY_FLAGS 0
128
129#define dbg() do {} while (0)
130#define dbg_at(__x) do {} while (0)
131#define dbg_val(__v) do {} while (0)
132#define dbg_val_at(__v, __x) do {} while (0)
133#define dump(addr, count) do {} while (0)
134#define dump_object(__o) do {} while (0)
135#define dump_object_ptr(__o) do {} while (0)
136#endif
137
138/* swap an endianness of 32-bit word */
139#define bswap32(N) ({ \
140 __typeof__(N) n = (N); \
141 ((n & 0x000000FF) << 24) | \
142 ((n & 0x0000FF00) << 8) | \
143 ((n & 0x00FF0000) >> 8) | \
144 ((n & 0xFF000000) >> 24); })
145
146#if CONFIG_TRACE
147/* dump up to 4 32-bit words into trace starting in ptr, idx is incremented inside
148 * unconditionally swaps endianness of data
149 * todo: use cpu_to_endianness so trace data will be independent of platform
150 */
151#define dump_hex(ptr, idx, len) \
152 do { \
153 __typeof__(idx) __i = (idx); \
154 __typeof__(ptr) __p = (ptr) + __i; \
155 __typeof__(idx) __l = (len) - __i; \
156 __typeof__(idx) __n = __l > 4 ? 4 : __l; \
157 if (__n == 4) { \
158 comp_info(dev, "%08x%08x%08x%08x", bswap32(__p[0]), bswap32(__p[1]), \
159 bswap32(__p[2]), bswap32(__p[3])); \
160 } else if (__n == 3) { \
161 comp_info(dev, "%08x%08x%08x", bswap32(__p[0]), bswap32(__p[1]), \
162 bswap32(__p[2])); \
163 } else if (__n == 2) { \
164 comp_info(dev, "%08x%08x", bswap32(__p[0]), bswap32(__p[1])); \
165 } else if (__n == 1) { \
166 comp_info(dev, "%08x", bswap32(__p[0])); \
167 } \
168 idx += __n; \
169 } while (0)
170#else
171
172#define dump_hex() do {} while (0)
173
174#endif
175
176#endif /* __SOF_DEBUG_DEBUG_H__ */
RTOS data and instruction cache invalidation and writeback helpers.
CPU header file.
IPC definitions.
Sound Open Firmware global runtime context.
Host-DSP IPC trace DMA configuration, filtering, and panic descriptors.