]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ALSA: hda: Remove page allocation redirection
authorTakashi Iwai <tiwai@suse.de>
Wed, 7 Aug 2019 18:02:31 +0000 (20:02 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 8 Aug 2019 14:34:49 +0000 (16:34 +0200)
The HD-audio core allocates and releases pages via driver's specific
dma_alloc_pages and dma_free_pages ops defined in bus->io_ops.  This
was because some platforms require the uncached pages and the handling
of page flags had to be done locally in the driver code.

Since the recent change in ALSA core memory allocator, we can simply
pass SNDRV_DMA_TYPE_DEV_UC for the uncached pages, and the only
difference became about this type to be passed to the core allocator.
That is, it's good time for cleaning up the mess.

This patch changes the allocation code in HD-audio core to call the
core allocator directly so that we get rid of dma_alloc_pages and
dma_free_pages io_ops.  If a driver needs the uncached pages, it has
to set bus->dma_type right after the bus initialization.

This is merely a code refactoring and shouldn't bring any behavior
changes.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hdaudio.h
sound/hda/ext/hdac_ext_bus.c
sound/hda/hdac_bus.c
sound/hda/hdac_controller.c
sound/hda/hdac_stream.c
sound/pci/hda/hda_intel.c
sound/pci/hda/hda_tegra.c
sound/soc/intel/skylake/skl-messages.c
sound/soc/sof/intel/hda-bus.c

index 612a17e375d026b0215572f6d9dec83e04ad0c37..20549def0a277d41ef889460526aa33751cc4269 100644 (file)
@@ -264,11 +264,6 @@ struct hdac_io_ops {
        u16 (*reg_readw)(u16 __iomem *addr);
        void (*reg_writeb)(u8 value, u8 __iomem *addr);
        u8 (*reg_readb)(u8 __iomem *addr);
-       /* Allocation ops */
-       int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size,
-                              struct snd_dma_buffer *buf);
-       void (*dma_free_pages)(struct hdac_bus *bus,
-                              struct snd_dma_buffer *buf);
 };
 
 #define HDA_UNSOL_QUEUE_SIZE   64
@@ -344,6 +339,7 @@ struct hdac_bus {
        /* CORB/RIRB and position buffers */
        struct snd_dma_buffer rb;
        struct snd_dma_buffer posbuf;
+       int dma_type;                   /* SNDRV_DMA_TYPE_XXX for CORB/RIRB */
 
        /* hdac_stream linked list */
        struct list_head stream_list;
index 4f9f1d2a2ec53cce983619f058d5282af6d8a10a..7825b74068f4b9a1bfce9bf739518fcd31386f46 100644 (file)
@@ -47,17 +47,6 @@ static u8 hdac_ext_readb(u8 __iomem *addr)
        return readb(addr);
 }
 
-static int hdac_ext_dma_alloc_pages(struct hdac_bus *bus, int type,
-                          size_t size, struct snd_dma_buffer *buf)
-{
-       return snd_dma_alloc_pages(type, bus->dev, size, buf);
-}
-
-static void hdac_ext_dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
-{
-       snd_dma_free_pages(buf);
-}
-
 static const struct hdac_io_ops hdac_ext_default_io = {
        .reg_writel = hdac_ext_writel,
        .reg_readl = hdac_ext_readl,
@@ -65,8 +54,6 @@ static const struct hdac_io_ops hdac_ext_default_io = {
        .reg_readw = hdac_ext_readw,
        .reg_writeb = hdac_ext_writeb,
        .reg_readb = hdac_ext_readb,
-       .dma_alloc_pages = hdac_ext_dma_alloc_pages,
-       .dma_free_pages = hdac_ext_dma_free_pages,
 };
 
 /**
index 14e57ffd5bc198a5bb69ba862f19e2b34cd8d283..00ea12e67dc8ebc5bfb1ac8466666a921902dcd0 100644 (file)
@@ -34,6 +34,7 @@ int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
        else
                bus->ops = &default_ops;
        bus->io_ops = io_ops;
+       bus->dma_type = SNDRV_DMA_TYPE_DEV;
        INIT_LIST_HEAD(&bus->stream_list);
        INIT_LIST_HEAD(&bus->codec_list);
        INIT_WORK(&bus->unsol_work, snd_hdac_bus_process_unsol_events);
index 3b0110545070ac1fec24e44aac251490c18203d7..7e7be8e4dcf9c3d7dd170ad2cbea0b949ec7f9e1 100644 (file)
@@ -575,12 +575,13 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
 {
        struct hdac_stream *s;
        int num_streams = 0;
+       int dma_type = bus->dma_type ? bus->dma_type : SNDRV_DMA_TYPE_DEV;
        int err;
 
        list_for_each_entry(s, &bus->stream_list, list) {
                /* allocate memory for the BDL for each stream */
-               err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
-                                                  BDL_SIZE, &s->bdl);
+               err = snd_dma_alloc_pages(dma_type, bus->dev,
+                                         BDL_SIZE, &s->bdl);
                num_streams++;
                if (err < 0)
                        return -ENOMEM;
@@ -589,16 +590,15 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
        if (WARN_ON(!num_streams))
                return -EINVAL;
        /* allocate memory for the position buffer */
-       err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
-                                          num_streams * 8, &bus->posbuf);
+       err = snd_dma_alloc_pages(dma_type, bus->dev,
+                                 num_streams * 8, &bus->posbuf);
        if (err < 0)
                return -ENOMEM;
        list_for_each_entry(s, &bus->stream_list, list)
                s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8);
 
        /* single page (at least 4096 bytes) must suffice for both ringbuffes */
-       return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
-                                           PAGE_SIZE, &bus->rb);
+       return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb);
 }
 EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages);
 
@@ -612,12 +612,12 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus)
 
        list_for_each_entry(s, &bus->stream_list, list) {
                if (s->bdl.area)
-                       bus->io_ops->dma_free_pages(bus, &s->bdl);
+                       snd_dma_free_pages(&s->bdl);
        }
 
        if (bus->rb.area)
-               bus->io_ops->dma_free_pages(bus, &bus->rb);
+               snd_dma_free_pages(&bus->rb);
        if (bus->posbuf.area)
-               bus->io_ops->dma_free_pages(bus, &bus->posbuf);
+               snd_dma_free_pages(&bus->posbuf);
 }
 EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages);
index 55d53b89ac21583e5f55308350dc54ed26b82843..fc68d4ce0a373c759558bbddaeb8b0ec3ab0f3d0 100644 (file)
@@ -680,8 +680,8 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
        azx_dev->locked = true;
        spin_unlock_irq(&bus->reg_lock);
 
-       err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV_SG,
-                                          byte_size, bufp);
+       err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, bus->dev,
+                                 byte_size, bufp);
        if (err < 0)
                goto err_alloc;
 
@@ -707,7 +707,7 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
        return azx_dev->stream_tag;
 
  error:
-       bus->io_ops->dma_free_pages(bus, bufp);
+       snd_dma_free_pages(bufp);
  err_alloc:
        spin_lock_irq(&bus->reg_lock);
        azx_dev->locked = false;
@@ -754,7 +754,7 @@ void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev,
        azx_dev->period_bytes = 0;
        azx_dev->format_val = 0;
 
-       bus->io_ops->dma_free_pages(bus, dmab);
+       snd_dma_free_pages(dmab);
        dmab->area = NULL;
 
        spin_lock_irq(&bus->reg_lock);
index cb8b0945547cdf2c0382fdc7e0bdb794401150b8..3bb4c26f27992bc389f5cd073304a19615c069c1 100644 (file)
@@ -1694,6 +1694,10 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
                return err;
        }
 
+       /* use the non-cached pages in non-snoop mode */
+       if (!azx_snoop(chip))
+               azx_bus(chip)->dma_type = SNDRV_DMA_TYPE_DEV_UC;
+
        /* Workaround for a communication error on CFL (bko#199007) and CNL */
        if (IS_CFL(pci) || IS_CNL(pci))
                azx_bus(chip)->polling_mode = 1;
@@ -1979,24 +1983,6 @@ static int disable_msi_reset_irq(struct azx *chip)
        return 0;
 }
 
