Hello everyone! 
I need reserve 256-512 Mb of continuous physical memory and have access to this 
memory from the user space. 
I decided to use CMA for memory reserving. 
Here are the steps on my idea that must be performed:
1. Reservation required amount of memory by CMA during system booting.
2. Parsing of CMA patch output which looks like for example: "CMA: reserved 256 
MiB at 27400000" and saving two parameters: size of CMA area = 256*1024*1024 
bytes and phys address of CMA area = 0x27400000.
3. Mapping of CMA area at /dev/mem file with offset = 0x27400000 using mmap(). 
(Of course,  CONFIG_STRICT_DEVMEM is disabled)
It would let me to read data directly from phys memory from user space.

But the next code make segmentation fault(there size = 1Mb):
int file;
void* start;
file=open("/dev/mem", O_RDWR | O_SYNC);
if ( (start = mmap(0, 1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, file, 
0x27400000)) == MAP_FAILED ){
    perror("mmap");
}
for (int offs = 0; offs<50; offs++){
     cout<<((char *)start)[offs];
}
Output of this code: "mmap: Invalid argument".
When I changed offset = 0x27400000 on 0, this code worked fine and program 
displayed trash. It also work for alot of offsets which I looked at /proc/iomem.
According to information from /proc/iomem, phys addr of CMA area (0x27400000 on 
my system) always situated in System RAM.
Does anyone have any ideas, how to mmap CMA area on /dev/mem? What am I doing 
wrong?
Thanks alot for any help!



_______________________________________________
Kernelnewbies mailing list
[email protected]
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to