Linux系统安装PCI驱动指南 (pci驱动 linux)

PCI(Peripheral Component Interconnect,外围部件互连)总线是目前许多计算机中用于连接周边设备的标准总线之一。Linux系统拥有广泛的驱动程序支持,包括PCI设备驱动程序。安装PCI驱动程序是Linux系统配置中重要的一部分。本文提供了Linux系统安装PCI驱动程序的详细指南。

之一步:确定PCI设备的信息

在安装PCI驱动程序之前,我们需要知道PCI设备的具体信息。为此,可以使用lspci命令。在终端窗口中输入命令“lspci”并按下回车键。该命令将返回一个PCI设备的列表。通常,该列表包括设备名称、厂商名称、设备ID和子系统ID。例如,以下是一个具有三个PCI设备的lspci输出:

00:00.0 Host bridge: Intel Corporation 440FX – 82441FX PMC [Natoma] (rev 02)

00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]

00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)

第二步:查找PCI设备的驱动程序

一旦确定了PCI设备的信息,下一步就是查找设备的驱动程序。通常情况下,Linux内核自带了大部分PCI设备的驱动程序。为了确定设备是否有内置的驱动程序,可以使用modinfo命令。在终端窗口中输入“modinfo”命令并输入PCI设备的名称。例如,如果我们想了解Intel 440FX芯片组的modinfo信息,可以输入以下命令:

modinfo intel-440fx

该命令将返回有关设备驱动程序的详细信息,包括版本号、作者和文件路径等。

如果设备的驱动程序没有被内置在内核中,那么我们需要从其他来源获取它。最常见的选项是在Linux内核源代码中查找驱动程序或从Linux社区的网站下载它。

第三步:安装PCI设备的驱动程序

在确定了设备驱动程序的来源,并将其下载或复制到计算机上之后,我们需要将其安装到Linux系统中。

在大多数情况下,驱动程序将在下载后作为源代码提供。为了安装驱动程序,我们需要使用构建工具像gcc等来编译它们。为此,我们需要打开终端并进入已解压缩的驱动程序文件夹:

$ cd /path/to/driver/source

接下来,运行“make”命令来编译驱动程序:

$ make

命令将开始构建一个Linux内核模块,并在当前文件夹中生成相应的文件。接下来,我们需要将模块加载到Linux内核中。为此,我们可以使用inod命令,例如:

$ sudo inod pci-driver.ko

在此示例中,“pci-driver”是设备驱动程序文件的名称,而“.ko”表示这是一个Linux内核模块。

如果驱动程序没有安装,则可以使用modprobe命令来安装它:

$ sudo modprobe pci-driver

该命令将安装设备驱动程序并将其添加到Linux内核中。

第四步:验证设备驱动程序是否正确安装

为了验证设备驱动程序是否正确安装,可以使用lspci命令再次运行该设备的列表。在返回的列表中,应该可以看到设备及其相应的驱动程序已正确安装。例如,以下是Intel 440FX芯片组安装了其相应驱动程序后的lspci输出:

00:00.0 Host bridge: Intel Corporation 440FX – 82441FX PMC [Natoma] (rev 02)

00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]

00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)

00:01.2 USB Controller: Intel Corporation 82371AB/EB/MB PIIX4 USB (rev 01)

00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 01)

在该列表中,可以看到该芯片组的所有设备都已正确识别,并且已正确安装其相应驱动程序。

结论

PCI设备是现代计算机中常见的设备类型,因此安装其驱动程序是管理和配置Linux系统的重要部分。通过使用本指南提供的简单步骤,可以轻松地安装任何PCI设备的驱动程序并将其添加到Linux内核中。

相关问题拓展阅读:

如何让linux重新枚举pci设备

