Skip to content

Commit a43ff5b

Browse files
committed
ALSA: hda - Pass bus io_ops directly from the top-level driver
One less redirection again. This also requires the change of the call order in the toplevel divers. Namely, the bus has to be created at first before other initializations since the memory allocation ops are called through bus object now. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 7e8be1b commit a43ff5b

6 files changed

Lines changed: 66 additions & 63 deletions

File tree

‎sound/pci/hda/hda_codec.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
516516
*/
517517
int snd_hda_bus_new(struct snd_card *card,
518518
const struct hdac_bus_ops *ops,
519+
const struct hdac_io_ops *io_ops,
519520
struct hda_bus **busp)
520521
{
521522
struct hda_bus *bus;
@@ -532,7 +533,7 @@ int snd_hda_bus_new(struct snd_card *card,
532533
if (!bus)
533534
return -ENOMEM;
534535

535-
err = snd_hdac_bus_init(&bus->core, card->dev, ops, NULL);
536+
err = snd_hdac_bus_init(&bus->core, card->dev, ops, io_ops);
536537
if (err < 0) {
537538
kfree(bus);
538539
return err;

‎sound/pci/hda/hda_codec.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ struct hda_codec {
328328
*/
329329
int snd_hda_bus_new(struct snd_card *card,
330330
const struct hdac_bus_ops *ops,
331+
const struct hdac_io_ops *io_ops,
331332
struct hda_bus **busp);
332333
int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
333334
unsigned int codec_addr, struct hda_codec **codecp);

‎sound/pci/hda/hda_controller.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@ static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
985985
static int azx_alloc_cmd_io(struct azx *chip)
986986
{
987987
/* single page (at least 4096 bytes) must suffice for both ringbuffes */
988-
return chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
989-
PAGE_SIZE, &chip->rb);
988+
return chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
989+
PAGE_SIZE, &chip->rb);
990990
}
991991

992992
static void azx_init_cmd_io(struct azx *chip)
@@ -1396,8 +1396,8 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
13961396
azx_dev->locked = 1;
13971397
spin_unlock_irq(&chip->reg_lock);
13981398

1399-
err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG,
1400-
byte_size, bufp);
1399+
err = chip->io_ops->dma_alloc_pages(&bus->core, SNDRV_DMA_TYPE_DEV_SG,
1400+
byte_size, bufp);
14011401
if (err < 0)
14021402
goto err_alloc;
14031403

@@ -1422,7 +1422,7 @@ static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
14221422
return azx_dev->stream_tag;
14231423

14241424
error:
1425-
chip->ops->dma_free_pages(chip, bufp);
1425+
chip->io_ops->dma_free_pages(&bus->core, bufp);
14261426
err_alloc:
14271427
spin_lock_irq(&chip->reg_lock);
14281428
if (azx_dev->opened)
@@ -1464,7 +1464,7 @@ static void azx_load_dsp_cleanup(struct hda_bus *bus,
14641464
azx_dev->period_bytes = 0;
14651465
azx_dev->format_val = 0;
14661466

1467-
chip->ops->dma_free_pages(chip, dmab);
1467+
chip->io_ops->dma_free_pages(&bus->core, dmab);
14681468
dmab->area = NULL;
14691469

14701470
spin_lock_irq(&chip->reg_lock);
@@ -1483,14 +1483,14 @@ int azx_alloc_stream_pages(struct azx *chip)
14831483
for (i = 0; i < chip->num_streams; i++) {
14841484
dsp_lock_init(&chip->azx_dev[i]);
14851485
/* allocate memory for the BDL for each stream */
1486-
err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1486+
err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
14871487
BDL_SIZE,
14881488
&chip->azx_dev[i].bdl);
14891489
if (err < 0)
14901490
return -ENOMEM;
14911491
}
14921492
/* allocate memory for the position buffer */
1493-
err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1493+
err = chip->io_ops->dma_alloc_pages(azx_bus(chip), SNDRV_DMA_TYPE_DEV,
14941494
chip->num_streams * 8, &chip->posbuf);
14951495
if (err < 0)
14961496
return -ENOMEM;
@@ -1509,13 +1509,13 @@ void azx_free_stream_pages(struct azx *chip)
15091509
if (chip->azx_dev) {
15101510
for (i = 0; i < chip->num_streams; i++)
15111511
if (chip->azx_dev[i].bdl.area)
1512-
chip->ops->dma_free_pages(
1513-
chip, &chip->azx_dev[i].bdl);
1512+
chip->io_ops->dma_free_pages(azx_bus(chip),
1513+
&chip->azx_dev[i].bdl);
15141514
}
15151515
if (chip->rb.area)
1516-
chip->ops->dma_free_pages(chip, &chip->rb);
1516+
chip->io_ops->dma_free_pages(azx_bus(chip), &chip->rb);
15171517
if (chip->posbuf.area)
1518-
chip->ops->dma_free_pages(chip, &chip->posbuf);
1518+
chip->io_ops->dma_free_pages(azx_bus(chip), &chip->posbuf);
15191519
}
15201520
EXPORT_SYMBOL_GPL(azx_free_stream_pages);
15211521

