allocating memory at boot

Philip Downer phil at pjd.me.uk
Fri Feb 18 10:58:10 EST 2011


sk.syed2 wrote:
>> I'm currently trying to port a (currently for unreleased hardware and
>> under nda) driver from x86 to arm and in doing so I've run into a
>> problem with allocating memory using pci_alloc_consistent. Looking into
>> it I can't allocate more than 1MB whereas I need to allocate at least
>> 2MB of contiguous memory.
>    I guess pci_alloc_consistent calls dma_alloc_coherent, so why does
> it fail to allocate 2MB of memory?
> What is the error do you see?

Well there is no warning or panic, pci_alloc_consistent returns NULL if 
I request 2MB. If I change my request to 1MB then it succeeds, 
everything is allocated correctly and I can use the memory without 
issues, but of course the device requires 2MB (well 6 buffers all 2MB in 
size) so it's of no use. If I attempt to request a second 1MB then 
pci_alloc_consistent also returns NULL for that second allocation.

I have looked at the code for dma_alloc_coherent etc and it seems to me 
that it's returning null because there isn't the space available to 
allocate the requested memory.

 > > The problem I've run into however is that I get a warning at boot
 > > which is:
 > >
 > > WARNING: at mm/bootmem.c:672
 > > alloc_arch_preferred_bootmem+0x34/0x64()
 >
 > You need to call alloc_bootmem at an early stage before slab is
 > initialized.

I was thinking that this might be the problem, but in order to do that 
I'd have to put the alloc_bootmem in core kernel code wouldn't I? This 
doesn't seem very appealing.

> Is the driver using the memory for DMA? Are you using the memory
> returned by alloc_bootmem directly?

Yes, it is used for DMA and I am using the memory returned by 
alloc_bootmem directly.

> Remember DMA works on physical addresses not virtual. You might have
> to use dma_map_single/dma_unmap_single.

Yes, I was aware that dma uses physical addresses, isn't that what 
alloc_bootmem returns? I'm not aware of dma_map_single etc I will look 
at that soon.

> Also does the h/w has any limitations of the physical memory range it
> can access? Like only first 64MB of RAM?

It's limited to 32bit addressing, but that should be fine for the 512mb 
of ram on the arm board which I have.

Thanks,

Phil




More information about the Kernelnewbies mailing list