在Linux下,lspci可以枚举所有PCI设镇梁备。它是通过读取PCI配置空间(PCI Configuration Space)信息来实现PCI设备的枚举的。这里,我通过两种方式来简单的模拟一下lspci的功能。一种是通过PCI总线的CF8和CFC端口来枚举(参考PCI总线规范);另一种是利用proc filesystem。

  方法一:这种方法需要对端口进行操作,在Linux下,普通应用程序没有权限读写I/O 端口,需圆仿要通过iopl或ioperm来提升权限,我的代码里面使用iopl。

  

   view plaincopyprint?

  /*

  * Enum all pci device via the PCI config register(CF8 and CFC).

  */

  #include

  #include

  #include

  #include

  

  #define PCI_MAX_BUS 255 /* 8 bits (0 ~ 255) */

  #define PCI_MAX_DEV 31 /* 5 bits (0 ~ 31) */

  #define PCI_MAX_FUN 7 /* 3 bits (0 ~ 7) */

  

  #define CONFIG_ADDRESS 0xCF8

  #define CONFIG_DATA 0xCFC

  

  #define PCICFG_REG_VID 0x00 /* Vendor id, 2 bytes */

  #define PCICFG_REG_DID 0x02 /* Device id, 2 bytes */

  #define PCICFG_REG_CMD 0x04 /* Command register, 2 bytes */

  #define PCICFG_REG_STAT 0x06 /* Status register, 2 bytes */

  #define PCICFG_REG_RID 0x08 /* Revision id, 1 byte */

  

  

  void list_pci_devices()

  {

  unsigned int bus, dev, fun;

  unsigned int addr, data;

  

  //printf(“BB:DD:FF VID:DID\n”);

  

  

  for (bus = 0; bus >16);

  addr = 0xL | (bus

  #include

  #include

  #include

  #include

  #include

  

  #define PCI_MAX_BUS 255 /* 8 bits (0 ~ 255) */

  #define PCI_MAX_DEV 31 /* 5 bits (0 ~ 31) */

  #define PCI_MAX_FUN 7 /* 3 bits (0 ~ 7) */

  

  /*

  * PCI Configuration Header offsets

  */

  #define PCICFG_REG_VID 0x00 /* Vendor id, 2 bytes */

  #define PCICFG_REG_DID 0x02 /* Device id, 2 bytes */

  #define PCICFG_REG_CMD 0x04 /* Command register, 2 bytes */

  #define PCICFG_REG_STAT 0x06 /* Status register, 2 bytes */

  #define PCICFG_REG_RID 0x08 /* Revision id, 1 byte */

  #define PCICFG_REG_PROG_INTF 0x09 /* Programming interface code, 1 byte */

  #define PCICFG_REG_SUBCLASS 0x0A /* Sub-class code, 1 byte */

  #define PCICFG_REG_BASCLASS 0x0B /* Base class code, 1 byte */

  #define PCICFG_REG_CACHE_LINESZ 0x0C /* Cache line size, 1 byte */

  #define PCICFG_REG_LATENCY_TIMER 0x0D /* Latency timer, 1 byte */

  #define PCICFG_REG_HEADER_TYPE 0x0E /* Header type, 1 byte */

  #define PCICFG_REG_BIST 0x0F /* Builtin self test, 1 byte */

  #define PCICFG_REG_BAR0 0x10 /* Base addr register 0, 4 bytes */

  #define PCICFG_REG_BAR1 0x14 /* Base addr register 1, 4 bytes */

  #define PCICFG_REG_BAR2 0x18 /* Base addr register 2, 4 bytes */

  #define PCICFG_REG_BAR3 0x1C /* Base addr register 3, 4 bytes */

  #define PCICFG_REG_BAR4 0x20 /* Base addr register 4, 4 bytes */

  #define PCICFG_REG_BAR5 0x24 /* Base addr register 5, 4 bytes */

  #define PCICFG_REG_CIS 0x28 /* Cardbus CIS Pointer */

  #define PCICFG_REG_SVID 0x2C /* Subsystem Vendor ID, 2 bytes */

  #define PCICFG_REG_SDID 0x2E /* Subsystem ID, 2 bytes */

  #define PCICFG_REG_ROMBAR 0x30 /* ROM base register, 4 bytes */

  #define PCICFG_REG_CAPPTR 0x34 /* Capabilities pointer, 1 byte */

  #define PCICFG_REG_INT_LINE 0x3C /* Interrupt line, 1 byte */

  #define PCICFG_REG_INT_PIN 0x3D /* Interrupt pin, 1 byte */

  #define PCICFG_REG_MIN_GNT 0x3E /* Minimum grant, 1 byte */

  #define PCICFG_REG_MAX_LAT 0x3F /* Maximum lat, 1 byte */

  

  

  void list_pci_devices()

  {

  unsigned int bus, dev, fun;

  

  //printf(“BB:DD:FF VID:DID(RID)\n”);

  

  

  for (bus = 0; bus >16;

  

  printf(“%02X:%02X:%02X”, bus, dev, fun);

  if (rid > 0) {

  printf(” %04X:%04X (rev %02X)\n”, vid, did, rid);

  } else {

  printf(” %04X:%04X\n”, vid, did);

  }

  }

  } // end func

  } // end device

  } // end bus

  }

  

  int main(int argc, char **argv)

  {

  list_pci_devices();

  

  return 0;

  }

  

  这两种方法各有优缺点,之一种方法方便移植到其他OS,第二种就只适用于Linux。但是,之一种方法需要对I/O port进行直接操作。第二种就不需要。

  注意:执行这两段代码时,需要超级用户(root) 权限。

  补充:今天在枚举 Westmere-EP Processor(Intel Xeon Processor 5500 Series(Nehalem-EP))的 IMC(Integrated Memory Controller)时发现一个问题。lspci无法枚举到IMC设备。Westmere-EP 是 Intel 新的处理器架构。和以往的CPU不一样,它把Memory Controller集成到了CPU里面。IMC控制器被映射到了PCI总线上,Bus Number 是0xFE~0xFF,procfs(/proc/bus/pci/)下没有这几个设备。但是,通过 CF8/CFC 端口可以枚举到这些设备。

  3. 这段代码是在驱动中可以用来查找特定的pci device,并且返回一个pci_dev的结构体变量。通过这样一个struct变量,内核提供的接口函数可以直接套用,如pci_read_config_word(),pci_write_config_word()等。

   view plaincopyprint?

  void list_pci_device()

  {

  struct pci_dev *dev;

  struct pci_bus *bus,*childbus;

  

  list_for_each_entry(bus, &pci_root_buses, node) { //globle pci_root_buses in pci.h

  list_for_each_entry(dev, &bus->devices, bus_list) { // for bus 0

  printk(“%02X:%02X:%02X %04X:%04X\n”,dev->bus->number,dev->devfn >> 3, dev->devfn & 0x07,dev->vendor,dev->device);

  }

  list_for_each_entry(childbus, &bus->children,node) { // for bus 1,2,3,…

  list_for_each_entry(dev, &childbus->devices, bus_list) {

  printk(“%02X:%02X:%02X %04X:%04X\n”,dev->bus->number,dev->devfn >> 3, dev->devfn & 0x07,dev->vendor,dev->device);

  }

  }

linux如何用驱动程序查看 计算机系统上的所有PCI设备的I/O配置信息。

# lspci -tv# 列出所有PCI设备

关于pci驱动 linux的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » Linux系统安装PCI驱动指南 (pci驱动 linux)