Skip to content

ASoC: SOF: add SOF_DBG_CHECK_SDW_PERIPHERAL debug flag#5741

Open
bardliao wants to merge 1 commit intothesofproject:topic/sof-devfrom
bardliao:for-sdw-ghost
Open

ASoC: SOF: add SOF_DBG_CHECK_SDW_PERIPHERAL debug flag#5741
bardliao wants to merge 1 commit intothesofproject:topic/sof-devfrom
bardliao:for-sdw-ghost

Conversation

@bardliao
Copy link
Copy Markdown
Collaborator

If the flag is set, the driver waits for and verifies the presence of SoundWire peripherals listed in the ACPI table. This prevents the system from probing non-existent (ghost) SoundWire devices.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SOF debug flag to optionally wait for SoundWire enumeration and filter out “ghost” peripherals listed in ACPI, avoiding machine-driver selection based on non-existent devices.

Changes:

  • Introduces SOF_DBG_CHECK_SDW_PERIPHERAL debug flag.
  • Adds an optional enumeration wait/verification step in hda_sdw_machine_select() before generating ACPI link/ADR structures.
  • Adds a local enumeration timeout constant.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
sound/soc/sof/sof-priv.h Adds a new SOF debug flag definition controlling SoundWire peripheral presence checks.
sound/soc/sof/intel/hda.c Implements the optional wait-for-enumeration logic during SoundWire default machine selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sound/soc/sof/intel/hda.c
Comment thread sound/soc/sof/intel/hda.c Outdated
for (i = 0; i < peripherals->num_peripherals; i++) {
slave = peripherals->array[i];

/* Check is the peripheral is present */
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo/grammar in the new comment: "Check is the peripheral is present" should be "Check if the peripheral is present" (and keep SoundWire capitalization consistent).

Suggested change
/* Check is the peripheral is present */
/* Check if the SoundWire peripheral is present */

Copilot uses AI. Check for mistakes.
Comment thread sound/soc/sof/sof-priv.h Outdated
* DSPLESS_MODE is not set.
* No audio functionality when enabled.
*/
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17) /* Check is Soundwire peripherals are
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar/capitalization in the new flag description: "Check is Soundwire peripherals are" should be "Check if SoundWire peripherals are".

Suggested change
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17) /* Check is Soundwire peripherals are
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17) /* Check if SoundWire peripherals are

Copilot uses AI. Check for mistakes.
Comment thread sound/soc/sof/intel/hda.c Outdated
Comment on lines +1427 to +1435
/* Check is the peripheral is present */
if (sof_debug_check_flag(SOF_DBG_CHECK_SDW_PERIPHERAL) && !slave->dev_num_sticky) {
/* Wait for the peripheral to enumerate */
time = wait_for_completion_timeout(&slave->enumeration_complete,
msecs_to_jiffies(ENUMERATION_TIMEOUT));
if (!time) {
dev_warn(&slave->dev, "SoundWire peripheral is not present\n");
continue;
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new continue when a SoundWire peripheral fails to enumerate can leave a link entry with num_adr == 0 while link_mask still includes that link. Several SoundWire helper paths iterate mach_params->links until num_adr == 0 (null-terminated contract), so an empty entry can prematurely terminate parsing and ignore later valid links/devices. Consider building a present_link_mask first (after the optional wait), allocating links based on that mask (+1 for a terminating entry), and only emitting link entries for links that have at least one present peripheral (and update mach->mach_params.link_mask accordingly).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment thread sound/soc/sof/intel/hda.c Outdated
return adr_dev;
}

#define ENUMERATION_TIMEOUT 3000
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENUMERATION_TIMEOUT is a very generic macro name and doesn’t document the unit. Rename it to something scoped (e.g. SOF_SDW_ENUMERATION_TIMEOUT_MS) and/or add a _MS suffix so it’s clear this value is in milliseconds.

Suggested change
#define ENUMERATION_TIMEOUT 3000
#define SOF_SDW_ENUMERATION_TIMEOUT_MS 3000

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 21, 2026 01:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sound/soc/sof/intel/hda.c Outdated
return adr_dev;
}

#define ENUMERATION_TIMEOUT 3000
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENUMERATION_TIMEOUT is a very generic macro name and the units aren’t obvious at the definition site. Since it’s passed to msecs_to_jiffies(), consider renaming to something like HDA_SDW_ENUMERATION_TIMEOUT_MS (or adding a short comment) to make the units and scope clear and reduce the risk of collisions.

Suggested change
#define ENUMERATION_TIMEOUT 3000
#define ENUMERATION_TIMEOUT 3000 /* milliseconds, used with msecs_to_jiffies() for HDA SoundWire enumeration */

Copilot uses AI. Check for mistakes.
@bardliao bardliao force-pushed the for-sdw-ghost branch 2 times, most recently from c2f293d to 21ea49d Compare April 22, 2026 09:55
Copilot AI review requested due to automatic review settings April 22, 2026 09:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sound/soc/sof/intel/hda.c Outdated
return NULL;

/*
* Recalculate the link_mask as a link will be empty if all peripherals on the link are
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace at the end of this comment line; please remove it to avoid checkpatch warnings.

Suggested change
* Recalculate the link_mask as a link will be empty if all peripherals on the link are
* Recalculate the link_mask as a link will be empty if all peripherals on the link are

Copilot uses AI. Check for mistakes.
Comment thread sound/soc/sof/sof-priv.h
Comment on lines +59 to +61
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17) /* Check if SoundWire peripherals are
* present while selecting machine driver
*/
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new macro definition line is very long due to the inline block comment; consider moving the comment above the #define (or shortening it) to better match kernel style and avoid checkpatch line-length warnings.

Suggested change
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17) /* Check if SoundWire peripherals are
* present while selecting machine driver
*/
/* Check if SoundWire peripherals are present while selecting machine driver */
#define SOF_DBG_CHECK_SDW_PERIPHERAL BIT(17)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This aligned to other DBG flag defines.

Comment thread sound/soc/sof/intel/hda.c
Comment on lines 1419 to +1423
links = devm_kcalloc(sdev->dev, link_num, sizeof(*links), GFP_KERNEL);
if (!links)
return NULL;

/*
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mach_params->links is expected to be terminated by an entry with num_adr == 0 (e.g. asoc_sdw_count_sdw_endpoints()/asoc_sdw_parse_sdw_endpoints() iterate for (adr_link = mach_params->links; adr_link->num_adr; adr_link++)). Here links is allocated with exactly link_num entries, so when all links have at least one enumerated peripheral there is no terminating element and the iteration can read past the end of the allocation. Allocate link_num + 1 entries (zero-initialized) and keep the last one as the terminator (or recompute link_num from the final mask and still add a terminator).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. I will submit another PR to address it.

If the flag is set, the driver waits for and verifies the presence of
SoundWire peripherals listed in the ACPI table. This prevents the system
from probing non-existent (ghost) SoundWire devices.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants