summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2019-08-07 14:02:31 -0400
committerTakashi Iwai <tiwai@suse.de>2019-08-08 10:34:49 -0400
commit619a1f195f93276dc8c6e33fe057e007adc9c288 (patch)
treec85080b44c4b7296f841f4d1424f4943b7806eaf
parent5f9e832c137075045d15cd6899ab0505cfb2ca4b (diff)
ALSA: hda: Remove page allocation redirection
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>
-rw-r--r--include/sound/hdaudio.h6
-rw-r--r--sound/hda/ext/hdac_ext_bus.c13
-rw-r--r--sound/hda/hdac_bus.c1
-rw-r--r--sound/hda/hdac_controller.c18
-rw-r--r--sound/hda/hdac_stream.c8
-rw-r--r--sound/pci/hda/hda_intel.c24
-rw-r--r--sound/pci/hda/hda_tegra.c16
-rw-r--r--sound/soc/intel/skylake/skl-messages.c15
-rw-r--r--sound/soc/sof/intel/hda-bus.c14
9 files changed, 21 insertions, 94 deletions
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index 612a17e375d0..20549def0a27 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -264,11 +264,6 @@ struct hdac_io_ops {
264 u16 (*reg_readw)(u16 __iomem *addr); 264 u16 (*reg_readw)(u16 __iomem *addr);
265 void (*reg_writeb)(u8 value, u8 __iomem *addr); 265 void (*reg_writeb)(u8 value, u8 __iomem *addr);
266 u8 (*reg_readb)(u8 __iomem *addr); 266 u8 (*reg_readb)(u8 __iomem *addr);
267 /* Allocation ops */
268 int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size,
269 struct snd_dma_buffer *buf);
270 void (*dma_free_pages)(struct hdac_bus *bus,
271 struct snd_dma_buffer *buf);
272}; 267};
273 268
274#define HDA_UNSOL_QUEUE_SIZE 64 269#define HDA_UNSOL_QUEUE_SIZE 64
@@ -344,6 +339,7 @@ struct hdac_bus {
344 /* CORB/RIRB and position buffers */ 339 /* CORB/RIRB and position buffers */
345 struct snd_dma_buffer rb; 340 struct snd_dma_buffer rb;
346 struct snd_dma_buffer posbuf; 341 struct snd_dma_buffer posbuf;
342 int dma_type; /* SNDRV_DMA_TYPE_XXX for CORB/RIRB */
347 343
348 /* hdac_stream linked list */ 344 /* hdac_stream linked list */
349 struct list_head stream_list; 345 struct list_head stream_list;
diff --git a/sound/hda/ext/hdac_ext_bus.c b/sound/hda/ext/hdac_ext_bus.c
index 4f9f1d2a2ec5..7825b74068f4 100644
--- a/sound/hda/ext/hdac_ext_bus.c
+++ b/sound/hda/ext/hdac_ext_bus.c
@@ -47,17 +47,6 @@ static u8 hdac_ext_readb(u8 __iomem *addr)
47 return readb(addr); 47 return readb(addr);
48} 48}
49 49
50static int hdac_ext_dma_alloc_pages(struct hdac_bus *bus, int type,
51 size_t size, struct snd_dma_buffer *buf)
52{
53 return snd_dma_alloc_pages(type, bus->dev, size, buf);
54}
55
56static void hdac_ext_dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
57{
58 snd_dma_free_pages(buf);
59}
60
61static const struct hdac_io_ops hdac_ext_default_io = { 50static const struct hdac_io_ops hdac_ext_default_io = {
62 .reg_writel = hdac_ext_writel, 51 .reg_writel = hdac_ext_writel,
63 .reg_readl = hdac_ext_readl, 52 .reg_readl = hdac_ext_readl,
@@ -65,8 +54,6 @@ static const struct hdac_io_ops hdac_ext_default_io = {
65 .reg_readw = hdac_ext_readw, 54 .reg_readw = hdac_ext_readw,
66 .reg_writeb = hdac_ext_writeb, 55 .reg_writeb = hdac_ext_writeb,
67 .reg_readb = hdac_ext_readb, 56 .reg_readb = hdac_ext_readb,
68 .dma_alloc_pages = hdac_ext_dma_alloc_pages,
69 .dma_free_pages = hdac_ext_dma_free_pages,
70}; 57};
71 58
72/** 59/**
diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c
index 14e57ffd5bc1..00ea12e67dc8 100644
--- a/sound/hda/hdac_bus.c
+++ b/sound/hda/hdac_bus.c
@@ -34,6 +34,7 @@ int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
34 else 34 else
35 bus->ops = &default_ops; 35 bus->ops = &default_ops;
36 bus->io_ops = io_ops; 36 bus->io_ops = io_ops;
37 bus->dma_type = SNDRV_DMA_TYPE_DEV;
37 INIT_LIST_HEAD(&bus->stream_list); 38 INIT_LIST_HEAD(&bus->stream_list);
38 INIT_LIST_HEAD(&bus->codec_list); 39 INIT_LIST_HEAD(&bus->codec_list);
39 INIT_WORK(&bus->unsol_work, snd_hdac_bus_process_unsol_events); 40 INIT_WORK(&bus->unsol_work, snd_hdac_bus_process_unsol_events);
diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c
index 3b0110545070..7e7be8e4dcf9 100644
--- a/sound/hda/hdac_controller.c
+++ b/sound/hda/hdac_controller.c
@@ -575,12 +575,13 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
575{ 575{
576 struct hdac_stream *s; 576 struct hdac_stream *s;
577 int num_streams = 0; 577 int num_streams = 0;
578 int dma_type = bus->dma_type ? bus->dma_type : SNDRV_DMA_TYPE_DEV;
578 int err; 579 int err;
579 580
580 list_for_each_entry(s, &bus->stream_list, list) { 581 list_for_each_entry(s, &bus->stream_list, list) {
581 /* allocate memory for the BDL for each stream */ 582 /* allocate memory for the BDL for each stream */
582 err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, 583 err = snd_dma_alloc_pages(dma_type, bus->dev,
583 BDL_SIZE, &s->bdl); 584 BDL_SIZE, &s->bdl);
584 num_streams++; 585 num_streams++;
585 if (err < 0) 586 if (err < 0)
586 return -ENOMEM; 587 return -ENOMEM;
@@ -589,16 +590,15 @@ int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
589 if (WARN_ON(!num_streams)) 590 if (WARN_ON(!num_streams))
590 return -EINVAL; 591 return -EINVAL;
591 /* allocate memory for the position buffer */ 592 /* allocate memory for the position buffer */
592 err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, 593 err = snd_dma_alloc_pages(dma_type, bus->dev,
593 num_streams * 8, &bus->posbuf); 594 num_streams * 8, &bus->posbuf);
594 if (err < 0) 595 if (err < 0)
595 return -ENOMEM; 596 return -ENOMEM;
596 list_for_each_entry(s, &bus->stream_list, list) 597 list_for_each_entry(s, &bus->stream_list, list)
597 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8); 598 s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8);
598 599
599 /* single page (at least 4096 bytes) must suffice for both ringbuffes */ 600 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
600 return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, 601 return snd_dma_alloc_pages(dma_type, bus->dev, PAGE_SIZE, &bus->rb);
601 PAGE_SIZE, &bus->rb);
602} 602}
603EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages); 603EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages);
604 604
@@ -612,12 +612,12 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus)
612 612
613 list_for_each_entry(s, &bus->stream_list, list) { 613 list_for_each_entry(s, &bus->stream_list, list) {
614 if (s->bdl.area) 614 if (s->bdl.area)
615 bus->io_ops->dma_free_pages(bus, &s->bdl); 615 snd_dma_free_pages(&s->bdl);
616 } 616 }
617 617
618 if (bus->rb.area) 618 if (bus->rb.area)
619 bus->io_ops->dma_free_pages(bus, &bus->rb); 619 snd_dma_free_pages(&bus->rb);
620 if (bus->posbuf.area) 620 if (bus->posbuf.area)
621 bus->io_ops->dma_free_pages(bus, &bus->posbuf); 621 snd_dma_free_pages(&bus->posbuf);
622} 622}
623EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages); 623EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages);
diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index 55d53b89ac21..fc68d4ce0a37 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -680,8 +680,8 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
680 azx_dev->locked = true; 680 azx_dev->locked = true;
681 spin_unlock_irq(&bus->reg_lock); 681 spin_unlock_irq(&bus->reg_lock);
682 682
683 err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV_SG, 683 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, bus->dev,
684 byte_size, bufp); 684 byte_size, bufp);
685 if (err < 0) 685 if (err < 0)
686 goto err_alloc; 686 goto err_alloc;
687 687
@@ -707,7 +707,7 @@ int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format,
707 return azx_dev->stream_tag; 707 return azx_dev->stream_tag;
708 708
709 error: 709 error:
710 bus->io_ops->dma_free_pages(bus, bufp); 710 snd_dma_free_pages(bufp);
711 err_alloc: 711 err_alloc:
712 spin_lock_irq(&bus->reg_lock); 712 spin_lock_irq(&bus->reg_lock);
713 azx_dev->locked = false; 713 azx_dev->locked = false;
@@ -754,7 +754,7 @@ void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev,
754 azx_dev->period_bytes = 0; 754 azx_dev->period_bytes = 0;
755 azx_dev->format_val = 0; 755 azx_dev->format_val = 0;
756 756
757 bus->io_ops->dma_free_pages(bus, dmab); 757 snd_dma_free_pages(dmab);
758 dmab->area = NULL; 758 dmab->area = NULL;
759 759
760 spin_lock_irq(&bus->reg_lock); 760 spin_lock_irq(&bus->reg_lock);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index cb8b0945547c..3bb4c26f2799 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1694,6 +1694,10 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
1694 return err; 1694 return err;
1695 } 1695 }
1696 1696
1697 /* use the non-cached pages in non-snoop mode */
1698 if (!azx_snoop(chip))
1699 azx_bus(chip)->dma_type = SNDRV_DMA_TYPE_DEV_UC;
1700
1697 /* Workaround for a communication error on CFL (bko#199007) and CNL */ 1701 /* Workaround for a communication error on CFL (bko#199007) and CNL */
1698 if (IS_CFL(pci) || IS_CNL(pci)) 1702 if (IS_CFL(pci) || IS_CNL(pci))
1699 azx_bus(chip)->polling_mode = 1; 1703 azx_bus(chip)->polling_mode = 1;
@@ -1979,24 +1983,6 @@ static int disable_msi_reset_irq(struct azx *chip)
1979 return 0; 1983 return 0;
1980} 1984}
1981 1985
1982/* DMA page allocation helpers. */
1983static int dma_alloc_pages(struct hdac_bus *bus,
1984 int type,
1985 size_t size,
1986 struct snd_dma_buffer *buf)
1987{
1988 struct azx *chip = bus_to_azx(bus);
1989
1990 if (!azx_snoop(chip) && type == SNDRV_DMA_TYPE_DEV)
1991 type = SNDRV_DMA_TYPE_DEV_UC;
1992 return snd_dma_alloc_pages(type, bus->dev, size, buf);
1993}
1994
1995static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
1996{
1997 snd_dma_free_pages(buf);
1998}
1999
2000static void pcm_mmap_prepare(struct snd_pcm_substream *substream, 1986static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
2001 struct vm_area_struct *area) 1987 struct vm_area_struct *area)
2002{ 1988{
@@ -2015,8 +2001,6 @@ static const struct hdac_io_ops pci_hda_io_ops = {
2015 .reg_readw = pci_azx_readw, 2001 .reg_readw = pci_azx_readw,
2016 .reg_writeb = pci_azx_writeb, 2002 .reg_writeb = pci_azx_writeb,
2017 .reg_readb = pci_azx_readb, 2003 .reg_readb = pci_azx_readb,
2018 .dma_alloc_pages = dma_alloc_pages,
2019 .dma_free_pages = dma_free_pages,
2020}; 2004};
2021 2005
2022static const struct hda_controller_ops pci_hda_ops = { 2006static const struct hda_controller_ops pci_hda_ops = {
diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c
index 7dbe9f39fc79..ba414cc639f1 100644
--- a/sound/pci/hda/hda_tegra.c
+++ b/sound/pci/hda/hda_tegra.c
@@ -76,20 +76,6 @@ MODULE_PARM_DESC(power_save,
76#endif 76#endif
77 77
78/* 78/*
79 * DMA page allocation ops.
80 */
81static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size,
82 struct snd_dma_buffer *buf)
83{
84 return snd_dma_alloc_pages(type, bus->dev, size, buf);
85}
86
87static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
88{
89 snd_dma_free_pages(buf);
90}
91
92/*
93 * Register access ops. Tegra HDA register access is DWORD only. 79 * Register access ops. Tegra HDA register access is DWORD only.
94 */ 80 */
95static void hda_tegra_writel(u32 value, u32 __iomem *addr) 81static void hda_tegra_writel(u32 value, u32 __iomem *addr)
@@ -153,8 +139,6 @@ static const struct hdac_io_ops hda_tegra_io_ops = {
153 .reg_readw = hda_tegra_readw, 139 .reg_readw = hda_tegra_readw,
154 .reg_writeb = hda_tegra_writeb, 140 .reg_writeb = hda_tegra_writeb,
155 .reg_readb = hda_tegra_readb, 141 .reg_readb = hda_tegra_readb,
156 .dma_alloc_pages = dma_alloc_pages,
157 .dma_free_pages = dma_free_pages,
158}; 142};
159 143
160static const struct hda_controller_ops hda_tegra_ops; /* nothing special */ 144static const struct hda_controller_ops hda_tegra_ops; /* nothing special */
diff --git a/sound/soc/intel/skylake/skl-messages.c b/sound/soc/intel/skylake/skl-messages.c
index febc070839e0..c6f9e05c929e 100644
--- a/sound/soc/intel/skylake/skl-messages.c
+++ b/sound/soc/intel/skylake/skl-messages.c
@@ -25,23 +25,12 @@
25static int skl_alloc_dma_buf(struct device *dev, 25static int skl_alloc_dma_buf(struct device *dev,
26 struct snd_dma_buffer *dmab, size_t size) 26 struct snd_dma_buffer *dmab, size_t size)
27{ 27{
28 struct hdac_bus *bus = dev_get_drvdata(dev); 28 return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dev, size, dmab);
29
30 if (!bus)
31 return -ENODEV;
32
33 return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, size, dmab);
34} 29}
35 30
36static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab) 31static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab)
37{ 32{
38 struct hdac_bus *bus = dev_get_drvdata(dev); 33 snd_dma_free_pages(dmab);
39
40 if (!bus)
41 return -ENODEV;
42
43 bus->io_ops->dma_free_pages(bus, dmab);
44
45 return 0; 34 return 0;
46} 35}
47 36
diff --git a/sound/soc/sof/intel/hda-bus.c b/sound/soc/sof/intel/hda-bus.c
index a7e6d8227df6..0bc93fa06b5b 100644
--- a/sound/soc/sof/intel/hda-bus.c
+++ b/sound/soc/sof/intel/hda-bus.c
@@ -51,18 +51,6 @@ static u8 sof_hda_readb(u8 __iomem *addr)
51 return readb(addr); 51 return readb(addr);
52} 52}
53 53
54static int sof_hda_dma_alloc_pages(struct hdac_bus *bus, int type,
55 size_t size, struct snd_dma_buffer *buf)
56{
57 return snd_dma_alloc_pages(type, bus->dev, size, buf);
58}
59
60static void sof_hda_dma_free_pages(struct hdac_bus *bus,
61 struct snd_dma_buffer *buf)
62{
63 snd_dma_free_pages(buf);
64}
65
66static const struct hdac_io_ops io_ops = { 54static const struct hdac_io_ops io_ops = {
67 .reg_writel = sof_hda_writel, 55 .reg_writel = sof_hda_writel,
68 .reg_readl = sof_hda_readl, 56 .reg_readl = sof_hda_readl,
@@ -70,8 +58,6 @@ static const struct hdac_io_ops io_ops = {
70 .reg_readw = sof_hda_readw, 58 .reg_readw = sof_hda_readw,
71 .reg_writeb = sof_hda_writeb, 59 .reg_writeb = sof_hda_writeb,
72 .reg_readb = sof_hda_readb, 60 .reg_readb = sof_hda_readb,
73 .dma_alloc_pages = sof_hda_dma_alloc_pages,
74 .dma_free_pages = sof_hda_dma_free_pages,
75}; 61};
76 62
77/* 63/*