Skip to content

Commit 4b86115

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: Intel: avs: Prepare for firmware tracing
Firmware provides its own debug functionality. While coredump is one of these, traces are the main area of interest. kfifo is enlisted to cache log data that is being pumped to driver through SRAM. Separate DSP operations are declared as actual feature implementation differs between firmware generations. As log gathering involves usage of IPCs, add all necessary: ENABLE_LOGS and SYSTEM_TIME. Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com> Link: https://lore.kernel.org/r/20220516101116.190192-8-cezary.rojewski@intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2f1f570 commit 4b86115

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed

sound/soc/intel/avs/avs.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/device.h>
1313
#include <linux/firmware.h>
14+
#include <linux/kfifo.h>
1415
#include <sound/hda_codec.h>
1516
#include <sound/hda_register.h>
1617
#include <sound/soc-component.h>
@@ -42,6 +43,10 @@ struct avs_dsp_ops {
4243
int (* const load_basefw)(struct avs_dev *, struct firmware *);
4344
int (* const load_lib)(struct avs_dev *, struct firmware *, u32);
4445
int (* const transfer_mods)(struct avs_dev *, bool, struct avs_module_entry *, u32);
46+
int (* const enable_logs)(struct avs_dev *, enum avs_log_enable, u32, u32, unsigned long,
47+
u32 *);
48+
int (* const log_buffer_offset)(struct avs_dev *, u32);
49+
int (* const log_buffer_status)(struct avs_dev *, union avs_notify_msg *);
4550
int (* const coredump)(struct avs_dev *, union avs_notify_msg *);
4651
};
4752

@@ -75,6 +80,16 @@ struct avs_fw_entry {
7580
struct list_head node;
7681
};
7782

83+
struct avs_debug {
84+
struct kfifo trace_fifo;
85+
spinlock_t fifo_lock; /* serialize I/O for trace_fifo */
86+
spinlock_t trace_lock; /* serialize debug window I/O between each LOG_BUFFER_STATUS */
87+
wait_queue_head_t trace_waitq;
88+
u32 aging_timer_period;
89+
u32 fifo_full_timer_period;
90+
u32 logged_resources; /* context dependent: core or library */
91+
};
92+
7893
/*
7994
* struct avs_dev - Intel HD-Audio driver data
8095
*
@@ -115,6 +130,8 @@ struct avs_dev {
115130
struct list_head path_list;
116131
spinlock_t path_list_lock;
117132
struct mutex path_mutex;
133+
134+
struct avs_debug dbg;
118135
};
119136

120137
/* from hda_bus to avs_dev */
@@ -279,4 +296,19 @@ int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned l
279296
unsigned long *tdms);
280297
int avs_hda_platform_register(struct avs_dev *adev, const char *name);
281298

299+
/* Firmware tracing helpers */
300+
301+
unsigned int __kfifo_fromio_locked(struct kfifo *fifo, const void __iomem *src, unsigned int len,
302+
spinlock_t *lock);
303+
304+
#define avs_log_buffer_size(adev) \
305+
((adev)->fw_cfg.trace_log_bytes / (adev)->hw_cfg.dsp_cores)
306+
307+
#define avs_log_buffer_addr(adev, core) \
308+
({ \
309+
s32 __offset = avs_dsp_op(adev, log_buffer_offset, core); \
310+
(__offset < 0) ? NULL : \
311+
(avs_sram_addr(adev, AVS_DEBUG_WINDOW) + __offset); \
312+
})
313+
282314
#endif /* __SOUND_SOC_INTEL_AVS_H */

sound/soc/intel/avs/ipc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static void avs_dsp_process_notification(struct avs_dev *adev, u64 header)
140140
data_size = sizeof(struct avs_notify_res_data);
141141
break;
142142

143+
case AVS_NOTIFY_LOG_BUFFER_STATUS:
143144
case AVS_NOTIFY_EXCEPTION_CAUGHT:
144145
break;
145146

@@ -170,6 +171,10 @@ static void avs_dsp_process_notification(struct avs_dev *adev, u64 header)
170171
complete(&adev->fw_ready);
171172
break;
172173

174+
case AVS_NOTIFY_LOG_BUFFER_STATUS:
175+
avs_dsp_op(adev, log_buffer_status, &msg);
176+
break;
177+
173178
case AVS_NOTIFY_EXCEPTION_CAUGHT:
174179
avs_dsp_exception_caught(adev, &msg);
175180
break;

sound/soc/intel/avs/messages.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,37 @@ int avs_ipc_get_modules_info(struct avs_dev *adev, struct avs_mods_info **info)
677677
return 0;
678678
}
679679

