Skip to contentSkip to conversation

Scatter-Gather buffer allocation before running on HDSP-MADI ?

DISCUSSION Winfried Ritsch 3 participants 12 messages Oct 4, 2003 – Oct 10, 2003 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello !

(A question from an newbie-developer to make it perfect ;-)

I am writing an ALSA-lowleveldriver for the RME HDSP-MADI card. (which have 64Audion in and out and an 128in64(= 8192Fader) Mixer see http://www.rme-audio.de/hdsp/hdspmadi.htm ) Coding is quite complete but I have trouble with the memory management.

The Card uses ScatterGather Buffer, each channel 64kB and this has to be asigned (to be safe) before activation, so I want to allocate SGbuffer (64+64)*64*1024=8388608 in 4k-blocks.

I do a

snd_pcm_lib_preallocate_pci_pages_for_all(hdspm->pci, pcm,8388608l,8388608l)

after making the pcm_device.

Here the questions:

1) How can I get the sgbuf pointer ?

... since in the streams runtime is not set and therefore (besides the Documentation says is (snd_pcm_sgbuf_t*)substream->dma_private which I couldnt find)

sgbuf = (snd_pcm_sgbuf_t*)substream->runtime->dma_private;

is not assigned.

but when I activate the card (for MIDI for example) there must be memory asigned und I think doing it in hw_params is to late.

2) If it is bound to substream is always the same substream the capture or playback or are the assigned dynamically on calling ?

mfg winfried ritsch

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#1 lore raw
Quoted 28 lines · Winfried Ritsch

Hello !

(A question from an newbie-developer to make it perfect ;-)

I am writing an ALSA-lowleveldriver for the RME HDSP-MADI card. (which have 64Audion in and out and an 128in64(= 8192Fader) Mixer see http://www.rme-audio.de/hdsp/hdspmadi.htm ) Coding is quite complete but I have trouble with the memory management.

The Card uses ScatterGather Buffer, each channel 64kB and this has to be asigned (to be safe) before activation, so I want to allocate SGbuffer (64+64)*64*1024=8388608 in 4k-blocks.

I do a

snd_pcm_lib_preallocate_pci_pages_for_all(hdspm->pci, pcm,8388608l,8388608l)

after making the pcm_device.

Here the questions:

1) How can I get the sgbuf pointer ?

... since in the streams runtime is not set and therefore (besides the Documentation says is (snd_pcm_sgbuf_t*)substream->dma_private which I couldnt find)

Quoted 6 lines

sgbuf = (snd_pcm_sgbuf_t*)substream->runtime->dma_private;

is not assigned.

but when I activate the card (for MIDI for example) there must be memory asigned und I think doing it in hw_params is to late.

Note that ALSA has SG routines only for PCM streams and it's lifetime is limited only for stream lifetime. If hardware needs to allocate a big buffer at the initialization phase, you have to do it yourself.

Quoted 2 lines

2) If it is bound to substream is always the same substream the capture or playback or are the assigned dynamically on calling ?

It depends on hardware parameters and on application. If your hardware supports multiple equal streams using same i/o connector (hardware mixing), then the substream might be allocated dynamically, but application might still request the exact substream number.

If your hardware uses only a few totaly independent streams, create PCM devices with one substream.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#2 lore raw

At Sun, 5 Oct 2003 21:01:58 +0200 (CEST),

Quoted 33 lines · Jaroslav
Quoted 30 lines · Winfried Ritsch

Hello !

(A question from an newbie-developer to make it perfect ;-)

I am writing an ALSA-lowleveldriver for the RME HDSP-MADI card. (which have 64Audion in and out and an 128in64(= 8192Fader) Mixer see http://www.rme-audio.de/hdsp/hdspmadi.htm ) Coding is quite complete but I have trouble with the memory management.

The Card uses ScatterGather Buffer, each channel 64kB and this has to be asigned (to be safe) before activation, so I want to allocate SGbuffer (64+64)*64*1024=8388608 in 4k-blocks.

I do a

snd_pcm_lib_preallocate_pci_pages_for_all(hdspm->pci, pcm,8388608l,8388608l)

after making the pcm_device.

Here the questions:

1) How can I get the sgbuf pointer ?

... since in the streams runtime is not set and therefore (besides the Documentation says is (snd_pcm_sgbuf_t*)substream->dma_private which I couldnt find)

sgbuf = (snd_pcm_sgbuf_t*)substream->runtime->dma_private;

Quoted 7 lines
Quoted 4 lines

is not assigned.

but when I activate the card (for MIDI for example) there must be memory asigned und I think doing it in hw_params is to late.

