<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Yeah it looks like a cache coherency problem from the first look.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">You may try enabling snooping on the DMA channel if MPC824X supports it. Check in Mode register setting.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Else you may want to use <FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">flush_dcache_range(start, last) <FONT color=#000000>functions and see if it helps.</FONT></SPAN></FONT>
<P class=MsoNormal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></FONT></P></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Lauri Ehrenpreis &lt;lauri.ehrenpreis@liewenthal.ee&gt;<BR>To: linuxppc-embedded@ozlabs.org<BR>Sent: Wednesday, October 11, 2006 7:20:03 AM<BR>Subject: Problems with DMA from user space on MPC834x (Cache coherency?)<BR><BR>
<DIV>Hi!<BR><BR>I have a problem with DMA from user space on a platform powered by MPC834x<BR>processor (which has powerpc e300 core inside). Our linux kernel version is<BR>2.6.17.<BR><BR>My user space program does something like this:<BR><BR>file_fd = open("/disk/file", O_RDONLY);<BR>result = read(file_fd, page_aligned_buf, len);<BR>call_driver_ioctl_which_performs_dma();<BR><BR>while /disk is mounted to a partition residing on USB memory stick or SD<BR>card.<BR>page_aligned_buf starts from page boundary and contains enough full pages<BR>for<BR>the data (so I can allways map full page with dma_map_page in kernel).<BR><BR>The buffer address and data length will then be passed to a driver, which<BR>calls<BR>get_user_pages, then maps each page with dma_map_page and tells a PCI<BR>device<BR>to start reading from that page:<BR><BR>...<BR>down_read(&amp;current-&gt;mm-&gt;mmap_sem);<BR>result = get_user_pages(current, current-&gt;mm, page_aligned_buf, nr_pages,<BR>0, 0, pages,
 NULL);<BR>up_read(&amp;current-&gt;mm-&gt;mmap_sem);<BR><BR>for (i = 0; i &lt; nr_pages; i++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;find_data_checksum(pages[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;dma_addr = dma_map_page(&amp;fpga.pci_dev-&gt;dev, pages[i], 0, PAGE_SIZE,<BR>DMA_TO_DEVICE);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;start_dma();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wait_until_dma_ready();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;dma_unmap_page(&amp;fpga.pci_dev-&gt;dev, dma_addr, dma_len, DMA_TO_DEVICE);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!checksum_ok_in_fpga())<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print_page_data();<BR>}<BR><BR>for (i = 0; i &lt; nr_pages; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;page_cache_release(pages[i]);<BR><BR>The problem is that sometimes the PCI device receives wrong bytes at random<BR>locations. I find the data checksum inside the driver and inside the FPGA.<BR>Inside the driver I use kmap(page) and kunmap(page) to access data on the<BR>user page. Sometimes the checksums
 do not match and I can see with the FPGA<BR>debugging tool, that the FPGA receives different data than the driver is<BR>printing out.<BR><BR>I have noticed 3 things regarding this error:<BR>1) When I copy the data I read from the block device to another buffer in<BR>userspace and pass this new buffer to the driver, then this error will<BR>never occur:<BR><BR>file_fd = open("/disk/file", O_RDONLY);<BR>result = read(file_fd, page_aligned_buf, len);<BR>memcpy(new_page_aligned_buf, page_aligned_buf, len);<BR>call_driver_ioctl_which_performs_dma(new_page_aligned_buf, len);<BR><BR>2) this error does not occur when I use copy_from_user instead of<BR>get_user_pages<BR>and dma_map_page inside driver.<BR><BR>3) this error does not occur on our previuos device, which has x86<BR>platform.<BR><BR>I am currently out of ideas what to do next.. It seems to me like a cache<BR>coherency problem. Can anyone suggest what might be
 wrong?<BR><BR>--<BR>_______________________________________________<BR>Linuxppc-embedded mailing list<BR>Linuxppc-embedded@ozlabs.org<BR><A href="https://ozlabs.org/mailman/listinfo/linuxppc-embedded" target=_blank>https://ozlabs.org/mailman/listinfo/linuxppc-embedded</A></DIV></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR></DIV></div><br></body></html>