xref: /linux/sound/soc/intel/avs/debug.h (revision 1bd470f27f283cfcfd5c94705a2fabbe5f1e4e9f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright(c) 2024-2025 Intel Corporation
4  *
5  * Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6  *          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7  */
8 
9 #ifndef __SOUND_SOC_INTEL_AVS_DEBUG_H
10 #define __SOUND_SOC_INTEL_AVS_DEBUG_H
11 
12 #include <linux/cleanup.h>
13 #include "messages.h"
14 #include "registers.h"
15 
16 struct avs_dev;
17 
18 #define avs_log_buffer_size(adev) \
19 	((adev)->fw_cfg.trace_log_bytes / (adev)->hw_cfg.dsp_cores)
20 
21 #define avs_log_buffer_addr(adev, core) \
22 ({										\
23 	s32 __offset = avs_dsp_op(adev, log_buffer_offset, core);		\
24 	(__offset < 0) ? NULL :							\
25 			 (avs_sram_addr(adev, AVS_DEBUG_WINDOW) + __offset);	\
26 })
27 
28 static inline int avs_log_buffer_status_locked(struct avs_dev *adev, union avs_notify_msg *msg)
29 {
30 	guard(spinlock_irqsave)(&adev->trace_lock);
31 
32 	return avs_dsp_op(adev, log_buffer_status, msg);
33 }
34 
35 struct avs_apl_log_buffer_layout {
36 	u32 read_ptr;
37 	u32 write_ptr;
38 	u8 buffer[];
39 } __packed;
40 static_assert(sizeof(struct avs_apl_log_buffer_layout) == 8);
41 
42 #define avs_apl_log_payload_size(adev) \
43 	(avs_log_buffer_size(adev) - sizeof(struct avs_apl_log_buffer_layout))
44 
45 #define avs_apl_log_payload_addr(addr) \
46 	(addr + sizeof(struct avs_apl_log_buffer_layout))
47 
48 #ifdef CONFIG_DEBUG_FS
49 int avs_register_probe_component(struct avs_dev *adev, const char *name);
50 
51 #define AVS_SET_ENABLE_LOGS_OP(name) \
52 	.enable_logs = avs_##name##_enable_logs
53 
54 bool avs_logging_fw(struct avs_dev *adev);
55 void avs_dump_fw_log(struct avs_dev *adev, const void __iomem *src, unsigned int len);
56 void avs_dump_fw_log_wakeup(struct avs_dev *adev, const void __iomem *src, unsigned int len);
57 
58 void avs_debugfs_init(struct avs_dev *adev);
59 void avs_debugfs_exit(struct avs_dev *adev);
60 
61 #else
62 static inline int avs_register_probe_component(struct avs_dev *adev, const char *name)
63 {
64 	return -EOPNOTSUPP;
65 }
66 
67 #define AVS_SET_ENABLE_LOGS_OP(name)
68 
69 static inline bool avs_logging_fw(struct avs_dev *adev)
70 {
71 	return false;
72 }
73 
74 static inline void avs_dump_fw_log(struct avs_dev *adev, const void __iomem *src, unsigned int len)
75 {
76 }
77 
78 static inline void avs_dump_fw_log_wakeup(struct avs_dev *adev, const void __iomem *src,
79 					  unsigned int len)
80 {
81 }
82 
83 static inline void avs_debugfs_init(struct avs_dev *adev) { }
84 static inline void avs_debugfs_exit(struct avs_dev *adev) { }
85 #endif
86 
87 #endif
88