@@ -1834,7 +1834,7 @@ int azx_bus_create(struct azx *chip, const char *model)
18341834
struct hda_bus *bus;
18351835
int err;
18361836

1837-
err = snd_hda_bus_new(chip->card, &bus_core_ops, &bus);
1837+
err = snd_hda_bus_new(chip->card, &bus_core_ops, chip->io_ops, &bus);
18381838
if (err < 0)
18391839
return err;
18401840

‎sound/pci/hda/hda_controller.h‎

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,8 @@ struct azx;
125125

126126
/* Functions to read/write to hda registers. */
127127
struct hda_controller_ops {
128-
/* Register Access */
129-
void (*reg_writel)(u32 value, u32 __iomem *addr);
130-
u32 (*reg_readl)(u32 __iomem *addr);
131-
void (*reg_writew)(u16 value, u16 __iomem *addr);
132-
u16 (*reg_readw)(u16 __iomem *addr);
133-
void (*reg_writeb)(u8 value, u8 __iomem *addr);
134-
u8 (*reg_readb)(u8 __iomem *addr);
135128
/* Disable msi if supported, PCI only */
136129
int (*disable_msi_reset_irq)(struct azx *);
137-
/* Allocation ops */
138-
int (*dma_alloc_pages)(struct azx *chip,
139-
int type,
140-
size_t size,
141-
struct snd_dma_buffer *buf);
142-
void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
143130
int (*substream_alloc_pages)(struct azx *chip,
144131
struct snd_pcm_substream *substream,
145132
size_t size);
@@ -179,6 +166,7 @@ struct azx {
179166

180167
/* Register interaction. */
181168
const struct hda_controller_ops *ops;
169+
const struct hdac_io_ops *io_ops;
182170

183171
/* position adjustment callbacks */
184172
azx_get_pos_callback_t get_position[2];
@@ -239,6 +227,8 @@ struct azx {
239227
#endif
240228
};
241229

230+
#define azx_bus(chip) (&(chip)->bus->core)
231+
242232
#ifdef CONFIG_X86
243233
#define azx_snoop(chip) ((chip)->snoop)
244234
#else
@@ -250,30 +240,30 @@ struct azx {
250240
*/
251241

252242
#define azx_writel(chip, reg, value) \
253-
((chip)->ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
243+
((chip)->io_ops->reg_writel(value, (chip)->remap_addr + AZX_REG_##reg))
254244
#define azx_readl(chip, reg) \
255-
((chip)->ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
245+
((chip)->io_ops->reg_readl((chip)->remap_addr + AZX_REG_##reg))
256246
#define azx_writew(chip, reg, value) \
257-
((chip)->ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
247+
((chip)->io_ops->reg_writew(value, (chip)->remap_addr + AZX_REG_##reg))
258248
#define azx_readw(chip, reg) \
259-
((chip)->ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
249+
((chip)->io_ops->reg_readw((chip)->remap_addr + AZX_REG_##reg))
260250
#define azx_writeb(chip, reg, value) \
261-
((chip)->ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
251+
((chip)->io_ops->reg_writeb(value, (chip)->remap_addr + AZX_REG_##reg))
262252
#define azx_readb(chip, reg) \
263-
((chip)->ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
253+
((chip)->io_ops->reg_readb((chip)->remap_addr + AZX_REG_##reg))
264254

265255
#define azx_sd_writel(chip, dev, reg, value) \
266-
((chip)->ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
256+
((chip)->io_ops->reg_writel(value, (dev)->sd_addr + AZX_REG_##reg))
267257
#define azx_sd_readl(chip, dev, reg) \
268-
((chip)->ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
258+
((chip)->io_ops->reg_readl((dev)->sd_addr + AZX_REG_##reg))
269259
#define azx_sd_writew(chip, dev, reg, value) \
270-
((chip)->ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
260+
((chip)->io_ops->reg_writew(value, (dev)->sd_addr + AZX_REG_##reg))
271261
#define azx_sd_readw(chip, dev, reg) \
272-
((chip)->ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
262+
((chip)->io_ops->reg_readw((dev)->sd_addr + AZX_REG_##reg))
273263
#define azx_sd_writeb(chip, dev, reg, value) \
274-
((chip)->ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
264+
((chip)->io_ops->reg_writeb(value, (dev)->sd_addr + AZX_REG_##reg))
275265
#define azx_sd_readb(chip, dev, reg) \
276-
((chip)->ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
266+
((chip)->io_ops->reg_readb((dev)->sd_addr + AZX_REG_##reg))
277267

278268
#define azx_has_pm_runtime(chip) \
279269
(!AZX_DCAPS_PM_RUNTIME || ((chip)->driver_caps & AZX_DCAPS_PM_RUNTIME))

‎sound/pci/hda/hda_intel.c‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,11 @@ static void azx_probe_work(struct work_struct *work)
13651365
/*
13661366
* constructor
13671367
*/
1368+
static const struct hdac_io_ops pci_hda_io_ops;
1369+
static const struct hda_controller_ops pci_hda_ops;
1370+
13681371
static int azx_create(struct snd_card *card, struct pci_dev *pci,
13691372
int dev, unsigned int driver_caps,
1370-
const struct hda_controller_ops *hda_ops,
13711373
struct azx **rchip)
13721374
{
13731375
static struct snd_device_ops ops = {
@@ -1394,7 +1396,8 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
13941396
mutex_init(&chip->open_mutex);
13951397
chip->card = card;
13961398
chip->pci = pci;
1397-
chip->ops = hda_ops;
1399+
chip->ops = &pci_hda_ops;
1400+
chip->io_ops = &pci_hda_io_ops;
13981401
chip->irq = -1;
13991402
chip->driver_caps = driver_caps;
14001403
chip->driver_type = driver_caps & 0xff;
@@ -1681,24 +1684,27 @@ static int disable_msi_reset_irq(struct azx *chip)
16811684
}
16821685

16831686
/* DMA page allocation helpers. */
1684-
static int dma_alloc_pages(struct azx *chip,
1687+
static int dma_alloc_pages(struct hdac_bus *bus,
16851688
int type,
16861689
size_t size,
16871690
struct snd_dma_buffer *buf)
16881691
{
1692+
struct azx *chip = to_hda_bus(bus)->private_data;
16891693
int err;
16901694

16911695
err = snd_dma_alloc_pages(type,
1692-
chip->card->dev,
1696+
bus->dev,
16931697
size, buf);
16941698
if (err < 0)
16951699
return err;
16961700
mark_pages_wc(chip, buf, true);
16971701
return 0;
16981702
}
16991703

1700-
static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
1704+
static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
17011705
{
1706+
struct azx *chip = to_hda_bus(bus)->private_data;
1707+
17021708
mark_pages_wc(chip, buf, false);
17031709
snd_dma_free_pages(buf);
17041710
}
@@ -1740,16 +1746,19 @@ static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
17401746
#endif
17411747
}
17421748

1743-
static const struct hda_controller_ops pci_hda_ops = {
1749+
static const struct hdac_io_ops pci_hda_io_ops = {
17441750
.reg_writel = pci_azx_writel,
17451751
.reg_readl = pci_azx_readl,
17461752
.reg_writew = pci_azx_writew,
17471753
.reg_readw = pci_azx_readw,
17481754
.reg_writeb = pci_azx_writeb,
17491755
.reg_readb = pci_azx_readb,
1750-
.disable_msi_reset_irq = disable_msi_reset_irq,
17511756
.dma_alloc_pages = dma_alloc_pages,
17521757
.dma_free_pages = dma_free_pages,
1758+
};
1759+
1760+
static const struct hda_controller_ops pci_hda_ops = {
1761+
.disable_msi_reset_irq = disable_msi_reset_irq,
17531762
.substream_alloc_pages = substream_alloc_pages,
17541763
.substream_free_pages = substream_free_pages,
17551764
.pcm_mmap_prepare = pcm_mmap_prepare,
@@ -1780,8 +1789,7 @@ static int azx_probe(struct pci_dev *pci,
17801789
return err;
17811790
}
17821791

1783-
err = azx_create(card, pci, dev, pci_id->driver_data,
1784-
&pci_hda_ops, &chip);
1792+
err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
17851793
if (err < 0)
17861794
goto out_free;
17871795
card->private_data = chip;
@@ -1862,6 +1870,10 @@ static int azx_probe_continue(struct azx *chip)
18621870
#endif
18631871
}
18641872

1873+
err = azx_bus_create(chip, model[dev]);
1874+
if (err < 0)
1875+
goto out_free;
1876+
18651877
err = azx_first_init(chip);
18661878
if (err < 0)
18671879
goto out_free;
@@ -1871,10 +1883,6 @@ static int azx_probe_continue(struct azx *chip)
18711883
#endif
18721884

18731885
/* create codec instances */
1874-
err = azx_bus_create(chip, model[dev]);
1875-
if (err < 0)
1876-
goto out_free;
1877-
18781886
err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);
18791887
if (err < 0)
18801888
goto out_free;

‎sound/pci/hda/hda_tegra.c‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ MODULE_PARM_DESC(power_save,
8787
/*
8888
* DMA page allocation ops.
8989
*/
90-
static int dma_alloc_pages(struct azx *chip, int type, size_t size,
90+
static int dma_alloc_pages(struct hdac_bus *bus, int type, size_t size,
9191
struct snd_dma_buffer *buf)
9292
{
93-
return snd_dma_alloc_pages(type, chip->card->dev, size, buf);
93+
return snd_dma_alloc_pages(type, bus->dev, size, buf);
9494
}
9595

96-
static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
96+
static void dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
9797
{
9898
snd_dma_free_pages(buf);
9999
}
@@ -173,7 +173,7 @@ static u8 hda_tegra_readb(u8 *addr)
173173
return (v >> shift) & 0xff;
174174
}
175175

176-
static const struct hda_controller_ops hda_tegra_ops = {
176+
static const struct hdac_io_ops hda_tegra_io_ops = {
177177
.reg_writel = hda_tegra_writel,
178178
.reg_readl = hda_tegra_readl,
179179
.reg_writew = hda_tegra_writew,
@@ -182,6 +182,9 @@ static const struct hda_controller_ops hda_tegra_ops = {
182182
.reg_readb = hda_tegra_readb,
183183
.dma_alloc_pages = dma_alloc_pages,
184184
.dma_free_pages = dma_free_pages,
185+
};
186+
187+
static const struct hda_controller_ops hda_tegra_ops = {
185188
.substream_alloc_pages = substream_alloc_pages,
186189
.substream_free_pages = substream_free_pages,
187190
};
@@ -409,7 +412,6 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
409412
*/
410413
static int hda_tegra_create(struct snd_card *card,
411414
unsigned int driver_caps,
412-
const struct hda_controller_ops *hda_ops,
413415
struct hda_tegra *hda)
414416
{
415417
static struct snd_device_ops ops = {
@@ -423,7 +425,8 @@ static int hda_tegra_create(struct snd_card *card,
423425
spin_lock_init(&chip->reg_lock);
424426
mutex_init(&chip->open_mutex);
425427
chip->card = card;
426-
chip->ops = hda_ops;
428+
chip->ops = &hda_tegra_ops;
429+
chip->io_ops = &hda_tegra_io_ops;
427430
chip->irq = -1;
428431
chip->driver_caps = driver_caps;
429432
chip->driver_type = driver_caps & 0xff;
@@ -471,7 +474,11 @@ static int hda_tegra_probe(struct platform_device *pdev)
471474
return err;
472475
}
473476

474-
err = hda_tegra_create(card, driver_flags, &hda_tegra_ops, hda);
477+
err = azx_bus_create(chip, NULL);
478+
if (err < 0)
479+
goto out_free;
480+
481+
err = hda_tegra_create(card, driver_flags, hda);
475482
if (err < 0)
476483
goto out_free;
477484
card->private_data = chip;
@@ -483,10 +490,6 @@ static int hda_tegra_probe(struct platform_device *pdev)
483490
goto out_free;
484491

485492
/* create codec instances */
486-
err = azx_bus_create(chip, NULL);
487-
if (err < 0)
488-
goto out_free;
489-
490493
err = azx_probe_codecs(chip, 0);
491494
if (err < 0)
492495
goto out_free;

0 commit comments

Comments
 (0)