Skip to content

Commit 77a23f2

Browse files
tiwaiperexg
authored andcommitted
ALSA: Clean up SG-buffer helper functions and macros
Clean up SG-buffer helper functions and macros. Helpers take substream as arguments now. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1 parent 46480b3 commit 77a23f2

15 files changed

Lines changed: 91 additions & 103 deletions

File tree

‎include/sound/memalloc.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ struct snd_dma_buffer {
6565
/*
6666
* Scatter-Gather generic device pages
6767
*/
68+
void *snd_malloc_sgbuf_pages(struct device *device,
69+
size_t size, struct snd_dma_buffer *dmab,
70+
size_t *res_size);
71+
int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
72+
6873
struct snd_sg_page {
6974
void *buf;
7075
dma_addr_t addr;
@@ -95,6 +100,13 @@ static inline dma_addr_t snd_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t off
95100
return sgbuf->table[offset >> PAGE_SHIFT].addr + offset % PAGE_SIZE;
96101
}
97102

103+
/*
104+
* return the virtual address at the corresponding offset
105+
*/
106+
static inline void *snd_sgbuf_get_ptr(struct snd_sg_buf *sgbuf, size_t offset)
107+
{
108+
return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE;
109+
}
98110

99111
/* allocate/release a buffer */
100112
int snd_dma_alloc_pages(int type, struct device *dev, size_t size,

‎include/sound/pcm.h‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,29 @@ int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
974974
int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
975975
int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
976976

977-
#define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_buffer_p->private_data)
978-
#define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size)
979-
#define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs)
980-
struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset);
977+
/*
978+
* SG-buffer handling
979+
*/
980+
#define snd_pcm_substream_sgbuf(substream) \
981+
((substream)->runtime->dma_buffer_p->private_data)
982+
983+
static inline dma_addr_t
984+
snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
985+
{
986+
struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
987+
return snd_sgbuf_get_addr(sg, ofs);
988+
}
989+
990+
static inline void *
991+
snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
992+
{
993+
struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
994+
return snd_sgbuf_get_ptr(sg, ofs);
995+
}
996+
997+
struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
998+
unsigned long offset);
999+
9811000

9821001
/* handle mmap counter - PCM mmap callback should handle this counter properly */
9831002
static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)

‎sound/core/memalloc.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ MODULE_DESCRIPTION("Memory allocator for ALSA system.");
4343
MODULE_LICENSE("GPL");
4444

4545

46-
/*
47-
*/
48-
49-
void *snd_malloc_sgbuf_pages(struct device *device,
50-
size_t size, struct snd_dma_buffer *dmab,
51-
size_t *res_size);
52-
int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
53-
5446
/*
5547
*/
5648

‎sound/pci/au88x0/au88x0.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ typedef struct {
125125
/* Virtual page extender stuff */
126126
int nr_periods;
127127
int period_bytes;
128-
struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
129128
int period_real;
130129
int period_virt;
131130

@@ -195,16 +194,14 @@ static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
195194

196195
/* DMA Engines. */
197196
static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
198-
struct snd_sg_buf * sgbuf, int size,
199-
int count);
197+
int size, int count);
200198
static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
201199
int dir, int fmt, int d,
202200
u32 offset);
203201
static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
204202
#ifndef CHIP_AU8810
205203
static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
206-
struct snd_sg_buf * sgbuf, int size,
207-
int count);
204+
int size, int count);
208205
static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
209206
u32 offset);
210207
static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);

‎sound/pci/au88x0/au88x0_core.c‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,19 +1097,12 @@ static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb)
10971097

