ASoC: SOF: Introduce num_cores and ref count per core
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Fri, 19 Nov 2021 19:26:13 +0000 (21:26 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 22 Nov 2021 15:40:16 +0000 (15:40 +0000)
Add two fields num_cores and dsp_cores_ref_count to
struct snd_sof_dev. These will be used to maintain the
ref count for each core to determine when it should be
powered up or down.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20211119192621.4096077-3-kai.vehmanen@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/imx/imx8.c
sound/soc/sof/imx/imx8m.c
sound/soc/sof/intel/bdw.c
sound/soc/sof/intel/byt.c
sound/soc/sof/intel/hda.c
sound/soc/sof/intel/pci-tng.c
sound/soc/sof/sof-priv.h

index 0aeb44d0acc7e40ddd5e6db38726e73ccb6ed6fa..2d0448b3c8c3e070fb42e78d3630efff588bba4a 100644 (file)
@@ -188,6 +188,7 @@ static int imx8_probe(struct snd_sof_dev *sdev)
        if (!priv)
                return -ENOMEM;
 
+       sdev->num_cores = 1;
        sdev->pdata->hw_pdata = priv;
        priv->dev = sdev->dev;
        priv->sdev = sdev;
index f454a5d0a87e9a43d5bd6542bdab95f197c71685..c94422323d675b159c1ea901a9e898d21821b727 100644 (file)
@@ -108,6 +108,7 @@ static int imx8m_probe(struct snd_sof_dev *sdev)
        if (!priv)
                return -ENOMEM;
 
+       sdev->num_cores = 1;
        sdev->pdata->hw_pdata = priv;
        priv->dev = sdev->dev;
        priv->sdev = sdev;
index 156006bed01749b16be4b79b4d9e7bdd4eaa6d8f..1a8a39a878fd1e0fa1f3f32a159c894cfad8160d 100644 (file)
@@ -412,10 +412,19 @@ static int bdw_probe(struct snd_sof_dev *sdev)
        const struct sof_dev_desc *desc = pdata->desc;
        struct platform_device *pdev =
                container_of(sdev->dev, struct platform_device, dev);
+       const struct sof_intel_dsp_desc *chip;
        struct resource *mmio;
        u32 base, size;
        int ret;
 
+       chip = get_chip_info(sdev->pdata);
+       if (!chip) {
+               dev_err(sdev->dev, "error: no such device supported\n");
+               return -EIO;
+       }
+
+       sdev->num_cores = chip->cores_num;
+
        /* LPE base */
        mmio = platform_get_resource(pdev, IORESOURCE_MEM,
                                     desc->resindex_lpe_base);
index e2fa08f1ae74e8abcd4dfd897459b2c889d91643..dcfeaedb8fd5ffa21173d8797b7f3d05d5cd7cb8 100644 (file)
@@ -113,10 +113,19 @@ static int byt_acpi_probe(struct snd_sof_dev *sdev)
        const struct sof_dev_desc *desc = pdata->desc;
        struct platform_device *pdev =
                container_of(sdev->dev, struct platform_device, dev);
+       const struct sof_intel_dsp_desc *chip;
        struct resource *mmio;
        u32 base, size;
        int ret;
 
+       chip = get_chip_info(sdev->pdata);
+       if (!chip) {
+               dev_err(sdev->dev, "error: no such device supported\n");
+               return -EIO;
+       }
+
+       sdev->num_cores = chip->cores_num;
+
        /* DSP DMA can only access low 31 bits of host memory */
        ret = dma_coerce_mask_and_coherent(sdev->dev, DMA_BIT_MASK(31));
        if (ret < 0) {
index 1ebf8db488b80a459c82d33363e541b77322d8e8..3c69e8fcd43b45d12e2782edd02d223ec8206f9d 100644 (file)
@@ -897,6 +897,8 @@ int hda_dsp_probe(struct snd_sof_dev *sdev)
                goto err;
        }
 
+       sdev->num_cores = chip->cores_num;
+
        hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
        if (!hdev)
                return -ENOMEM;
index 18eb41b8a8f4aa2a18af0028c226789fcd4be416..f8c841caa36226b441118024144959b8986b5dbb 100644 (file)
@@ -55,9 +55,18 @@ static int tangier_pci_probe(struct snd_sof_dev *sdev)
        struct snd_sof_pdata *pdata = sdev->pdata;
        const struct sof_dev_desc *desc = pdata->desc;
        struct pci_dev *pci = to_pci_dev(sdev->dev);
+       const struct sof_intel_dsp_desc *chip;
        u32 base, size;
        int ret;
 
+       chip = get_chip_info(sdev->pdata);
+       if (!chip) {
+               dev_err(sdev->dev, "error: no such device supported\n");
+               return -EIO;
+       }
+
+       sdev->num_cores = chip->cores_num;
+
        /* DSP DMA can only access low 31 bits of host memory */
        ret = dma_coerce_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31));
        if (ret < 0) {
index 9a8af76b2f8b93d8a7c24b1c00f030dd1e2e8c36..a56f3c8b483f8ce666c8e90a8064ee6b27d8d48d 100644 (file)
@@ -71,6 +71,9 @@ extern int sof_core_debug;
 /* So far the primary core on all DSPs has ID 0 */
 #define SOF_DSP_PRIMARY_CORE 0
 
+/* max number of DSP cores */
+#define SOF_MAX_DSP_NUM_CORES 8
+
 /* DSP power state */
 enum sof_dsp_power_states {
        SOF_DSP_PM_D0,
@@ -477,6 +480,18 @@ struct snd_sof_dev {
 
        bool msi_enabled;
 
+       /* DSP core context */
+       u32 num_cores;
+
+       /*
+        * ref count per core that will be modified during system suspend/resume and during pcm
+        * hw_params/hw_free. This doesn't need to be protected with a mutex because pcm
+        * hw_params/hw_free are already protected by the PCM mutex in the ALSA framework in
+        * sound/core/ when streams are active and during system suspend/resume, streams are
+        * already suspended.
+        */
+       int dsp_core_ref_count[SOF_MAX_DSP_NUM_CORES];
+
        void *private;                  /* core does not touch this */
 };