打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Chapter 7. PCI Devices

Chapter 7. PCI Devices

TheLinux pci interface provides a mechanism to accessthe PCI bus address spaces from user programs.

Performing programmed I/O on pci devices on SGILinux systems involves the following steps:

  1. Examine /proc/bus/pci/devices and obtain offsets for thebase address registers (BARs) of the devices that you want to map. Theformat of the lines is as follows (with field widths in the number ofhexadecimal characters shown, and line breaks added for readability):

    bus:2x (slotnumber<<3_|_fn):2x vend:8x bar0 bar1 bar2 bar3 ...

    For example:

    if ((fptr = fopen( "/proc/bus/pci/devices", "r")) == NULL) {                printf( "Unable to open /proc/bus/pci/devices\n" );        }        while(fgets(buf, sizeof(buf) - 1, fptr)) {                sscanf( buf, "%2x%2x %8x %*x %lx %lx %lx %lx %lx %lx %lx %lx %*lx %*lx %*lx %*lx %*lx %*lx",                &sbus, &sdevfn, &svend, &sbar[0], &sbar[1], &sbar[2], &sbar[3],                &sbar[4], &sbar[5], &sbar[6], &sbar[7]);                if(( sbus == bus ) && (sdevfn == devfn)) {                        /* This is the bus, slot and function we're looking for,                          * so save the base address register offset information.  */                        for(int i=0; i> 16;                        device = svend & 0xffff;                }        }        fclose( fptr );

  2. Open the appropriate device file for the bus,slot, and function in which you are interested. The device files are namedas follows:

    /proc/bus/pci/bus/slot.function

    For example:

    memfile = (char*) malloc( 32 );        sprintf( memfile, "/proc/bus/pci/%02d/%02d.%d", bus, slot, function );        fd = open( memfile, O_RDWR );

  3. Set the memory map state for the file to MEM space using the PCIIOC_MMAP_IS_MEM requestto the ioctl() system call.

    For example:

    ioctl(fd, PCIIOC_MMAP_IS_MEM);

  4. Map the opened file, using the offset obtainedin step 1 as the offsetparameter.

    For example:

    tmpPtr = (char *) mmap( NULL, (size_t) len, PROT_READ | PROT_WRITE,                MAP_SHARED, fd, (off_t) offset[bar]);

For a complete example, see Appendix D, “Reading MAC Addresses Sample Program”.

For details about kernel-level PCI device drivers, see the Linux Device Driver Programmer's Guide-Porting to SGI Altix Systems,

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用 /sys 文件系统访问 Linux 内核
sysfs 文件系统
Input event驱动
如何查看Linux 硬件配置信息 - 无度 - 博客园
如何判断自己的手机是UFS还是eMMC?
linux中probe函数传递参数的寻找(下)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服