<HTML><BODY>Sorry, I forgot it. I use i386 processor<br><br><br>Вторник, 21 января 2014, 17:05 UTC от Jeff Haran &lt;Jeff.Haran@citrix.com&gt;:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        <div id="">








<div class="WordSection1">
<p class="MsoNormal"><font size="2" color="#1f497d" face="Calibri"><span style="font-size:11.0pt;font-family:&quot;calibriquotquotsans-serifquotmso-bidi-font-family:&quot;timesnewromanquotcolor:#1F497D">&nbsp;</span></font></p>
<p class="MsoNormal"><font size="2" color="#1f497d" face="Calibri"><span style="font-size:11.0pt;font-family:&quot;calibriquotquotsans-serifquotmso-bidi-font-family:&quot;timesnewromanquotcolor:#1F497D">&nbsp;</span></font></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><font size="2" face="Tahoma"><span style="font-size:10.0pt;font-family:&quot;tahomaquotquotsans-serifquotmso-fareast-font-family:&quot;timesnewromanquotfont-weight:bold">From:</span></font></b><font size="2" face="Tahoma"><span style="font-size:10.0pt;font-family:&quot;tahomaquotquotsans-serifquotmso-fareast-font-family:&quot;">
 kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org]
<b><span style="font-weight:bold">On Behalf Of </span></b>?????? ???????<br>
<b><span style="font-weight:bold">Sent:</span></b> Tuesday, January 21, 2014 1:45 AM<br>
<b><span style="font-weight:bold">To:</span></b> kernelnewbies@kernelnewbies.org<br>
<b><span style="font-weight:bold">Subject:</span></b> mmap CMA area on /dev/mem</span></font></p>
</div>
</div>
<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Hello everyone!
<br>
I need reserve 256-512 Mb of continuous physical memory and have access to this memory from the user space.
<br>
I decided to use CMA for memory reserving. <br>
Here are the steps on my idea that must be performed:<br>
1. Reservation required amount of memory by CMA during system booting.<br>
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.<br>
3. Mapping of CMA area at /dev/mem file with offset =&nbsp;0x27400000 using mmap(). (Of course,&nbsp;</span></font><font size="2" face="Arial"><span style="font-size:10.5pt;font-family:&quot;">CONFIG_STRICT_DEVMEM is disabled)</span></font><br>
It would let me to read data directly from phys memory from user space.<br>
<br>
But the next code make segmentation fault(there size = 1Mb):</p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">int file;<br>
void* start;</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">file=open("/dev/mem", O_RDWR | O_SYNC);</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">if ( (start = mmap(0, 1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0x27400000)) == MAP_FAILED ){<br>
&nbsp; &nbsp; perror("mmap");<br>
}</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">for (int offs = 0; offs&lt;50; offs++){<br>
&nbsp; &nbsp; &nbsp;cout&lt;&lt;((char *)start)[offs];<br>
}</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Output of this code: "mmap: Invalid argument".</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">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.<br>
According to information from /proc/iomem, phys addr of CMA area (0x27400000 on my system) always situated in System RAM.</span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">Does anyone have any ideas, how to mmap CMA area on /dev/mem? What am I doing wrong?<br>
Thanks alot for any help!</span></font></p>
<p style="margin-bottom:12.0pt"><font size="3" face="Times New Roman"><span style="font-size:12.0pt"><br>
<font color="#1f497d"><span style="color:#1F497D">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.</span></font></span></font></p>
<p style="margin-bottom:12.0pt"><font size="2" color="#1f497d" face="Calibri"><span style="font-size:11.0pt;font-family:&quot;calibriquotquotsans-serifquotmso-bidi-font-family:&quot;timesnewromanquotcolor:#1F497D">Jeff Haran</span></font></p>
<p style="margin-bottom:12.0pt"><font size="2" color="#1f497d" face="Calibri"><span style="font-size:11.0pt;font-family:&quot;calibriquotquotsans-serifquotmso-bidi-font-family:&quot;timesnewromanquotcolor:#1F497D">&nbsp;</span></font></p>
<p style="margin-bottom:12.0pt"><font size="2" color="#1f497d" face="Calibri"><span style="font-size:11.0pt;font-family:&quot;calibriquotquotsans-serifquotmso-bidi-font-family:&quot;timesnewromanquotcolor:#1F497D">&nbsp;</span></font></p>
</div>
</div>


_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="sentmsg?compose&amp;To=Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br>
</div>
</blockquote>
<br>
<br>-- <br>Кирилл Луценко<br></BODY></HTML>