PCIe Driver - How Does User Space Access It?

I am writing a PCIe driver for Linux, currently without DMA, and I need to know how to read and write to a PCIe device when it is turned on from user space.

In the driver, I do the basics in probe ():

pci_enable_device(); pci_request_regions(); pci_iomap(); 

But how can I access this memory from user space for reading and writing? Do I add files to my PCIe driver? Does the pci_iomap memory appear in any place where user space code can be called:

 open('mapped memory location'); mmap(...); 

If so, what is the location?

Note. A PCIe device will not connect to any Linux subsystem, such as audio, Ethernet, etc.

+5
source share
2 answers

You can register devices using functions such as register_chrdev and device_create . Consider the source source for / dev / null and / dev / mem :

 static int __init chr_dev_init(void) { int minor; if (register_chrdev(MEM_MAJOR, "mem", &memory_fops)) printk("unable to get major %d for memory devs\n", MEM_MAJOR); mem_class = class_create(THIS_MODULE, "mem"); if (IS_ERR(mem_class)) return PTR_ERR(mem_class); mem_class->devnode = mem_devnode; for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { if (!devlist[minor].name) continue; /* * Create /dev/port? */ if ((minor == DEVPORT_MINOR) && !arch_has_dev_port()) continue; device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor), NULL, devlist[minor].name); } return tty_init(); } fs_initcall(chr_dev_init); 
0
source

If you just want to export memory from kernel space to user space and get interrupts, consider a UIO driver .

With its help, all calls will be performed through the / dev / uioX file. You can do mmap () on it to export memory, and you can read (with read lock) to β€œcatch” the interrupt.

UIO is great for PCIe, there is already a driver in the kernel for it.

+2
source

Source: https://habr.com/ru/post/1242560/


All Articles