* MPC8260 strange virtual addresses returned by kmalloc()
@ 2005-01-05 13:38 Laurent Lagrange
2005-01-05 17:41 ` Eugene Surovegin
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Lagrange @ 2005-01-05 13:38 UTC (permalink / raw)
To: linuxppc-embedded
[-- Attachment #1: Type: text/plain, Size: 1630 bytes --]
Hi and Happy New Year to all,
I use a Linux 2.4.25 kernel on a MPC8260 custom board with 128MB of RAM.
PCI is activated and my drivers are loaded as modules.
The RAM is mapped at 0xC0000000 as usual.
On MPC8XX I used kmalloc and iopa to get the physical addresses of the
allocated buffers.
On MPC82XX I used kmalloc and __pa for the same thing and it worked fine
with previous kernel.
But now, when I want to use kmalloc, I get addresses like 0xC9xxxxxx.
The __pa gives me physical addresses 0x09xxxxxx which are out of my physical
RAM.
I tried old iopa function and got some real physical addresses and the
module works.
The virt_to_bus gives me too addresses like 0x09xxxxxx
(ie substract kernel base address 0xC0000000 as usual).
I don't understand why I get virtual addresses which seem to be out of my
memory and why it runs.
More, I have a global variable which is a little buffer. It is also mapped
at a 0xC9xxxxxx address.
Has anyone an idea or a link to a detailed howto ?
Thanks
Bye
Laurent
PS : Linux console informations about memory.
Memory BAT mapping: BAT2=128Mb, BAT3=0Mb, residual: 0Mb
Linux version 2.4.25 (version gcc 3.2.3)
On node 0 totalpages: 32768
zone(0): 32768 pages.
zone(1): 0 pages.
zone(2): 0 pages.
...
Memory: 127008k available (948k kernel code, 296k data, 60k init, 0k
highmem)
Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
Inode cache hash table entries: 8192 (order: 4, 65536 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 8192 (order: 3, 32768 bytes)
Page-cache hash table entries: 32768 (order: 5, 131072 bytes)
[-- Attachment #2: Type: text/html, Size: 4205 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: MPC8260 strange virtual addresses returned by kmalloc()
2005-01-05 13:38 MPC8260 strange virtual addresses returned by kmalloc() Laurent Lagrange
@ 2005-01-05 17:41 ` Eugene Surovegin
2005-01-06 17:42 ` Laurent Lagrange
0 siblings, 1 reply; 4+ messages in thread
From: Eugene Surovegin @ 2005-01-05 17:41 UTC (permalink / raw)
To: Laurent Lagrange; +Cc: linuxppc-embedded
On Wed, Jan 05, 2005 at 02:38:12PM +0100, Laurent Lagrange wrote:
> Hi and Happy New Year to all,
>
> I use a Linux 2.4.25 kernel on a MPC8260 custom board with 128MB of RAM.
> PCI is activated and my drivers are loaded as modules.
> The RAM is mapped at 0xC0000000 as usual.
>
> On MPC8XX I used kmalloc and iopa to get the physical addresses of the
> allocated buffers.
> On MPC82XX I used kmalloc and __pa for the same thing and it worked fine
> with previous kernel.
>
> But now, when I want to use kmalloc, I get addresses like 0xC9xxxxxx.
> The __pa gives me physical addresses 0x09xxxxxx which are out of my physical
> RAM.
> I tried old iopa function and got some real physical addresses and the
> module works.
> The virt_to_bus gives me too addresses like 0x09xxxxxx
> (ie substract kernel base address 0xC0000000 as usual).
>
> I don't understand why I get virtual addresses which seem to be out of my
> memory and why it runs.
Yeah, this looks strange, please, check that this address is really
from kmalloc and not from vmalloc.
Also, check that PAGE_OFFSET is really 0xc000'0000.
> More, I have a global variable which is a little buffer. It is also mapped
> at a 0xC9xxxxxx address.
Is this global variable in the loaded module? If yes, this is normal,
because modules are loaded into vmalloced space and you cannot use
__pa for such addresses.
--
Eugene
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: MPC8260 strange virtual addresses returned by kmalloc()
2005-01-05 17:41 ` Eugene Surovegin
@ 2005-01-06 17:42 ` Laurent Lagrange
2005-01-06 18:59 ` Eugene Surovegin
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Lagrange @ 2005-01-06 17:42 UTC (permalink / raw)
To: 'Eugene Surovegin'; +Cc: linuxppc-embedded
Hi Eugene
My PAGE_OFFSET is defined as follow :
#define PAGE_OFFSET CONFIG_KERNEL_START in
./linux/include/asm-ppc/page.h
#define CONFIG_KERNEL_START (0xc0000000) in
./linux/include/linux/autoconf.h
After reading kmalloc manual pages, I am in doubt.
My call is like
if ((tmpbuffer = kmalloc(128 * 1024, GFP_KERNEL)) == NULL){
return(1);
}
This is the first time, I kmallocate a 128KB buffer which seems to be the
max
contiguous memory space which can be allocated.
Is it true on PPC ? Some PPC drivers seems to only allocate multiple
PAGE_SIZE (4KB) buffers.
My allocated buffer is intended to be used for DMA accesses.
Must I add the GFP_DMA flag to force the kmalloc to use contiguous memory ?
The Linux code for vmalloc is based on successive kmalloc calls, but I don't
know
what the kmalloc do when the desired size is greater than the PAGE_SIZE.
What is the right way to allocate big (128KB ???) DMA buffers ?
The manual pages say "Only for DMA kmalloc or __get_dma_pages() has to be
used"
The global variable is well in the loaded module.
OK, I use a kmalloc for the buffer instead of using the global variable.
Thanks for your ideas.
Laurent
-----Message d'origine-----
De : Eugene Surovegin [mailto:ebs@ebshome.net]
Envoye : mer. 5 janvier 2005 18:42
A : Laurent Lagrange
Cc : linuxppc-embedded@ozlabs.org
Objet : Re: MPC8260 strange virtual addresses returned by kmalloc()
On Wed, Jan 05, 2005 at 02:38:12PM +0100, Laurent Lagrange wrote:
> Hi and Happy New Year to all,
>
> I use a Linux 2.4.25 kernel on a MPC8260 custom board with 128MB of RAM.
> PCI is activated and my drivers are loaded as modules.
> The RAM is mapped at 0xC0000000 as usual.
>
> On MPC8XX I used kmalloc and iopa to get the physical addresses of the
> allocated buffers.
> On MPC82XX I used kmalloc and __pa for the same thing and it worked fine
> with previous kernel.
>
> But now, when I want to use kmalloc, I get addresses like 0xC9xxxxxx.
> The __pa gives me physical addresses 0x09xxxxxx which are out of my
physical
> RAM.
> I tried old iopa function and got some real physical addresses and the
> module works.
> The virt_to_bus gives me too addresses like 0x09xxxxxx
> (ie substract kernel base address 0xC0000000 as usual).
>
> I don't understand why I get virtual addresses which seem to be out of my
> memory and why it runs.
Yeah, this looks strange, please, check that this address is really
from kmalloc and not from vmalloc.
Also, check that PAGE_OFFSET is really 0xc000'0000.
> More, I have a global variable which is a little buffer. It is also mapped
> at a 0xC9xxxxxx address.
Is this global variable in the loaded module? If yes, this is normal,
because modules are loaded into vmalloced space and you cannot use
__pa for such addresses.
--
Eugene
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: MPC8260 strange virtual addresses returned by kmalloc()
2005-01-06 17:42 ` Laurent Lagrange
@ 2005-01-06 18:59 ` Eugene Surovegin
0 siblings, 0 replies; 4+ messages in thread
From: Eugene Surovegin @ 2005-01-06 18:59 UTC (permalink / raw)
To: Laurent Lagrange; +Cc: linuxppc-embedded
On Thu, Jan 06, 2005 at 06:42:50PM +0100, Laurent Lagrange wrote:
> My PAGE_OFFSET is defined as follow :
> #define PAGE_OFFSET CONFIG_KERNEL_START in
> ./linux/include/asm-ppc/page.h
> #define CONFIG_KERNEL_START (0xc0000000) in
> ./linux/include/linux/autoconf.h
>
> After reading kmalloc manual pages, I am in doubt.
> My call is like
> if ((tmpbuffer = kmalloc(128 * 1024, GFP_KERNEL)) == NULL){
> return(1);
> }
>
> This is the first time, I kmallocate a 128KB buffer which seems to be the
> max
> contiguous memory space which can be allocated.
> Is it true on PPC ? Some PPC drivers seems to only allocate multiple
> PAGE_SIZE (4KB) buffers.
kmalloc implementation isn't PPC specific. It's the same code for
every arch.
Regardless, if kmalloc cannot allocate amount of memory you have
requested, it'll return NULL and you must handle this gracefully.
kmalloc _always_ allocate physically continuous pages. That's why
trying to allocate 128K is bad idea, because it's more likely to fail.
> My allocated buffer is intended to be used for DMA accesses.
> Must I add the GFP_DMA flag to force the kmalloc to use contiguous memory ?
You need to use this flag to get DMA memory, although on PPC usually
all RAM is available for DMA.
> > The Linux code for vmalloc is based on successive kmalloc calls, but I don't
> know
> what the kmalloc do when the desired size is greater than the PAGE_SIZE.
That's not correct. vmalloc uses kmalloc only to allocate vm_struct.
Actual memory is allocated using alloc_page and then this page is
mapped by installing PTE into the kernel page table.
> What is the right way to allocate big (128KB ???) DMA buffers ?
> The manual pages say "Only for DMA kmalloc or __get_dma_pages() has to be
> used"
Generally for PAGE_SIZE * n allocations it's more efficient to use
__get_free_pages and friends. But kmalloc should also be OK. The only
limitation is the maximum size of such allocations, but you already
know this.
> The global variable is well in the loaded module.
> OK, I use a kmalloc for the buffer instead of using the global variable.
Memory for DMA should always be allocated using specially designed
functions. Don't use stack or static storage unless you know what you
are doing :).
--
Eugene
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-01-06 18:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-05 13:38 MPC8260 strange virtual addresses returned by kmalloc() Laurent Lagrange
2005-01-05 17:41 ` Eugene Surovegin
2005-01-06 17:42 ` Laurent Lagrange
2005-01-06 18:59 ` Eugene Surovegin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).