aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-08-21 07:00:13 -0400
committerJaroslav Kysela <perex@perex.cz>2008-08-25 03:57:18 -0400
commit77a23f2695bb2de0cd74599400dc55109c531b72 (patch)
tree4960195e04016928dea83deb85e0f3bf97024a8a /sound/pci
parent46480b3a5f88f20dbf25d95fe74d7b4798d5bc86 (diff)
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>
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/au88x0/au88x0.h7
-rw-r--r--sound/pci/au88x0/au88x0_core.c38
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c14
-rw-r--r--sound/pci/bt87x.c5
-rw-r--r--sound/pci/echoaudio/echoaudio.c14
-rw-r--r--sound/pci/emu10k1/memory.c12
-rw-r--r--sound/pci/hda/hda_intel.c3
-rw-r--r--sound/pci/riptide/riptide.c13
-rw-r--r--sound/pci/rme9652/hdspm.c18
-rw-r--r--sound/pci/trident/trident_memory.c13
-rw-r--r--sound/pci/via82xx.c5
-rw-r--r--sound/pci/via82xx_modem.c5
12 files changed, 56 insertions, 91 deletions
diff --git a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
index 4aad35bba11a..cf46bba563cf 100644
--- a/sound/pci/au88x0/au88x0.h
+++ b/sound/pci/au88x0/au88x0.h
@@ -125,7 +125,6 @@ typedef struct {
125 /* Virtual page extender stuff */ 125 /* Virtual page extender stuff */
126 int nr_periods; 126 int nr_periods;
127 int period_bytes; 127 int period_bytes;
128 struct snd_sg_buf *sgbuf; /* DMA Scatter Gather struct */
129 int period_real; 128 int period_real;
130 int period_virt; 129 int period_virt;
131 130
@@ -195,16 +194,14 @@ static void vortex_adb_setsrc(vortex_t * vortex, int adbdma,
195 194
196/* DMA Engines. */ 195/* DMA Engines. */
197static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma, 196static void vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
198 struct snd_sg_buf * sgbuf, int size, 197 int size, int count);
199 int count);
200static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie, 198static void vortex_adbdma_setmode(vortex_t * vortex, int adbdma, int ie,
201 int dir, int fmt, int d, 199 int dir, int fmt, int d,
202 u32 offset); 200 u32 offset);
203static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb); 201static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb);
204#ifndef CHIP_AU8810 202#ifndef CHIP_AU8810
205static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma, 203static void vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
206 struct snd_sg_buf * sgbuf, int size, 204 int size, int count);
207 int count);
208static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */ 205static void vortex_wtdma_setmode(vortex_t * vortex, int wtdma, int ie, int fmt, int d, /*int e, */
209 u32 offset); 206 u32 offset);
210static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb); 207static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb);
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index 1900fa6bc51e..b070e5714514 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -1097,19 +1097,12 @@ static void vortex_adbdma_setstartbuffer(vortex_t * vortex, int adbdma, int sb)
1097 1097
1098static void 1098static void
1099vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma, 1099vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1100 struct snd_sg_buf * sgbuf, int psize, int count) 1100 int psize, int count)
1101{ 1101{
1102 stream_t *dma = &vortex->dma_adb[adbdma]; 1102 stream_t *dma = &vortex->dma_adb[adbdma];
1103 1103
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
1110 dma->period_bytes = psize; 1104 dma->period_bytes = psize;
1111 dma->nr_periods = count; 1105 dma->nr_periods = count;
1112 dma->sgbuf = sgbuf;
1113 1106
1114 dma->cfg0 = 0; 1107 dma->cfg0 = 0;
1115 dma->cfg1 = 0; 1108 dma->cfg1 = 0;
@@ -1120,26 +1113,26 @@ vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1120 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize - 1); 1113 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize - 1);
1121 hwwrite(vortex->mmio, 1114 hwwrite(vortex->mmio,
1122 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0xc, 1115 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0xc,
1123 snd_sgbuf_get_addr(sgbuf, psize * 3)); 1116 snd_pcm_sgbuf_get_addr(dma->substream, psize * 3));
1124 /* 3 pages */ 1117 /* 3 pages */
1125 case 3: 1118 case 3:
1126 dma->cfg0 |= 0x12000000; 1119 dma->cfg0 |= 0x12000000;
1127 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc); 1120 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
1128 hwwrite(vortex->mmio, 1121 hwwrite(vortex->mmio,
1129 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x8, 1122 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x8,
1130 snd_sgbuf_get_addr(sgbuf, psize * 2)); 1123 snd_pcm_sgbuf_get_addr(dma->substream, psize * 2));
1131 /* 2 pages */ 1124 /* 2 pages */
1132 case 2: 1125 case 2:
1133 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize - 1); 1126 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize - 1);
1134 hwwrite(vortex->mmio, 1127 hwwrite(vortex->mmio,
1135 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x4, 1128 VORTEX_ADBDMA_BUFBASE + (adbdma << 4) + 0x4,
1136 snd_sgbuf_get_addr(sgbuf, psize)); 1129 snd_pcm_sgbuf_get_addr(dma->substream, psize));
1137 /* 1 page */ 1130 /* 1 page */
1138 case 1: 1131 case 1:
1139 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc); 1132 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize - 1) << 0xc);
1140 hwwrite(vortex->mmio, 1133 hwwrite(vortex->mmio,
1141 VORTEX_ADBDMA_BUFBASE + (adbdma << 4), 1134 VORTEX_ADBDMA_BUFBASE + (adbdma << 4),
1142 snd_sgbuf_get_addr(sgbuf, 0)); 1135 snd_pcm_sgbuf_get_addr(dma->substream, 0));
1143 break; 1136 break;
1144 } 1137 }
1145 //printk("vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n", dma->cfg0, dma->cfg1); 1138 //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)
1205 //hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr); 1198 //hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr);
1206 hwwrite(vortex->mmio, 1199 hwwrite(vortex->mmio,
1207 VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2), 1200 VORTEX_ADBDMA_BUFBASE + (((adbdma << 2) + pp) << 2),
1208 snd_sgbuf_get_addr(dma->sgbuf, 1201 snd_pcm_sgbuf_get_addr(dma->substream,
1209 dma->period_bytes * p)); 1202 dma->period_bytes * p));
1210 /* Force write thru cache. */ 1203 /* Force write thru cache. */
1211 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + 1204 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE +
@@ -1244,7 +1237,10 @@ static void vortex_adbdma_resetup(vortex_t *vortex, int adbdma) {
1244 if (pp >= 4) 1237 if (pp >= 4)
1245 pp -= 4; 1238 pp -= 4;
1246 } 1239 }
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));
1248 /* Force write thru cache. */ 1244 /* Force write thru cache. */
1249 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + (((adbdma << 2)+pp) << 2)); 1245 hwread(vortex->mmio, VORTEX_ADBDMA_BUFBASE + (((adbdma << 2)+pp) << 2));
1250 } 1246 }
@@ -1367,13 +1363,12 @@ static void vortex_wtdma_setstartbuffer(vortex_t * vortex, int wtdma, int sb)
1367 1363
1368static void 1364static void
1369vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma, 1365vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
1370 struct snd_sg_buf * sgbuf, int psize, int count) 1366 int psize, int count)
1371{ 1367{
1372 stream_t *dma = &vortex->dma_wt[wtdma]; 1368 stream_t *dma = &vortex->dma_wt[wtdma];
1373 1369
1374 dma->period_bytes = psize; 1370 dma->period_bytes = psize;
1375 dma->nr_periods = count; 1371 dma->nr_periods = count;
1376 dma->sgbuf = sgbuf;
1377 1372
1378 dma->cfg0 = 0; 1373 dma->cfg0 = 0;
1379 dma->cfg1 = 0; 1374 dma->cfg1 = 0;
@@ -1383,23 +1378,23 @@ vortex_wtdma_setbuffers(vortex_t * vortex, int wtdma,
1383 case 4: 1378 case 4:
1384 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize-1); 1379 dma->cfg1 |= 0x88000000 | 0x44000000 | 0x30000000 | (psize-1);
1385 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0xc, 1380 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));
1387 /* 3 pages */ 1382 /* 3 pages */
1388 case 3: 1383 case 3:
1389 dma->cfg0 |= 0x12000000; 1384 dma->cfg0 |= 0x12000000;
1390 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc); 1385 dma->cfg1 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
1391 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x8, 1386 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));
1393 /* 2 pages */ 1388 /* 2 pages */
1394 case 2: 1389 case 2:
1395 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize-1); 1390 dma->cfg0 |= 0x88000000 | 0x44000000 | 0x10000000 | (psize-1);
1396 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4) + 0x4, 1391 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));
1398 /* 1 page */ 1393 /* 1 page */
1399 case 1: 1394 case 1:
1400 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc); 1395 dma->cfg0 |= 0x80000000 | 0x40000000 | ((psize-1) << 0xc);
1401 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4), 1396 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFBASE + (wtdma << 4),
1402 snd_sgbuf_get_addr(sgbuf, 0)); 1397 snd_pcm_sgbuf_get_addr(dma->substream, 0));
1403 break; 1398 break;
1404 } 1399 }
1405 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFCFG0 + (wtdma << 3), dma->cfg0); 1400 hwwrite(vortex->mmio, VORTEX_WTDMA_BUFCFG0 + (wtdma << 3), dma->cfg0);
@@ -1465,7 +1460,8 @@ static int vortex_wtdma_bufshift(vortex_t * vortex, int wtdma)
1465 hwwrite(vortex->mmio, 1460 hwwrite(vortex->mmio,
1466 VORTEX_WTDMA_BUFBASE + 1461 VORTEX_WTDMA_BUFBASE +
1467 (((wtdma << 2) + pp) << 2), 1462 (((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));
1469 /* Force write thru cache. */ 1465 /* Force write thru cache. */
1470 hwread(vortex->mmio, VORTEX_WTDMA_BUFBASE + 1466 hwread(vortex->mmio, VORTEX_WTDMA_BUFBASE +
1471 (((wtdma << 2) + pp) << 2)); 1467 (((wtdma << 2) + pp) << 2));
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index f9a58b4a30eb..b9d2f202cf9b 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -189,7 +189,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
189{ 189{
190 vortex_t *chip = snd_pcm_substream_chip(substream); 190 vortex_t *chip = snd_pcm_substream_chip(substream);
191 stream_t *stream = (stream_t *) (substream->runtime->private_data); 191 stream_t *stream = (stream_t *) (substream->runtime->private_data);
192 struct snd_sg_buf *sgbuf;
193 int err; 192 int err;
194 193
195 // Alloc buffer memory. 194 // Alloc buffer memory.
@@ -199,8 +198,6 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
199 printk(KERN_ERR "Vortex: pcm page alloc failed!\n"); 198 printk(KERN_ERR "Vortex: pcm page alloc failed!\n");
200 return err; 199 return err;
201 } 200 }
202 //sgbuf = (struct snd_sg_buf *) substream->runtime->dma_private;
203 sgbuf = snd_pcm_substream_sgbuf(substream);
204 /* 201 /*
205 printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params), 202 printk(KERN_INFO "Vortex: periods %d, period_bytes %d, channels = %d\n", params_periods(hw_params),
206 params_period_bytes(hw_params), params_channels(hw_params)); 203 params_period_bytes(hw_params), params_channels(hw_params));
@@ -226,7 +223,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
226 stream = substream->runtime->private_data = &chip->dma_adb[dma]; 223 stream = substream->runtime->private_data = &chip->dma_adb[dma];
227 stream->substream = substream; 224 stream->substream = substream;
228 /* Setup Buffers. */ 225 /* Setup Buffers. */
229 vortex_adbdma_setbuffers(chip, dma, sgbuf, 226 vortex_adbdma_setbuffers(chip, dma,
230 params_period_bytes(hw_params), 227 params_period_bytes(hw_params),
231 params_periods(hw_params)); 228 params_periods(hw_params));
232 } 229 }
@@ -240,7 +237,7 @@ snd_vortex_pcm_hw_params(struct snd_pcm_substream *substream,
240 &chip->dma_wt[substream->number]; 237 &chip->dma_wt[substream->number];
241 stream->dma = substream->number; 238 stream->dma = substream->number;
242 stream->substream = substream; 239 stream->substream = substream;
243 vortex_wtdma_setbuffers(chip, substream->number, sgbuf, 240 vortex_wtdma_setbuffers(chip, substream->number,
244 params_period_bytes(hw_params), 241 params_period_bytes(hw_params),
245 params_periods(hw_params)); 242 params_periods(hw_params));
246 } 243 }
@@ -392,13 +389,6 @@ static snd_pcm_uframes_t snd_vortex_pcm_pointer(struct snd_pcm_substream *substr
392 return (bytes_to_frames(substream->runtime, current_ptr)); 389 return (bytes_to_frames(substream->runtime, current_ptr));
393} 390}
394 391
395/* Page callback. */
396/*
397static struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset) {
398
399
400}
401*/
402/* operators */ 392/* operators */
403static struct snd_pcm_ops snd_vortex_playback_ops = { 393static struct snd_pcm_ops snd_vortex_playback_ops = {
404 .open = snd_vortex_pcm_open, 394 .open = snd_vortex_pcm_open,
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 4ecdd635ed1d..3aa8d973540a 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -227,7 +227,6 @@ static inline void snd_bt87x_writel(struct snd_bt87x *chip, u32 reg, u32 value)
227static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream, 227static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream,
228 unsigned int periods, unsigned int period_bytes) 228 unsigned int periods, unsigned int period_bytes)
229{ 229{
230 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
231 unsigned int i, offset; 230 unsigned int i, offset;
232 u32 *risc; 231 u32 *risc;
233 232
@@ -246,6 +245,7 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
246 rest = period_bytes; 245 rest = period_bytes;
247 do { 246 do {
248 u32 cmd, len; 247 u32 cmd, len;
248 unsigned int addr;
249 249
250 len = PAGE_SIZE - (offset % PAGE_SIZE); 250 len = PAGE_SIZE - (offset % PAGE_SIZE);
251 if (len > rest) 251 if (len > rest)
@@ -260,7 +260,8 @@ static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substrea
260 if (len == rest) 260 if (len == rest)
261 cmd |= RISC_EOL | RISC_IRQ; 261 cmd |= RISC_EOL | RISC_IRQ;
262 *risc++ = cpu_to_le32(cmd); 262 *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);
264 offset += len; 265 offset += len;
265 rest -= len; 266 rest -= len;
266 } while (rest > 0); 267 } while (rest > 0);
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 160d47054922..8dbc5c4ba421 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -490,7 +490,6 @@ static int init_engine(struct snd_pcm_substream *substream,
490{ 490{
491 struct echoaudio *chip; 491 struct echoaudio *chip;
492 int err, per, rest, page, edge, offs; 492 int err, per, rest, page, edge, offs;
493 struct snd_sg_buf *sgbuf;
494 struct audiopipe *pipe; 493 struct audiopipe *pipe;
495 494
496 chip = snd_pcm_substream_chip(substream); 495 chip = snd_pcm_substream_chip(substream);
@@ -531,10 +530,6 @@ static int init_engine(struct snd_pcm_substream *substream,
531 return err; 530 return err;
532 } 531 }
533 532
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));
538 sglist_init(chip, pipe); 533 sglist_init(chip, pipe);
539 edge = PAGE_SIZE; 534 edge = PAGE_SIZE;
540 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params); 535 for (offs = page = per = 0; offs < params_buffer_bytes(hw_params);
@@ -543,16 +538,15 @@ static int init_engine(struct snd_pcm_substream *substream,
543 if (offs + rest > params_buffer_bytes(hw_params)) 538 if (offs + rest > params_buffer_bytes(hw_params))
544 rest = params_buffer_bytes(hw_params) - offs; 539 rest = params_buffer_bytes(hw_params) - offs;
545 while (rest) { 540 while (rest) {
541 dma_addr_t addr;
542 addr = snd_pcm_sgbuf_get_addr(substream, offs);
546 if (rest <= edge - offs) { 543 if (rest <= edge - offs) {
547 sglist_add_mapping(chip, pipe, 544 sglist_add_mapping(chip, pipe, addr, rest);
548 snd_sgbuf_get_addr(sgbuf, offs),
549 rest);
550 sglist_add_irq(chip, pipe); 545 sglist_add_irq(chip, pipe);
551 offs += rest; 546 offs += rest;
552 rest = 0; 547 rest = 0;
553 } else { 548 } else {
554 sglist_add_mapping(chip, pipe, 549 sglist_add_mapping(chip, pipe, addr,
555 snd_sgbuf_get_addr(sgbuf, offs),
556 edge - offs); 550 edge - offs);
557 rest -= edge - offs; 551 rest -= edge - offs;
558 offs = edge; 552 offs = edge;
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index e8ad56ed34fa..6a47672f930a 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -296,7 +296,6 @@ struct snd_util_memblk *
296snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream) 296snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *substream)
297{ 297{
298 struct snd_pcm_runtime *runtime = substream->runtime; 298 struct snd_pcm_runtime *runtime = substream->runtime;
299 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
300 struct snd_util_memhdr *hdr; 299 struct snd_util_memhdr *hdr;
301 struct snd_emu10k1_memblk *blk; 300 struct snd_emu10k1_memblk *blk;
302 int page, err, idx; 301 int page, err, idx;
@@ -321,16 +320,9 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
321 */ 320 */
322 idx = 0; 321 idx = 0;
323 for (page = blk->first_page; page <= blk->last_page; page++, idx++) { 322 for (page = blk->first_page; page <= blk->last_page; page++, idx++) {
323 unsigned long ofs = idx << PAGE_SHIFT;
324 dma_addr_t addr; 324 dma_addr_t addr;
325#ifdef CONFIG_SND_DEBUG 325 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
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;
334 if (! is_valid_page(emu, addr)) { 326 if (! is_valid_page(emu, addr)) {
335 printk(KERN_ERR "emu: failure page = %d\n", idx); 327 printk(KERN_ERR "emu: failure page = %d\n", idx);
336 mutex_unlock(&hdr->block_mutex); 328 mutex_unlock(&hdr->block_mutex);
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 39f22318803d..e4d038f423fc 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -998,7 +998,6 @@ static int setup_bdle(struct snd_pcm_substream *substream,
998 struct azx_dev *azx_dev, u32 **bdlp, 998 struct azx_dev *azx_dev, u32 **bdlp,
999 int ofs, int size, int with_ioc) 999 int ofs, int size, int with_ioc)
1000{ 1000{
1001 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
1002 u32 *bdl = *bdlp; 1001 u32 *bdl = *bdlp;
1003 1002
1004 while (size > 0) { 1003 while (size > 0) {
@@ -1008,7 +1007,7 @@ static int setup_bdle(struct snd_pcm_substream *substream,
1008 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) 1007 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
1009 return -EINVAL; 1008 return -EINVAL;
1010 1009
1011 addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs); 1010 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
1012 /* program the address field of the BDL entry */ 1011 /* program the address field of the BDL entry */
1013 bdl[0] = cpu_to_le32((u32)addr); 1012 bdl[0] = cpu_to_le32((u32)addr);
1014 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1013 bdl[1] = cpu_to_le32(upper_32_bits(addr));
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 124f9a2f1535..e9f0706ed3e4 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1483,7 +1483,6 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1483{ 1483{
1484 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1484 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1485 struct snd_pcm_runtime *runtime = substream->runtime; 1485 struct snd_pcm_runtime *runtime = substream->runtime;
1486 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
1487 struct pcmhw *data = get_pcmhwdev(substream); 1486 struct pcmhw *data = get_pcmhwdev(substream);
1488 struct cmdif *cif = chip->cif; 1487 struct cmdif *cif = chip->cif;
1489 unsigned char *lbuspath = NULL; 1488 unsigned char *lbuspath = NULL;
@@ -1515,9 +1514,9 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1515 lbuspath = data->paths.stereo; 1514 lbuspath = data->paths.stereo;
1516 break; 1515 break;
1517 } 1516 }
1518 snd_printdd("use sgdlist at 0x%p and buffer at 0x%p\n", 1517 snd_printdd("use sgdlist at 0x%p\n",
1519 data->sgdlist.area, sgbuf); 1518 data->sgdlist.area);
1520 if (data->sgdlist.area && sgbuf) { 1519 if (data->sgdlist.area) {
1521 unsigned int i, j, size, pages, f, pt, period; 1520 unsigned int i, j, size, pages, f, pt, period;
1522 struct sgd *c, *p = NULL; 1521 struct sgd *c, *p = NULL;
1523 1522
@@ -1535,6 +1534,7 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1535 pt = 0; 1534 pt = 0;
1536 j = 0; 1535 j = 0;
1537 for (i = 0; i < pages; i++) { 1536 for (i = 0; i < pages; i++) {
1537 unsigned int ofs, addr;
1538 c = &data->sgdbuf[i]; 1538 c = &data->sgdbuf[i];
1539 if (p) 1539 if (p)
1540 p->dwNextLink = cpu_to_le32(data->sgdlist.addr + 1540 p->dwNextLink = cpu_to_le32(data->sgdlist.addr +
@@ -1542,8 +1542,9 @@ static int snd_riptide_prepare(struct snd_pcm_substream *substream)
1542 sizeof(struct 1542 sizeof(struct
1543 sgd))); 1543 sgd)));
1544 c->dwNextLink = cpu_to_le32(data->sgdlist.addr); 1544 c->dwNextLink = cpu_to_le32(data->sgdlist.addr);
1545 c->dwSegPtrPhys = 1545 ofs = j << PAGE_SHIFT;
1546 cpu_to_le32(sgbuf->table[j].addr + pt); 1546 addr = snd_pcm_sgbuf_get_addr(substream, ofs) + pt;
1547 c->dwSegPtrPhys = cpu_to_le32(addr);
1547 pt = (pt + f) % PAGE_SIZE; 1548 pt = (pt + f) % PAGE_SIZE;
1548 if (pt == 0) 1549 if (pt == 0)
1549 j++; 1550 j++;
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 83c92e6082a2..98762f909d64 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -535,7 +535,8 @@ static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm);
535static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm); 535static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm);
536static int hdspm_autosync_ref(struct hdspm * hdspm); 536static int hdspm_autosync_ref(struct hdspm * hdspm);
537static int snd_hdspm_set_defaults(struct hdspm * hdspm); 537static int snd_hdspm_set_defaults(struct hdspm * hdspm);
538static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, 538static void hdspm_set_sgbuf(struct hdspm * hdspm,
539 struct snd_pcm_substream *substream,
539 unsigned int reg, int channels); 540 unsigned int reg, int channels);
540 541
541static inline int HDSPM_bit2freq(int n) 542static inline int HDSPM_bit2freq(int n)
@@ -3604,8 +3605,6 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3604 int i; 3605 int i;
3605 pid_t this_pid; 3606 pid_t this_pid;
3606 pid_t other_pid; 3607 pid_t other_pid;
3607 struct snd_sg_buf *sgbuf;
3608
3609 3608
3610 spin_lock_irq(&hdspm->lock); 3609 spin_lock_irq(&hdspm->lock);
3611 3610
@@ -3673,11 +3672,9 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3673 if (err < 0) 3672 if (err < 0)
3674 return err; 3673 return err;
3675 3674
3676 sgbuf = snd_pcm_substream_sgbuf(substream);
3677
3678 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 3675 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3679 3676
3680 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferOut, 3677 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
3681 params_channels(params)); 3678 params_channels(params));
3682 3679
3683 for (i = 0; i < params_channels(params); ++i) 3680 for (i = 0; i < params_channels(params); ++i)
@@ -3688,7 +3685,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3688 snd_printdd("Allocated sample buffer for playback at %p\n", 3685 snd_printdd("Allocated sample buffer for playback at %p\n",
3689 hdspm->playback_buffer); 3686 hdspm->playback_buffer);
3690 } else { 3687 } else {
3691 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferIn, 3688 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
3692 params_channels(params)); 3689 params_channels(params));
3693 3690
3694 for (i = 0; i < params_channels(params); ++i) 3691 for (i = 0; i < params_channels(params); ++i)
@@ -3703,7 +3700,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
3703 snd_printdd("Allocated sample buffer for %s at 0x%08X\n", 3700 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
3704 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 3701 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
3705 "playback" : "capture", 3702 "playback" : "capture",
3706 snd_pcm_sgbuf_get_addr(sgbuf, 0)); 3703 snd_pcm_sgbuf_get_addr(substream, 0));
3707 */ 3704 */
3708 /* 3705 /*
3709 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", 3706 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
@@ -4253,13 +4250,14 @@ static int __devinit snd_hdspm_preallocate_memory(struct hdspm * hdspm)
4253 return 0; 4250 return 0;
4254} 4251}
4255 4252
4256static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, 4253static void hdspm_set_sgbuf(struct hdspm * hdspm,
4254 struct snd_pcm_substream *substream,
4257 unsigned int reg, int channels) 4255 unsigned int reg, int channels)
4258{ 4256{
4259 int i; 4257 int i;
4260 for (i = 0; i < (channels * 16); i++) 4258 for (i = 0; i < (channels * 16); i++)
4261 hdspm_write(hdspm, reg + 4 * i, 4259 hdspm_write(hdspm, reg + 4 * i,
4262 snd_pcm_sgbuf_get_addr(sgbuf, (size_t) 4096 * i)); 4260 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
4263} 4261}
4264 4262
4265/* ------------- ALSA Devices ---------------------------- */ 4263/* ------------- ALSA Devices ---------------------------- */
diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c
index 2fe3b1fab53a..f9779e23fe57 100644
--- a/sound/pci/trident/trident_memory.c
+++ b/sound/pci/trident/trident_memory.c
@@ -194,7 +194,6 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
194 struct snd_util_memblk *blk; 194 struct snd_util_memblk *blk;
195 struct snd_pcm_runtime *runtime = substream->runtime; 195 struct snd_pcm_runtime *runtime = substream->runtime;
196 int idx, page; 196 int idx, page;
197 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
198 197
199 if (snd_BUG_ON(runtime->dma_bytes <= 0 || 198 if (snd_BUG_ON(runtime->dma_bytes <= 0 ||
200 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * 199 runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES *
@@ -212,18 +211,14 @@ snd_trident_alloc_sg_pages(struct snd_trident *trident,
212 mutex_unlock(&hdr->block_mutex); 211 mutex_unlock(&hdr->block_mutex);
213 return NULL; 212 return NULL;
214 } 213 }
215 if (lastpg(blk) - firstpg(blk) >= sgbuf->pages) {
216 snd_printk(KERN_ERR "page calculation doesn't match: allocated pages = %d, trident = %d/%d\n", sgbuf->pages, firstpg(blk), lastpg(blk));
217 __snd_util_mem_free(hdr, blk);
218 mutex_unlock(&hdr->block_mutex);
219 return NULL;
220 }
221 214
222 /* set TLB entries */ 215 /* set TLB entries */
223 idx = 0; 216 idx = 0;
224 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { 217 for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) {
225 dma_addr_t addr = sgbuf->table[idx].addr; 218 unsigned long ofs = idx << PAGE_SHIFT;
226 unsigned long ptr = (unsigned long)sgbuf->table[idx].buf; 219 dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs);
220 unsigned long ptr = (unsigned long)
221 snd_pcm_sgbuf_get_ptr(substream, ofs);
227 if (! is_valid_page(addr)) { 222 if (! is_valid_page(addr)) {
228 __snd_util_mem_free(hdr, blk); 223 __snd_util_mem_free(hdr, blk);
229 mutex_unlock(&hdr->block_mutex); 224 mutex_unlock(&hdr->block_mutex);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 84ea35d8b252..8766848bbe68 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -420,7 +420,6 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
420{ 420{
421 unsigned int i, idx, ofs, rest; 421 unsigned int i, idx, ofs, rest;
422 struct via82xx *chip = snd_pcm_substream_chip(substream); 422 struct via82xx *chip = snd_pcm_substream_chip(substream);
423 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
424 423
425 if (dev->table.area == NULL) { 424 if (dev->table.area == NULL) {
426 /* the start of each lists must be aligned to 8 bytes, 425 /* the start of each lists must be aligned to 8 bytes,
@@ -449,12 +448,14 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
449 do { 448 do {
450 unsigned int r; 449 unsigned int r;
451 unsigned int flag; 450 unsigned int flag;
451 unsigned int addr;
452 452
453 if (idx >= VIA_TABLE_SIZE) { 453 if (idx >= VIA_TABLE_SIZE) {
454 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 454 snd_printk(KERN_ERR "via82xx: too much table size!\n");
455 return -EINVAL; 455 return -EINVAL;
456 } 456 }
457 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 457 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
458 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
458 r = PAGE_SIZE - (ofs % PAGE_SIZE); 459 r = PAGE_SIZE - (ofs % PAGE_SIZE);
459 if (rest < r) 460 if (rest < r)
460 r = rest; 461 r = rest;
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 640c338ce0ab..5bd79d2a5a15 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -281,7 +281,6 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
281{ 281{
282 unsigned int i, idx, ofs, rest; 282 unsigned int i, idx, ofs, rest;
283 struct via82xx_modem *chip = snd_pcm_substream_chip(substream); 283 struct via82xx_modem *chip = snd_pcm_substream_chip(substream);
284 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
285 284
286 if (dev->table.area == NULL) { 285 if (dev->table.area == NULL) {
287 /* the start of each lists must be aligned to 8 bytes, 286 /* the start of each lists must be aligned to 8 bytes,
@@ -310,12 +309,14 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
310 do { 309 do {
311 unsigned int r; 310 unsigned int r;
312 unsigned int flag; 311 unsigned int flag;
312 unsigned int addr;
313 313
314 if (idx >= VIA_TABLE_SIZE) { 314 if (idx >= VIA_TABLE_SIZE) {
315 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 315 snd_printk(KERN_ERR "via82xx: too much table size!\n");
316 return -EINVAL; 316 return -EINVAL;
317 } 317 }
318 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs)); 318 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
319 ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
319 r = PAGE_SIZE - (ofs % PAGE_SIZE); 320 r = PAGE_SIZE - (ofs % PAGE_SIZE);
320 if (rest < r) 321 if (rest < r)
321 r = rest; 322 r = rest;