Note that ALSA has SG routines only for PCM streams and it's lifetime is limited only for stream lifetime.

well, this is no longer true. the sg-buffer allocation is handled generally in snd-page-alloc module (although only PCM handlers use it in practice :)
and we have preallocation for sg PCM buffers now, too.

Quoted 2 lines

If hardware needs to allocate a big
buffer at the initialization phase, you have to do it yourself.

the SG buffers should be pre-allocated via snd_pcm_lib_preallocate_sg_pages() and _for_all() functions instead of snd_pcm_lib_preallocate_pci_pages() and co.
in addition, in hw_params() callback, you'll need to map the sg-pages like below:

	struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
	...
	for_all_pages { /* rewrite as you like */
		/* get the physical address by snd_pcm_sgbuf_get_addr(). */
		/* set this address on the hardware's address table */
		do_my_mapping(snd_pcm_sgbuf_get_addr(sgbuf, offset));
	}

check via82xx.c as an example (or emu10k1 driver as a more complex case).

you can find a brief information in my tutorial ("Non-Contiguous Buffers" section in "Buffer and Memory Management").

Takashi

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#3 lore raw

Thanx that cleared a lot.

I thought so,

since I want to allocate once and then leave it, (because I dont want an exlusiv use of capture and playback ...)

Please three more questions:

1) I found also the function:

snd_malloc_sgbuf_pages(hdspm->pci, wanted, dmab)

Can I allocate memory with these before initializing a substream and write it to hardware and then set all the buffer data in the substream:

  runtime->dma_area = hdspm->p_dmab.area;
  runtime->dma_addr =  hdspm->p_dmab.addr;
  runtime->dma_private =  hdspm->p_dmab.private_data;
  runtime->dma_bytes = hdspm->p_dmab.bytes;

Do I miss something ?

2) If SG_BUF makes continous virtual buffer

why there is a

.pages=snd_pcm_sgbuf_ops_page

function needed ?
what is the purpose of this ?

3) Just for my understanding:

SG allocates scattered physical memory and maps it to continous virtual:

when I allocate via

snd_malloc_sgbuf_pages(hdspm->pci, wanted, dmab)

I test the memory so get a syslog:

hdspm.c:2788: Preallocated 8192 kBytes
hdspm.c:2831: dmab(d27b7a84): area=e2db1000, addr=0, bytes = 0 (wanted 4194304), private=ce4a25c0

hdspm.c:2834: area Start: e2db1000 End:e31b0ffc diff=4194300 hdspm.c:2839: phys Start: b65b000 End:f6acffc diff=-67444732 hdspm.c:2845: bus_to_virt Start: cb65b000 End:cf6acffc diff=-67444732

(src of this see at the end)

Which tells me
- virt is ok 4194304
- phys is scattered so also any diff number is ok.
- but bus_to_virt of physical adress should make a continous, but it doesnt - Why ?

Thanx a lot.

mfg winfried

Anhang:

(test sg_memory)

...

  if((buf = snd_malloc_sgbuf_pages(hdspm->pci, wanted, dmab)) == NULL){
    snd_printd("playback SG-buffer allocating error\n");
    return -EINVAL;
  }

snd_printd("area Start: %lx End:%lx diff=%ld\n",

	     dmab->area,dmab->area+wanted-4,wanted-4);
  snd_printd("phys Start: %lx End:%lx diff=%ld\n",
	     snd_pcm_sgbuf_get_addr(sgbuf,0),
	     snd_pcm_sgbuf_get_addr(sgbuf,wanted-4),
	     snd_pcm_sgbuf_get_addr(sgbuf,0)
	     - snd_pcm_sgbuf_get_addr(sgbuf,wanted-4));

snd_printd("bus_to_virt Start: %lx End:%lx diff=%ld\n",

	     bus_to_virt(snd_pcm_sgbuf_get_addr(sgbuf,0)),
	     bus_to_virt(snd_pcm_sgbuf_get_addr(sgbuf,wanted-4)),
	     bus_to_virt(snd_pcm_sgbuf_get_addr(sgbuf,0))
	     - bus_to_virt(snd_pcm_sgbuf_get_addr(sgbuf,wanted-4)));

....

Quoted 79 lines

At Sun, 5 Oct 2003 21:01:58 +0200 (CEST),

Quoted 13 lines · Jaroslav
Quoted 10 lines · Winfried Ritsch

Hello !

(A question from an newbie-developer to make it perfect ;-)