10981098
static void
10991099
vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1100-
struct snd_sg_buf * sgbuf, int psize, int count)
1100+
int psize, int count)
11011101
{
11021102
stream_t *dma = &vortex->dma_adb[adbdma];
11031103

1104-
if (sgbuf == NULL) {
1105-
printk(KERN_INFO "vortex: FATAL: sgbuf is NULL!\n");
1106-
return;
1107-
}
1108-
//printk(KERN_INFO "vortex: page count = %d, tblcount = %d\n", count, sgbuf->tblsize);
1109-
11101104
dma->period_bytes = psize;
11111105
dma->nr_periods = count;
1112-
dma->sgbuf = sgbuf;
11131106

11141107
dma->cfg0 = 0;
11151108
dma->cfg1 = 0;
@@ -1120,26 +1113,26 @@ vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
11201113
dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize - 1);
11211114
hwwrite(vortex->mmio,
11221115
VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0xc,
1123-
snd_sgbuf_get_addr(sgbuf, psize * 3));
1116+
snd_pcm_sgbuf_get_addr(dma->substream, psize * 3));
11241117
/* 3 pages */
11251118
case 3:
11261119
dma->cfg0 |= 0x12000000;
11271120
dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
11281121
hwwrite(vortex->mmio,
11291122
VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x8,
1130-
snd_sgbuf_get_addr(sgbuf, psize * 2));
1123+
snd_pcm_sgbuf_get_addr(dma->substream, psize * 2));
11311124
/* 2 pages */
11321125
case 2:
11331126
dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize - 1);
11341127
hwwrite(vortex->mmio,
11351128
VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x4,
1136-
snd_sgbuf_get_addr(sgbuf, psize));
1129+
snd_pcm_sgbuf_get_addr(dma->substream, psize));
11371130
/* 1 page */
11381131
case 1:
11391132
dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
11401133
hwwrite(vortex->mmio,
11411134
VORTEX_ADBDMA_BUFBASE + (adbdma << 4),
1142-
snd_sgbuf_get_addr(sgbuf, 0));
1135+
snd_pcm_sgbuf_get_addr(dma->substream, 0));
11431136
break;
11441137
}
11451138
//printk("vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n", dma->cfg0, dma->cfg1);
@@ -1205,7 +1198,7 @@ static int vortex_adbdma_bufshift(vortex_t * vortex, int adbdma)
12051198
//hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr);
12061199
hwwrite(vortex->mmio,
12071200
VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2),
1208-
snd_sgbuf_get_addr(dma->sgbuf,
1201+
snd_pcm_sgbuf_get_addr(dma->substream,
12091202
dma->period_bytes * p));
12101203
/* Force write thru cache. */
12111204
hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE +
@@ -1244,7 +1237,10 @@ static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma) {
12441237
if (pp >= 4)
12451238
pp -= 4;
12461239
}
1247-
hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), snd_sgbuf_get_addr(dma->sgbuf, dma->period_bytes * p));
1240+
hwwrite(vortex->mmio,
1241+
VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2),
1242+
snd_pcm_sgbuf_get_addr(dma->substream,
1243+
dma->period_bytes * p));
12481244
/* Force write thru cache. */
12491245
hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + (((adbdma << 2)+pp) << 2));
12501246
}
@@ -1367,13 +1363,12 @@ static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb)
13671363

13681364
static void
13691365
vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
1370-
struct snd_sg_buf * sgbuf, int psize, int count)
1366+
int psize, int count)
13711367
{
13721368
stream_t *dma = &vortex->dma_wt[wtdma];
13731369

13741370
dma->period_bytes = psize;
13751371
dma->nr_periods = count;
1376-
dma->sgbuf = sgbuf;
13771372

13781373
dma->cfg0 = 0;
13791374
dma->cfg1 = 0;
@@ -1383,23 +1378,23 @@ vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
13831378
case 4:
13841379
dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize-1);
13851380
hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0xc,
1386-
snd_sgbuf_get_addr(sgbuf, psize * 3));
1381+
snd_pcm_sgbuf_get_addr(dma->substream, psize * 3));
13871382
/* 3 pages */
13881383
case 3:
13891384
dma->cfg0 |= 0x12000000;
13901385
dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
13911386
hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x8,
1392-
snd_sgbuf_get_addr(sgbuf, psize * 2));
1387+
snd_pcm_sgbuf_get_addr(dma->substream, psize * 2));
13931388
/* 2 pages */
13941389
case 2:
13951390
dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize-1);
13961391
hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x4,
1397-
snd_sgbuf_get_addr(sgbuf, psize));
1392+
snd_pcm_sgbuf_get_addr(dma->substream, psize));
13981393
/* 1 page */
13991394
case 1:
14001395
dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
14011396
hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4),
1402-
snd_sgbuf_get_addr(sgbuf, 0));
1397+
snd_pcm_sgbuf_get_addr(dma->substream, 0));
14031398
break;
14041399
}
14051400
hwwrite(vortex->mmio, VORTEX_WTDMA_BUFCFG0 + (wtdma << 3), dma->cfg0);
@@ -1465,7 +1460,8 @@ static int vortex_wtdma_bufshift(vortex_t * vortex, int wtdma)
14651460
hwwrite(vortex->mmio,
14661461
VORTEX_WTDMA_BUFBASE +
14671462
(((wtdma << 2) + pp) << 2),
1468-
snd_sgbuf_get_addr(dma->sgbuf, dma->period_bytes * p));
1463+
snd_pcm_sgbuf_get_addr(dma->substream,
1464+
dma->period_bytes * p));
14691465
/* Force write thru cache. */
14701466
hwread(vortex->mmio, VORTEX_WTDMA_BUFBASE +
14711467
(((wtdma << 2) + pp) << 2));

