Skip to contentSkip to conversation

Getting physical address of the DMA buffer

DISCUSSION Pharaoh . 2 participants 5 messages Jun 26, 2007 – Jun 27, 2007

lore
Share & tools
lore

Pharaoh .

author
#0 lore raw

Hi

I have allocated the DMA buffer using snd_pcm_lib_malloc_pages() and it was preallocated as:

snd_pcm_lib_preallocate_pages_for_all(pcm,

                                              SNDRV_DMA_TYPE_CONTINUOUS,
                                              snd_dma_continuous_data
                                              (GFP_KERNEL),
                                              128 * 1024, 128 * 1024);

and then,

snd_pcm_lib_malloc_pages(substream,

                                        params_buffer_bytes(hw_params));

None of these calls fail.

The physical address of the allocated buffer is shown as 0 in my case since according to 'Writing an ALSA driver' the physical address of the DMA buffer will
not be accessble from the main CPU. Is that why the physical address is shown as 0?

Also, in my pointer function, I need the DMA buffers physical address to calculate the
position in buffer etc. How can do that since runtime->dma_addr is 0 for me?

Apologies for longish mail but I have to paste the actual paragraphs here to clear my
understanding in less number of emails by avoiding further emails.

In chapter 5, in DMA buffer information, it is said that,

1. The dma_area holds the buffer pointer (the logical address). You can call memcpy
from/to this pointer. Meanwhile, dma_addr holds the physical address of the buffer. This field is specified only when the buffer is a linear buffer.

and in descrition of prepare callback it says,

2. The physical address of the allocated buffer is set to runtime->dma_area.

Statements 1 and 2 contradict each other or I am mis reading them?

How should I get the physical address in pointer callbacks? As runtime->dma_area or runtime->dma_addr which is 0?

-pharaoh.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#1 lore raw
Quoted 7 lines · Pharaoh .

I have allocated the DMA buffer using snd_pcm_lib_malloc_pages() and it was preallocated as:

snd_pcm_lib_preallocate_pages_for_all(pcm,

                                      SNDRV_DMA_TYPE_CONTINUOUS,
                                      snd_dma_continuous_data
                                      (GFP_KERNEL),

SNDRV_DMA_TYPE_CONTINUOUS is for a buffer that cannot be accessed over DMA.

What kind of bus does your hardware use, and how would you allocate memory for it?

Regards,
Clemens

author
#2 lore raw
Quoted 12 lines · Clemens Ladisch
Quoted 7 lines · Pharaoh .

I have allocated the DMA buffer using snd_pcm_lib_malloc_pages() and it was preallocated as:

snd_pcm_lib_preallocate_pages_for_all(pcm,

                                      SNDRV_DMA_TYPE_CONTINUOUS,
                                      snd_dma_continuous_data
                                      (GFP_KERNEL),

SNDRV_DMA_TYPE_CONTINUOUS is for a buffer that cannot be accessed over DMA.

Quoted 7 lines

What kind of bus does your hardware use, and how would you allocate memory for it?

Regards,
Clemens

Continuous buffers unrelated to the bus type can be allocated using SNDRV_DMA_TYPE_CONTINUOUS right? I am referring a standard driver from omap source tree, and the buffer allocation functions I have copied from there and they should be same for the range of OMAPs since the dma handling is same for them.

Quoted 2 lines

SNDRV_DMA_TYPE_CONTINUOUS is for a buffer that cannot be accessed over DMA.

Thats why I get runtime->dma_addr as 0.

#3 lore raw
Quoted 4 lines · Pharaoh .
Quoted 3 lines · Clemens Ladisch

SNDRV_DMA_TYPE_CONTINUOUS is for a buffer that cannot be accessed over DMA.

Quoted 8 lines
Quoted 2 lines

What kind of bus does your hardware use, and how would you allocate memory for it?

Continuous buffers unrelated to the bus type can be allocated using SNDRV_DMA_TYPE_CONTINUOUS right? I am referring a standard driver from omap source tree, and the buffer allocation functions I have copied from there and they should be same for the range of OMAPs since the dma handling is same for them.

I don't know anything about OMAP.

If the processor doesn't use a MMU, then the memory addresses as seen by the CPU are the same as those used by a device using DMA. In that case, you could use SNDRV_DMA_TYPE_CONTINUOUS and the correct address would be available as runtime->dma_area.

HTH
Clemens

author
#4 lore raw

Okay got it now. The omap I am using has a ARM926 which has a MMU. So I shouldn't be using SNDRV_DMA_TYPE_CONTINUOUS. I will try to allocate using other methods.

Quoted 25 lines · Clemens Ladisch
Quoted 4 lines · Pharaoh .
Quoted 3 lines · Clemens Ladisch

SNDRV_DMA_TYPE_CONTINUOUS is for a buffer that cannot be accessed over DMA.

Quoted 8 lines
Quoted 2 lines

What kind of bus does your hardware use, and how would you allocate memory for it?

Continuous buffers unrelated to the bus type can be allocated using SNDRV_DMA_TYPE_CONTINUOUS right? I am referring a standard driver from omap source tree, and the buffer allocation functions I have copied from there and they should be same for the range of OMAPs since the dma handling is same for them.

I don't know anything about OMAP.

If the processor doesn't use a MMU, then the memory addresses as seen by the CPU are the same as those used by a device using DMA. In that case, you could use SNDRV_DMA_TYPE_CONTINUOUS and the correct address would be available as runtime->dma_area.

HTH
Clemens