xref: /qemu/docs/pcie_pci_bridge.txt (revision 9e2423ef)
1c1800a16SAleksandr BezzubikovGeneric PCI Express to PCI Bridge
2c1800a16SAleksandr Bezzubikov================================
3c1800a16SAleksandr Bezzubikov
4c1800a16SAleksandr BezzubikovDescription
5c1800a16SAleksandr Bezzubikov===========
6c1800a16SAleksandr BezzubikovPCIE-to-PCI bridge is a new method for legacy PCI
7c1800a16SAleksandr Bezzubikovhierarchies creation on Q35 machines.
8c1800a16SAleksandr Bezzubikov
9c1800a16SAleksandr BezzubikovPreviously Intel DMI-to-PCI bridge was used for this purpose.
10c1800a16SAleksandr BezzubikovBut due to its strict limitations - no support of hot-plug,
11c1800a16SAleksandr Bezzubikovno cross-platform and cross-architecture support - a new generic
12c1800a16SAleksandr BezzubikovPCIE-to-PCI bridge should now be used for any legacy PCI device usage
13c1800a16SAleksandr Bezzubikovwith PCI Express machine.
14c1800a16SAleksandr Bezzubikov
15c1800a16SAleksandr BezzubikovThis generic PCIE-PCI bridge is a cross-platform device,
16c1800a16SAleksandr Bezzubikovcan be hot-plugged into appropriate root port (requires additional actions,
17c1800a16SAleksandr Bezzubikovsee 'PCIE-PCI bridge hot-plug' section),
18c1800a16SAleksandr Bezzubikovand supports devices hot-plug into the bridge itself
19c1800a16SAleksandr Bezzubikov(with some limitations, see below).
20c1800a16SAleksandr Bezzubikov
21c1800a16SAleksandr BezzubikovHot-plug of legacy PCI devices into the bridge
22c1800a16SAleksandr Bezzubikovis provided by bridge's built-in Standard hot-plug Controller.
23c1800a16SAleksandr BezzubikovThough it still has some limitations, see below.
24c1800a16SAleksandr Bezzubikov
25c1800a16SAleksandr BezzubikovPCIE-PCI bridge hot-plug
26c1800a16SAleksandr Bezzubikov=======================
27c1800a16SAleksandr BezzubikovGuest OSes require extra efforts to enable PCIE-PCI bridge hot-plug.
28c1800a16SAleksandr BezzubikovMotivation - now on init any PCI Express root port which doesn't have
29c1800a16SAleksandr Bezzubikovany device plugged in, has no free buses reserved to provide any of them
30c1800a16SAleksandr Bezzubikovto a hot-plugged devices in future.
31c1800a16SAleksandr Bezzubikov
32c1800a16SAleksandr BezzubikovTo solve this problem we reserve additional buses on a firmware level.
33c1800a16SAleksandr BezzubikovCurrently only SeaBIOS is supported.
34c1800a16SAleksandr BezzubikovThe way of bus number to reserve delivery is special
35c1800a16SAleksandr BezzubikovRed Hat vendor-specific PCI capability, added to the root port
36c1800a16SAleksandr Bezzubikovthat is planned to have PCIE-PCI bridge hot-plugged in.
37c1800a16SAleksandr Bezzubikov
38c1800a16SAleksandr BezzubikovCapability layout (defined in include/hw/pci/pci_bridge.h):
39c1800a16SAleksandr Bezzubikov
40c1800a16SAleksandr Bezzubikov    uint8_t id;     Standard PCI capability header field
41c1800a16SAleksandr Bezzubikov    uint8_t next;   Standard PCI capability header field
42c1800a16SAleksandr Bezzubikov    uint8_t len;    Standard PCI vendor-specific capability header field
43c1800a16SAleksandr Bezzubikov
44c1800a16SAleksandr Bezzubikov    uint8_t type;   Red Hat vendor-specific capability type
45c1800a16SAleksandr Bezzubikov                    List of currently existing types:
46c1800a16SAleksandr Bezzubikov                        RESOURCE_RESERVE = 1
47c1800a16SAleksandr Bezzubikov
48c1800a16SAleksandr Bezzubikov
49c1800a16SAleksandr Bezzubikov    uint32_t bus_res;   Minimum number of buses to reserve
50c1800a16SAleksandr Bezzubikov
51c1800a16SAleksandr Bezzubikov    uint64_t io;           IO space to reserve
52c1800a16SAleksandr Bezzubikov    uint32_t mem           Non-prefetchable memory to reserve
53c1800a16SAleksandr Bezzubikov
54c1800a16SAleksandr Bezzubikov    At most one of the following two fields may be set to a value
55c1800a16SAleksandr Bezzubikov    different from -1:
56c1800a16SAleksandr Bezzubikov    uint32_t mem_pref_32;  Prefetchable memory to reserve (32-bit MMIO)
57c1800a16SAleksandr Bezzubikov    uint64_t mem_pref_64;  Prefetchable memory to reserve (64-bit MMIO)
58c1800a16SAleksandr Bezzubikov
59c1800a16SAleksandr BezzubikovIf any reservation field is -1 then this kind of reservation is not
60c1800a16SAleksandr Bezzubikovneeded and must be ignored by firmware.
61c1800a16SAleksandr Bezzubikov
62c1800a16SAleksandr BezzubikovAt the moment this capability is used only in QEMU generic PCIe root port
63c1800a16SAleksandr Bezzubikov(-device pcie-root-port). Capability construction function takes all reservation
64c1800a16SAleksandr Bezzubikovfields values from corresponding device properties. By default all of them are
65c1800a16SAleksandr Bezzubikovset to -1 to leave root port's default behavior unchanged.
66c1800a16SAleksandr Bezzubikov
67c1800a16SAleksandr BezzubikovUsage
68c1800a16SAleksandr Bezzubikov=====
69c1800a16SAleksandr BezzubikovA detailed command line would be:
70c1800a16SAleksandr Bezzubikov
71c1800a16SAleksandr Bezzubikov[qemu-bin + storage options] \
72c1800a16SAleksandr Bezzubikov-m 2G \
73*9e2423efSVincent Bernat-device pcie-root-port,bus=pcie.0,id=rp1,slot=1 \
74*9e2423efSVincent Bernat-device pcie-root-port,bus=pcie.0,id=rp2,slot=2 \
75*9e2423efSVincent Bernat-device pcie-root-port,bus=pcie.0,id=rp3,slot=3,bus-reserve=1 \
76c1800a16SAleksandr Bezzubikov-device pcie-pci-bridge,id=br1,bus=rp1 \
77c1800a16SAleksandr Bezzubikov-device pcie-pci-bridge,id=br2,bus=rp2 \
78c1800a16SAleksandr Bezzubikov-device e1000,bus=br1,addr=8
79c1800a16SAleksandr Bezzubikov
80c1800a16SAleksandr BezzubikovThen in monitor it's OK to execute next commands:
81c1800a16SAleksandr Bezzubikovdevice_add pcie-pci-bridge,id=br3,bus=rp3 \
82c1800a16SAleksandr Bezzubikovdevice_add e1000,bus=br2,addr=1 \
83c1800a16SAleksandr Bezzubikovdevice_add e1000,bus=br3,addr=1
84c1800a16SAleksandr Bezzubikov
85c1800a16SAleksandr BezzubikovHere you have:
86c1800a16SAleksandr Bezzubikov (1) Cold-plugged:
87c1800a16SAleksandr Bezzubikov    - Root ports: 1 QEMU generic root port with the capability mentioned above,
88c1800a16SAleksandr Bezzubikov                  2 QEMU generic root ports without this capability;
89c1800a16SAleksandr Bezzubikov    - 2 PCIE-PCI bridges plugged into 2 different root ports;
90c1800a16SAleksandr Bezzubikov    - e1000 plugged into the first bridge.
91c1800a16SAleksandr Bezzubikov (2) Hot-plugged:
92c1800a16SAleksandr Bezzubikov    - PCIE-PCI bridge, plugged into QEMU generic root port;
93c1800a16SAleksandr Bezzubikov    - 2 e1000 cards, one plugged into the cold-plugged PCIE-PCI bridge,
94c1800a16SAleksandr Bezzubikov                     another plugged into the hot-plugged bridge.
95c1800a16SAleksandr Bezzubikov
96c1800a16SAleksandr BezzubikovLimitations
97c1800a16SAleksandr Bezzubikov===========
98c1800a16SAleksandr BezzubikovThe PCIE-PCI bridge can be hot-plugged only into pcie-root-port that
99c1800a16SAleksandr Bezzubikovhas proper 'bus-reserve' property value to provide secondary bus for the
100c1800a16SAleksandr Bezzubikovhot-plugged bridge.
101c1800a16SAleksandr Bezzubikov
102c1800a16SAleksandr BezzubikovWindows 7 and older versions don't support hot-plug devices into the PCIE-PCI bridge.
103c1800a16SAleksandr BezzubikovTo enable device hot-plug into the bridge on Linux there're 3 ways:
104c1800a16SAleksandr Bezzubikov1) Build shpchp module with this patch http://www.spinics.net/lists/linux-pci/msg63052.html
105c1800a16SAleksandr Bezzubikov2) Use kernel 4.14+ where the patch mentioned above is already merged.
106c1800a16SAleksandr Bezzubikov3) Set 'msi' property to off - this forces the bridge to use legacy INTx,
107c1800a16SAleksandr Bezzubikov    which allows the bridge to notify the OS about hot-plug event without having
108c1800a16SAleksandr Bezzubikov    BUSMASTER set.
109c1800a16SAleksandr Bezzubikov
110c1800a16SAleksandr BezzubikovImplementation
111c1800a16SAleksandr Bezzubikov==============
112c1800a16SAleksandr BezzubikovThe PCIE-PCI bridge is based on PCI-PCI bridge, but also accumulates PCI Express
113d61a363dSYoni Bettanfeatures as a PCI Express device.
114c1800a16SAleksandr Bezzubikov
115