All of lore.kernel.org
 help / color / mirror / Atom feed
* mmap CMA area on  /dev/mem
@ 2014-01-21  9:44 Кирилл Луценко
  2014-01-21 17:05 ` Jeff Haran
  0 siblings, 1 reply; 4+ messages in thread
From: Кирилл Луценко @ 2014-01-21  9:44 UTC (permalink / raw)
  To: kernelnewbies


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@/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!



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140121/934536ca/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* mmap CMA area on  /dev/mem
  2014-01-21  9:44 mmap CMA area on /dev/mem Кирилл Луценко
@ 2014-01-21 17:05 ` Jeff Haran
  2014-01-21 17:37   ` Re[2]: " Кирилл Луценко
  2014-01-21 18:47   ` Кирилл Луценко
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Haran @ 2014-01-21 17:05 UTC (permalink / raw)
  To: kernelnewbies



From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of ?????? ???????
Sent: Tuesday, January 21, 2014 1:45 AM
To: kernelnewbies at kernelnewbies.org
Subject: mmap CMA area on /dev/mem


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!

You don?t say what kind of processor you are running this on, but if its x86_64 you might want to look@your kernel configuration. If CONFIG_X86_PAT is configured you will have problems mapping memory to user space. It basically implements the same restrictions as CONFIG_STRICT_DEVMEM.

Jeff Haran




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140121/0c3d8eb5/attachment-0001.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re[2]: mmap CMA area on  /dev/mem
  2014-01-21 17:05 ` Jeff Haran
@ 2014-01-21 17:37   ` Кирилл Луценко
  2014-01-21 18:47   ` Кирилл Луценко
  1 sibling, 0 replies; 4+ messages in thread
From: Кирилл Луценко @ 2014-01-21 17:37 UTC (permalink / raw)
  To: kernelnewbies

 Sorry, I forgot it. I use i386 processor


???????, 21 ?????? 2014, 17:05 UTC ?? Jeff Haran <Jeff.Haran@citrix.com>:
>?
>?
From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of  ?????? ???????
>Sent: Tuesday, January 21, 2014 1:45 AM
>To: kernelnewbies at kernelnewbies.org
>Subject: mmap CMA area on /dev/mem
>?
>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!
>
>You don?t say what kind of processor you are running this on, but if its x86_64 you might want to look at your kernel configuration. If CONFIG_X86_PAT is configured you will have problems mapping memory to user
 space. It basically implements the same restrictions as CONFIG_STRICT_DEVMEM.
>Jeff Haran
>?
>? _______________________________________________
>Kernelnewbies mailing list
>Kernelnewbies at kernelnewbies.org
>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>


-- 
?????? ???????
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140121/72a2c65d/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re[2]: mmap CMA area on  /dev/mem
  2014-01-21 17:05 ` Jeff Haran
  2014-01-21 17:37   ` Re[2]: " Кирилл Луценко
@ 2014-01-21 18:47   ` Кирилл Луценко
  1 sibling, 0 replies; 4+ messages in thread
From: Кирилл Луценко @ 2014-01-21 18:47 UTC (permalink / raw)
  To: kernelnewbies

 I disabled CONFIG_x86_PAT and mmap() has started to work! ?Thank you so much, Jeff!


???????, 21 ?????? 2014, 17:05 UTC ?? Jeff Haran <Jeff.Haran@citrix.com>:
>?
>?
From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of  ?????? ???????
>Sent: Tuesday, January 21, 2014 1:45 AM
>To: kernelnewbies at kernelnewbies.org
>Subject: mmap CMA area on /dev/mem
>?
>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!
>
>You don?t say what kind of processor you are running this on, but if its x86_64 you might want to look at your kernel configuration. If CONFIG_X86_PAT is configured you will have problems mapping memory to user
 space. It basically implements the same restrictions as CONFIG_STRICT_DEVMEM.
>Jeff Haran
>?
>? _______________________________________________
>Kernelnewbies mailing list
>Kernelnewbies at kernelnewbies.org
>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>


-- 
?????? ???????
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140121/36410ebc/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-21 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-21  9:44 mmap CMA area on /dev/mem Кирилл Луценко
2014-01-21 17:05 ` Jeff Haran
2014-01-21 17:37   ` Re[2]: " Кирилл Луценко
2014-01-21 18:47   ` Кирилл Луценко

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.