-/* DMA page allocation helpers.  */
-static int dma_alloc_pages(struct hdac_bus *bus,
-                          int type,
-                          size_t size,
-                          struct snd_dma_buffer *buf)
-{
-       struct azx *chip = bus_to_azx(bus);
-
-       if (!azx_snoop(chip) && type == SNDRV_DMA_TYPE_DEV)
-               type = SNDRV_DMA_TYPE_DEV_UC;
-       return snd_dma_alloc_pages(type, bus->dev, size, buf);
-}
-
-static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
-{
-       snd_dma_free_pages(buf);
-}
-
 static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
                             struct vm_area_struct *area)
 {
@@ -2015,8 +2001,6 @@ static const struct hdac_io_ops pci_hda_io_ops = {
        .reg_readw = pci_azx_readw,
        .reg_writeb = pci_azx_writeb,
        .reg_readb = pci_azx_readb,
-       .dma_alloc_pages = dma_alloc_pages,
-       .dma_free_pages = dma_free_pages,
 };
 
 static const struct hda_controller_ops pci_hda_ops = {
index 7dbe9f39fc798277912d58ef8c004c977a5eeacf..ba414cc639f1d85b16056e57897d53c835735898 100644 (file)
@@ -75,20 +75,6 @@ MODULE_PARM_DESC(power_save,
 #define power_save     0
 #endif
 
-/*
- * DMA page allocation ops.
- */
-static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size,
-                          struct snd_dma_buffer *buf)
-{
-       return snd_dma_alloc_pages(type, bus->dev, size, buf);
-}
-
-static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
-{
-       snd_dma_free_pages(buf);
-}
-
 /*
  * Register access ops. Tegra HDA register access is DWORD only.
  */
@@ -153,8 +139,6 @@ static const struct hdac_io_ops hda_tegra_io_ops = {
        .reg_readw = hda_tegra_readw,
        .reg_writeb = hda_tegra_writeb,
        .reg_readb = hda_tegra_readb,
-       .dma_alloc_pages = dma_alloc_pages,
-       .dma_free_pages = dma_free_pages,
 };
 
 static const struct hda_controller_ops hda_tegra_ops; /* nothing special */
index febc070839e022f8aa03da5e2c499165a54cfb7f..c6f9e05c929e48a6b3a9f41f085f46fb40276692 100644 (file)
 static int skl_alloc_dma_buf(struct device *dev,
                struct snd_dma_buffer *dmab, size_t size)
 {
-       struct hdac_bus *bus = dev_get_drvdata(dev);
-
-       if (!bus)
-               return -ENODEV;
-
-       return  bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, size, dmab);
+       return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, dmab);
 }
 
 static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab)
 {
-       struct hdac_bus *bus = dev_get_drvdata(dev);
-
-       if (!bus)
-               return -ENODEV;
-
-       bus->io_ops->dma_free_pages(bus, dmab);
-
+       snd_dma_free_pages(dmab);
        return 0;
 }
 
index a7e6d8227df6f45727b8f2dfcd911df700bdbe67..0bc93fa06b5b93bb6f927d3fe226d0e86b1f5a15 100644 (file)
@@ -51,18 +51,6 @@ static u8 sof_hda_readb(u8 __iomem *addr)
        return readb(addr);
 }
 
-static int sof_hda_dma_alloc_pages(struct hdac_bus *bus, int type,
-                                  size_t size, struct snd_dma_buffer *buf)
-{
-       return snd_dma_alloc_pages(type, bus->dev, size, buf);
-}
-
-static void sof_hda_dma_free_pages(struct hdac_bus *bus,
-                                  struct snd_dma_buffer *buf)
-{
-       snd_dma_free_pages(buf);
-}
-
 static const struct hdac_io_ops io_ops = {
        .reg_writel = sof_hda_writel,
        .reg_readl = sof_hda_readl,
@@ -70,8 +58,6 @@ static const struct hdac_io_ops io_ops = {
        .reg_readw = sof_hda_readw,
        .reg_writeb = sof_hda_writeb,
        .reg_readb = sof_hda_readb,
-       .dma_alloc_pages = sof_hda_dma_alloc_pages,
-       .dma_free_pages = sof_hda_dma_free_pages,
 };
 
 /*