Skip to content

Commit 210ddc3

Browse files
committed
ASoC: SOF: debug: List the loaded topology files in fw_profile/tplg_name
The fw_profile/tplg_name debugfs file exposes the topology file name selected for the platform. When function topologies are used, the selected name is a placeholder (sof-<platform>-dummy.tplg) which does not tell which topology files have actually been loaded. Replace the static name with a list of the loaded topology files, one per line, set by snd_sof_load_topology() after a successful load and cleared again when the loading fails or when the topology is removed in sof_pcm_remove(). The topology path prefix is dropped from the names as it is exposed separately via fw_profile/tplg_path. The file is backed by a seq_file reader instead of debugfs_create_str() so that the list can be replaced under a mutex without racing with concurrent readers. While no topology is loaded the selected topology name is shown. For monolithic topologies the content of the file is unchanged. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 43442ea commit 210ddc3

5 files changed

Lines changed: 81 additions & 3 deletions

File tree

‎sound/soc/sof/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
699699
mutex_init(&sdev->ipc_client_mutex);
700700
mutex_init(&sdev->client_event_handler_mutex);
701701
mutex_init(&sdev->dsp_fw_boot_mutex);
702+
mutex_init(&sdev->loaded_tplg_names_mutex);
702703

703704
/* set default timeouts if none provided */
704705
if (plat_data->desc->ipc_timeout == 0)

‎sound/soc/sof/debug.c‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/debugfs.h>
1515
#include <linux/io.h>
1616
#include <linux/pm_runtime.h>
17+
#include <linux/seq_file.h>
1718
#include <sound/sof/ext_manifest.h>
1819
#include <sound/sof/debug.h>
1920
#include "sof-priv.h"
@@ -313,6 +314,28 @@ int snd_sof_dbg_memory_info_init(struct snd_sof_dev *sdev)
313314
}
314315
EXPORT_SYMBOL_GPL(snd_sof_dbg_memory_info_init);
315316

317+
static int sof_dbg_tplg_name_show(struct seq_file *m, void *v)
318+
{
319+
struct snd_sof_dev *sdev = m->private;
320+
321+
/* fall back to the selected topology name while no topology is loaded */
322+
mutex_lock(&sdev->loaded_tplg_names_mutex);
323+
seq_printf(m, "%s\n", sdev->loaded_tplg_names ?: sdev->pdata->tplg_filename);
324+
mutex_unlock(&sdev->loaded_tplg_names_mutex);
325+
326+
return 0;
327+
}
328+
DEFINE_SHOW_ATTRIBUTE(sof_dbg_tplg_name);
329+
330+
/* Takes ownership of the devm allocated tplg_names, NULL clears the list */
331+
void sof_debug_set_tplg_name(struct snd_sof_dev *sdev, char *tplg_names)
332+
{
333+
mutex_lock(&sdev->loaded_tplg_names_mutex);
334+
devm_kfree(sdev->dev, sdev->loaded_tplg_names);
335+
sdev->loaded_tplg_names = tplg_names;
336+
mutex_unlock(&sdev->loaded_tplg_names_mutex);
337+
}
338+
316339
int snd_sof_dbg_init(struct snd_sof_dev *sdev)
317340
{
318341
const struct snd_sof_dsp_ops *ops = sof_ops(sdev);
@@ -355,8 +378,8 @@ int snd_sof_dbg_init(struct snd_sof_dev *sdev)
355378
(char **)&plat_data->tplg_filename_prefix);
356379
debugfs_create_str("fw_name", 0444, fw_profile,
357380
(char **)&plat_data->fw_filename);
358-
debugfs_create_str("tplg_name", 0444, fw_profile,
359-
(char **)&plat_data->tplg_filename);
381+
debugfs_create_file("tplg_name", 0444, fw_profile, sdev,
382+
&sof_dbg_tplg_name_fops);
360383
debugfs_create_u32("ipc_type", 0444, fw_profile,
361384
(u32 *)&plat_data->ipc_type);
362385

‎sound/soc/sof/pcm.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,11 @@ static int sof_pcm_probe(struct snd_soc_component *component)
808808

809809
static void sof_pcm_remove(struct snd_soc_component *component)
810810
{
811+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
812+
811813
/* remove topology */
812814
snd_soc_tplg_component_remove(component);
815+
sof_debug_set_tplg_name(sdev, NULL);
813816
}
814817

