GP2X How To Get Physical Memory Address?


Franxis

MAME 4 ALL
Joined
Aug 22, 2004
Messages
788
Age
49
Location
Spain
Website
franxis.zxq.net
Is there any way to get real physical memory address from the address returned by malloc() ???

I have tried to implement hardware blitter in MAME, but i have no performance improvement because i'm ordered to have the MAME frame video buffer in high memory and then memory access to this buffer is slower (65% of malloc memory speed?) and this buffer is extensivelly used by MAME core. Any way to put it in normal malloc() memory and get the physical address by any method?

Thanks and regards. B)
 
Franxis posted on Mar 28 2006 at 07:46 PM said:
Is there any way to get real physical memory address from the address returned by malloc() ???

I have tried to implement hardware blitter in MAME, but i have no performance improvement because i'm ordered to have the MAME frame video buffer in high memory and then memory access to this buffer is slower (65% of malloc memory speed?) and this buffer is extensivelly used by MAME core. Any way to put it in normal malloc() memory and get the physical address by any method?

Thanks and regards. B)
Ugly idea:

1. Allocate your memory with malloc. Hope it is contiguous in physical memory (or modify this technique in even uglier ways to deal with it).

2. Fill your allocated memory with magic cookie values

3. Using mmap, map the entire physical range in which the allocate memory could occur.

4. Search the mmapped memory for the magic cookies.
 
Last edited by a moderator:
I have some code from when I tried this out. Quick-and-dirty, it can only allocate 128kb of continuous memory. With a bit more effort I think it could be modified for more, so if there's any interest I can post it up.
 
It would be interesting see your approach. Another thing to keep in mind is that the data cache would need to be flushed before any blitter activity to make sure that physical memory is the same as what our code thinks it is.

Dzz's approach could possibly work, but it is very much a brute force approach that would be hugely inefficient.
 
There's only one way of obtaining contiguous memory and getting a physical memory pointer from it, and that's by using kernel functions that are not available to user applications.

So the only thing you can do (apart from what Dzz says, which may or may not work on gp2x linux) is write a kernel module that allocate physical memory, state the reason is DMA access, and then mmap that memory from your user code. This does mean your limited to 128kB though, as theoddbot says, which is normally not enough. It also means that the memory is allocate in the first 32MB.

The only other thing I'm looking at is hacking the VM translation tables, but this would require both kernel mode + supervisor access to get CP15 control, and Linux itself may decide to scribble over it once you've set it up.
 
Back
Top