‎sound/pci/au88x0/au88x0_pcm.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
189189
{
190190
vortex_t *chip = snd_pcm_substream_chip(substream);
191191
stream_t *stream = (stream_t *) (substream->runtime->private_data);
192-
struct snd_sg_buf *sgbuf;
193192
int err;
194193

195194
// Alloc buffer memory.
@@ -199,8 +198,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
199198
printk(KERN_ERR "Vortex: pcm page alloc failed!\n");
200199
return err;
201200
}
202-
//sgbuf = (struct snd_sg_buf *) substream->runtime->dma_private;
203-
sgbuf = snd_pcm_substream_sgbuf(substream);
204201
/*
205202
printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params),
206203
params_period_bytes(hw_params), params_channels(hw_params));
@@ -226,7 +223,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
226223
stream = substream->runtime->private_data = &chip->dma_adb[dma];
227224
stream->substream = substream;
228225
/* Setup Buffers. */
229-
vortex_adbdma_setbuffers(chip, dma, sgbuf,
226+
vortex_adbdma_setbuffers(chip, dma,
230227
params_period_bytes(hw_params),
231228
params_periods(hw_params));
232229
}
@@ -240,7 +237,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
240237
&chip->dma_wt[substream->number];
241238
stream->dma = substream->number;
242239
stream->substream = substream;
243-
vortex_wtdma_setbuffers(chip, substream->number, sgbuf,
240+
vortex_wtdma_setbuffers(chip, substream->number,
244241
params_period_bytes(hw_params),
245242
params_periods(hw_params));
246243
}
@@ -392,13 +389,6 @@ static snd_pcm_uframes_t snd_vortex_pcm_pointer(struct snd_pcm_substream *substr
392389
return (bytes_to_frames(substream->runtime, current_ptr));
393390
}
394391

395-
/* Page callback. */
396-
/*
397-
static struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset) {
398-
399-
400-
}
401-
*/
402392
/* operators */
403393
static struct snd_pcm_ops snd_vortex_playback_ops = {
404394
.open = snd_vortex_pcm_open,

‎sound/pci/bt87x.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ static inline void snd_bt87x_writel(struct snd_bt87x *chip, u32 reg, u32 value)
227227
static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream,
228228
unsigned int periods, unsigned int period_bytes)
229229
{
230-
struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
231230
unsigned int i, offset;
232231
u32 *risc;
233232

@@ -246,6 +245,7 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
246245
rest = period_bytes;
247246
do {
248247
u32 cmd, len;
248+
unsigned int addr;
249249

250250
len = PAGE_SIZE - (offset % PAGE_SIZE);
251251
if (len > rest)
@@ -260,7 +260,8 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
260260
if (len == rest)
261261
cmd |= RISC_EOL | RISC_IRQ;
262262
*risc++ = cpu_to_le32(cmd);
263-
*risc++ = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, offset));
263+
addr = snd_pcm_sgbuf_get_addr(substream, offset);
264+
*risc++ = cpu_to_le32(addr);
264265
offset += len;
265266
rest -= len;
266267
} while (rest > 0);