680+
int avs_ipc_set_enable_logs(struct avs_dev *adev, u8 *log_info, size_t size)
681+
{
682+
int ret;
683+
684+
ret = avs_ipc_set_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
685+
AVS_BASEFW_ENABLE_LOGS, log_info, size);
686+
if (ret)
687+
dev_err(adev->dev, "enable logs failed: %d\n", ret);
688+
689+
return ret;
690+
}
691+
692+
int avs_ipc_set_system_time(struct avs_dev *adev)
693+
{
694+
struct avs_sys_time sys_time;
695+
int ret;
696+
u64 us;
697+
698+
/* firmware expects UTC time in micro seconds */
699+
us = ktime_to_us(ktime_get());
700+
sys_time.val_l = us & UINT_MAX;
701+
sys_time.val_u = us >> 32;
702+
703+
ret = avs_ipc_set_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
704+
AVS_BASEFW_SYSTEM_TIME, (u8 *)&sys_time, sizeof(sys_time));
705+
if (ret)
706+
dev_err(adev->dev, "set system time failed: %d\n", ret);
707+
708+
return ret;
709+
}
710+
680711
int avs_ipc_copier_set_sink_format(struct avs_dev *adev, u16 module_id,
681712
u8 instance_id, u32 sink_id,
682713
const struct avs_audio_format *src_fmt,

sound/soc/intel/avs/messages.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ union avs_reply_msg {
186186
enum avs_notify_msg_type {
187187
AVS_NOTIFY_PHRASE_DETECTED = 4,
188188
AVS_NOTIFY_RESOURCE_EVENT = 5,
189+
AVS_NOTIFY_LOG_BUFFER_STATUS = 6,
189190
AVS_NOTIFY_FW_READY = 8,
190191
AVS_NOTIFY_EXCEPTION_CAUGHT = 10,
191192
AVS_NOTIFY_MODULE_EVENT = 12,
@@ -203,6 +204,10 @@ union avs_notify_msg {
203204
u32 msg_direction:1;
204205
u32 msg_target:1;
205206
};
207+
struct {
208+
u16 rsvd:12;
209+
u16 core:4;
210+
} log;
206211
};
207212
union {
208213
u32 val;
@@ -329,12 +334,21 @@ int avs_ipc_set_d0ix(struct avs_dev *adev, bool enable_pg, bool streaming);
329334
#define AVS_BASEFW_INST_ID 0
330335

331336
enum avs_basefw_runtime_param {
337+
AVS_BASEFW_ENABLE_LOGS = 6,
332338
AVS_BASEFW_FIRMWARE_CONFIG = 7,
333339
AVS_BASEFW_HARDWARE_CONFIG = 8,
334340
AVS_BASEFW_MODULES_INFO = 9,
335341
AVS_BASEFW_LIBRARIES_INFO = 16,
342+
AVS_BASEFW_SYSTEM_TIME = 20,
343+
};
344+
345+
enum avs_log_enable {
346+
AVS_LOG_DISABLE = 0,
347+
AVS_LOG_ENABLE = 1
336348
};
337349

350+
int avs_ipc_set_enable_logs(struct avs_dev *adev, u8 *log_info, size_t size);
351+
338352
struct avs_fw_version {
339353
u16 major;
340354
u16 minor;
@@ -502,6 +516,13 @@ static inline bool avs_module_entry_is_loaded(struct avs_module_entry *mentry)
502516

503517
int avs_ipc_get_modules_info(struct avs_dev *adev, struct avs_mods_info **info);
504518

519+
struct avs_sys_time {
520+
u32 val_l;
521+
u32 val_u;
522+
} __packed;
523+
524+
int avs_ipc_set_system_time(struct avs_dev *adev);
525+
505526
/* Module configuration */
506527

507528
#define AVS_MIXIN_MOD_UUID \

sound/soc/intel/avs/registers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#define AVS_UPLINK_WINDOW AVS_FW_REGS_WINDOW
5959
/* HOST -> DSP communication window */
6060
#define AVS_DOWNLINK_WINDOW 1
61+
#define AVS_DEBUG_WINDOW 2
6162

6263
/* registry I/O helpers */
6364
#define avs_sram_offset(adev, window_idx) \

sound/soc/intel/avs/utils.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#include <linux/firmware.h>
10+
#include <linux/kfifo.h>
1011
#include <linux/slab.h>
1112
#include "avs.h"
1213
#include "messages.h"
@@ -299,3 +300,25 @@ void avs_release_firmwares(struct avs_dev *adev)
299300
kfree(entry);
300301
}
301302
}
303+
304+
unsigned int __kfifo_fromio_locked(struct kfifo *fifo, const void __iomem *src, unsigned int len,
305+
spinlock_t *lock)
306+
{
307+
struct __kfifo *__fifo = &fifo->kfifo;
308+
unsigned long flags;
309+
unsigned int l, off;
310+
311+
spin_lock_irqsave(lock, flags);
312+
len = min(len, kfifo_avail(fifo));
313+
off = __fifo->in & __fifo->mask;
314+
l = min(len, kfifo_size(fifo) - off);
315+
316+
memcpy_fromio(__fifo->data + off, src, l);
317+
memcpy_fromio(__fifo->data, src + l, len - l);
318+
/* Make sure data copied from SRAM is visible to all CPUs. */
319+
smp_mb();
320+
__fifo->in += len;
321+
spin_unlock_irqrestore(lock, flags);
322+
323+
return len;
324+
}

0 commit comments

Comments
 (0)