Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sound/soc/sof/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
{
struct snd_sof_pdata *plat_data = sdev->pdata;
int ret;
int tries = 0;

/* probe the DSP hardware */
ret = snd_sof_probe(sdev);
Expand Down Expand Up @@ -181,11 +182,13 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
goto ipc_err;
}

fw_load_retry:
/* load the firmware */
ret = snd_sof_load_firmware(sdev);
if (ret < 0) {
dev_err(sdev->dev, "error: failed to load DSP firmware %d\n",
ret);

goto fw_load_err;
}

Expand All @@ -199,6 +202,12 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
if (ret < 0) {
dev_err(sdev->dev, "error: failed to boot DSP firmware %d\n",
ret);
/* when the DSP boots but FW_READY fails, tentatively retry */
if (ret == -EIO && ++tries < sof_ops(sdev)->firmware_boot_retries) {
dev_warn(sdev->dev, "retrying DSP boot, iteration %d\n", tries);
goto fw_load_retry;

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't we have to reset the sdev->fw_state to SOF_FW_BOOT_PREPARE when retrying? You could also extract snd_sof_load_firmware() and snd_sof_run_firmware() into a separate function and call it in a loop, thus avoiding a goto, but I'll probably do that anyway when my VirtIO patches reach that state... since they're touching this code too.

}

goto fw_run_err;
}

Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/imx/imx8.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ struct imx8_priv {

static void imx8_get_reply(struct snd_sof_dev *sdev)
{
struct snd_sof_ipc_msg *msg = sdev->msg;
struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
struct sof_ipc_reply reply;
int ret = 0;

if (!msg) {
if (msg->ipc_complete) {
dev_warn(sdev->dev, "unexpected ipc interrupt\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/imx/imx8m.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ struct imx8m_priv {

static void imx8m_get_reply(struct snd_sof_dev *sdev)
{
struct snd_sof_ipc_msg *msg = sdev->msg;
struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
struct sof_ipc_reply reply;
int ret = 0;

if (!msg) {
if (msg->ipc_complete) {
dev_warn(sdev->dev, "unexpected ipc interrupt\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/intel/bdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static int bdw_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)

static void bdw_get_reply(struct snd_sof_dev *sdev)
{
struct snd_sof_ipc_msg *msg = sdev->msg;
struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
struct sof_ipc_reply reply;
int ret = 0;

Expand All @@ -379,7 +379,7 @@ static void bdw_get_reply(struct snd_sof_dev *sdev)
* ipc belongs to none of the ipcs sent from driver.
* In this case, the driver must ignore the ipc.
*/
if (!msg) {
if (msg->ipc_complete) {
dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n");
return;
}
Expand Down
64 changes: 50 additions & 14 deletions sound/soc/sof/intel/byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void byt_get_registers(struct snd_sof_dev *sdev,
{
u32 offset = sdev->dsp_oops_offset;

/* first read regsisters */
/* first read registers */
sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));

/* note: variable AR register array is not read */
Expand All @@ -121,31 +121,32 @@ static void byt_dump(struct snd_sof_dev *sdev, u32 flags)
struct sof_ipc_dsp_oops_xtensa xoops;
struct sof_ipc_panic_info panic_info;
u32 stack[BYT_STACK_DUMP_SIZE];
u64 status, panic, imrd, imrx;
u64 ipcd, ipcx, imrd, imrx;

/* now try generic SOF status messages */
status = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCD);
panic = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCX);
ipcd = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCD);
ipcx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCX);
imrx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRX);
imrd = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRD);

byt_get_registers(sdev, &xoops, &panic_info, stack,
BYT_STACK_DUMP_SIZE);
snd_sof_get_status(sdev, status, panic, &xoops, &panic_info, stack,
snd_sof_get_status(sdev, ipcd, ipcx, &xoops, &panic_info, stack,
BYT_STACK_DUMP_SIZE);

/* provide some context for firmware debug */
imrx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRX);
imrd = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRD);
dev_err(sdev->dev,
"error: ipc host -> DSP: pending %s complete %s raw 0x%llx\n",
(panic & SHIM_IPCX_BUSY) ? "yes" : "no",
(panic & SHIM_IPCX_DONE) ? "yes" : "no", panic);
(ipcx & SHIM_BYT_IPCX_BUSY) ? "yes" : "no",
(ipcx & SHIM_BYT_IPCX_DONE) ? "yes" : "no", ipcx);
dev_err(sdev->dev,
"error: mask host: pending %s complete %s raw 0x%llx\n",
(imrx & SHIM_IMRX_BUSY) ? "yes" : "no",
(imrx & SHIM_IMRX_DONE) ? "yes" : "no", imrx);
dev_err(sdev->dev,
"error: ipc DSP -> host: pending %s complete %s raw 0x%llx\n",
(status & SHIM_IPCD_BUSY) ? "yes" : "no",
(status & SHIM_IPCD_DONE) ? "yes" : "no", status);
(ipcd & SHIM_BYT_IPCD_BUSY) ? "yes" : "no",
(ipcd & SHIM_BYT_IPCD_DONE) ? "yes" : "no", ipcd);
dev_err(sdev->dev,
"error: mask DSP: pending %s complete %s raw 0x%llx\n",
(imrd & SHIM_IMRD_BUSY) ? "yes" : "no",
Expand Down Expand Up @@ -250,7 +251,7 @@ static int byt_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)

static void byt_get_reply(struct snd_sof_dev *sdev)
{
struct snd_sof_ipc_msg *msg = sdev->msg;
struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
struct sof_ipc_reply reply;
int ret = 0;

Expand All @@ -259,7 +260,7 @@ static void byt_get_reply(struct snd_sof_dev *sdev)
* ipc belongs to none of the ipcs sent from driver.
* In this case, the driver must ignore the ipc.
*/
if (!msg) {
if (msg->ipc_complete) {
dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n");
return;
}
Expand Down Expand Up @@ -327,7 +328,9 @@ static int byt_run(struct snd_sof_dev *sdev)

/* release stall and wait to unstall */
snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_CSR,
SHIM_BYT_CSR_STALL, 0x0);
SHIM_BYT_CSR_XT_SNOOP | SHIM_BYT_CSR_STALL,
SHIM_BYT_CSR_XT_SNOOP);

ghost Jul 14, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does this enable PCIe snooping of the DSP traffic? And without it it's disabled? I'm not an expert in that but in general that seems like a good thing to maintain cache coherency? I don't know why it would be possible to disable it, but maybe my guess is wrong and it's something different entirely.

ghost Jul 14, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's wrong, will remove this.

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would that leave snooping disabled? Or does that flag disable snooping when set?


while (tries--) {
if (!(snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_CSR) &
SHIM_BYT_CSR_PWAITMODE))
Expand Down Expand Up @@ -730,6 +733,7 @@ static int byt_acpi_probe(struct snd_sof_dev *sdev)
container_of(sdev->dev, struct platform_device, dev);
struct resource *mmio;
u32 base, size;
u32 pmc_status;
int ret;

/* DSP DMA can only access low 31 bits of host memory */
Expand Down Expand Up @@ -764,6 +768,36 @@ static int byt_acpi_probe(struct snd_sof_dev *sdev)
sdev->mmio_bar = BYT_DSP_BAR;
sdev->mailbox_bar = BYT_DSP_BAR;

/* PCI base */
mmio = platform_get_resource(pdev, IORESOURCE_MEM,
desc->resindex_pcicfg_base);
if (mmio) {
base = mmio->start;
size = resource_size(mmio);
} else {
dev_err(sdev->dev, "error: failed to get PCI base at idx %d\n",
desc->resindex_pcicfg_base);
return -ENODEV;
}

dev_dbg(sdev->dev, "PCI base at 0x%x size 0x%x", base, size);
sdev->bar[BYT_PCI_BAR] = devm_ioremap(sdev->dev, base, size);
if (!sdev->bar[BYT_PCI_BAR]) {
dev_err(sdev->dev,
"error: failed to ioremap PCI base 0x%x size 0x%x\n",
base, size);
return -ENODEV;
}
dev_dbg(sdev->dev, "PCI VADDR %p\n", sdev->bar[BYT_PCI_BAR]);

pmc_status = snd_sof_dsp_read(sdev, BYT_PCI_BAR, PCI_PMCS);
if (pmc_status & 0x3) {
dev_err(sdev->dev, "error: PMC status does not indicated D0 state %x\n",

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

typo "indicate"

pmc_status);
return -ENODEV;

}

/* IMR base - optional */
if (desc->resindex_imr_base == -1)
goto irq;
Expand Down Expand Up @@ -954,6 +988,8 @@ const struct snd_sof_dsp_ops sof_cht_ops = {
/*Firmware loading */
.load_firmware = snd_sof_load_firmware_memcpy,

.firmware_boot_retries = 2,

/* PM */
.suspend = byt_suspend,
.resume = byt_resume,
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/intel/hda-ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int hda_dsp_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg)

void hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev)
{
struct snd_sof_ipc_msg *msg = sdev->msg;
struct snd_sof_ipc_msg *msg = &sdev->ipc->msg;
struct sof_ipc_reply reply;
struct sof_ipc_cmd_hdr *hdr;
int ret = 0;
Expand All @@ -77,7 +77,7 @@ void hda_dsp_ipc_get_reply(struct snd_sof_dev *sdev)
* ipc belongs to none of the ipcs sent from driver.
* In this case, the driver must ignore the ipc.
*/
if (!msg) {
if (msg->ipc_complete) {
dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n");
return;
}
Expand Down
1 change: 1 addition & 0 deletions sound/soc/sof/intel/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#define SHIM_BYT_CSR_VECTOR_SEL BIT(1)
#define SHIM_BYT_CSR_STALL BIT(2)
#define SHIM_BYT_CSR_PWAITMODE BIT(3)
#define SHIM_BYT_CSR_XT_SNOOP BIT(11)

/* ISRX / ISC */
#define SHIM_ISRX_BUSY BIT(1)
Expand Down
14 changes: 0 additions & 14 deletions sound/soc/sof/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ static void ipc_stream_message(struct snd_sof_dev *sdev, u32 msg_cmd);
* IPC message Tx/Rx message handling.
*/

/* SOF generic IPC data */
struct snd_sof_ipc {
struct snd_sof_dev *sdev;

/* protects messages and the disable flag */
struct mutex tx_mutex;
/* disables further sending of ipc's */
bool disable_ipc_tx;

struct snd_sof_ipc_msg msg;
};

struct sof_ipc_ctrl_data_params {
size_t msg_bytes;
size_t hdr_bytes;
Expand Down Expand Up @@ -260,8 +248,6 @@ static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header,
if (msg_bytes)
memcpy(msg->msg_data, msg_data, msg_bytes);

sdev->msg = msg;

ret = snd_sof_dsp_send_msg(sdev, msg);
/* Next reply that we receive will be related to this message */
if (!ret)
Expand Down
24 changes: 12 additions & 12 deletions sound/soc/sof/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,6 @@ int snd_sof_run_firmware(struct snd_sof_dev *sdev)

init_waitqueue_head(&sdev->boot_wait);

/* create read-only fw_version debugfs to store boot version info */
if (sdev->first_boot) {
ret = snd_sof_debugfs_buf_item(sdev, &sdev->fw_version,
sizeof(sdev->fw_version),
"fw_version", 0444);
/* errors are only due to memory allocation, not debugfs */
if (ret < 0) {
dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n");
return ret;
}
}

/* perform pre fw run operations */
ret = snd_sof_dsp_pre_fw_run(sdev);
if (ret < 0) {
Expand Down Expand Up @@ -790,6 +778,18 @@ int snd_sof_run_firmware(struct snd_sof_dev *sdev)
/* fw boot is complete. Update the active cores mask */
sdev->enabled_cores_mask = init_core_mask;

/* create read-only fw_version debugfs to store boot version info */
if (sdev->first_boot) {
ret = snd_sof_debugfs_buf_item(sdev, &sdev->fw_version,
sizeof(sdev->fw_version),
"fw_version", 0444);
/* errors are only due to memory allocation, not debugfs */
if (ret < 0) {
dev_err(sdev->dev, "error: snd_sof_debugfs_buf_item failed\n");
return ret;

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This also changes the error processing semantics: before this patch if debugfs file creation failed, we wouldn't boot the firmware, now the firmware is already running but we still fail probing... Maybe make this a soft failure now?

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@plbossart I think we shoudl keep the debugfs creationg before attempting to boot. The sdev->fw_version member is populated when the FW_READY IPC message is received and if you move this to after boot is complete, I think this would never get populated

ghost Jul 15, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ranj063 this was to work around the debugfs error warnings that the item is already created if you try and reboot multiple times when FW_READY never happens.

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@plbossart ahh I see. Then I think this should be moved to ipc.c where we handle the FW_READY IPC. That would for sure indicate that the FW boot is complete and so its good to create the debugfs entry and copy the fw_version from the IPC reply.

ghost Jul 15, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well we don't want to have a memory allocation failure in ipc.c, we should maybe create this earlier instead of in the firmware_run function.

ghost Jul 15, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

then maybe we should just create this during dbg init?

}
}

return 0;
}
EXPORT_SYMBOL(snd_sof_run_firmware);
Expand Down
14 changes: 13 additions & 1 deletion sound/soc/sof/sof-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct snd_sof_dsp_ops {
int (*load_firmware)(struct snd_sof_dev *sof_dev); /* mandatory */
int (*load_module)(struct snd_sof_dev *sof_dev,
struct snd_sof_mod_hdr *hdr); /* optional */
int firmware_boot_retries;
/*
* FW ready checks for ABI compatibility and creates
* memory windows at first boot
Expand Down Expand Up @@ -341,6 +342,18 @@ struct snd_sof_ipc_msg {
bool ipc_complete;
};

/* SOF generic IPC data */
struct snd_sof_ipc {
struct snd_sof_dev *sdev;

/* protects messages and the disable flag */
struct mutex tx_mutex;
/* disables further sending of ipc's */
bool disable_ipc_tx;

struct snd_sof_ipc_msg msg;
};

enum snd_sof_fw_state {
SOF_FW_BOOT_NOT_STARTED = 0,
SOF_FW_BOOT_PREPARE,
Expand Down Expand Up @@ -386,7 +399,6 @@ struct snd_sof_dev {
struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */
struct snd_sof_mailbox host_box; /* Host initiated IPC */
struct snd_sof_mailbox stream_box; /* Stream position update */
struct snd_sof_ipc_msg *msg;
int ipc_irq;
u32 next_comp_id; /* monotonic - reset during S3 */

Expand Down