815818
static int sof_pcm_ack(struct snd_soc_component *component,

‎sound/soc/sof/sof-priv.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ struct snd_sof_dev {
656656
struct snd_soc_component *component;
657657
u32 enabled_cores_mask; /* keep track of enabled cores */
658658
bool led_present;
659+
/* newline separated list of the loaded topology files for debugfs */
660+
char *loaded_tplg_names;
661+
struct mutex loaded_tplg_names_mutex; /* protects loaded_tplg_names */
659662

660663
/* FW configuration */
661664
struct sof_ipc_window *info_window;
@@ -798,6 +801,7 @@ static inline void snd_sof_ipc_process_reply(struct snd_sof_dev *sdev, u32 msg_i
798801
*/
799802
int snd_sof_dbg_init(struct snd_sof_dev *sdev);
800803
void snd_sof_free_debug(struct snd_sof_dev *sdev);
804+
void sof_debug_set_tplg_name(struct snd_sof_dev *sdev, char *tplg_names);
801805
int snd_sof_debugfs_buf_item(struct snd_sof_dev *sdev,
802806
void *base, size_t size,
803807
const char *name, mode_t mode);

‎sound/soc/sof/topology.c‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2509,11 +2509,40 @@ static const struct snd_soc_tplg_ops sof_dspless_tplg_ops = {
25092509
.bytes_ext_ops_count = ARRAY_SIZE(sof_dspless_bytes_ext_ops),
25102510
};
25112511

2512+
/*
2513+
* Append the name of a loaded topology file to the list exposed via debugfs.
2514+
* The topology path prefix is dropped as it is exposed separately.
2515+
*/
2516+
static int sof_tplg_names_append(struct snd_sof_dev *sdev, char **names,
2517+
const char *file)
2518+
{
2519+
const char *prefix = sdev->pdata->tplg_filename_prefix;
2520+
size_t prefix_len = strlen(prefix);
2521+
char *new_names;
2522+
2523+
if (!strncmp(file, prefix, prefix_len) && file[prefix_len] == '/')
2524+
file += prefix_len + 1;
2525+
2526+
if (*names)
2527+
new_names = devm_kasprintf(sdev->dev, GFP_KERNEL, "%s\n%s",
2528+
*names, file);
2529+
else
2530+
new_names = devm_kstrdup(sdev->dev, file, GFP_KERNEL);
2531+
if (!new_names)
2532+
return -ENOMEM;
2533+
2534+
devm_kfree(sdev->dev, *names);
2535+
*names = new_names;
2536+
2537+
return 0;
2538+
}
2539+
25122540
int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
25132541
{
25142542
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
25152543
struct snd_sof_pdata *sof_pdata = sdev->pdata;
25162544
const char *tplg_filename_prefix = sof_pdata->tplg_filename_prefix;
2545+
char *tplg_names = NULL;
25172546
int tplg_cnt = 0;
25182547
int ret;
25192548
int i;
@@ -2590,6 +2619,10 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
25902619
tplg_files[i], ret);
25912620
goto out;
25922621
}
2622+
2623+
ret = sof_tplg_names_append(sdev, &tplg_names, tplg_files[i]);
2624+
if (ret < 0)
2625+
goto out;
25932626
}
25942627

25952628
/* Loading user defined topologies */
@@ -2632,12 +2665,24 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
26322665
*/
26332666
goto out;
26342667
}
2668+
2669+
ret = sof_tplg_names_append(sdev, &tplg_names, feature_topology);
2670+
if (ret < 0)
2671+
goto out;
26352672
}
26362673

26372674
/* call sof_complete when topologies are loaded successfully */
26382675
ret = sof_complete(scomp);
2676+
if (ret < 0)
2677+
goto out;
2678+
2679+
/* Update the list of loaded topologies exposed via debugfs */
2680+
sof_debug_set_tplg_name(sdev, tplg_names);
2681+
tplg_names = NULL;
26392682

26402683
out:
2684+
devm_kfree(sdev->dev, tplg_names);
2685+
26412686
if (ret >= 0 && sdev->led_present)
26422687
ret = snd_ctl_led_request();
26432688

@@ -2646,8 +2691,10 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
26462691
* component probe fails. If snd_soc_tplg_component_load() failed, it
26472692
* has removed it already and this call is a no-op.
26482693
*/
2649-
if (ret < 0)
2694+
if (ret < 0) {
26502695
snd_soc_tplg_component_remove(scomp);
2696+
sof_debug_set_tplg_name(sdev, NULL);
2697+
}
26512698

26522699
return ret;
26532700
}

0 commit comments

Comments
 (0)