Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading and writing into fpga using PCIe driver.

345 views
Skip to first unread message

sangee...@gmail.com

unread,
Nov 21, 2012, 8:41:33 AM11/21/12
to
Hi,

I'm new to PCI-e drivers working on Xilinx ML605 Virtex-6 FPGA board. The PCIe End Point (32-bit) of the FPGA has been enabled: Bar0, 1 MB. I want to accomplish a simple read/ write operation to the BAR0 location (note: I'm not using DMA). I have registered as a char device and can read all configuration space registers. I'm following the Xilinx XAPP1022 Memory endpoint test given by Xilinx.

Please could you suggest a way to read and write into memory location with offset say 0x04 from BAR 0 base location. I used ioremap and wrote into gBaseVirt (virtual address) using memcpy (to write into bar0 base address). My read and write functions in driver part are as follows:

Write module:

ssize_t XPCIe_Write(struct file *filp, const char *buf, size_t count,
loff_t *f_pos)
{
memcpy((char *)gBaseVirt, buf, count);
printk(KERN_INFO "\n\n***write module***\n");
printk("%s: XPCIe_Write: %d bytes have been written...@ address 0x%x ",
gDrvrName, count, gBaseVirt);
return (0);
}


Read module:

ssize_t XPCIe_Read(struct file *filp, char *buf, size_t count, loff_t
*f_pos)
{
memcpy(buf, (char *)gBaseVirt, count);
printk(KERN_INFO "\n***Read module***");
printk(KERN_INFO "%s: XPCIe_Read: %d bytes have been read... from
address 0x%x\n", gDrvrName, count, gBaseVirt);
return (0);
}


gBaseVirt is a pointer to kernel address after mapping bar0.

Please advice if this is correct. If not, please suggest another way to do so.



Tim Roberts

unread,
Nov 21, 2012, 11:27:17 PM11/21/12
to
sangee...@gmail.com wrote:
>
>Please could you suggest a way to read and write into memory location with
>offset say 0x04 from BAR 0 base location. I used ioremap and wrote into
>gBaseVirt (virtual address) using memcpy (to write into bar0 base
>address). My read and write functions in driver part are as follows:

Once you have a mapped address, it's just a pointer, like any other C
pointer. You treat it like memory. For example, to write a 32-bit value
to BAR 0 + 4, you could do:

unsigned long * ptr = (unsigned long *)gBaseVirt;
gBaseVirt[1] = 0x12345678;

"memcpy" also works. It seems a bit wasteful for writing 4 bytes at a
time, but it certainly works.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
0 new messages