All of lore.kernel.org
 help / color / mirror / Atom feed
* Scatter-Gather buffer allocation before running on HDSP-MADI ?
@ 2003-10-04 16:15 Winfried Ritsch
  2003-10-05 19:01 ` Jaroslav Kysela
  0 siblings, 1 reply; 12+ messages in thread
From: Winfried Ritsch @ 2003-10-04 16:15 UTC (permalink / raw)
  To: alsa-devel


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-04 16:15 Scatter-Gather buffer allocation before running on HDSP-MADI ? Winfried Ritsch
@ 2003-10-05 19:01 ` Jaroslav Kysela
  2003-10-06 13:50   ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: Jaroslav Kysela @ 2003-10-05 19:01 UTC (permalink / raw)
  To: Winfried Ritsch; +Cc: alsa-devel

On Sat, 4 Oct 2003, Winfried Ritsch wrote:

>
> 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.

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.

> 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 <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-05 19:01 ` Jaroslav Kysela
@ 2003-10-06 13:50   ` Takashi Iwai
  2003-10-06 17:19     ` ritsch
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2003-10-06 13:50 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Winfried Ritsch, alsa-devel

At Sun, 5 Oct 2003 21:01:58 +0200 (CEST),
Jaroslav wrote:
> 
> On Sat, 4 Oct 2003, Winfried Ritsch wrote:
> 
> >
> > 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.
> 
> 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.

>  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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-06 13:50   ` Takashi Iwai
@ 2003-10-06 17:19     ` ritsch
  2003-10-06 17:38       ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: ritsch @ 2003-10-06 17:19 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

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)));
  ....

> At Sun, 5 Oct 2003 21:01:58 +0200 (CEST),
> Jaroslav wrote:
> > 
> > On Sat, 4 Oct 2003, Winfried Ritsch wrote:
> > 
> > >
> > > 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.
> > 
> > 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.
> 
> >  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
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/alsa-devel
> 


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-06 17:19     ` ritsch
@ 2003-10-06 17:38       ` Takashi Iwai
  2003-10-07 16:25         ` Winfried Ritsch
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2003-10-06 17:38 UTC (permalink / raw)
  To: ritsch; +Cc: alsa-devel

At Mon, 06 Oct 2003 19:19:08 +0200 (CEST),
ritsch@iem.at 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:
> 
>   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.

> 
> 2) If SG_BUF makes continous virtual buffer
> 
>    why there is a 
> 
>      .pages=snd_pcm_sgbuf_ops_page 
       ^^^^^^
       .page  (without 's')
>  
>    function needed ?
>    what is the purpose of this ?  

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

> 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 ?

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-06 17:38       ` Takashi Iwai
@ 2003-10-07 16:25         ` Winfried Ritsch
  2003-10-07 16:43           ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: Winfried Ritsch @ 2003-10-07 16:25 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-07 16:25         ` Winfried Ritsch
@ 2003-10-07 16:43           ` Takashi Iwai
       [not found]             ` <1065776616.3f8675e8b202e@iem.at>
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2003-10-07 16:43 UTC (permalink / raw)
  To: Winfried Ritsch; +Cc: alsa-devel

At Tue, 7 Oct 2003 18:25:50 +0200,
Winfried Ritsch wrote:
> 
> 
> 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))

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

> 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 ?

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

> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
       [not found]             ` <1065776616.3f8675e8b202e@iem.at>
@ 2003-10-10 11:39               ` Takashi Iwai
  2003-10-10 11:57                 ` Jaroslav Kysela
  0 siblings, 1 reply; 12+ messages in thread
From: Takashi Iwai @ 2003-10-10 11:39 UTC (permalink / raw)
  To: ritsch; +Cc: alsa-devel

At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),
ritsch@iem.at 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:
> 
> > > 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.
> 
> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-10 11:39               ` Takashi Iwai
@ 2003-10-10 11:57                 ` Jaroslav Kysela
  2003-10-10 12:06                   ` Takashi Iwai
  0 siblings, 1 reply; 12+ messages in thread
From: Jaroslav Kysela @ 2003-10-10 11:57 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: ritsch, alsa-devel

On Fri, 10 Oct 2003, Takashi Iwai wrote:

> At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),
> ritsch@iem.at 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:
> >
> > > > 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.
> >
> > 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.

> 	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.

> 	}

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-10 11:57                 ` Jaroslav Kysela
@ 2003-10-10 12:06                   ` Takashi Iwai
  2003-10-10 12:15                     ` Jaroslav Kysela
  2003-10-10 15:23                     ` Winfried Ritsch
  0 siblings, 2 replies; 12+ messages in thread
From: Takashi Iwai @ 2003-10-10 12:06 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: ritsch, alsa-devel

At Fri, 10 Oct 2003 13:57:10 +0200 (CEST),
Jaroslav wrote:
> 
> On Fri, 10 Oct 2003, Takashi Iwai wrote:
> 
> > At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),
> > ritsch@iem.at 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:
> > >
> > > > > 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.
> > >
> > > 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.

> > 	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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-10 12:06                   ` Takashi Iwai
@ 2003-10-10 12:15                     ` Jaroslav Kysela
  2003-10-10 15:23                     ` Winfried Ritsch
  1 sibling, 0 replies; 12+ messages in thread
From: Jaroslav Kysela @ 2003-10-10 12:15 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: ritsch, alsa-devel

On Fri, 10 Oct 2003, Takashi Iwai wrote:

> At Fri, 10 Oct 2003 13:57:10 +0200 (CEST),
> Jaroslav wrote:
> >
> > On Fri, 10 Oct 2003, Takashi Iwai wrote:
> >
> > > At Fri, 10 Oct 2003 11:03:36 +0200 (CEST),
> > > ritsch@iem.at 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:
> > > >
> > > > > > 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.
> > > >
> > > > 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.
>
> > > 	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.

Yes, sorry for my confusion.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Scatter-Gather buffer allocation before running on HDSP-MADI ?
  2003-10-10 12:06                   ` Takashi Iwai
  2003-10-10 12:15                     ` Jaroslav Kysela
@ 2003-10-10 15:23                     ` Winfried Ritsch
  1 sibling, 0 replies; 12+ messages in thread
From: Winfried Ritsch @ 2003-10-10 15:23 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Jaroslav Kysela, ritsch, alsa-devel


Hello,

Thanks, 

>> > 	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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-10-10 15:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-04 16:15 Scatter-Gather buffer allocation before running on HDSP-MADI ? Winfried Ritsch
2003-10-05 19:01 ` Jaroslav Kysela
2003-10-06 13:50   ` Takashi Iwai
2003-10-06 17:19     ` ritsch
2003-10-06 17:38       ` Takashi Iwai
2003-10-07 16:25         ` Winfried Ritsch
2003-10-07 16:43           ` Takashi Iwai
     [not found]             ` <1065776616.3f8675e8b202e@iem.at>
2003-10-10 11:39               ` Takashi Iwai
2003-10-10 11:57                 ` Jaroslav Kysela
2003-10-10 12:06                   ` Takashi Iwai
2003-10-10 12:15                     ` Jaroslav Kysela
2003-10-10 15:23                     ` Winfried Ritsch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.