Need to access PCIe memory space directly from user space - LS1088ARDB-PB

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need to access PCIe memory space directly from user space - LS1088ARDB-PB

690 Views
gsuresh_12
Contributor II

I am using LS1088ARDB-PB Hardware and I ported NXP LSDK 2012 main (GNU/LINUX 5.4.47 aarch64) software. I have connected one PCIe based board externally to the LS1088ARDB-PB PCIe 1 port. I can see the external connected PCIe board details by giving command of "lspci -v" in the user space. 

I would like to understand how to access direct memory spaces of Base Address Register (BAR) memory address space from user space?

Please suggest if I need to enable to get an access or any code available to Write/Read memory mapped BAR address space?  

Thanks & Regards

Suresh

0 Kudos
Reply
2 Replies

677 Views
yipingwang
NXP TechSupport
NXP TechSupport
UIO system can allow user to access bar memory from user space, please refer to https://www.kernel.org/doc/html/v4.14/driver-api/uio-howto.html.
 

Writing userspace driver using uio_pci_generic

Userspace driver can use pci sysfs interface, or the libpci library that wraps it, to talk to the device and to re-enable interrupts by writing to the command register.

Example code using uio_pci_generic

Here is some sample userspace driver code using uio_pci_generic:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
    int uiofd;
    int configfd;
    int err;
    int i;
    unsigned icount;
    unsigned char command_high;

    uiofd = open("/dev/uio0", O_RDONLY);
    if (uiofd < 0) {
        perror("uio open:");
        return errno;
    }
    configfd = open("/sys/class/uio/uio0/device/config", O_RDWR);
    if (configfd < 0) {
        perror("config open:");
        return errno;
    }

    /* Read and cache command value */
    err = pread(configfd, &command_high, 1, 5);
    if (err != 1) {
        perror("command config read:");
        return errno;
    }
    command_high &= ~0x4;

    for(i = 0;; ++i) {
        /* Print out a message, for debugging. */
        if (i == 0)
            fprintf(stderr, "Started uio test driver.\n");
        else
            fprintf(stderr, "Interrupts: %d\n", icount);

        /****************************************/
        /* Here we got an interrupt from the
           device. Do something to it. */
        /****************************************/

        /* Re-enable interrupts. */
        err = pwrite(configfd, &command_high, 1, 5);
        if (err != 1) {
            perror("config write:");
            break;
        }

        /* Wait for next interrupt. */
        err = read(uiofd, &icount, 4);
        if (err != 4) {
            perror("uio read:");
            break;
        }

    }
    return errno;
}
0 Kudos
Reply

673 Views
gsuresh_12
Contributor II

Thank you for your reply, I will try this code and will let you know the behavior.

Regards

Suresh

0 Kudos
Reply