Skip to content

Commit 19abfef

Browse files
committed
ALSA: hda: Direct MMIO accesses
HD-audio drivers access to the mmio registers indirectly via the corresponding bus->io_ops callbacks. This is because some platform (notably Tegra SoC) requires the word-aligned access. But it's rather a rare case, and other platforms suffer from the penalties by indirect calls unnecessarily. This patch is an attempt to optimize and cleanup for this situation. Now the special aligned access is used only when a new kconfig CONFIG_SND_HDA_ALIGNED_MMIO is set. And the HD-audio core itself provides the aligned MMIO access helpers instead of the driver side. If Kconfig isn't set (as default), the standard helpers like readl() or writel() are used directly. A couple of places in ASoC Intel drivers have the access via io_ops reg_writel(), and they are replaced with the direct writel() calls. And now with this patch, the whole bus->io_ops becomes empty, so it's dropped completely. The bus initialization functions are changed accordingly as well to drop the whole bus->io_ops. Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 619a1f1 commit 19abfef

13 files changed

Lines changed: 75 additions & 248 deletions

File tree

‎include/sound/hdaudio.h‎

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,6 @@ struct hdac_ext_bus_ops {
253253
int (*hdev_detach)(struct hdac_device *hdev);
254254
};
255255

256-
/*
257-
* Lowlevel I/O operators
258-
*/
259-
struct hdac_io_ops {
260-
/* mapped register accesses */
261-
void (*reg_writel)(u32 value, u32 __iomem *addr);
262-
u32 (*reg_readl)(u32 __iomem *addr);
263-
void (*reg_writew)(u16 value, u16 __iomem *addr);
264-
u16 (*reg_readw)(u16 __iomem *addr);
265-
void (*reg_writeb)(u8 value, u8 __iomem *addr);
266-
u8 (*reg_readb)(u8 __iomem *addr);
267-
};
268-
269256
#define HDA_UNSOL_QUEUE_SIZE 64
270257
#define HDA_MAX_CODECS 8 /* limit by controller side */
271258

@@ -299,7 +286,6 @@ struct hdac_rb {
299286
struct hdac_bus {
300287
struct device *dev;
301288
const struct hdac_bus_ops *ops;
302-
const struct hdac_io_ops *io_ops;
303289
const struct hdac_ext_bus_ops *ext_ops;
304290

305291
/* h/w resources */
@@ -380,8 +366,7 @@ struct hdac_bus {
380366
};
381367

382368
int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
383-
const struct hdac_bus_ops *ops,
384-
const struct hdac_io_ops *io_ops);
369+
const struct hdac_bus_ops *ops);
385370
void snd_hdac_bus_exit(struct hdac_bus *bus);
386371
int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr,
387372
unsigned int cmd, unsigned int *res);
@@ -425,21 +410,38 @@ int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
425410
int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus);
426411
void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus);
427412

413+
#ifdef CONFIG_SND_HDA_ALIGNED_MMIO
414+
unsigned int snd_hdac_aligned_read(void __iomem *addr, unsigned int mask);
415+
void snd_hdac_aligned_write(unsigned int val, void __iomem *addr,
416+
unsigned int mask);
417+
#define snd_hdac_reg_writeb(v, addr) snd_hdac_aligned_write(v, addr, 0xff)
418+
#define snd_hdac_reg_writew(v, addr) snd_hdac_aligned_write(v, addr, 0xffff)
419+
#define snd_hdac_reg_readb(addr) snd_hdac_aligned_read(addr, 0xff)
420+
#define snd_hdac_reg_readw(addr) snd_hdac_aligned_read(addr, 0xffff)
421+
#else /* CONFIG_SND_HDA_ALIGNED_MMIO */
422+
#define snd_hdac_reg_writeb(val, addr) writeb(val, addr)
423+
#define snd_hdac_reg_writew(val, addr) writew(val, addr)
424+
#define snd_hdac_reg_readb(addr) readb(addr)
425+
#define snd_hdac_reg_readw(addr) readw(addr)
426+
#endif /* CONFIG_SND_HDA_ALIGNED_MMIO */
427+
#define snd_hdac_reg_writel(val, addr) writel(val, addr)
428+
#define snd_hdac_reg_readl(addr) readl(addr)
429+
428430
/*
429431
* macros for easy use
430432
*/
431433
#define _snd_hdac_chip_writeb(chip, reg, value) \
432-
((chip)->io_ops->reg_writeb(value, (chip)->remap_addr + (reg)))
434+
snd_hdac_reg_writeb(value, (chip)->remap_addr + (reg))
433435
#define _snd_hdac_chip_readb(chip, reg) \
434-
((chip)->io_ops->reg_readb((chip)->remap_addr + (reg)))
436+
snd_hdac_reg_readb((chip)->remap_addr + (reg))
435437
#define _snd_hdac_chip_writew(chip, reg, value) \
436-
((chip)->io_ops->reg_writew(value, (chip)->remap_addr + (reg)))
438+
snd_hdac_reg_writew(value, (chip)->remap_addr + (reg))
437439
#define _snd_hdac_chip_readw(chip, reg) \
438-
((chip)->io_ops->reg_readw((chip)->remap_addr + (reg)))
440+
snd_hdac_reg_readw((chip)->remap_addr + (reg))
439441
#define _snd_hdac_chip_writel(chip, reg, value) \
440-
((chip)->io_ops->reg_writel(value, (chip)->remap_addr + (reg)))
442+
snd_hdac_reg_writel(value, (chip)->remap_addr + (reg))
441443
#define _snd_hdac_chip_readl(chip, reg) \
442-
((chip)->io_ops->reg_readl((chip)->remap_addr + (reg)))
444+
snd_hdac_reg_readl((chip)->remap_addr + (reg))
443445