‎sound/pci/echoaudio/echoaudio.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ static int init_engine(struct snd_pcm_substream *substream,
490490
{
491491
struct echoaudio *chip;
492492
int err, per, rest, page, edge, offs;
493-
struct snd_sg_buf *sgbuf;
494493
struct audiopipe *pipe;
495494

496495
chip = snd_pcm_substream_chip(substream);
@@ -531,10 +530,6 @@ static int init_engine(struct snd_pcm_substream *substream,
531530
return err;
532531
}
533532

534-
sgbuf = snd_pcm_substream_sgbuf(substream);
535-
536-
DE_HWP(("pcm_hw_params table size=%d pages=%d\n",
537-
sgbuf->size, sgbuf->pages));
538533
sglist_init(chip, pipe);
539534
edge = PAGE_SIZE;
540535
for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
@@ -543,16 +538,15 @@ static int init_engine(struct snd_pcm_substream *substream,
543538
if (offs + rest > params_buffer_bytes(hw_params))
544539
rest = params_buffer_bytes(hw_params) - offs;
545540
while (rest) {
541+
dma_addr_t addr;
542+
addr = snd_pcm_sgbuf_get_addr(substream, offs);
546543
if (rest <= edge - offs) {
547-
sglist_add_mapping(chip, pipe,
548-
snd_sgbuf_get_addr(sgbuf, offs),
549-
rest);
544+
sglist_add_mapping(chip, pipe, addr, rest);
550545
sglist_add_irq(chip, pipe);
551546
offs += rest;
552547
rest = 0;
553548
} else {
554-
sglist_add_mapping(chip, pipe,
555-
snd_sgbuf_get_addr(sgbuf, offs),
549+
sglist_add_mapping(chip, pipe, addr,
556550
edge - offs);
557551
rest -= edge - offs;
558552
offs = edge;

‎sound/pci/emu10k1/memory.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ struct snd_util_memblk *
296296
snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream)
297297
{
298298
struct snd_pcm_runtime *runtime = substream->runtime;
299-
struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
300299
struct snd_util_memhdr *hdr;
301300
struct snd_emu10k1_memblk *blk;
302301
int page, err, idx;
@@ -321,16 +320,9 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
321320
*/
322321
idx = 0;
323322
for (page = blk->first_page; page <= blk->last_page; page++, idx++) {
323+
unsigned long ofs = idx << PAGE_SHIFT;
324324
dma_addr_t addr;
325-
#ifdef CONFIG_SND_DEBUG
326-
if (idx >= sgbuf->pages) {
327-
printk(KERN_ERR "emu: pages overflow! (%d-%d) for %d\n",
328-
blk->first_page, blk->last_page, sgbuf->pages);
329-
mutex_unlock(&hdr->block_mutex);
330-
return NULL;
331-
}
332-
#endif
333-
addr = sgbuf->table[idx].addr;
325+
addr = snd_pcm_sgbuf_get_addr(substream, ofs);
334326
if (! is_valid_page(emu, addr)) {
335327
printk(KERN_ERR "emu: failure page = %d\n", idx);
336328
mutex_unlock(&hdr->block_mutex);

‎sound/pci/hda/hda_intel.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,6 @@ static int setup_bdle(struct snd_pcm_substream *substream,
998998
struct azx_dev *azx_dev, u32 **bdlp,
999999
int ofs, int size, int with_ioc)
10001000
{
1001-
struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
10021001
u32 *bdl = *bdlp;
10031002

10041003
while (size > 0) {
@@ -1008,7 +1007,7 @@ static int setup_bdle(struct snd_pcm_substream *substream,
10081007
if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
10091008
return -EINVAL;
10101009

1011-
addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
1010+
addr = snd_pcm_sgbuf_get_addr(substream, ofs);
10121011
/* program the address field of the BDL entry */
10131012
bdl[0] = cpu_to_le32((u32)addr);
10141013
bdl[1] = cpu_to_le32(upper_32_bits(addr));

0 commit comments

Comments
 (0)