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
9#ifndef __SOF_DEBUG_DEBUG_H__
10#define __SOF_DEBUG_DEBUG_H__
11
12#include <sof/common.h>
13#include <rtos/panic.h>
14#include <rtos/cache.h>
15#include <sof/lib/cpu.h>
16#include <rtos/sof.h>
17#include <rtos/string.h>
18#include <ipc/info.h>
19#include <ipc/trace.h>
20
21#include <stddef.h>
22#include <stdint.h>
23
24#ifndef RELATIVE_FILE
25#error "This file requires RELATIVE_FILE to be defined. " \
26 "Add it to CMake's target with sof_append_relative_path_definitions."
27#endif
28
29#if CONFIG_DEBUG
30
31#include <sof/lib/mailbox.h>
32
33#define DEBUG_SET_FW_READY_FLAGS \
34( \
35 SOF_IPC_INFO_BUILD | \
36 (IS_ENABLED(CONFIG_GDB_DEBUG) ? SOF_IPC_INFO_GDB : 0) \
37)
38
39/* dump file and line to start of mailbox or shared memory */
40#define dbg() \
41 do { \
42 volatile uint32_t *__m = (uint32_t *)mailbox_get_debug_base(); \
43 *(__m++) = (RELATIVE_FILE[0] << 24) + \
44 (RELATIVE_FILE[1] << 16) + \
45 (RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
46 *(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
47 (__func__[2] << 8) + (__func__[3]); \
48 *__m = __LINE__; \
49 } while (0)
50
51/* dump file and line to offset in mailbox or shared memory */
52#define dbg_at(__x) \
53 do { \
54 volatile uint32_t *__m = \
55 (uint32_t *)mailbox_get_debug_base() + __x; \
56 *(__m++) = (RELATIVE_FILE[0] << 24) + \
57 (RELATIVE_FILE[1] << 16) + \
58 (RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
59 *(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
60 (__func__[2] << 8) + (__func__[3]); \
61 *__m = __LINE__; \
62 } while (0)
63
64/* dump value to start of mailbox or shared memory */
65#define dbg_val(__v) \
66 do { \
67 volatile uint32_t *__m = \
68 (volatile uint32_t *)mailbox_get_debug_base(); \
69 *__m = __v; \
70 } while (0)
71
72/* dump value to offset in mailbox or shared memory */
73#define dbg_val_at(__v, __x) \
74 do { \
75 volatile uint32_t *__m = \
76 (volatile uint32_t *)mailbox_get_debug_base() + __x; \
77 *__m = __v; \
78 } while (0)
79
80/* dump data area at addr and size count to start of mailbox or shared memory */
81#define dump(addr, count) \
82 do { \
83 volatile uint32_t *__m = (uint32_t *)mailbox_get_debug_base(); \
84 volatile uint32_t *__a = (uint32_t *)addr; \
85 volatile int __c = count; \
86 while (__c--) \
87 *(__m++) = *(__a++); \
88 } while (0)
89
90/* dump data area at addr and size count at mailbox offset or shared memory */
91#define dump_at(addr, count, offset) \
92 do { \
93 volatile uint32_t *__m = \
94 (uint32_t *)mailbox_get_debug_base() + offset; \
95 volatile uint32_t *__a = (uint32_t *)addr; \
96 volatile int __c = count; \
97 while (__c--) \
98 *(__m++) = *(__a++); \
99 } while (0)
100
101/* dump object to start of mailbox */
102#define dump_object(__o) \
103 do { \
104 dbg(); \
105 dump(&__o, sizeof(__o) >> 2); \
106 } while (0)
107
108/* dump object from pointer at start of mailbox */
109#define dump_object_ptr(__o) \
110 do { \
111 dbg(); \
112 dump(__o, sizeof(*(__o)) >> 2); \
113 } while (0)
114
115#define dump_object_ptr_at(__o, __at) \
116 do { \
117 dbg(); \
118 dump_at(__o, sizeof(*(__o)) >> 2, __at);\
119 } while (0)
120
121#else
122
123#define DEBUG_SET_FW_READY_FLAGS \
124( \
125 (IS_ENABLED(CONFIG_GDB_DEBUG) ? SOF_IPC_INFO_GDB : 0) \
126)
127
128#define dbg() do {} while (0)
129#define dbg_at(__x) do {} while (0)
130#define dbg_val(__v) do {} while (0)
131#define dbg_val_at(__v, __x) do {} while (0)
132#define dump(addr, count) do {} while (0)
133#define dump_object(__o) do {} while (0)
134#define dump_object_ptr(__o) do {} while (0)
135#endif
136
137/* swap an endianness of 32-bit word */
138#define bswap32(N) ({ \
139 __typeof__(N) n = (N); \
140 ((n & 0x000000FF) << 24) | \
141 ((n & 0x0000FF00) << 8) | \
142 ((n & 0x00FF0000) >> 8) | \
143 ((n & 0xFF000000) >> 24); })
144
145#if CONFIG_TRACE
146/* dump up to 4 32-bit words into trace starting in ptr, idx is incremented inside
147 * unconditionally swaps endianness of data
148 * todo: use cpu_to_endianness so trace data will be independent of platform
149 */
150#define dump_hex(ptr, idx, len) \
151 do { \
152 __typeof__(idx) __i = (idx); \
153 __typeof__(ptr) __p = (ptr) + __i; \
154 __typeof__(idx) __l = (len) - __i; \
155 __typeof__(idx) __n = __l > 4 ? 4 : __l; \
156 if (__n == 4) { \
157 comp_info(dev, "%08x%08x%08x%08x", bswap32(__p[0]), bswap32(__p[1]), \
158 bswap32(__p[2]), bswap32(__p[3])); \
159 } else if (__n == 3) { \
160 comp_info(dev, "%08x%08x%08x", bswap32(__p[0]), bswap32(__p[1]), \
161 bswap32(__p[2])); \
162 } else if (__n == 2) { \
163 comp_info(dev, "%08x%08x", bswap32(__p[0]), bswap32(__p[1])); \
164 } else if (__n == 1) { \
165 comp_info(dev, "%08x", bswap32(__p[0])); \
166 } \
167 idx += __n; \
168 } while (0)
169#else
170
171#define dump_hex() do {} while (0)
172
173#endif
174
175#endif /* __SOF_DEBUG_DEBUG_H__ */
CPU header file.
IPC definitions.
IPC definitions.