I am writing an ALSA-lowleveldriver for the RME HDSP-MADI card. (which have 64Audion in and out and an 128in64(= 8192Fader) Mixer see http://www.rme-audio.de/hdsp/hdspmadi.htm ) Coding is quite complete but I have trouble with the memory management.

Quoted 7 lines
Quoted 7 lines

The Card uses ScatterGather Buffer, each channel 64kB and this has to be asigned (to be safe) before activation, so I want to allocate SGbuffer (64+64)*64*1024=8388608 in 4k-blocks.

I do a

snd_pcm_lib_preallocate_pci_pages_for_all(hdspm->pci,

pcm,8388608l,8388608l)

Quoted 8 lines
Quoted 8 lines

after making the pcm_device.

Here the questions:

1) How can I get the sgbuf pointer ?

... since in the streams runtime is not set and therefore (besides

the

Quoted 1 line
Quoted 1 line

Documentation says is (snd_pcm_sgbuf_t*)substream->dma_private which

I

Quoted 10 lines
Quoted 8 lines

couldnt find)

sgbuf = (snd_pcm_sgbuf_t*)substream->runtime->dma_private;

is not assigned.

but when I activate the card (for MIDI for example) there must be memory asigned und I think doing it in hw_params is to late.

Note that ALSA has SG routines only for PCM streams and it's lifetime

is

Quoted 1 line

limited only for stream lifetime.

well, this is no longer true. the sg-buffer allocation is handled generally in snd-page-alloc module (although only PCM handlers use it in practice :)
and we have preallocation for sg PCM buffers now, too.

Quoted 2 lines

If hardware needs to allocate a big
buffer at the initialization phase, you have to do it yourself.

the SG buffers should be pre-allocated via snd_pcm_lib_preallocate_sg_pages() and _for_all() functions instead of snd_pcm_lib_preallocate_pci_pages() and co.
in addition, in hw_params() callback, you'll need to map the sg-pages like below:

	struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
	...
	for_all_pages { /* rewrite as you like */
		/* get the physical address by snd_pcm_sgbuf_get_addr(). */
		/* set this address on the hardware's address table */
		do_my_mapping(snd_pcm_sgbuf_get_addr(sgbuf, offset));
	}

check via82xx.c as an example (or emu10k1 driver as a more complex case).

you can find a brief information in my tutorial ("Non-Contiguous Buffers" section in "Buffer and Memory Management").

Takashi

Quoted 9 lines

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#4 lore raw

At Mon, 06 Oct 2003 19:19:08 +0200 (CEST),

Quoted 18 lines · [email protected] wrote:

Thanx that cleared a lot.

I thought so,

since I want to allocate once and then leave it, (because I dont want an exlusiv use of capture and playback ...)

Please three more questions:

1) I found also the function:

snd_malloc_sgbuf_pages(hdspm->pci, wanted, dmab)

Can I allocate memory with these before initializing a substream and write it to hardware and then set all the buffer data in the substream:

Quoted 6 lines
  runtime->dma_area = hdspm->p_dmab.area;
  runtime->dma_addr =  hdspm->p_dmab.addr;
  runtime->dma_private =  hdspm->p_dmab.private_data;
  runtime->dma_bytes = hdspm->p_dmab.bytes;

Do I miss something ?

the above is doable, but the preallocation mechanism is exactly what you want here. i'd recommend to simply pre-allocate the buffers and use snd_pcm_lib_malloc_pages() and snd_pcm_lib_free_pages() in hw_params and hw_free callbacks.

Quoted 6 lines

2) If SG_BUF makes continous virtual buffer

why there is a

.pages=snd_pcm_sgbuf_ops_page

^^^^^^
.page (without 's')

Quoted 3 lines

function needed ?
what is the purpose of this ?

this is mandatory to handle nopage callback in the mmap. check pcm_native.c.

Quoted 19 lines

3) Just for my understanding:

SG allocates scattered physical memory and maps it to continous virtual:

when I allocate via

snd_malloc_sgbuf_pages(hdspm->pci, wanted, dmab)

I test the memory so get a syslog:

hdspm.c:2788: Preallocated 8192 kBytes
hdspm.c:2831: dmab(d27b7a84): area=e2db1000, addr=0, bytes = 0 (wanted 4194304), private=ce4a25c0

hdspm.c:2834: area Start: e2db1000 End:e31b0ffc diff=4194300 hdspm.c:2839: phys Start: b65b000 End:f6acffc diff=-67444732 hdspm.c:2845: bus_to_virt Start: cb65b000 End:cf6acffc diff=-67444732

Quoted 7 lines

(src of this see at the end)

Which tells me
- virt is ok 4194304
- phys is scattered so also any diff number is ok.
- but bus_to_virt of physical adress should make a continous, but it doesnt - Why ?

