<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 9pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Dear all,<BR>
I had some problem when I use mmap() file operation in the device driver file operation. My situation can be described as:<BR>
&nbsp;<BR>
1. I reserve 2MB DDR memory as a look-up-table (LUT)&nbsp;for my customized device. The physical start&nbsp;address in the memory is 0x03000000 and the size is 2MB. <BR>
&nbsp;<BR>
2. In the device driver, I use mmap file operation to make this memory area directly accessible by application programs. In the mmap file operation, it looks like:<BR>
&nbsp;<BR>
&nbsp; if(remap_pfn_range(vma, vma-&gt;vm_start, vma-&gt;vm_pgoff, vma-&gt;vm_end - vma-&gt;vm_start, vma-&gt;vm_page_prot)){<BR>&nbsp;&nbsp;&nbsp;&nbsp; return -EAGAIN;<BR>&nbsp;&nbsp; }<BR>
&nbsp;<BR>
3. In the application program, I read from a file and initialize the LUT area. I use the following sentence to mmap the physical address into a virtual one which could be accessed by the application:<BR>
&nbsp;<BR>
&nbsp; // the physical address is from 0x03000000 with a size of LUT_SIZE_IN_BYTE equal to 2MB<BR>
&nbsp; lut_mem_base = (unsigned int *) mmap(0, LUT_SIZE_IN_BYTE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x03000000);<BR>
&nbsp;<BR>
Then, I initialize the LUT area with the virtual address specified by lut_mem_base. <BR>
&nbsp;<BR>
&nbsp; for(i=0;;i++){<BR>
&nbsp;&nbsp;&nbsp; fread(&amp;buf, sizeof(unsigned int), 1, fp);<BR>
&nbsp;&nbsp;&nbsp; *(lut_mem_base + i) = buf;<BR>
&nbsp;&nbsp;&nbsp; if(feop(fp)){<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>
&nbsp;&nbsp;&nbsp; }<BR>
&nbsp; }<BR>
&nbsp;<BR>
4. After the initialization of the LUT memory area, in the device driver, DMA transfer will be enabled using the physical address of 0x03000000 as the source address. The destination is a register in my customized device. The data is fed from the memory to my device register. <BR>
&nbsp;<BR>
HOWEVER, I found that the data fed to the device register is not the same as the one used to initialize the LUT memory. Maybe the DMA fetches wrong data from different addresses and feeds to my device. Since this is my first time to use mmap, I am not self-confident to my program, both in the device driver and in the application. Is there anything wrong with my mmap part? I will appreciate so much if some experts could give me some hints. Thanks in advance.<BR>
&nbsp;<BR>
BR<BR>
Ming<BR>
&nbsp;<BR>
&nbsp;<BR>
&nbsp;<BR>
&nbsp;<BR>
&nbsp;<BR>
&nbsp;<BR><br /><hr />Windows Live Writer,支持离线撰写博客内容,随时随地想写就写。 <a href='http://get.live.cn/product/writer.html' target='_new'>立即使用!</a></body>
</html>