Home Ask Login Register

Developers Planet

Your answer is one click away!

user2205930 February 2016

PCIe Driver - How does user space access it?

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

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


But then how do I access this memory from user space to read and write? Do I add file operations to my PCIe driver? Does the memory from pci_iomap show up some place where the user space code can call:

open('mapped memory location');

If so then what is the location?

Note: the PCIe device will not plugging into any Linux subsystems such as audio, Ethernet, etc.


antiduh February 2016

You can register devices using functions like register_chrdev and device_create. Consider the kernel 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)

         * Create /dev/port?
        if ((minor == DEVPORT_MINOR) && !arch_has_dev_port())

        device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
                  NULL, devlist[minor].name);

    return tty_init();


FabienM February 2016

If you just want to export memory from the kernel space to the user space and get interrupts, think about the UIO driver.

With it, all the accesses will be done through /dev/uioX file. You can do mmap() on it to export memory and you can read (with a blocking read) to "catch" the interrupt.

UIO is perfectly suited for PCIe, there already is a driver in kernel for it.

Post Status

Asked in February 2016
Viewed 1,917 times
Voted 10
Answered 2 times


Leave an answer

Quote of the day: live life