you cannot calculate the virtual address from the physical address uniquely. a physical page can be mapped to different multiple virtual pages. (the ALSA's sg-buffer handler uses the vmap() for the virtual areas, btw.)

Takashi

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#5 lore raw

Thanx that cleared a lot.

So I managed now to put it in hw_params and it works in some way. needed an additional

There is one point I found:

- when I preallocate with for playback and capture 2*4194304 = 8388608 Bytes:

snd_pcm_lib_preallocate_sg_pages_for_all(hdspm->pci, pcm,8388608,8388608))

and then in hw_params for one substream do a:

snd_pcm_lib_malloc_pages(substream, 4194304);

I got a sgbuf with size=8388608 not 4194304. So it takes all the memory at first.

Then I tried to preallcate 4194304 and it nearly works (see below).

... since in it prealloctes the mem for 2 substreams (seen in pcm_memory.c).

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

What should be the right way ?

a) Allocating the sum of both ?

b) Acllocate with the value of one substream ?

c) should I call snd_pcm_lib_preallocate_sg_pages_for_all twice ? (also free pages twice)

mfg winfried

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

#6 lore raw

At Tue, 7 Oct 2003 18:25:50 +0200,

Quoted 7 lines · Winfried Ritsch

Thanx that cleared a lot.

So I managed now to put it in hw_params and it works in some way. needed an additional

Quoted 6 lines

There is one point I found:

- when I preallocate with for playback and capture 2*4194304 = 8388608 Bytes:

snd_pcm_lib_preallocate_sg_pages_for_all(hdspm->pci, pcm,8388608,8388608))

this will allocate 838608 bytes for _each_ stream. so, you'll eventually allocate double.

Quoted 7 lines

and then in hw_params for one substream do a:

snd_pcm_lib_malloc_pages(substream, 4194304);

I got a sgbuf with size=8388608 not 4194304. So it takes all the memory at first.

Quoted 7 lines

Then I tried to preallcate 4194304 and it nearly works (see below).

... since in it prealloctes the mem for 2 substreams (seen in pcm_memory.c).

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

the SG-buffer allocation size is aligned (round up) to PAGE_SIZE. (note that PAGE_SIZE is not always 4K byte on other architectures.)

Quoted 8 lines

What should be the right way ?

a) Allocating the sum of both ?

b) Acllocate with the value of one substream ?

c) should I call snd_pcm_lib_preallocate_sg_pages_for_all twice ? (also free pages twice)

it's b). call the function with the size allocated for each stream.

but please note that the preallocation doesn't assure that the given buffer size is allocated.

also, snd_pcm_lib_malloc_pages() should be called with the configured buffer size (if the hardware supports different size of buffer -- i suppose it does). it would be like:

	snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));

in hw_params callback.

Takashi

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),

Quoted 17 lines · [email protected] wrote:

Hello,

the hdsp-madi card with the hdspm driver seems to work now. so I want do a clean out of the code:

I asking how should I do this:

Quoted 7 lines
Quoted 3 lines

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

the SG-buffer allocation size is aligned (round up) to PAGE_SIZE. (note that PAGE_SIZE is not always 4K byte on other architectures.)

Quoted 7 lines

Ok on my i386 architecture I have 4k pages and
the rme card needs 4k buffers.

So how to code this that it works on all architectures getting a SG Buf with 4k buffers.

Do I have to do something by doing preallocation ?

on linux, the least page size is 4K byte (so far, all architectures are so). thus, simply do a loop like

	offset = 0; /* bytes */
	while (offset < total_size) {
		dma_addr_t addr = snd_sgbuf_get_addr(sgbuf, offset);
		map_this_addr_to_my_hw_table(addr);
		offset += 4096; /* 4k */
	}

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

#9 lore raw
Quoted 22 lines · Takashi Iwai

At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),

Quoted 20 lines · [email protected] wrote:

Hello,

the hdsp-madi card with the hdspm driver seems to work now. so I want do a clean out of the code:

I asking how should I do this:

Quoted 7 lines
Quoted 3 lines

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

the SG-buffer allocation size is aligned (round up) to PAGE_SIZE. (note that PAGE_SIZE is not always 4K byte on other architectures.)

Ok on my i386 architecture I have 4k pages and
the rme card needs 4k buffers.

Quoted 7 lines
Quoted 4 lines

So how to code this that it works on all architectures getting a SG Buf with 4k buffers.

Do I have to do something by doing preallocation ?

on linux, the least page size is 4K byte (so far, all architectures are so). thus, simply do a loop like

