readme.txt + pcie.c + in.txt +Makefile

可参考源码是: lspci

readme.txt

Please open the terminal in your linux system, then:

1.Please install two lib about pcie:

apt-get install libpciaccess-dev

apt-get install pciutils-dev

2.Please find the road path of libpci.a in your system, follows the commands:

cd /usr

find ./ -name "*pci*"

then, please modify the road path of the Makefile.

(in my ubuntu, it's road path: /usr/lib/i386-linux-gnu/libpci.a )

3.Please go into the directory of pcie.c, follows the commands:

make

./pcie

4. If you want to write pcie's configuration space, please write your data into the in.txt file.

Separating each byte with space .Such as "3a 4b 5c 6d 7e".

5. You computer may be poweroff, when you modify the byte 37, 38, 39 of PCIE configuration space. (that is,if you modify the Base Address Register 6)

pcie.c

#include

#include

#include

#include "/usr/include/pci/pci.h"

#include "/usr/include/pciaccess.h"

int config_space_read(int vendor_id, int device_id, int print){

int i = 0;

int ret = 0;

struct pci_access * myaccess;

struct pci_dev * mydev;

myaccess = pci_alloc();

pci_init(myaccess);

pci_scan_bus(myaccess);

for (mydev = myaccess->devices; mydev; mydev = mydev->next){

pci_fill_info(mydev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);

if(mydev->vendor_id == vendor_id && mydev->device_id == device_id){

if (print == 1){

printf("Configuration space content:\n");

for (i = 0; i < 64; i++) {

ret = pci_read_byte(mydev, i);

printf("%d: %02x \t", i, ret);

if(i%4 == 3 ){

printf("\n");

}

}

}else{

for (i = 0; i < 64; i++) {

pci_read_byte(mydev, i);

}

}

return 1;

}

}

pci_free_dev(mydev);

pci_cleanup(myaccess);

return 0;

}

int config_space_write(int vendor_id, int device_id, int position, unsigned int data[],int length){

int i = 0;

struct pci_access * myaccess;

struct pci_dev * mydev;

int flag;

myaccess = pci_alloc();

pci_init(myaccess);

pci_scan_bus(myaccess);

for (mydev = myaccess->devices; mydev; mydev = mydev->next){

pci_fill_info(mydev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);

if(mydev->vendor_id == vendor_id && mydev->device_id == device_id){

for(i = 0; i < length; i++, position++){

pci_write_byte(mydev, position, data[i]);

}

return 1;

}

}

pci_free_dev(mydev);

pci_cleanup(myaccess);

return 0;

}

void main(void){

int vendor_id ;

int device_id ;

int choose ;

int num ;

int length ;

unsigned int data[256] = {0};

int position = 0;

int i = 0 ;

int flag = 1;

FILE *fp;

int print = 0;

printf("Please input vid & pid(for example:8086 1c02):");

scanf("%x%x", &vendor_id, &device_id);

printf("\t\t 1-Configuration space read test\t\t 2-Configuration space write test \n please choose:");

scanf("%d", &choose);

switch(choose){

case 1:{

printf("Enter the number of times :");

scanf("%d", &num);

print = 1;

config_space_read(vendor_id, device_id, print);

print = 0;

for(i = 1; i < num; i++){

config_space_read(vendor_id, device_id, print);

}

printf("Read PCIE configuration space %d times\n", num);

break;

}

case 2:{

printf("Enter the number of times:");

scanf("%d", &num);

printf("Enter the starting position (decimal):");

scanf("%d", &position);

printf("Enter the length:");

scanf("%d", &length);

fp = fopen("in.txt", "r");

if (fp == NULL){

printf("Can't open file!\n");

return ;

}

for(i = 0; i< length; i++){

fscanf(fp, "%x", &data[i]);

}

printf("The data is :\n");

for(i = 0; i< length; i++){

printf("%x \t", data[i]);

if (i%4 == 3){

printf("\n");

}

}

printf("\n");

fclose(fp);

for(i = 0; i < num; i++){

flag = config_space_write(vendor_id, device_id, position, data, length);

if(flag == 0){

printf("This device not exist!\n");

}

}

printf("Write PCIE configuration space %d times\n", num);

print = 1;

config_space_read(vendor_id, device_id, print);

break;

}

}

return ;

}in.txt

ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

Makefile

pcie:pcie.c gcc -Wall -o pcie pcie.c /usr/lib/i386-linux-gnu/libpci.a -lz clean: rm -fr *.o *~

linux配置pcie无线网卡,【Linux c】读写pcie配置空间(安装lib库)相关推荐

  1. linux里面启用无线网卡,linux启用无线网卡上网

    1.使用cat /proc/version查看linux内核版本号,我的系统是Linux version 2.6.32-220.el6.i686 2.使用cat /etc/issue查看linux发行 ...

  2. linux使用windows无线网卡,linux下安装windows xp无线网卡驱动

    linux下安装windows xp无线网卡驱动 发布时间:2008-08-16 20:59:51来源:红联作者:Htgiot 大概对瑞银有用 一.安装及配置步骤: (1)解压: tar -zxvf ...

  3. PCIE AER Linux 驱动详解

    文章目录 Abstract 1. Introduction 2. PCIe Advanced Error Reportion Driver 2.1 PCIe AER Topology 2.2 PCIe ...

  4. linux多个pcie设备同时访问,linux – 是否可以写入在同一PCIe插槽上使用不同PCIe通道的多个设备?...

    我正在编写一个支持多个设备的Linux设备驱动程序.我有一个x8 PCIe卡,上面有4个这样的设备.每个都通过PCIe交换机运行并获得2个PCIe通道.有没有办法让驱动程序同时写入多个通道?如果是这样 ...

  5. Linux(debian7)操作基础(三)之PCI/PCI-E设备配置空间

    ⑴ 概念 PCI和PCI Express,是计算机常使用的一种高速总线.操作系统中的PCI/PCI-E设备驱动以及操作系统内核,都需要访问PCI及PCI-E配置空间.PCI/PCI-E设备的正常运行, ...

  6. linux识别riser卡,Riser卡和PCIe槽位

    图2-24中Riser卡可以安装在模组1或者模组2上,安装在IO模组1时,PCIe槽位为Slot 1~Slot 3,当安装在IO模组2时,PCIe槽位为Slot 4~Slot 6. 图2-24 3x8 ...

  7. linux设备资源分配,基于Linux 简化 AMP 配置使其更方便更动态地分配资源

    描述 嵌入式系统一般分为两大类:需要硬实时性能的:和不需要硬实时性能的.过去,我们不得不做出艰难抉择: 选择实时操作系统的性能还是我们钟爱的 Linux 系统的丰富特性,然后努力弥补不足之处? 如今, ...

  8. 嵌入式linux文件系统格式,嵌入式Linux的文件系统分区及数据读写方法与流程

    本发明涉及Linux系统的数据存储管理领域,特别是涉及一种基于NANDFlash存储器和UBIFS文件系统的嵌入式Linux的文件系统分区及数据读写方法. 背景技术: ::目前Linux操作系统由于源 ...

  9. linux中mysql主主搭建_mysql 主从配置 主主配置

    MySQL 主从( MySQL Replication) ,主要用于 MySQL 的时时备份或者读写分离.在配置之前先做一下准备工作,配置两台 mysql 服务器,如果你的机器不能同时跑两台 Linu ...

最新文章

  1. 【问题收集·中级】关于XMPP使用Base传送图片
  2. 自主云服务器处理器_云服务器哪家的CPU最便宜且好用
  3. 如何查找两个列表之间的差异?
  4. Django 【补充】ORM多对多正向查询
  5. 资讯|WebRTC M90 更新
  6. python中的字符串处理
  7. python中星号变量的几种特殊用法
  8. totolinkn200up怎么设置_totolinkN200R无线路由器如何设置啊,求高人指点
  9. 无规则弹窗自动点击插件_vscode 插件会了吧,英语不好的赶紧下载 自动分析源码中的陌生单词、点击朗读单词...
  10. XP去除开机登陆画面
  11. C++最普通的定时器功能实现
  12. Vector Math for 3D Computer Graphics (Bradley Kjell 著)
  13. 人脸识别之特征脸方法(Eigenface)PCA方法
  14. 老弟教你用CSS和JS实现曾经风靡一时的微信打飞机游戏
  15. Win10 最下面的任务栏不显示正在打开的窗口了,打开任何东西任务栏都不显示
  16. 完全平方数的几种判定方法与算法用时
  17. c语言编写生日祝福语大全,生日卡片祝福语(精选50句)
  18. 微信OAuth2.0 登录流程以及安全性分析
  19. 英语面试自我介绍java_java面试英语自我介绍
  20. [IMX6Q][Android5.1]移植笔记 --- Kernel启动无法挂载文件系统

热门文章

  1. 输入数值n,计算并输出下列多项式的值:S = 1 + 1/1! + 1/2! + 1/3! + 1/4! + ... + 1/n!
  2. 修建道路(最小生成树)
  3. 企业使用云平台,存在的三个问题
  4. 平板安装Ubuntu18.04教程
  5. CRM客户管理系统在市面上这么多?应该如何选型?各行业选型CRM必看!
  6. 仅逗oier们一笑(不定期更新中)
  7. 【VulnHub靶机渗透】一:BullDog2
  8. android 系统gpu 调试_基于Android系统的GPU动态调频方案 | Imagination中文技术社区
  9. `Computer-Algorithm` 数论基础知识 (同余,取模,快速幂,质数,互质,约数,质因子)
  10. 如何进行 Linux 服务器安全维护