Sound Open Firmware
Loading...
Searching...
No Matches
trace.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 * Artur Kloniecki <arturx.kloniecki@linux.intel.com>
8 * Karol Trzcinski <karolx.trzcinski@linux.intel.com>
9 */
10
11#ifndef __SOF_TRACE_TRACE_H__
12#define __SOF_TRACE_TRACE_H__
13
14#ifndef RELATIVE_FILE
15#error "This file requires RELATIVE_FILE to be defined. " \
16 "Add it to CMake's target with sof_append_relative_path_definitions."
17#endif
18
19#include <rtos/sof.h>
20#include <stdbool.h>
21#include <stdint.h>
22#include <string.h>
23
24#ifdef __ZEPHYR__
25#include <zephyr/kernel.h>
26#include <zephyr/logging/log.h>
27#endif
28
29#if !CONFIG_LIBRARY
30#include <platform/trace/trace.h>
31#endif
32#include <sof/common.h>
33
34#if CONFIG_ZEPHYR_LOG || CONFIG_LIBRARY || CONFIG_ARCH_POSIX_LIBFUZZER
35#include <sof/lib/uuid.h>
36#endif
37#include <sof/trace/preproc.h>
39
40/* Silences compiler warnings about unused variables */
41#define trace_unused(class, ctx, id_1, id_2, format, ...) \
42 SOF_TRACE_UNUSED(ctx, id_1, id_2, ##__VA_ARGS__)
43
44#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG)
45
46#define tr_err(ctx, fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
47#define tr_warn(ctx, fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__)
48#define tr_info(ctx, fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
49#define tr_dbg(ctx, fmt, ...) LOG_DBG(fmt, ##__VA_ARGS__)
50
51#elif CONFIG_TRACE
52
53#include "trace-soflogger.h"
54
55#else
56
57#define tr_err(ctx, fmt, ...) \
58 trace_unused(_TRACE_INV_CLASS, ctx, _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
59#define tr_warn(ctx, fmt, ...) \
60 trace_unused(_TRACE_INV_CLASS, ctx, _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
61#define tr_info(ctx, fmt, ...) \
62 trace_unused(_TRACE_INV_CLASS, ctx, _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
63#define tr_dbg(ctx, fmt, ...) \
64 trace_unused(_TRACE_INV_CLASS, ctx, _TRACE_INV_ID, _TRACE_INV_ID, fmt, ##__VA_ARGS__)
65
66#endif
67
68#ifndef CONFIG_TRACE
69
70struct trace_filter;
71struct sof;
72
73#define trace_event_with_ids(class, ctx, id_1, id_2, format, ...) \
74 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
75#define trace_event_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
76 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
77
78#define trace_warn_with_ids(class, ctx, id_1, id_2, format, ...) \
79 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
80#define trace_warn_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
81 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
82
83#define tracev_event_with_ids(class, ctx, id_1, id_2, format, ...) \
84 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
85
86#define trace_point(x) do {} while (0)
87
88static inline void trace_flush_dma_to_mbox(void) { }
89static inline void trace_on(void) { }
90static inline void trace_off(void) { }
91static inline void trace_init(struct sof *sof) { }
92static inline int trace_filter_update(const struct trace_filter *filter)
93 { return 0; }
94
95#define trace_error_with_ids(class, ctx, id_1, id_2, format, ...) \
96 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
97#define trace_error_atomic_with_ids(class, ctx, id_1, id_2, format, ...) \
98 trace_unused(class, ctx, id_1, id_2, format, ##__VA_ARGS__)
99
100#define trace_dev_err(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
101 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
102 get_id_m(dev), get_subid_m(dev), \
103 fmt, ##__VA_ARGS__)
104#define trace_dev_warn(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
105 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
106 get_id_m(dev), get_subid_m(dev), \
107 fmt, ##__VA_ARGS__)
108#define trace_dev_info(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
109 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
110 get_id_m(dev), get_subid_m(dev), \
111 fmt, ##__VA_ARGS__)
112#define trace_dev_dbg(get_ctx_m, get_id_m, get_subid_m, dev, fmt, ...) \
113 trace_event_with_ids(_TRACE_INV_CLASS, get_ctx_m(dev), \
114 get_id_m(dev), get_subid_m(dev), \
115 fmt, ##__VA_ARGS__)
116
117static inline void mtrace_printf(int log_level, const char *format_str, ...)
118{
119};
120
121#endif /* !CONFIG_TRACE */
122
124#define _TRACE_INV_ID -1
125
129#define _TRACE_INV_CLASS TRACE_CLASS_DEPRECATED
130
134struct sof_uuid_entry;
135struct tr_ctx {
136 const struct sof_uuid_entry *uuid_p;
137 uint32_t level;
138};
139
140#if defined(UNIT_TEST) || !defined(CONFIG_TRACE)
141#define TRACE_CONTEXT_SECTION
142#else
143#define TRACE_CONTEXT_SECTION __section(".trace_ctx")
144#endif
145
152#define DECLARE_TR_CTX(ctx_name, uuid, default_log_level) \
153 struct tr_ctx ctx_name TRACE_CONTEXT_SECTION = { \
154 .uuid_p = uuid, \
155 .level = default_log_level, \
156 }
157
158/* Only define these two macros for XTOS to avoid the collision with
159 * zephyr/include/zephyr/logging/log.h
160 */
161#ifndef __ZEPHYR__
162#define LOG_MODULE_REGISTER(ctx, level)
163#define LOG_MODULE_DECLARE(ctx, level)
164#endif
165
166#endif /* __SOF_TRACE_TRACE_H__ */
Connects UUID with component description.
Definition uuid.h:77
General firmware context.
Definition sof.h:44
Definition trace.h:135
uint32_t level
Default log level.
Definition trace.h:137
const struct sof_uuid_entry * uuid_p
UUID pointer, use SOF_UUID() to init.
Definition trace.h:136
Definition trace-soflogger.h:21
void trace_flush_dma_to_mbox(void)
void trace_init(struct sof *sof)
int trace_filter_update(const struct trace_filter *elem)
void trace_off(void)
#define mtrace_printf(log_level, format_str,...)
Direct, low-level access to mbox / shared memory logging when DMA tracing is either not initialized y...
Definition trace-soflogger.h:363
void trace_on(void)