ALSA: hda - Pull pages allocation to hda_controller
authorDylan Reid <dgreid@chromium.org>
Fri, 28 Feb 2014 23:41:23 +0000 (15:41 -0800)
committerTakashi Iwai <tiwai@suse.de>
Sat, 1 Mar 2014 10:22:30 +0000 (11:22 +0100)
Pull allocation from first_init to a new function in hda_controller.c.
Short term this will allow the dsp loader to be moved as well.  In
later commits it will allow the same allocation to be used by the
platform hda driver.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_controller.c
sound/pci/hda/hda_controller.h
sound/pci/hda/hda_intel.c

index fcc5c3063967df9592a4314bc007784c7e6a01b0..bf5e89027fc1632bb93b1a927ff856d550075492 100644 (file)
@@ -1014,5 +1014,48 @@ int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
 }
 EXPORT_SYMBOL_GPL(azx_attach_pcm_stream);
 
+int azx_alloc_stream_pages(struct azx *chip)
+{
+       int i, err;
+       struct snd_card *card = chip->card;
+
+       for (i = 0; i < chip->num_streams; i++) {
+               dsp_lock_init(&chip->azx_dev[i]);
+               /* allocate memory for the BDL for each stream */
+               err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
+                                                BDL_SIZE,
+                                                &chip->azx_dev[i].bdl);
+               if (err < 0) {
+                       dev_err(card->dev, "cannot allocate BDL\n");
+                       return -ENOMEM;
+               }
+       }
+       /* allocate memory for the position buffer */
+       err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
+                                        chip->num_streams * 8, &chip->posbuf);
+       if (err < 0) {
+               dev_err(card->dev, "cannot allocate posbuf\n");
+               return -ENOMEM;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(azx_alloc_stream_pages);
+
+void azx_free_stream_pages(struct azx *chip)
+{
+       int i;
+       if (chip->azx_dev) {
+               for (i = 0; i < chip->num_streams; i++)
+                       if (chip->azx_dev[i].bdl.area)
+                               chip->ops->dma_free_pages(
+                                       chip, &chip->azx_dev[i].bdl);
+       }
+       if (chip->rb.area)
+               chip->ops->dma_free_pages(chip, &chip->rb);
+       if (chip->posbuf.area)
+               chip->ops->dma_free_pages(chip, &chip->posbuf);
+}
+EXPORT_SYMBOL_GPL(azx_free_stream_pages);
+
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Common HDA driver funcitons");
index a62cdde93a2bb77a19c023415a1460349b584dd1..9ea6b44e033d079a1ac2d9dd16b723a6cf44c86d 100644 (file)
@@ -54,4 +54,8 @@ int setup_bdle(struct azx *chip,
 #define dsp_is_locked(dev)     0
 #endif
 
+/* Allocation functions. */
+int azx_alloc_stream_pages(struct azx *chip);
+void azx_free_stream_pages(struct azx *chip);
+
 #endif /* __SOUND_HDA_CONTROLLER_H */
index f86ee2bb45297dfad4ca77df23cea35dd94f6949..4a0b228d70f7b4f46ae37b961549689fd6e0fa8f 100644 (file)
@@ -1864,16 +1864,7 @@ static int azx_free(struct azx *chip)
        if (chip->remap_addr)
                iounmap(chip->remap_addr);
 
-       if (chip->azx_dev) {
-               for (i = 0; i < chip->num_streams; i++)
-                       if (chip->azx_dev[i].bdl.area)
-                               chip->ops->dma_free_pages(
-                                       chip, &chip->azx_dev[i].bdl);
-       }
-       if (chip->rb.area)
-               chip->ops->dma_free_pages(chip, &chip->rb);
-       if (chip->posbuf.area)
-               chip->ops->dma_free_pages(chip, &chip->posbuf);
+       azx_free_stream_pages(chip);
        if (chip->region_requested)
                pci_release_regions(chip->pci);
        pci_disable_device(chip->pci);
@@ -2210,7 +2201,7 @@ static int azx_first_init(struct azx *chip)
        int dev = chip->dev_index;
        struct pci_dev *pci = chip->pci;
        struct snd_card *card = chip->card;
-       int i, err;
+       int err;
        unsigned short gcap;
 
 #if BITS_PER_LONG != 64
@@ -2322,24 +2313,9 @@ static int azx_first_init(struct azx *chip)
                return -ENOMEM;
        }
 
-       for (i = 0; i < chip->num_streams; i++) {
-               dsp_lock_init(&chip->azx_dev[i]);
-               /* allocate memory for the BDL for each stream */
-               err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
-                                                BDL_SIZE,
-                                                &chip->azx_dev[i].bdl);
-               if (err < 0) {
-                       dev_err(card->dev, "cannot allocate BDL\n");
-                       return -ENOMEM;
-               }
-       }
-       /* allocate memory for the position buffer */
-       err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
-                                        chip->num_streams * 8, &chip->posbuf);
-       if (err < 0) {
-               dev_err(card->dev, "cannot allocate posbuf\n");
-               return -ENOMEM;
-       }
+       err = azx_alloc_stream_pages(chip);
+       if (err < 0)
+               return err;
        /* allocate CORB/RIRB */
        err = azx_alloc_cmd_io(chip);
        if (err < 0)
This page took 0.028427 seconds and 5 git commands to generate.