Nope. Old alpha arch has 8K pages.

Quoted 5 lines
	offset = 0; /* bytes */
	while (offset < total_size) {
		dma_addr_t addr = snd_sgbuf_get_addr(sgbuf, offset);
		map_this_addr_to_my_hw_table(addr);
		offset += 4096; /* 4k */

I suggest to use PAGE_SIZE define here.

Quoted 1 line
	}

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

#10 lore raw

At Fri, 10 Oct 2003 13:57:10 +0200 (CEST),

Quoted 28 lines · Jaroslav
Quoted 25 lines · Takashi Iwai

At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),

Quoted 23 lines · [email protected] wrote:

Hello,

the hdsp-madi card with the hdspm driver seems to work now. so I want do a clean out of the code:

I asking how should I do this:

Quoted 7 lines
Quoted 3 lines

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

the SG-buffer allocation size is aligned (round up) to PAGE_SIZE. (note that PAGE_SIZE is not always 4K byte on other architectures.)

Ok on my i386 architecture I have 4k pages and
the rme card needs 4k buffers.

So how to code this that it works on all architectures getting a SG Buf with 4k buffers.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Do I have to do something by doing preallocation ?

on linux, the least page size is 4K byte (so far, all architectures are so). thus, simply do a loop like

Nope. Old alpha arch has 8K pages.

well, i wrote "least" size in the above :)
in fact, ia64 can have up to 64kb pages (configurable).

the page size is equal with or greater than 4k. and since the size is power of two, the kernel page is always aligned (at least) to 4k boundary.

Quoted 7 lines
Quoted 5 lines
	offset = 0; /* bytes */
	while (offset < total_size) {
		dma_addr_t addr = snd_sgbuf_get_addr(sgbuf, offset);
		map_this_addr_to_my_hw_table(addr);
		offset += 4096; /* 4k */

I suggest to use PAGE_SIZE define here.

no, it must be 4096 (or better to define other const), which corresponds to the page size of the sound card.

the point of the code above is:

- the hardware page size is 4k byte independent from archs.
- you can use snd_sgbuf_get_addr() macro to retrieve the physical address of each 4k page regardless of the kernel page size.

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

#11 lore raw
Quoted 52 lines · Takashi Iwai

At Fri, 10 Oct 2003 13:57:10 +0200 (CEST),

Quoted 28 lines · Jaroslav
Quoted 25 lines · Takashi Iwai

At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),

Quoted 23 lines · [email protected] wrote:

Hello,

the hdsp-madi card with the hdspm driver seems to work now. so I want do a clean out of the code:

I asking how should I do this:

Quoted 7 lines
Quoted 3 lines

at least I have to allocate one page more = 4194304+4096, to get no Segmentation fault, but that could be the hardware too, since hdsp also needs one page more ?

the SG-buffer allocation size is aligned (round up) to PAGE_SIZE. (note that PAGE_SIZE is not always 4K byte on other architectures.)

Ok on my i386 architecture I have 4k pages and
the rme card needs 4k buffers.

So how to code this that it works on all architectures getting a SG Buf with 4k buffers.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Do I have to do something by doing preallocation ?

on linux, the least page size is 4K byte (so far, all architectures are so). thus, simply do a loop like

Nope. Old alpha arch has 8K pages.

well, i wrote "least" size in the above :)
in fact, ia64 can have up to 64kb pages (configurable).

the page size is equal with or greater than 4k. and since the size is power of two, the kernel page is always aligned (at least) to 4k boundary.

Quoted 7 lines
Quoted 5 lines
	offset = 0; /* bytes */
	while (offset < total_size) {
		dma_addr_t addr = snd_sgbuf_get_addr(sgbuf, offset);
		map_this_addr_to_my_hw_table(addr);
		offset += 4096; /* 4k */

I suggest to use PAGE_SIZE define here.

Quoted 8 lines

no, it must be 4096 (or better to define other const), which corresponds to the page size of the sound card.

the point of the code above is:

- the hardware page size is 4k byte independent from archs.
- you can use snd_sgbuf_get_addr() macro to retrieve the physical address of each 4k page regardless of the kernel page size.

Yes, sorry for my confusion.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php

#12 lore raw
In reply to Takashi Iwai

Hello,

Thanks,

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
	offset = 0; /* bytes */
	while (offset < total_size) {
		dma_addr_t addr = snd_sgbuf_get_addr(sgbuf, offset);
		map_this_addr_to_my_hw_table(addr);
		offset += 4096; /* 4k */

If PAGE_SIZE is never less than 4k then the code is good and I did it this way, I seems to work quite stable.

mfg winfried

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php