First, PCI simple introduction PCI is a peripheral bus specification. Let's take a look at what a bus is: A bus is a path or channel for transmitting signals. Typically, the bus is an electrical connection to one or more conductors, and all the devices connected on the bus can receive the full transmission at the same time. The bus consists of an electrical interface and a programming interface. This article discusses the device drivers under Linux, so focus on programming interfaces. PCI is the abbreviation for peripheral Component Interconnect (peripheral interconnect) and is commonly used as a peripheral bus on desktops and larger computers. The PCI architecture is designed as a replacement for the ISA standard, with three main goals: better performance when transferring data between computers and peripherals, platform agnostic, and simplifying the task of adding and removing peripherals to the system.
Second, PCI addressing From now on, I want to illustrate the problem as much as possible through some practical examples, while the descriptive narrative of reducing the theoretical aspects of the problem, because, related to the theory of things, can be found elsewhere. Let's take a look at the example, my computer has a 1G ram,1g after the physical memory address space is the external device IO mapping on the system memory address space. /proc/iomem describes the mapping of all device I/O in the system to the memory address space. Let's see how the first device at the beginning of the 1G was described in/proc/iomem: 40000000-400003ff:0000:00:1f.1 This is a PCI device, 40000000-400003FF is the memory address space that it maps, occupies the location of the bytes of the memory address space, and 0000:00:1F.1 is the address of a PCI peripheral, separated by a colon and a comma into 4 parts, The first 16-bit represents the domain, the second 8-bit represents a bus number, the third 5-bit represents a device number, and finally 3-bit, which represents the function number. Because the PCI specification agrees that a single system has up to 256 buses, the bus number is 8 bits. However, for large systems, this is not enough, so, introduced the concept of a domain, each PCI domain can have up to 256 bus, each bus can support 32 devices, so the device number is 5 bits, and each device can have up to 8 functions, so the function number is 3 bits. Thus, we can conclude that the address of the above PCI device is the number 1th function on the No. 31st device on the No. No. 0 field No. 0 bus. What exactly is this PCI device? The following is the output of the LSPCI command on my computer: 00:00.0 host Bridge:intel Corporation 82845 845 (Brookdale) Chipset Host Bridge (Rev. 04) 00:01.0 PCI Bridge:intel Corporation 82845 845 (Brookdale) Chipset AGP Bridge (Rev. 04) 00:1d.0 USB Controller:intel Corporation 82801ca/cam USB (Hub #1) (rev. 02) 00:1d.1 USB Controller:intel Corporation 82801ca/cam USB (Hub #2) (rev. 02) 00:1e.0 PCI Bridge:intel Corporation 82801 Mobile PCI bridge (Rev. 42) 00:1f.0 Isa Bridge:intel Corporation 82801CAM Isa Bridge (LPC) (rev 02) 00:1F.1 IDE Interface:intel Corporation 82801CAM IDE U100 (rev 02) 00:1F.3 Smbus:intel Corporation 82801ca/cam SMBus Controller (rev. 02) 00:1F.5 Multimedia Audio Controller:intel Corporation 82801ca/cam AC ' Audio Controller (rev 02) 00:1F.6 Modem:intel Corporation 82801ca/cam AC ' 02 Modem Controller 01:00.0 VGA compatible Controller:nvidia Corporation NV17 [GeForce4 420 Go] (rev A3) 02:00.0 FireWire (IEEE 1394): VIA Technologies, Inc. IEEE 1394 Host Controller (Rev. 46) 02:01.0 Ethernet Controller:realtek Semiconductor Co., Ltd. rtl-8139/8139c/8139c+ (Rev 10) 02:04.0 CardBus Bridge:o2 Micro, Inc. OZ6933 CardBus Controller (rev. 01) 02:04.1 CardBus Bridge:o2 Micro, Inc. OZ6933 CardBus Controller (rev. 01) LSPCI does not indicate a domain, but for a PC, there is typically only one domain, or domain No. 0. With this output we can see that it is an IDE interface. As can be seen from the above output, My computer has 3 PCI buses (number No. 0, number 1th, 2nd) together. On a single system, inserting multiple buses is done through the Bridge (bridge), which is a special PCI peripheral for connecting the bus. So, the overall layout of the PCI system is tree-shaped, and we can draw the tree structure of the PCI system on my computer through the above LSPCI output: 00:00.0 (main bridge)--00:01.0 (PCI bridge)-----01:00:0 (NVIDIA graphics card) | |---00:1d (USB controller)--00:1d:0 (USB1 Controller) | | | |--00:1d:1 (USB2 Controller) | |-00:1e:0 (PCI bridge)--02:00.0 (IEEE1394) | | | |-02:01.0 (8139 NIC) | | | |-02:04 (CardBus Bridge) -02:04.0 (bridge 1) | | | |--02:04.1 (bridge 2) | |-00:1F (multifunction Board) -00:1f:0 (ISA bridge) | |--00:1f:1 (IDE interface) | |--00:1f:3 (SMBus) | |--00:1f:5 (multimedia sound Controller) | |--00:1f:6 (Modem) By being able to conclude, I have 8 PCI devices on my computer, among which there are 4 on bus No. 0 (main bridge) and 1 on bus 1th and 2nd on bus 3. The 00:1f is a multi-function board with 5 functions. Each PCI device has its mapped memory address space and its I/O area, which is easier to understand. In addition, the PCI device also has its configuration register. With the configuration register, the PCI driver does not need to detect the device. The layout of the configuration register is standardized, and the 4 bytes of the configuration space contain a unique feature ID, so the driver can identify its device by querying the specific ID of the peripheral. Therefore, the main innovation of the PCI interface standard above ISA is to configure the address space. As already mentioned, the PCI driver does not need to detect the device, which is due to the configuration address space. During the system boot phase, the PCI hardware device remains inactive, but each PCI motherboard is equipped with firmware capable of handling PCI, and the firmware provides access to the device configuration address space by reading and writing the registers in the PCI controller. The first 64 bytes of the configured address space are standardized, providing information such as vendor number, device number, version, and so on, uniquely identifying a PCI device. At the same time, it also provides up to 6 I/O address areas, each of which can be memory or I/O addresses. These several I/O address areas are the only way that the driver finds the exact location of the device mapping to memory and I/O space. With these two points, the PCI driver is finished with the equivalent of probing capabilities. For details about the 64-byte configuration space, refer to the third version of the Linux device driver P306, which is no longer detailed. Below, let's take a look at the configuration space of the 8139too NIC device. In the 2.6 kernel system, you can see very many folders named after the PCI device name under the folder/sys/bus/pci/drivers/, but not that these devices are present in your system. We go to the 8139too folder, which has a folder named after its device address 0000:02:01.0. You can find a lot of information about this NIC device in this folder. Among these, resource recorded 6 I/O address areas. The contents are as follows: 0x0000000000003400 0x00000000000034ff 0x0000000000000101 0x00000000e0000800 0x00000000e00008ff 0x0000000000000200 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 It can be seen from this file that the 8139too device uses two I/O address areas, the first is the I/O port range It maps, and the second is the memory address space it maps. About these two values can be verified in/proc/iomem and/proc/ioport. -[0000:00]-+-00.0 +-02.0 +-1d.0 +-1d.1 +-1d.2 +-1d.7 +-1e.0-[0000:01]--+-02.0 | /-05.0 +-1f.0 +-1f.1 +-1f.3 /-1f.5 00:00.0 Host bridge:intel Corporation 82845g/gl[brookdale-g]/ge/pe DRAM controller/host-hub Interface (rev. 03) 00:02.0 VGA compatible Controller:intel Corporation 82845g/gl[brookdale-g]/ge Chipset Integrated Graphics Device (rev. 03) 00:1d.0 USB Controller:intel Corporation 82801db/dbl/dbm (ich4/ich4-l/ich4-m) USB UHCI Controller #1 (rev 02) 00:1d.1 USB Controller:intel Corporation 82801db/dbl/dbm (ich4/ich4-l/ich4-m) USB UHCI Controller #2 (rev 02) 00:1d.2 USB Controller:intel Corporation 82801db/dbl/dbm (ich4/ich4-l/ich4-m) USB UHCI Controller #3 (rev 02) 00:1d.7 USB Controller:intel Corporation 82801db/dbm (ich4/ich4-m) USB2 EHCI Controller (rev 02) 00:1e.0 PCI Bridge:intel Corporation 82801 PCI bridge (Rev. 82) 00:1f.0 ISA Bridge:intel Corporation 82801db/dbl (ich4/ich4-l) LPC Interface Bridge (rev. 02) (LPC Hub Controller 1) 00:1F.1 IDE Interface:intel Corporation 82801DB (ICH4) IDE Controller (rev. 02) 00:1F.3 Smbus:intel Corporation 82801db/dbl/dbm (ich4/ich4-l/ich4-m) SMBus Controller (rev. 02) 00:1F.5 Multimedia Audio Controller:intel Corporation 82801db/dbl/dbm (ich4/ich4-l/ich4-m) AC ' Audio Controller (rev 02 ) 01:02.0 communication controller:conexant HSF 56k HSFI Modem (rev 01) 01:05.0 Ethernet Controller:realtek Semiconductor Co., Ltd. rtl-8139/8139c/8139c+ (Rev 10) |