diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index adc7c37145d640..734c42f9c85559 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -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); @@ -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; } @@ -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; + } + goto fw_run_err; } diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c index bc0628c7b88c48..127df87aece13e 100644 --- a/sound/soc/sof/imx/imx8.c +++ b/sound/soc/sof/imx/imx8.c @@ -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; } diff --git a/sound/soc/sof/imx/imx8m.c b/sound/soc/sof/imx/imx8m.c index 3b9c560cd40f61..1665d98d8987dc 100644 --- a/sound/soc/sof/imx/imx8m.c +++ b/sound/soc/sof/imx/imx8m.c @@ -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; } diff --git a/sound/soc/sof/intel/bdw.c b/sound/soc/sof/intel/bdw.c index 99fd0bd7276e22..7ad84d1d447d3d 100644 --- a/sound/soc/sof/intel/bdw.c +++ b/sound/soc/sof/intel/bdw.c @@ -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; @@ -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; } diff --git a/sound/soc/sof/intel/byt.c b/sound/soc/sof/intel/byt.c index 49f67f1b94e0ba..9959166ed46739 100644 --- a/sound/soc/sof/intel/byt.c +++ b/sound/soc/sof/intel/byt.c @@ -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 */ @@ -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", @@ -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; @@ -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; } @@ -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); + while (tries--) { if (!(snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_CSR) & SHIM_BYT_CSR_PWAITMODE)) @@ -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 */ @@ -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", + pmc_status); + return -ENODEV; + + } + /* IMR base - optional */ if (desc->resindex_imr_base == -1) goto irq; @@ -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, diff --git a/sound/soc/sof/intel/hda-ipc.c b/sound/soc/sof/intel/hda-ipc.c index c91aa951df2261..fe82a021ac87e8 100644 --- a/sound/soc/sof/intel/hda-ipc.c +++ b/sound/soc/sof/intel/hda-ipc.c @@ -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; @@ -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; } diff --git a/sound/soc/sof/intel/shim.h b/sound/soc/sof/intel/shim.h index 6fe8b004b50eff..370ebb36d394d2 100644 --- a/sound/soc/sof/intel/shim.h +++ b/sound/soc/sof/intel/shim.h @@ -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) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index 36e2d4d43da4a8..312379db85c331 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -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; @@ -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) diff --git a/sound/soc/sof/loader.c b/sound/soc/sof/loader.c index 42e0e3e58869a5..8aea048f68dae3 100644 --- a/sound/soc/sof/loader.c +++ b/sound/soc/sof/loader.c @@ -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) { @@ -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; + } + } + return 0; } EXPORT_SYMBOL(snd_sof_run_firmware); diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 9bee2aab750daf..74731f1e448303 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -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 @@ -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, @@ -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 */