444446
/* read/write a register, pass without AZX_REG_ prefix */
445447
#define snd_hdac_chip_writel(chip, reg, value) \
@@ -544,24 +546,19 @@ int snd_hdac_get_stream_stripe_ctl(struct hdac_bus *bus,
544546
/*
545547
* macros for easy use
546548
*/
547-
#define _snd_hdac_stream_write(type, dev, reg, value) \
548-
((dev)->bus->io_ops->reg_write ## type(value, (dev)->sd_addr + (reg)))
549-
#define _snd_hdac_stream_read(type, dev, reg) \
550-
((dev)->bus->io_ops->reg_read ## type((dev)->sd_addr + (reg)))
551-
552549
/* read/write a register, pass without AZX_REG_ prefix */
553550
#define snd_hdac_stream_writel(dev, reg, value) \
554-
_snd_hdac_stream_write(l, dev, AZX_REG_ ## reg, value)
551+
snd_hdac_reg_writel(value, (dev)->sd_addr + AZX_REG_ ## reg)
555552
#define snd_hdac_stream_writew(dev, reg, value) \
556-
_snd_hdac_stream_write(w, dev, AZX_REG_ ## reg, value)
553+
snd_hdac_reg_writew(value, (dev)->sd_addr + AZX_REG_ ## reg)
557554
#define snd_hdac_stream_writeb(dev, reg, value) \
558-
_snd_hdac_stream_write(b, dev, AZX_REG_ ## reg, value)
555+
snd_hdac_reg_writeb(value, (dev)->sd_addr + AZX_REG_ ## reg)
559556
#define snd_hdac_stream_readl(dev, reg) \
560-
_snd_hdac_stream_read(l, dev, AZX_REG_ ## reg)
557+
snd_hdac_reg_readl((dev)->sd_addr + AZX_REG_ ## reg)
561558
#define snd_hdac_stream_readw(dev, reg) \
562-
_snd_hdac_stream_read(w, dev, AZX_REG_ ## reg)
559+
snd_hdac_reg_readw((dev)->sd_addr + AZX_REG_ ## reg)
563560
#define snd_hdac_stream_readb(dev, reg) \
564-
_snd_hdac_stream_read(b, dev, AZX_REG_ ## reg)
561+
snd_hdac_reg_readb((dev)->sd_addr + AZX_REG_ ## reg)
565562

566563
/* update a register, pass without AZX_REG_ prefix */
567564
#define snd_hdac_stream_updatel(dev, reg, mask, val) \

‎include/sound/hdaudio_ext.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
88
const struct hdac_bus_ops *ops,
9-
const struct hdac_io_ops *io_ops,
109
const struct hdac_ext_bus_ops *ext_ops);
1110

1211
void snd_hdac_ext_bus_exit(struct hdac_bus *bus);

‎sound/hda/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ config SND_HDA_CORE
66
config SND_HDA_DSP_LOADER
77
bool
88

9+
config SND_HDA_ALIGNED_MMIO
10+
bool
11+
912
config SND_HDA_COMPONENT
1013
bool
1114

‎sound/hda/ext/hdac_ext_bus.c‎

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,67 +17,22 @@
1717
MODULE_DESCRIPTION("HDA extended core");
1818
MODULE_LICENSE("GPL v2");
1919

20-
static void hdac_ext_writel(u32 value, u32 __iomem *addr)
21-
{
22-
writel(value, addr);
23-
}
24-
25-
static u32 hdac_ext_readl(u32 __iomem *addr)
26-
{
27-
return readl(addr);
28-
}
29-
30-
static void hdac_ext_writew(u16 value, u16 __iomem *addr)
31-
{
32-
writew(value, addr);
33-
}
34-
35-
static u16 hdac_ext_readw(u16 __iomem *addr)
36-
{
37-
return readw(addr);
38-
}
39-
40-
static void hdac_ext_writeb(u8 value, u8 __iomem *addr)
41-
{
42-
writeb(value, addr);
43-
}
44-
45-
static u8 hdac_ext_readb(u8 __iomem *addr)
46-
{
47-
return readb(addr);
48-
}
49-
50-
static const struct hdac_io_ops hdac_ext_default_io = {
51-
.reg_writel = hdac_ext_writel,
52-
.reg_readl = hdac_ext_readl,
53-
.reg_writew = hdac_ext_writew,
54-
.reg_readw = hdac_ext_readw,
55-
.reg_writeb = hdac_ext_writeb,
56-
.reg_readb = hdac_ext_readb,
57-
};
58-
5920
/**
6021
* snd_hdac_ext_bus_init - initialize a HD-audio extended bus
6122
* @ebus: the pointer to extended bus object
6223
* @dev: device pointer
6324
* @ops: bus verb operators
64-
* @io_ops: lowlevel I/O operators, can be NULL. If NULL core will use
6525
* default ops
6626
*
6727
* Returns 0 if successful, or a negative error code.
6828
*/
6929
int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
7030
const struct hdac_bus_ops *ops,
71-
const struct hdac_io_ops *io_ops,
7231
const struct hdac_ext_bus_ops *ext_ops)
7332
{
7433
int ret;
7534

76-
/* check if io ops are provided, if not load the defaults */
77-
if (io_ops == NULL)
78-
io_ops = &hdac_ext_default_io;
79-
80-
ret = snd_hdac_bus_init(bus, dev, ops, io_ops);
35+
ret = snd_hdac_bus_init(bus, dev, ops);
8136
if (ret < 0)
8237
return ret;
8338

‎sound/hda/hdac_bus.c‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ static const struct hdac_bus_ops default_ops = {
1919
* snd_hdac_bus_init - initialize a HD-audio bas bus
2020
* @bus: the pointer to bus object
2121
* @ops: bus verb operators
22-
* @io_ops: lowlevel I/O operators
2322
*
2423
* Returns 0 if successful, or a negative error code.
2524
*/
2625
int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
27-
const struct hdac_bus_ops *ops,
28-
const struct hdac_io_ops *io_ops)
26+
const struct hdac_bus_ops *ops)
2927
{
3028
memset(bus, 0, sizeof(*bus));
3129
bus->dev = dev;
3230
if (ops)
3331
bus->ops = ops;
3432
else
3533
bus->ops = &default_ops;
36-
bus->io_ops = io_ops;
3734
bus->dma_type = SNDRV_DMA_TYPE_DEV;
3835
INIT_LIST_HEAD(&bus->stream_list);
3936
INIT_LIST_HEAD(&bus->codec_list);
@@ -218,3 +215,33 @@ void snd_hdac_bus_remove_device(struct hdac_bus *bus,
218215
flush_work(&bus->unsol_work);
219216
}
220217
EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device);
218+
219+
#ifdef CONFIG_SND_HDA_ALIGNED_MMIO
220+
/* Helpers for aligned read/write of mmio space, for Tegra */
221+
unsigned int snd_hdac_aligned_read(void __iomem *addr, unsigned int mask)
222+
{
223+
void __iomem *aligned_addr =
224+
(void __iomem *)((unsigned long)(addr) & ~0x3);
225+
unsigned int shift = ((unsigned long)(addr) & 0x3) << 3;
226+
unsigned int v;
227+
228+
v = readl(aligned_addr);
229+
return (v >> shift) & mask;
230+
}
231+
EXPORT_SYMBOL_GPL(snd_hdac_aligned_read);
232+
233+
void snd_hdac_aligned_write(unsigned int val, void __iomem *addr,
234+
unsigned int mask)
235+
{
236+
void __iomem *aligned_addr =
237+
(void __iomem *)((unsigned long)(addr) & ~0x3);
238+
unsigned int shift = ((unsigned long)(addr) & 0x3) << 3;
239+
unsigned int v;
240+
241+
v = readl(aligned_addr);
242+
v &= ~(mask << shift);
243+
v |= val << shift;
244+
writel(v, aligned_addr);
245+
}
246+
EXPORT_SYMBOL_GPL(snd_hdac_aligned_write);
247+
#endif /* CONFIG_SND_HDA_ALIGNED_MMIO */

‎sound/pci/hda/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config SND_HDA_TEGRA
2626
tristate "NVIDIA Tegra HD Audio"
2727
depends on ARCH_TEGRA
2828
select SND_HDA
29+
select SND_HDA_ALIGNED_MMIO
2930
help
3031
Say Y here to support the HDA controller present in NVIDIA
3132
Tegra SoCs

‎sound/pci/hda/hda_controller.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,14 +1202,12 @@ void snd_hda_bus_reset(struct hda_bus *bus)
12021202
}
12031203

12041204
/* HD-audio bus initialization */
1205-
int azx_bus_init(struct azx *chip, const char *model,
1206-
const struct hdac_io_ops *io_ops)
1205+
int azx_bus_init(struct azx *chip, const char *model)
12071206
{
12081207
struct hda_bus *bus = &chip->bus;
12091208
int err;
12101209

1211-
err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops,
1212-
io_ops);
1210+
err = snd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops);
12131211
if (err < 0)
12141212
return err;
12151213

‎sound/pci/hda/hda_controller.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ void azx_stop_chip(struct azx *chip);
206206
irqreturn_t azx_interrupt(int irq, void *dev_id);
207207

208208
/* Codec interface */
209-
int azx_bus_init(struct azx *chip, const char *model,
210-
const struct hdac_io_ops *io_ops);
209+
int azx_bus_init(struct azx *chip, const char *model);
211210
int azx_probe_codecs(struct azx *chip, unsigned int max_slots);
212211
int azx_codec_configure(struct azx *chip);
213212
int azx_init_streams(struct azx *chip);

‎sound/pci/hda/hda_intel.c‎

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,6 @@ static int default_bdl_pos_adj(struct azx *chip)
16271627
/*
16281628
* constructor
16291629
*/
1630-
static const struct hdac_io_ops pci_hda_io_ops;
16311630
static const struct hda_controller_ops pci_hda_ops;
16321631

16331632
static int azx_create(struct snd_card *card, struct pci_dev *pci,
@@ -1687,7 +1686,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
16871686
else
16881687
chip->bdl_pos_adj = bdl_pos_adj[dev];
16891688

1690-
err = azx_bus_init(chip, model[dev], &pci_hda_io_ops);
1689+
err = azx_bus_init(chip, model[dev]);
16911690
if (err < 0) {
16921691
kfree(hda);
16931692
pci_disable_device(pci);
@@ -1932,41 +1931,6 @@ static void azx_firmware_cb(const struct firmware *fw, void *context)
19321931
}
19331932
#endif
19341933

1935-
/*
1936-
* HDA controller ops.
1937-
*/
1938-
1939-
/* PCI register access. */
1940-
static void pci_azx_writel(u32 value, u32 __iomem *addr)
1941-
{
1942-
writel(value, addr);
1943-
}
1944-
1945-
static u32 pci_azx_readl(u32 __iomem *addr)
1946-
{
1947-
return readl(addr);
1948-
}
1949-
1950-
static void pci_azx_writew(u16 value, u16 __iomem *addr)
1951-
{
1952-
writew(value, addr);
1953-
}
1954-
1955-
static u16 pci_azx_readw(u16 __iomem *addr)
1956-
{
1957-
return readw(addr);
1958-
}
1959-
1960-
static void pci_azx_writeb(u8 value, u8 __iomem *addr)
1961-
{
1962-
writeb(value, addr);
1963-
}
1964-
1965-
static u8 pci_azx_readb(u8 __iomem *addr)
1966-
{
1967-
return readb(addr);
1968-
}
1969-
19701934
static int disable_msi_reset_irq(struct azx *chip)
19711935
{
19721936
struct hdac_bus *bus = azx_bus(chip);
@@ -1994,15 +1958,6 @@ static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
19941958
#endif
19951959
}
19961960

1997-
static const struct hdac_io_ops pci_hda_io_ops = {
1998-
.reg_writel = pci_azx_writel,
1999-
.reg_readl = pci_azx_readl,
2000-
.reg_writew = pci_azx_writew,
2001-
.reg_readw = pci_azx_readw,
2002-
.reg_writeb = pci_azx_writeb,
2003-
.reg_readb = pci_azx_readb,
2004-
};
2005-
20061961
static const struct hda_controller_ops pci_hda_ops = {
20071962
.disable_msi_reset_irq = disable_msi_reset_irq,
20081963
.pcm_mmap_prepare = pcm_mmap_prepare,

0 commit comments

Comments
 (0)