ASoC/soundwire: AMD ACP6x (Rembrandt) SoundWire speaker support
Subsystems (4)
cover ASoC/soundwire: AMD ACP6x (Rembrandt) SoundWire speaker support
The HP Dragonfly Pro ONE (AMD Rembrandt, ACP PCI revision 0x60) has no working internal speakers under Linux. Its speakers are two Realtek RT1316 SDCA amplifiers on SoundWire link 0 of the ACP SoundWire controller:
\_SB.PCI0.GP17.ACP.SDWC.SLV0.AF04 (_ADR 0x000030025D131601) \_SB.PCI0.GP17.ACP.SDWC.SLV1.AF04 (_ADR 0x000031025D131601)
-> manufacturer 0x025D (Realtek), part 0x1316 (RT1316)
-> link 0, unique id 0/1, aggregated as one stereo "Speaker" endpoint
None of the in-tree AMD ACP drivers can drive these amplifiers:
* snd_pci_acp6x (sound/soc/amd/yc) is the only driver that accepts the ACP6x revision (0x60). It implements the PDM/DMIC path only, so the machine results in a capture-only card (pcmC1D0c) and the speakers never appear.
* snd-pci-ps (sound/soc/amd/ps, ACP6.3/7.x) has the SoundWire manager,
SDW DMA and machine plumbing, but rejects revision 0x60.
* drivers/soundwire/amd_manager.c only knows the ACP6.3 and ACP7.x register maps.
* sound/soc/amd/acp/amd-sdw-acpi.c only reads the modern "mipi-sdw-manager-list" property; Rembrandt firmware uses the legacy "mipi-sdw-master-list" name.
This series makes the ACP6x SoundWire path usable and routes this board through it:
1-2 accept the ACP6x PCI revisions in the SoundWire manager driver
3-4 accept them in the Pink Sardine (ps) platform header and SDW DMA
5 add an ACP6x RT1316 machine table
6 add a FLAG_AMD_LEGACY_SDW DMI entry for board 8A7F so that
snd_pci_acp6x releases the device to snd-pci-ps
7 teach snd-pci-ps to probe the ACP6x SoundWire (and integrated PDM)
hardware
8 teach the generic amd_sdw machine driver about ACP6x
9 accept the legacy "mipi-sdw-master-list" property
10 harden the ACP interrupt path (fixes a boot panic found in testing: the IRQ handler runs before the platform devices exist)
11 restore the legacy bus clock defaults when firmware omits the
MIPI DisCo clock properties (fixes a -22 SDW probe failure found in testing)
Assumptions that need hardware validation by the reporter:
* The ACP6x SoundWire manager and SDW DMA register blocks are register compatible with ACP6.3 (the series reuses the ACP6.3 register maps and stream/IRQ associations). AMD shares the ACP_SW_* register definitions between ACP6.3 and ACP7.0, which makes this plausible, but it is not verified against a Rembrandt datasheet.
* The ACP6x SDW controller child is the device at _ADR 0x02 under the ACP, and Rembrandt firmware does not describe the PDM controller (DMIC) in ACPI, so the PDM path is enabled unconditionally for ACP6x.
The series has been built and booted on the target machine; the ACP6x SoundWire controller is now probed. The register-map assumptions above still need to be confirmed by actually playing audio.
Corey Smith (11):
soundwire: amd: add ACP6x PCI revision ids
soundwire: amd: support ACP6x SoundWire managers
ASoC: amd: ps: add ACP6x PCI revision ids
ASoC: amd: ps: support ACP6x in the SoundWire DMA driver
ASoC: amd: acp: add ACP6x (Rembrandt) SoundWire machine table
ASoC: amd: acp-config: route HP Dragonfly Pro ONE through the ACP6x
SDW stack
ASoC: amd: ps: probe the ACP6x SoundWire stack
ASoC: amd: acp: add ACP6x SoundWire quirks and machine support
soundwire: amd: accept the legacy mipi-sdw-master-list property
ASoC: amd: ps: harden the ACP interrupt path for ACP6x
soundwire: amd: provide defaults for the bus clock properties
drivers/soundwire/amd_manager.c | 33 +++++++ include/linux/soundwire/sdw_amd.h | 2 + sound/soc/amd/acp-config.c | 19 +++++ sound/soc/amd/acp/Makefile | 2 +- sound/soc/amd/acp/acp-sdw-legacy-mach.c | 20 +++++ sound/soc/amd/acp/amd-rmb-acpi-match.c | 63 ++++++++++++++++ sound/soc/amd/acp/amd-sdw-acpi.c | 15 +++- sound/soc/amd/acp/soc_amd_sdw_common.h | 2 + sound/soc/amd/mach-config.h | 7 ++ sound/soc/amd/ps/acp63.h | 5 ++ sound/soc/amd/ps/pci-ps.c | 129 ++++++++++++++++++++++++-------- sound/soc/amd/ps/ps-sdw-dma.c | 12 ++- 12 files changed, 273 insertions(+), 36 deletions(-) create mode 100644 sound/soc/amd/acp/amd-rmb-acpi-match.c
PATCH 1/11 soundwire: amd: add ACP6x PCI revision ids
Add the PCI revision ids for the SoundWire-capable ACP6x (Rembrandt) audio co-processor: 0x60 (ACP6x) and 0x6f (ACP6xR).
--- include/linux/soundwire/sdw_amd.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/soundwire/sdw_amd.h +2 -0
@@ -27,6 +27,8 @@#define ACP_SDW0 0#define ACP_SDW1 1#define AMD_SDW_MAX_MANAGER_COUNT 2 +#define ACP6X_PCI_REV_ID 0x60 +#define ACP6XR_PCI_REV_ID 0x6f#define ACP63_PCI_REV_ID 0x63#define ACP70_PCI_REV_ID 0x70#define ACP71_PCI_REV_ID 0x71
PATCH 2/11 soundwire: amd: support ACP6x SoundWire managers
In reply to Corey SmithRembrandt (ACP6x) uses the same SoundWire manager layout as ACP6.3:
the SDW0/SDW1 data-port register maps and the TX/RX port counts are identical. Accept the ACP6x PCI revisions and reuse the ACP6.3 register maps and port counts.
This assumes the ACP6x SoundWire block is register compatible with ACP6.3 and needs to be validated on hardware.
--- drivers/soundwire/amd_manager.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/soundwire/amd_manager.c +8 -0
@@ -559,6 +559,8 @@ static int amd_sdw_port_params(struct sdw_bus *bus, struct sdw_port_params *p_padev_dbg (amd_manager->dev,"p_params->num:0x%x\n" , p_params->num);switch (amd_manager->acp_rev) { +case ACP6X_PCI_REV_ID : +case ACP6XR_PCI_REV_ID :case ACP63_PCI_REV_ID :switch (amd_manager->instance) {case ACP_SDW0 :
@@ -602,6 +604,8 @@ static int amd_sdw_transport_params(struct sdw_bus *bus,u32 offset_reg, lane_ctrl_ch_en_reg;switch (amd_manager->acp_rev) { +case ACP6X_PCI_REV_ID : +case ACP6XR_PCI_REV_ID :case ACP63_PCI_REV_ID :switch (amd_manager->instance) {case ACP_SDW0 :
@@ -674,6 +678,8 @@ static int amd_sdw_port_enable(struct sdw_bus *bus,u32 lane_ctrl_ch_en_reg;switch (amd_manager->acp_rev) { +case ACP6X_PCI_REV_ID : +case ACP6XR_PCI_REV_ID :case ACP63_PCI_REV_ID :switch (amd_manager->instance) {case ACP_SDW0 :
@@ -1100,6 +1106,8 @@ static int amd_sdw_manager_probe(struct platform_device *pdev) amd_manager->bus.controller_id =0 ;dev_dbg (dev,"acp_rev:0x%x\n" , amd_manager->acp_rev);switch (amd_manager->acp_rev) { +case ACP6X_PCI_REV_ID : +case ACP6XR_PCI_REV_ID :case ACP63_PCI_REV_ID :switch (amd_manager->instance) {case ACP_SDW0 :
PATCH 3/11 ASoC: amd: ps: add ACP6x PCI revision ids
In reply to Corey SmithAdd the ACP6x (Rembrandt) PCI revision ids, the ACP6x register range and the ACPI address of the ACP SoundWire controller child (\_SB.PCI0.GP17.ACP.SDWC, _ADR 0x02) to the ACP6.3/7.x platform header so the Pink Sardine driver can bind to ACP6x as well.
--- sound/soc/amd/ps/acp63.h | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/amd/ps/acp63.h +5 -0
@@ -9,8 +9,12 @@#include <sound/acp63_chip_offset_byte.h> #define ACP_DEVICE_ID 0x15E2 +#define ACP6X_REG_START 0x1240000 +#define ACP6X_REG_END 0x1250200#define ACP63_REG_START 0x1240000#define ACP63_REG_END 0x125C000 +#define ACP6X_PCI_REV 0x60 +#define ACP6XR_PCI_REV 0x6f#define ACP63_PCI_REV 0x63#define ACP70_PCI_REV 0x70#define ACP71_PCI_REV 0x71
@@ -60,6 +64,7 @@#define ACP_DMIC_DEV 2#define ACP63_DMIC_ADDR 2 +#define ACP6X_SDW_ADDR 2#define ACP63_SDW_ADDR 5#define AMD_SDW_MAX_MANAGERS 2
[email protected]
AI reviewRe: [PATCH 3/11] ASoC: amd: ps: add ACP6x PCI revision ids
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ASoC: amd: ps: ACP6X_REG_END truncates SoundWire DMA scratch PTE range --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ASoC: amd: ps: ACP6X_REG_END truncates SoundWire DMA scratch PTE range --
commit ad82886a02e0737dcd97ae5c1b3d4d8287cac193
Author: Corey Smith <[email protected]>
ASoC: amd: ps: add ACP6x PCI revision ids
This commit adds ACP6x (Rembrandt) PCI revision IDs, the ACP6x register range, and the SoundWire controller ACPI address to the Pink Sardine header so the driver can bind to ACP6x devices.
sound/soc/amd/ps/acp63.h line 13
Quoted 10 lines
sound/soc/amd/ps/acp63.h +2
-0@@ -9,8 +9,12 @@#include <sound/acp63_chip_offset_byte.h> #define ACP_DEVICE_ID 0x15E2 +#define ACP6X_REG_START 0x1240000 +#define ACP6X_REG_END 0x1250200
[Severity: Medium]
Should ACP6X_REG_END be 0x125C000 instead of 0x1250200?
Defining ACP6X_REG_END as 0x1250200 (matching the PDM-only Yellow Carp header in sound/soc/amd/yc/acp6x.h) sizes the ACP6x register range to 0x10200 bytes. When snd_acp63_probe() sets adata->reg_range to ACP6X_REG_END - ACP6X_REG_START, create_acp63_platform_devs() creates the IORESOURCE_MEM resource for amd_ps_sdw_dma with a size of 0x10201 bytes, which acp63_sdw_platform_probe() maps via devm_ioremap().
However, SoundWire DMA page table entries in ACP scratch memory start past 0x10200:
sound/soc/amd/ps/acp63.h:
#define SDW0_PTE_OFFSET 0x400
...
#define ACP_SDW_PTE_OFFSET 0x100
#define SDW_PTE_OFFSET(i) (SDW0_PTE_OFFSET + ((i) * 0x600))When acp63_config_dma() in sound/soc/amd/ps/ps-sdw-dma.c programs the SoundWire DMA PTEs during PCM hw_params or resume, it writes to offsets 0x10400 through 0x10B80 past acp_base (since ACP_SCRATCH_REG_0 is 0x10000):
sound/soc/amd/ps/ps-sdw-dma.c:acp63_config_dma() {
...
sdw_dma_pte_offset = SDW_PTE_OFFSET(stream->instance);
val = sdw_dma_pte_offset + (stream_id * ACP_SDW_PTE_OFFSET);
...
for (page_idx = 0; page_idx < stream->num_pages; page_idx++) {
...
writel(low, acp_base + ACP_SCRATCH_REG_0 + val);
high |= BIT(31);
writel(high, acp_base + ACP_SCRATCH_REG_0 + val + 4);
...
}This accesses MMIO offsets beyond the declared resource and devm_ioremap() size. Note that commit 253ce07d2a09 ("ASoC: amd: ps: modify ACP register end address macro") previously updated ACP63_REG_END from 0x1250200 to 0x125C000 for this reason, and sound/soc/sof/amd/pci-rmb.c also defines ACP6x_REG_END as 0x125C000.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/11 ASoC: amd: ps: support ACP6x in the SoundWire DMA driver
In reply to Corey SmithExtend the ACP SoundWire DMA driver to the ACP6x revisions, reusing the ACP6.3 DMA ring-buffer register maps and stream/IRQ associations.
--- sound/soc/amd/ps/ps-sdw-dma.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
sound/soc/amd/ps/ps-sdw-dma.c +11 -1
@@ -247,6 +247,8 @@ static int acp63_configure_sdw_ringbuffer(void __iomem *acp_base, u32 stream_id,u32 sdw_mem_window_offset;switch (acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :switch (manager_instance) {case ACP_SDW0 :
@@ -360,6 +362,8 @@ static int acp63_sdw_dma_hw_params(struct snd_soc_component *component,return -EINVAL ; stream_id = stream->stream_id;switch (sdw_data->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :switch (stream->instance) {case ACP_SDW0 :
@@ -437,6 +441,8 @@ static u64 acp63_sdw_get_byte_count(struct acp_sdw_dma_stream *stream, void __io byte_count.bytescount =0 ;switch (acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :switch (stream->instance) {case ACP_SDW0 :
@@ -518,6 +524,8 @@ static int acp63_sdw_dma_close(struct snd_soc_component *component,if (!stream)return -EINVAL ;switch (sdw_data->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :switch (stream->instance) {case ACP_SDW0 :
@@ -564,6 +572,8 @@ static int acp63_sdw_dma_enable(struct snd_pcm_substream *substream, stream = substream->runtime->private_data; stream_id = stream->stream_id;switch (acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :switch (stream->instance) {case ACP_SDW0 :
@@ -777,7 +787,7 @@ static int acp63_sdw_pcm_resume(struct device *dev)struct sdw_dma_dev_data *sdw_data; sdw_data =dev_get_drvdata (dev); -if (sdw_data->acp_rev ==ACP63_PCI_REV ) +if (sdw_data->acp_rev <ACP70_PCI_REV )return acp63_restore_sdw_dma_config (sdw_data);else return acp70_restore_sdw_dma_config (sdw_data);
PATCH 5/11 ASoC: amd: acp: add ACP6x (Rembrandt) SoundWire machine table
In reply to Corey SmithAdd an ACPI machine table for ACP6x platforms using two RT1316 SDCA speaker amplifiers as an aggregated stereo pair on SoundWire link 0. The HP Dragonfly Pro ONE (board 8A7F) exposes them as _ADR 0x000030025D131601 (left) and 0x000031025D131601 (right).
--- sound/soc/amd/acp/Makefile | 2 +- sound/soc/amd/acp/amd-rmb-acpi-match.c | 63 ++++++++++++++++++++++++++ sound/soc/amd/mach-config.h | 1 + 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 sound/soc/amd/acp/amd-rmb-acpi-match.c
sound/soc/amd/acp/Makefile +1 -1
@@ -23,7 +23,7 @@ snd-acp70-y := acp70.o snd-acp-mach-y := acp-mach-common.o snd-acp-legacy-mach-y := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o snd-acp-sof-mach-y := acp-sof-mach.o -snd-soc-acpi-amd-match-y := amd-acp63-acpi-match.o amd-acp70-acpi-match.o +snd-soc-acpi-amd-match-y := amd-rmb-acpi-match.o amd-acp63-acpi-match.o amd-acp70-acpi-match.o snd-soc-acpi-amd-match-$(CONFIG_SND_SOC_ACPI_AMD_SDCA_QUIRKS) += soc-acpi-amd-sdca-quirks.o snd-acp-sdw-mach-y := acp-sdw-mach-common.o snd-acp-sdw-sof-mach-y += acp-sdw-sof-mach.o
sound/soc/amd/acp/amd-rmb-acpi-match.c new file +63 -0
63 lines not on this page · raw message
sound/soc/amd/mach-config.h +1 -0
@@ -22,6 +22,7 @@extern struct snd_soc_acpi_mach snd_soc_acpi_amd_sof_machines[];extern struct snd_soc_acpi_mach snd_soc_acpi_amd_rmb_sof_machines[];extern struct snd_soc_acpi_mach snd_soc_acpi_amd_vangogh_sof_machines[]; +extern struct snd_soc_acpi_mach snd_soc_acpi_amd_rmb_sdw_machines[];extern struct snd_soc_acpi_mach snd_soc_acpi_amd_acp63_sof_machines[];extern struct snd_soc_acpi_mach snd_soc_acpi_amd_acp63_sdw_machines[];extern struct snd_soc_acpi_mach snd_soc_acpi_amd_acp63_sof_sdw_machines[];
PATCH 6/11 ASoC: amd: acp-config: route HP Dragonfly Pro ONE through the ACP6x SDW stack
In reply to Corey SmithThe HP Dragonfly Pro ONE (DMI board 8A7F) is an AMD Rembrandt (ACP6x) platform whose speakers are two Realtek RT1316 SoundWire amplifiers. The default driver for ACP6x is snd_pci_acp6x, which only implements the PDM/DMIC path, so the speakers never appear.
Add a FLAG_AMD_LEGACY_SDW config flag and a DMI entry selecting it for this board. The flag makes snd_pci_acp6x bail out (it refuses any non-zero flag) so that snd-pci-ps can claim the device instead.
--- sound/soc/amd/acp-config.c | 19 +++++++++++++++++++ sound/soc/amd/mach-config.h | 6 ++++++ 2 files changed, 25 insertions(+)
sound/soc/amd/acp-config.c +19 -0
@@ -251,6 +251,25 @@ static const struct config_entry config_table[] = { {} }, }, + { +/* +* HP Dragonfly Pro ONE (AMD Rembrandt / ACP6x, board 8A7F). +* Speakers are two RT1316 SDCA amplifiers on the ACP SoundWire +* link 0. Use the legacy ACP SoundWire stack rather than the +* DMIC-only snd_pci_acp6x driver. +*/ + .flags = FLAG_AMD_LEGACY_SDW, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "HP"), + DMI_MATCH(DMI_BOARD_NAME, "8A7F"), + }, + }, + {} + }, + }, };static int snd_amd_acp_acpi_find_config (struct pci_dev *pci)
sound/soc/amd/mach-config.h +6 -0
@@ -16,6 +16,12 @@#define FLAG_AMD_SOF_ONLY_DMIC BIT(2)#define FLAG_AMD_LEGACY BIT(3)#define FLAG_AMD_LEGACY_ONLY_DMIC BIT(4) +/* +* Route the platform through the legacy ACP SoundWire stack +* (snd-pci-ps + snd-ps-sdw-dma + amd_sdw machine driver) instead of +* the DMIC-only snd_pci_acp6x driver. +*/ +#define FLAG_AMD_LEGACY_SDW BIT(5)#define ACP_PCI_DEV_ID 0x15E2
PATCH 7/11 ASoC: amd: ps: probe the ACP6x SoundWire stack
In reply to Corey SmithAccept the ACP6x PCI revisions in the Pink Sardine PCI driver when the FLAG_AMD_LEGACY_SDW quirk selected it and wire up the ACP6x specific pieces:
- reuse the ACP6.3 hardware ops (power/reset, DMA IRQ);
- use the ACP6x register range for the platform resources;
- select snd_soc_acpi_amd_rmb_sdw_machines as the machine table;
- probe the SoundWire controller at ACP6X_SDW_ADDR (_ADR 0x02).
Rembrandt firmware does not advertise the integrated PDM (DMIC) controller through "acp-audio-device-type", so enable the PDM path unconditionally for ACP6x, matching the legacy snd_pci_acp6x driver.
--- sound/soc/amd/ps/pci-ps.c | 85 ++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 19 deletions(-)
sound/soc/amd/ps/pci-ps.c +66 -19
@@ -418,27 +418,54 @@ static int get_acp63_device_config(struct pci_dev *pci, struct acp63_dev_data *aacp_hw_get_config (pci, acp_data); +if (acp_data->acp_rev ==ACP6X_PCI_REV || acp_data->acp_rev ==ACP6XR_PCI_REV ) { +/* +* Rembrandt firmware does not describe the integrated PDM +* (DMIC) controller through "acp-audio-device-type" and uses +* the legacy "mipi-sdw-master-list" property name. Boards +* reaching this driver were routed here because they expose +* the ACP SoundWire controller, and the PDM controller is +* always present, so enable both. +*/ + acp_data->is_pdm_config = true; + acp_data->is_sdw_config = true; + } +if (acp_data->is_pdm_config) { - pdm_dev =acpi_find_child_device (ACPI_COMPANION (&pci->dev),ACP63_DMIC_ADDR ,0 ); -if (pdm_dev) { -/* is_dmic_dev flag will be set when ACP PDM controller device exists */ -if (!acpi_dev_get_property (pdm_dev,"acp-audio-device-type" , -ACPI_TYPE_INTEGER , &obj) && - obj->integer.value ==ACP_DMIC_DEV ) - dmic_en = true; - } +if (acp_data->acp_rev ==ACP6X_PCI_REV || + acp_data->acp_rev ==ACP6XR_PCI_REV ) { +/* +* ACP6x always integrates the PDM controller and its +* firmware does not gate it behind _WOV. +*/ + dmic_en = true; + }else { + pdm_dev =acpi_find_child_device (ACPI_COMPANION (&pci->dev), +ACP63_DMIC_ADDR ,0 ); +if (pdm_dev) { +/* is_dmic_dev flag will be set when ACP PDM controller device exists */ +if (!acpi_dev_get_property (pdm_dev,"acp-audio-device-type" , +ACPI_TYPE_INTEGER , &obj) && + obj->integer.value ==ACP_DMIC_DEV ) + dmic_en = true; + } - handle =ACPI_HANDLE (&pci->dev); - ret =acpi_evaluate_integer (handle,"_WOV" ,NULL , &dmic_status); -if (!ACPI_FAILURE (ret)) - wov_en = dmic_status; + handle =ACPI_HANDLE (&pci->dev); + ret =acpi_evaluate_integer (handle,"_WOV" ,NULL , &dmic_status); +if (!ACPI_FAILURE (ret)) + wov_en = dmic_status; + } }if (dmic_en && wov_en) is_dmic_dev = true;if (acp_data->is_sdw_config) { - ret =acp_scan_sdw_devices (&pci->dev,ACP63_SDW_ADDR ); +if (acp_data->acp_rev ==ACP6X_PCI_REV || + acp_data->acp_rev ==ACP6XR_PCI_REV ) + ret =acp_scan_sdw_devices (&pci->dev,ACP6X_SDW_ADDR ); +else + ret =acp_scan_sdw_devices (&pci->dev,ACP63_SDW_ADDR );if (!ret && acp_data->info.link_mask) is_sdw_dev = true; }
@@ -487,7 +514,7 @@ static int create_acp63_platform_devs(struct pci_dev *pci, struct acp63_dev_data } adata->res->flags =IORESOURCE_MEM ; adata->res->start = addr; - adata->res->end = addr + (ACP63_REG_END -ACP63_REG_START ); + adata->res->end = addr + adata->reg_range;memset (&pdevinfo,0 ,sizeof (pdevinfo)); }
@@ -556,6 +583,8 @@ static int acp_hw_init_ops(struct acp63_dev_data *adata, struct pci_dev *pci)return -ENOMEM ;switch (adata->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :acp63_hw_init_ops (adata->hw_ops);break ;
@@ -581,20 +610,33 @@ static int snd_acp63_probe(struct pci_dev *pci, irqflags =IRQF_SHARED ; -/* Return if acp config flag is defined */ +/* +* Return if an acp config flag is defined, except for +* FLAG_AMD_LEGACY_SDW which explicitly selects this driver's +* SoundWire stack over the DMIC-only snd_pci_acp6x driver. +*/ flag =snd_amd_acp_find_config (pci); -if (flag) +if (flag && flag !=FLAG_AMD_LEGACY_SDW )return -ENODEV ; -/* ACP PCI revision id check for ACP6.3, ACP7.0 & ACP7.1 platforms */ +/* ACP PCI revision id check for ACP6.x, ACP6.3, ACP7.0 & ACP7.1 platforms */ switch (pci->revision) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV : +/* +* ACP6x (Rembrandt) is handled here only when the DMI quirk +* routed the platform away from the DMIC-only driver. +*/ +if (flag !=FLAG_AMD_LEGACY_SDW ) +return -ENODEV ; +break ;case ACP63_PCI_REV :case ACP70_PCI_REV :case ACP71_PCI_REV :case ACP72_PCI_REV :break ;default : -dev_dbg (&pci->dev,"acp63/acp70/acp71 pci device not found\n" ); +dev_dbg (&pci->dev,"acp6x/acp63/acp70/acp71 pci device not found\n" );return -ENODEV ; }if (pci_enable_device (pci)) {
@@ -622,7 +664,10 @@ static int snd_acp63_probe(struct pci_dev *pci, goto release_regions; } adata->addr = addr; - adata->reg_range =ACP63_REG_END -ACP63_REG_START ; +if (pci->revision ==ACP6X_PCI_REV || pci->revision ==ACP6XR_PCI_REV ) + adata->reg_range =ACP6X_REG_END -ACP6X_REG_START ; +else + adata->reg_range =ACP63_REG_END -ACP63_REG_START ; adata->acp_rev = pci->revision; adata->subsystem_vendor = pci->subsystem_vendor; adata->subsystem_device = pci->subsystem_device;
@@ -657,6 +702,8 @@ static int snd_acp63_probe(struct pci_dev *pci, }if (adata->acp_rev >=ACP70_PCI_REV ) adata->machines = snd_soc_acpi_amd_acp70_sdw_machines; +else if (adata->acp_rev ==ACP6X_PCI_REV || adata->acp_rev ==ACP6XR_PCI_REV ) + adata->machines = snd_soc_acpi_amd_rmb_sdw_machines;else adata->machines = snd_soc_acpi_amd_acp63_sdw_machines;
[email protected]
AI reviewRe: [PATCH 7/11] ASoC: amd: ps: probe the ACP6x SoundWire stack
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ASoC: amd: ps: truncated ACP6x reg_range in snd_acp63_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ASoC: amd: ps: truncated ACP6x reg_range in snd_acp63_probe()
--
commit 936e882d9f0167141cc5ea00f82706fe1b5cf051
Author: Corey Smith <[email protected]>
ASoC: amd: ps: probe the ACP6x SoundWire stack
This commit enables probing ACP6x (Rembrandt) PCI revisions in the Pink Sardine PCI driver when the FLAG_AMD_LEGACY_SDW quirk is set, wiring up the ACP6x register range, hardware ops, SoundWire controller address, and machine tables.
Quoted 4 lines
sound/soc/amd/ps/pci-ps.c +0
-0
[ ... ]
Quoted 8 lines
sound/soc/amd/ps/pci-ps.c +1
-1@@ -487,7 +514,7 @@ static int create_acp63_platform_devs(struct pci_dev *pci, struct acp63_dev_data } adata->res->flags =IORESOURCE_MEM ; adata->res->start = addr; - adata->res->end = addr + (ACP63_REG_END -ACP63_REG_START ); + adata->res->end = addr + adata->reg_range;memset (&pdevinfo,0 ,sizeof (pdevinfo)); }
[ ... ]
sound/soc/amd/ps/pci-ps.c static int snd_acp63_probe(struct pci_dev *pci, · line 670
Quoted 9 lines
sound/soc/amd/ps/pci-ps.c +4
-1@@ -622,7 +664,10 @@ static int snd_acp63_probe(struct pci_dev *pci, goto release_regions; } adata->addr = addr; - adata->reg_range =ACP63_REG_END -ACP63_REG_START ; +if (pci->revision ==ACP6X_PCI_REV || pci->revision ==ACP6XR_PCI_REV ) + adata->reg_range =ACP6X_REG_END -ACP6X_REG_START ; +else + adata->reg_range =ACP63_REG_END -ACP63_REG_START ;
[Severity: Medium]
Is ACP6X_REG_END - ACP6X_REG_START large enough for the amd_ps_sdw_dma platform device resource on ACP6x?
For ACP6X_PCI_REV and ACP6XR_PCI_REV, snd_acp63_probe() sets adata->reg_range to ACP6X_REG_END - ACP6X_REG_START (0x1250200 - 0x1240000 = 0x10200). create_acp63_platform_devs() then uses adata->reg_range to set the end of the IORESOURCE_MEM resource passed to amd_ps_sdw_dma, which acp63_sdw_platform_probe() in sound/soc/amd/ps/ps-sdw-dma.c maps with a size of 0x10201 bytes:
sound/soc/amd/ps/ps-sdw-dma.c:acp63_sdw_platform_probe() {
...
sdw_data->acp_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
...
}However, when configuring a SoundWire PCM stream during hw_params (acp63_sdw_dma_hw_params() -> acp63_config_dma()) or system resume (acp63_restore_sdw_dma_config() -> acp63_config_dma()), acp63_config_dma() in sound/soc/amd/ps/ps-sdw-dma.c writes page table entries to ACP_SCRATCH_REG_0 (0x10000) + val:
sound/soc/amd/ps/ps-sdw-dma.c:acp63_config_dma() {
...
sdw_dma_pte_offset = SDW_PTE_OFFSET(stream->instance);
val = sdw_dma_pte_offset + (stream_id * ACP_SDW_PTE_OFFSET);
...
for (page_idx = 0; page_idx < stream->num_pages; page_idx++) {
...
writel(low, acp_base + ACP_SCRATCH_REG_0 + val);
high |= BIT(31);
writel(high, acp_base + ACP_SCRATCH_REG_0 + val + 4);
...
}
}Because SDW_PTE_OFFSET(0) is 0x400, SDW_PTE_OFFSET(1) is 0xA00, and ACP_SDW_PTE_OFFSET is 0x100, these SoundWire DMA PTE writes occur at offsets 0x10400..0x10B7C, past the 0x10200 end of adata->res and the requested devm_ioremap() length.
ACP6X_REG_END (0x1250200) comes from the DMIC-only driver where PDM PTEs start at PDM_PTE_OFFSET (0x0) and only need 64 bytes of ACP_SCRATCH_REG_0. Should ACP6X_REG_END or adata->reg_range be large enough to cover the SoundWire PTE region in ACP_SCRATCH_REG_0 as well?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH 8/11 ASoC: amd: acp: add ACP6x SoundWire quirks and machine support
In reply to Corey SmithTeach the generic AMD SoundWire machine driver to handle ACP6x: reuse the ACP6.3 CPU pin mapping and the amd_ps_sdw_dma/acp_ps_pdm_dma platform components, and add a DMI quirk for the HP Dragonfly Pro ONE (board 8A7F) enabling the RT1316 speaker amplifiers and the ACP DMIC.
--- sound/soc/amd/acp/acp-sdw-legacy-mach.c | 20 ++++++++++++++++++++ sound/soc/amd/acp/soc_amd_sdw_common.h | 2 ++ 2 files changed, 22 insertions(+)
sound/soc/amd/acp/acp-sdw-legacy-mach.c +20 -0
@@ -135,6 +135,20 @@ static const struct dmi_system_id soc_sdw_quirk_table[] = { }, .driver_data = (void *)(ASOC_SDW_ACP_DMIC), }, + { + /* + * HP Dragonfly Pro ONE (board 8A7F, AMD Rembrandt / ACP6x): + * two RT1316 SDCA speaker amplifiers exposed as an aggregated + * "Speaker" endpoint on SoundWire link 0, together with the ACP + * PDM DMIC. + */ + .callback = soc_sdw_quirk_cb, + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "HP"), + DMI_MATCH(DMI_BOARD_NAME, "8A7F"), + }, + .driver_data = (void *)((ASOC_SDW_CODEC_SPKR) | (ASOC_SDW_ACP_DMIC)), + }, {} };
@@ -216,6 +230,8 @@ static int create_sdw_dailink(struct snd_soc_card *card, }switch (amd_ctx->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV : ret =get_acp63_cpu_pin_id (ffs (soc_end->link_mask) -1 , *be_id, &cpu_pin_id, dev);
@@ -329,6 +345,8 @@ static int create_sdw_dailinks(struct snd_soc_card *card,return -ENOMEM ;switch (amd_ctx->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :case ACP70_PCI_REV :case ACP71_PCI_REV :
@@ -377,6 +395,8 @@ static int create_dmic_dailinks(struct snd_soc_card *card,return -ENOMEM ;switch (amd_ctx->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :case ACP70_PCI_REV :case ACP71_PCI_REV :
sound/soc/amd/acp/soc_amd_sdw_common.h +2 -0
@@ -18,6 +18,8 @@#define ACP63_SDW_MAX_LINKS 2#define AMD_SDW_MAX_GROUPS 9 +#define ACP6X_PCI_REV 0x60 +#define ACP6XR_PCI_REV 0x6f#define ACP63_PCI_REV 0x63#define ACP70_PCI_REV 0x70#define ACP71_PCI_REV 0x71
[email protected]
AI reviewRe: [PATCH 8/11] ASoC: amd: acp: add ACP6x SoundWire quirks and machine support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] ASoC: amd: ACP6X_REG_END truncates MMIO range needed by acp63_config_dma() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ASoC: amd: ACP6X_REG_END truncates MMIO range needed by acp63_config_dma() --
commit d2bc6f9f5ef056a066db2b434d5d1ed6b31dee36
Author: Corey Smith <[email protected]>
ASoC: amd: acp: add ACP6x SoundWire quirks and machine support
This commit adds ACP6x support to the generic AMD SoundWire machine driver by reusing the ACP6.3 CPU pin mapping and the amd_ps_sdw_dma and acp_ps_pdm_dma platform components. It also adds a DMI quirk for the HP Dragonfly Pro ONE (board 8A7F).
Quoted 4 lines
sound/soc/amd/acp/acp-sdw-legacy-mach.c +0
-0
[ ... ]
sound/soc/amd/acp/acp-sdw-legacy-mach.c static int create_sdw_dailinks(struct snd_soc_card *card, · line 360
Quoted 9 lines
sound/soc/amd/acp/acp-sdw-legacy-mach.c +2
-0@@ -337,6 +353,8 @@ static int create_sdw_dailinks(struct snd_soc_card *card,return -ENOMEM ;switch (amd_ctx->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :case ACP70_PCI_REV :case ACP71_PCI_REV :
[Severity: Medium]
When create_sdw_dailinks() binds ACP6X_PCI_REV and ACP6XR_PCI_REV SoundWire DAI links to amd_ps_sdw_dma.0, does acp63_sdw_dma_hw_params() -> acp63_config_dma() end up writing SoundWire PTEs beyond the MMIO resource range configured for ACP6x?
In sound/soc/amd/ps/acp63.h, ACP6X_REG_END is defined at offset 0x10200 from ACP6X_REG_START:
#define ACP6X_REG_START 0x1240000
#define ACP6X_REG_END 0x1250200
#define ACP63_REG_START 0x1240000
#define ACP63_REG_END 0x125C000In sound/soc/amd/ps/pci-ps.c, snd_acp63_probe() uses this range for ACP6x, and create_acp63_platform_devs() passes it as the IORESOURCE_MEM resource to the child platform devices:
if (pci->revision == ACP6X_PCI_REV || pci->revision == ACP6XR_PCI_REV)
adata->reg_range = ACP6X_REG_END - ACP6X_REG_START;
else
adata->reg_range = ACP63_REG_END - ACP63_REG_START;acp63_sdw_platform_probe() in sound/soc/amd/ps/ps-sdw-dma.c then maps that resource via devm_ioremap(&pdev->dev, res->start, resource_size(res)), which only covers 0x10201 bytes (up to ACP_SCRATCH_REG_0 + 0x200).
However, when a SoundWire PCM substream is configured, acp63_config_dma() in sound/soc/amd/ps/ps-sdw-dma.c writes PTEs into scratch memory at:
sdw_dma_pte_offset = SDW_PTE_OFFSET(stream->instance);
val = sdw_dma_pte_offset + (stream_id * ACP_SDW_PTE_OFFSET);
...
writel(low, acp_base + ACP_SCRATCH_REG_0 + val);
high |= BIT(31);
writel(high, acp_base + ACP_SCRATCH_REG_0 + val + 4);Since ACP_SCRATCH_REG_0 is 0x10000 and SDW_PTE_OFFSET(stream->instance) is 0x400 for SDW0 and 0xa00 for SDW1, these writes span offsets 0x10400..0x10b7f, which is past the 0x10200 limit set by ACP6X_REG_END (unlike the 0x125C000 end address used in sound/soc/amd/acp/acp-pci.c and sound/soc/sof/amd/pci-rmb.c).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH 9/11 soundwire: amd: accept the legacy mipi-sdw-master-list property
In reply to Corey SmithRembrandt (ACP6x) firmware describes the controller links with the legacy MIPI property name "mipi-sdw-master-list" instead of the current "mipi-sdw-manager-list". Fall back to the legacy name when the modern one is not present.
--- sound/soc/amd/acp/amd-sdw-acpi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
sound/soc/amd/acp/amd-sdw-acpi.c +12 -3
@@ -36,9 +36,18 @@ int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info) ret =fwnode_property_read_u32_array (acpi_fwnode_handle (adev),"mipi-sdw-manager-list" , &sdw_bitmap,1 );if (ret) { -dev_err (&adev->dev, -"Failed to read mipi-sdw-manager-list: %d\n" , ret); -return -EINVAL ; +/* +* Rembrandt (ACP6x) firmware uses the legacy MIPI property +* name "mipi-sdw-master-list". +*/ + ret =fwnode_property_read_u32_array (acpi_fwnode_handle (adev), +"mipi-sdw-master-list" , + &sdw_bitmap,1 ); +if (ret) { +dev_err (&adev->dev, +"Failed to read SoundWire manager list: %d\n" , ret); +return -EINVAL ; + } } count =hweight32 (sdw_bitmap);/* Check count is within bounds */
PATCH 10/11 ASoC: amd: ps: harden the ACP interrupt path for ACP6x
In reply to Corey SmithThe ACP PCI interrupt is requested before create_acp63_platform_devs() populates adata->sdw, adata->pdm_dev and adata->sdw_dma_dev, while acp63_irq_handler() unconditionally dereferences those pointers as soon as the corresponding bit is set in ACP_EXTERNAL_INTR_STAT/_STAT1.
This was harmless on the ACP6.3 boards the driver was written for, but on ACP6x the interrupt status/control register layout differs, so a pending interrupt can be served while the device pointers are still NULL. Because it happens in interrupt context that is a fatal exception and panics the kernel on boot.
- only walk adata->sdw when it is non-NULL;
- only use adata->pdm_dev when it is non-NULL;
- only dispatch the SoundWire DMA handler once adata->sdw_dma_dev exists;
- treat ACP6x like ACP6.3 in check_and_handle_sdw_dma_irq() so the DMA interrupt status is recorded for the Rembrandt link as well.
--- sound/soc/amd/ps/pci-ps.c | 44 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-)
sound/soc/amd/ps/pci-ps.c +32 -12
@@ -112,6 +112,8 @@ static short int check_and_handle_sdw_dma_irq(struct acp63_dev_data *adata, u32break ; }switch (adata->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV : adata->acp63_sdw0_dma_intr_stat[stream_id] =1 ;break ;
@@ -126,6 +128,8 @@ static short int check_and_handle_sdw_dma_irq(struct acp63_dev_data *adata, u32 } }switch (adata->acp_rev) { +case ACP6X_PCI_REV : +case ACP6XR_PCI_REV :case ACP63_PCI_REV :if (ext_intr_stat1 &ACP63_P1_AUDIO1_RX_THRESHOLD ) { writel(ACP63_P1_AUDIO1_RX_THRESHOLD,
@@ -209,18 +213,28 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) ext_intr_stat =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT );if (ext_intr_stat &ACP_SDW0_STAT ) {writel (ACP_SDW0_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +/* +* The handler may run before the SoundWire manager devices +* have been created (shared IRQ lines can fire as soon as +* they are registered, and the ACP interrupts are enabled by +* acp_hw_init() before create_acp63_platform_devs() runs). +*/ +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; } ext_intr_stat1 =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 );if (ext_intr_stat1 &ACP_SDW1_STAT ) {writel (ACP_SDW1_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
@@ -237,16 +251,22 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) wake_irq_flag =check_and_handle_acp70_sdw_wake_irq (adata);if (ext_intr_stat &BIT (PDM_DMA_STAT )) { - ps_pdm_data =dev_get_drvdata (&adata->pdm_dev->dev);writel (BIT (PDM_DMA_STAT ), adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); -if (ps_pdm_data->capture_stream) -snd_pcm_period_elapsed (ps_pdm_data->capture_stream); +if (adata->pdm_dev) { + ps_pdm_data =dev_get_drvdata (&adata->pdm_dev->dev); +if (ps_pdm_data && ps_pdm_data->capture_stream) +snd_pcm_period_elapsed (ps_pdm_data->capture_stream); + } irq_flag =1 ; } - sdw_dma_irq_flag =check_and_handle_sdw_dma_irq (adata, ext_intr_stat, ext_intr_stat1); -if (sdw_dma_irq_flag) -return IRQ_WAKE_THREAD ; +/* The SoundWire DMA device may not exist yet during probe */ +if (adata->sdw_dma_dev) { + sdw_dma_irq_flag =check_and_handle_sdw_dma_irq (adata, ext_intr_stat, + ext_intr_stat1); +if (sdw_dma_irq_flag) +return IRQ_WAKE_THREAD ; + }if (irq_flag || wake_irq_flag)return IRQ_HANDLED ;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 10/11] ASoC: amd: ps: harden the ACP interrupt path for ACP6x
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] ASoC: amd: ps: unacknowledged DMA IRQ and NULL sdw_data in acp63_irq_handler() - [High] ASoC: amd…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] ASoC: amd: ps: unacknowledged DMA IRQ and NULL sdw_data in acp63_irq_handler()
- [High] ASoC: amd: ps: NULL sdw->pdev[i] dereference in acp63_irq_handler() --
commit 00d5bef454b30567a1333bcc6ac7ae59904adf98
Author: Corey Smith <[email protected]>
ASoC: amd: ps: harden the ACP interrupt path for ACP6x
This commit adds NULL checks for adata->sdw, adata->pdm_dev, and adata->sdw_dma_dev in acp63_irq_handler(), and extends check_and_handle_sdw_dma_irq() to handle ACP6X_PCI_REV and ACP6XR_PCI_REV.
Quoted 4 lines
sound/soc/amd/ps/pci-ps.c +0
-0
[ ... ]
Quoted 24 lines
sound/soc/amd/ps/pci-ps.c +11
-3@@ -209,18 +213,28 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) ext_intr_stat =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT );if (ext_intr_stat &ACP_SDW0_STAT ) {writel (ACP_SDW0_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); - amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +/* +* The handler may run before the SoundWire manager devices +* have been created (shared IRQ lines can fire as soon as +* they are registered, and the ACP interrupts are enabled by +* acp_hw_init() before create_acp63_platform_devs() runs). +*/ +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[0 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; } ext_intr_stat1 =readl (adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 );if (ext_intr_stat1 &ACP_SDW1_STAT ) {writel (ACP_SDW1_STAT , adata->acp63_base +ACP_EXTERNAL_INTR_STAT1 );
sound/soc/amd/ps/pci-ps.c static irqreturn_t acp63_irq_handler(int irq, void *dev_id) · line 239
Quoted 10 lines
sound/soc/amd/ps/pci-ps.c +5
-3- amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); -if (amd_manager) -schedule_work (&amd_manager->amd_sdw_irq_thread); +if (adata->sdw) { + amd_manager =dev_get_drvdata (&adata->sdw->pdev[1 ]->dev); +if (amd_manager) +schedule_work (&amd_manager->amd_sdw_irq_thread); + } irq_flag =1 ; }
[Severity: High]
Can adata->sdw->pdev[0] or adata->sdw->pdev[1] still be NULL here when adata->sdw is non-NULL?
In drivers/soundwire/amd_init.c:sdw_amd_probe_controller(), ctx->pdev[index] is only registered for links enabled in link_mask:
for (index = 0; index < count; index++) {
if (!(link_mask & BIT(index)))
continue;
...
ctx->pdev[index] = platform_device_register_full(&pdevinfo[index]);On single-link platforms where only one link is set in link_mask (for example, link_mask == BIT(0) where adata->sdw->pdev[1] remains NULL), if a pending or spurious ACP_SDW1_STAT or ACP_SDW0_STAT bit is set in ACP_EXTERNAL_INTR_STAT1 or ACP_EXTERNAL_INTR_STAT, acp63_irq_handler() will pass the adata->sdw check and pass &adata->sdw->pdev[i]->dev to dev_get_drvdata(), dereferencing a NULL pdev[i] pointer in hard IRQ context.
Note that handle_acp70_sdw_wake_event() in sound/soc/amd/ps/pci-ps.c (called from acp63_irq_handler() -> check_and_handle_acp70_sdw_wake_irq()) also dereferences adata->sdw->pdev[0] and adata->sdw->pdev[1] without checking adata->sdw or adata->sdw->pdev[i] first, whereas handle_acp63_sdw_pme_event() in sound/soc/amd/ps/ps-common.c checks both adata->sdw and adata->sdw->pdev[i]. Should both acp63_irq_handler() and handle_acp70_sdw_wake_event() check adata->sdw->pdev[i] before calling dev_get_drvdata()?
Quoted 16 lines
sound/soc/amd/ps/pci-ps.c +5
-3@@ -237,16 +251,22 @@ static irqreturn_t acp63_irq_handler(int irq, void *dev_id) wake_irq_flag =check_and_handle_acp70_sdw_wake_irq (adata);if (ext_intr_stat &BIT (PDM_DMA_STAT )) { - ps_pdm_data =dev_get_drvdata (&adata->pdm_dev->dev);writel (BIT (PDM_DMA_STAT ), adata->acp63_base +ACP_EXTERNAL_INTR_STAT ); -if (ps_pdm_data->capture_stream) -snd_pcm_period_elapsed (ps_pdm_data->capture_stream); +if (adata->pdm_dev) { + ps_pdm_data =dev_get_drvdata (&adata->pdm_dev->dev); +if (ps_pdm_data && ps_pdm_data->capture_stream) +snd_pcm_period_elapsed (ps_pdm_data->capture_stream); + } irq_flag =1 ; }
sound/soc/amd/ps/pci-ps.c static irqreturn_t acp63_irq_handler(int irq, void *dev_id) · line 269
Quoted 10 lines
sound/soc/amd/ps/pci-ps.c +7
-3- sdw_dma_irq_flag =check_and_handle_sdw_dma_irq (adata, ext_intr_stat, ext_intr_stat1); -if (sdw_dma_irq_flag) -return IRQ_WAKE_THREAD ; +/* The SoundWire DMA device may not exist yet during probe */ +if (adata->sdw_dma_dev) { + sdw_dma_irq_flag =check_and_handle_sdw_dma_irq (adata, ext_intr_stat, + ext_intr_stat1); +if (sdw_dma_irq_flag) +return IRQ_WAKE_THREAD ; + }
[Severity: High]
Does skipping check_and_handle_sdw_dma_irq() when adata->sdw_dma_dev is NULL leave pending SoundWire DMA interrupt bits uncleared, and can waking the IRQ thread as soon as adata->sdw_dma_dev is non-NULL dereference a NULL sdw_data?
Unlike the ACP_SDW0_STAT, ACP_SDW1_STAT, and BIT(PDM_DMA_STAT) branches above, which clear their status bits in ACP_EXTERNAL_INTR_STAT / ACP_EXTERNAL_INTR_STAT1 before checking the device pointers, the writel() calls that clear the SoundWire DMA interrupt status bits are inside check_and_handle_sdw_dma_irq():
if (ext_intr_stat & ACP63_SDW_DMA_IRQ_MASK) {
for (index = ACP_AUDIO2_RX_THRESHOLD; index <= ACP_AUDIO0_TX_THRESHOLD; index++) {
if (ext_intr_stat & BIT(index)) {
writel(BIT(index), adata->acp63_base + ACP_EXTERNAL_INTR_STAT);If a SoundWire DMA interrupt bit is pending while adata->sdw_dma_dev is NULL (during snd_acp63_probe() before create_acp63_platform_devs(), or on a PDM-only configuration), skipping check_and_handle_sdw_dma_irq() leaves the hardware status bit asserted and returns IRQ_NONE on a shared level-triggered PCI interrupt line, causing an unhandled interrupt storm.
Furthermore, in sound/soc/amd/ps/pci-ps.c:create_acp63_platform_devs():
adata->sdw_dma_dev = platform_device_register_full(&pdevinfo);
adata->sdw_dma_dev becomes non-NULL before the amd_ps_sdw_dma driver (acp63_sdw_platform_probe() in sound/soc/amd/ps/ps-sdw-dma.c, which may be in a separate module) binds to the device and sets drvdata (or holds an ERR_PTR if registration fails). Because this patch also adds ACP6X_PCI_REV and ACP6XR_PCI_REV to check_and_handle_sdw_dma_irq(), an interrupt in that window returns IRQ_WAKE_THREAD and runs acp63_irq_thread() -> acp63_sdw_dma_irq_thread() (or acp70_sdw_dma_irq_thread()) in sound/soc/amd/ps/ps-common.c:
sdw_data = dev_get_drvdata(&adata->sdw_dma_dev->dev);
for (stream_id = 0; stream_id < ACP63_SDW0_DMA_MAX_STREAMS; stream_id++) {
if (adata->acp63_sdw0_dma_intr_stat[stream_id]) {
if (sdw_data->acp63_sdw0_dma_stream[stream_id])
snd_pcm_period_elapsed(sdw_data->acp63_sdw0_dma_stream[stream_id]);which dereferences sdw_data without checking if it is NULL.
Should check_and_handle_sdw_dma_irq() always run to clear the hardware status bits, and should acp63_sdw_dma_irq_thread() / acp70_sdw_dma_irq_thread() (or acp63_irq_handler() before returning IRQ_WAKE_THREAD) verify that adata->sdw_dma_dev and dev_get_drvdata(&adata->sdw_dma_dev->dev) are valid?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH 11/11 soundwire: amd: provide defaults for the bus clock properties
In reply to Corey SmithThe manager clock configuration was moved from hard-coded values to the MIPI DisCo properties (max clock frequency, default frame rate and default row size). Rembrandt (ACP6x) firmware does not describe those properties on the SoundWire link nodes, so sdw_master_read_prop() leaves them zeroed and amd_sdw_clk_init_ctrl() aborts the manager start-up with -EINVAL. On the HP Dragonfly Pro ONE this makes the whole snd-pci-ps probe fail with error -22 and no SoundWire device is created.
Restore the legacy defaults when the firmware does not provide them:
a 12 MHz bus clock, a 48 kHz frame rate and the 50 x 10 frame shape. Platforms whose firmware does describe the properties are unaffected.
--- drivers/soundwire/amd_manager.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/soundwire/amd_manager.c +25 -0
@@ -25,6 +25,12 @@#define DRV_NAME "amd_sdw_manager" +/* +* Frame rate used when firmware does not describe the MIPI DisCo clock +* properties on the SoundWire link nodes. +*/ +#define AMD_SDW_DEFAULT_FRAME_RATE 48000 +#define to_amd_sdw (b) container_of(b, struct amd_sdw_manager, bus)static int amd_sdw_clk_init_ctrl (struct amd_sdw_manager *amd_manager)
@@ -752,8 +758,27 @@ static int sdw_master_read_amd_prop(struct sdw_bus *bus)static int amd_prop_read (struct sdw_bus *bus) { +struct sdw_master_prop *prop = &bus->prop; +sdw_master_read_prop (bus);sdw_master_read_amd_prop (bus); + +/* +* Some platforms, Rembrandt (ACP6x) in particular, do not describe +* the MIPI DisCo clock properties on the SoundWire link nodes. The +* values read by sdw_master_read_prop() then stay zeroed and +* amd_sdw_clk_init_ctrl() fails with -EINVAL. Restore the defaults +* the driver used before the clock configuration was moved to +* firmware: a 12 MHz bus clock, a 48 kHz frame rate and the 50 x 10 +* frame shape. +*/ +if (!prop->max_clk_freq) + prop->max_clk_freq =AMD_SDW_DEFAULT_CLK_FREQ ; +if (!prop->default_frame_rate) + prop->default_frame_rate =AMD_SDW_DEFAULT_FRAME_RATE ; +if (!prop->default_row) + prop->default_row =AMD_SDW_DEFAULT_ROWS ; +return 0 ; }
Mukunda,Vijendar
maintainerQuoted 56 lines · Corey Smith
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
The HP Dragonfly Pro ONE (AMD Rembrandt, ACP PCI revision
0x60) has no working internal speakers under Linux. Its speakers are two Realtek RT1316 SDCA amplifiers on SoundWire link 0 of the ACP SoundWire controller:\_SB.PCI0.GP17.ACP.SDWC.SLV0.AF04 (_ADR 0x000030025D131601) \_SB.PCI0.GP17.ACP.SDWC.SLV1.AF04 (_ADR 0x000031025D131601) -> manufacturer 0x025D (Realtek), part 0x1316 (RT1316) -> link 0, unique id 0/1, aggregated as one stereo "Speaker" endpointNone of the in-tree AMD ACP drivers can drive these amplifiers:
*
snd_pci_acp6x(sound/soc/amd/yc) is the only driver that accepts the ACP6x revision (0x60). It implements the PDM/DMIC path only, so the machine results in a capture-only card (pcmC1D0c) and the speakers never appear.
* snd-pci-ps (sound/soc/amd/ps, ACP6.3/7.x) has the SoundWire manager,SDW DMA and machine plumbing, but rejects revision 0x60.*
drivers/soundwire/amd_manager.conly knows the ACP6.3 and ACP7.x register maps.
*sound/soc/amd/acp/amd-sdw-acpi.conly reads the modern "mipi-sdw-manager-list" property; Rembrandt firmware uses the legacy "mipi-sdw-master-list" name.This series makes the ACP6x SoundWire path usable and routes this board through it:
1-2 accept the ACP6x PCI revisions in the SoundWire manager driver 3-4 accept them in the Pink Sardine (ps) platform header and SDW DMA 5 add an ACP6x RT1316 machine table 6 add a FLAG_AMD_LEGACY_SDW DMI entry for board 8A7F so that snd_pci_acp6x releases the device to snd-pci-ps 7 teach snd-pci-ps to probe the ACP6x SoundWire (and integrated PDM) hardware 8 teach the generic amd_sdw machine driver about ACP6x 9 accept the legacy "mipi-sdw-master-list" property 10 harden the ACP interrupt path (fixes a boot panic found intesting: the IRQ handler runs before the platform devices exist)
11 restore the legacy bus clock defaults when firmware omits the
MIPI DisCo clock properties (fixes a -22 SDW probe failure found in testing)Assumptions that need hardware validation by the reporter:
* The ACP6x SoundWire manager and SDW DMA register blocks are register compatible with ACP6.3 (the series reuses the ACP6.3 register maps and stream/IRQ associations). AMD shares the ACP_SW_* register definitions between ACP6.3 and ACP7.0, which makes this plausible, but it is not verified against a Rembrandt datasheet.
* The ACP6x SDW controller child is the device at_ADR0x02under the ACP, and Rembrandt firmware does not describe the PDM controller (DMIC) in ACPI, so the PDM path is enabled unconditionally for ACP6x.
Quoted 3 lines
The series has been built and booted on the target machine; the ACP6x SoundWire controller is now probed. The register-map assumptions above still need to be confirmed by actually playing audio.
++
RMB platform support is already present under sound/soc/amd/yc. Adding RMB support directly under sound/soc/amd/ps without considering the existing implementation may break functionality on existing platforms.
RMB also supports different audio I/O configurations, including HDA, PDM and SoundWire, so this needs to be handled appropriately rather than enabling the platform unconditionally in the PS driver.
Please run scripts/get_maintainer.pl on the patch series and include the relevant ASoC/ALSA maintainers when resending the series.
Once the series is resent with the appropriate maintainers in Cc, I will provide detailed review comments on the individual patches.
Quoted 28 lines
Corey Smith (11):
soundwire: amd: add ACP6x PCI revision ids
soundwire: amd: support ACP6x SoundWire managers
ASoC: amd: ps: add ACP6x PCI revision ids
ASoC: amd: ps: support ACP6x in the SoundWire DMA driver
ASoC: amd: acp: add ACP6x (Rembrandt) SoundWire machine table
ASoC: amd: acp-config: route HP Dragonfly Pro ONE through the ACP6x
SDW stack
ASoC: amd: ps: probe the ACP6x SoundWire stack
ASoC: amd: acp: add ACP6x SoundWire quirks and machine support
soundwire: amd: accept the legacy mipi-sdw-master-list property
ASoC: amd: ps: harden the ACP interrupt path for ACP6x
soundwire: amd: provide defaults for the bus clock propertiesdrivers/soundwire/amd_manager.c | 33 +++++++ include/linux/soundwire/sdw_amd.h | 2 + sound/soc/amd/acp-config.c | 19 +++++ sound/soc/amd/acp/Makefile | 2 +- sound/soc/amd/acp/acp-sdw-legacy-mach.c | 20 +++++ sound/soc/amd/acp/amd-rmb-acpi-match.c | 63 ++++++++++++++++ sound/soc/amd/acp/amd-sdw-acpi.c | 15 +++- sound/soc/amd/acp/soc_amd_sdw_common.h | 2 + sound/soc/amd/mach-config.h | 7 ++ sound/soc/amd/ps/acp63.h | 5 ++ sound/soc/amd/ps/pci-ps.c | 129 ++++++++++++++++++++++++-------- sound/soc/amd/ps/ps-sdw-dma.c | 12 ++- 12 files changed, 273 insertions(+), 36 deletions(-)create mode 100644
sound/soc/amd/acp/amd-rmb-acpi-match.c