User Tools

Site Tools


pci_configuration_space

This is an old revision of the document!


PCI Configuration Space

Jedes PCI-Gerät hat seinen eigenen PCI Configuration Space im Speicher. Mit pciconf -l können darüber Informationen zu PCI-Geräten ausgegeben werden. Hier die Ausgabe einer FreeBSD 16.0-CURRENT VM, die über einen VirtualBox Hypervisor auf macOS mit Apple Silicon läuft.

% pciconf -l
vgapci0@pci0:0:0:0:	class=0x030000 rev=0x00 hdr=0x00 vendor=0x15ad device=0x0406 subvendor=0x15ad subdevice=0x0406
none0@pci0:0:1:0:	class=0x088000 rev=0x00 hdr=0x00 vendor=0x80ee device=0xcafe subvendor=0x0000 subdevice=0x0000
none1@pci0:0:2:0:	class=0x040300 rev=0x01 hdr=0x00 vendor=0x8086 device=0x2668 subvendor=0x8384 subdevice=0x7680
pcib1@pci0:0:3:0:	class=0x060401 rev=0xf2 hdr=0x01 vendor=0x8086 device=0x2448 subvendor=0x0000 subdevice=0x0000
xhci0@pci0:0:6:0:	class=0x0c0330 rev=0x00 hdr=0x00 vendor=0x8086 device=0x1e31 subvendor=0x0000 subdevice=0x0000
em0@pci0:0:8:0:	class=0x020000 rev=0x02 hdr=0x00 vendor=0x8086 device=0x100e subvendor=0x8086 subdevice=0x001e
em1@pci0:0:9:0:	class=0x020000 rev=0x02 hdr=0x00 vendor=0x8086 device=0x100e subvendor=0x8086 subdevice=0x001e
virtio_pci0@pci0:0:10:0:	class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1000 subvendor=0x1af4 subdevice=0x0001
ahci0@pci0:0:16:0:	class=0x010601 rev=0x02 hdr=0x00 vendor=0x8086 device=0x2829 subvendor=0x0000 subdevice=0x0000

Hier betrachte ich den VirtIO Netwerkadapter genauer.

Mit dem Parameter v gibt pciconf die Namen zu den IDs der class, device, usw. aus.

% pciconf -lv virtio_pci0@pci0:0:10:0
virtio_pci0@pci0:0:10:0:	class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1000 subvendor=0x1af4 subdevice=0x0001
    vendor     = 'Red Hat, Inc.'
    device     = 'Virtio network device'
    class      = network
    subclass   = ethernet

Mit dem Parameter r kann pciconf den PCI Configuration Space direkt ausgeben. Der Parameter b gibt an, dass der Configuration Space Byteweise ausgelesen werden soll und 0x0:0x32 gibt den Bereich an, der ausgelesen werden soll.

% sudo pciconf -rb virtio_pci0@pci0:0:10:0 0x0:0x3f
f4 1a 00 10 17 00 10 00  00 00 00 02 00 00 00 00 
01 00 00 00 00 00 00 00  00 60 85 e1 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 f4 1a 01 00 
00 00 00 00 40 00 00 00  00 00 00 00 ff 01 00 00 

Der PCI Configuration Space enthält mehr, als pciconf bisher ausgegeben hat. Es nutzt das folgende Format.

   Bit 0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 Byte +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    0 |           Vendor ID           |            Device ID          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    4 |            Command            |             Status            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    8 |  Revision ID  |                  Class Code                   |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   12 | Cache Line S. |  Lat. Timer   |  Header Type  |     BIST      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   16 |                             BAR 1                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   20 |                             BAR 2                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   24 |                             BAR 3                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   28 |                             BAR 4                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   32 |                             BAR 5                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   36 |                             BAR 6                             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   40 |                       Cardbus CIS Pointer                     |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   44 |       Subsystem Vendor ID      |        Subsystem ID          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   48 |                 Expansion ROM Base Address                    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   52 | Cap. Pointer  |                   Reserved                    |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   56 |.                           Reserved                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   60 |Interrupt Line | Interrupt Pin |    Min Gnt.   |    Max Lat.   |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Die Bytes sind in Little Endian. Die ersten zwei Bytes sind also 0x1af4, die die Vendor ID angeben.

Interessant sind die Base Address Registers (BARs), über die weitere Informationen zum PCI-Gerät angegeben werden können. Das erste Bit den Typ an. Es gibt Memory (0) und I/O (1). Hauptsächlich gibt ein BAR die Base Address an, das ist die Adresse unter der die BAR Region im Speicher befindet.

Bei dem PCI-Gerät gibt es zwei BARs.

01 00 00 00 00 00 00 00 00 60 85 e1 00 00 00 00 00 00 00 00 00 00 00 00

% pciconf -lb virtio_pci0@pci0:0:10:0
virtio_pci0@pci0:0:10:0:	class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1000 subvendor=0x1af4 subdevice=0x0001
    bar   [10] = type I/O Port, range 32, base 0, size 32, enabled
    bar   [18] = type Memory, range 32, base 0xe1856000, size 8192, enabled
pci_configuration_space.1772276572.txt.gz · Last modified: by msvoelker