Skip to content

Commit 226263f

Browse files
zuban32mstsirkin
authored andcommitted
hw/pci: add QEMU-specific PCI capability to the Generic PCI Express Root Port
To enable hotplugging of a newly created pcie-pci-bridge, we need to tell firmware (e.g. SeaBIOS) to reserve additional buses or IO/MEM/PREF space for pcie-root-port. Additional bus reservation allows us to hotplug pcie-pci-bridge into this root port. The number of buses and IO/MEM/PREF space to reserve are provided to the device via a corresponding property, and to the firmware via new PCI capability. The properties' default values are -1 to keep default behavior unchanged. Signed-off-by: Aleksandr Bezzubikov <zuban32s@gmail.com> Reviewed-by: Marcel Apfelbaum <marcel@redhat.com> Tested-by: Marcel Apfelbaum <marcel@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 70e1ee5 commit 226263f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

hw/pci-bridge/gen_pcie_root_port.c

+36
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "hw/pci/pcie_port.h"
1717

1818
#define TYPE_GEN_PCIE_ROOT_PORT "pcie-root-port"
19+
#define GEN_PCIE_ROOT_PORT(obj) \
20+
OBJECT_CHECK(GenPCIERootPort, (obj), TYPE_GEN_PCIE_ROOT_PORT)
1921

2022
#define GEN_PCIE_ROOT_PORT_AER_OFFSET 0x100
2123
#define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR 1
@@ -26,6 +28,13 @@ typedef struct GenPCIERootPort {
2628
/*< public >*/
2729

2830
bool migrate_msix;
31+
32+
/* additional resources to reserve on firmware init */
33+
uint32_t bus_reserve;
34+
uint64_t io_reserve;
35+
uint64_t mem_reserve;
36+
uint64_t pref32_reserve;
37+
uint64_t pref64_reserve;
2938
} GenPCIERootPort;
3039

3140
static uint8_t gen_rp_aer_vector(const PCIDevice *d)
@@ -60,6 +69,24 @@ static bool gen_rp_test_migrate_msix(void *opaque, int version_id)
6069
return rp->migrate_msix;
6170
}
6271

72+
static void gen_rp_realize(DeviceState *dev, Error **errp)
73+
{
74+
PCIDevice *d = PCI_DEVICE(dev);
75+
GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d);
76+
PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d);
77+
78+
rpc->parent_realize(dev, errp);
79+
80+
int rc = pci_bridge_qemu_reserve_cap_init(d, 0, grp->bus_reserve,
81+
grp->io_reserve, grp->mem_reserve, grp->pref32_reserve,
82+
grp->pref64_reserve, errp);
83+
84+
if (rc < 0) {
85+
rpc->parent_class.exit(d);
86+
return;
87+
}
88+
}
89+
6390
static const VMStateDescription vmstate_rp_dev = {
6491
.name = "pcie-root-port",
6592
.version_id = 1,
@@ -78,6 +105,11 @@ static const VMStateDescription vmstate_rp_dev = {
78105

79106
static Property gen_rp_props[] = {
80107
DEFINE_PROP_BOOL("x-migrate-msix", GenPCIERootPort, migrate_msix, true),
108+
DEFINE_PROP_UINT32("bus-reserve", GenPCIERootPort, bus_reserve, -1),
109+
DEFINE_PROP_SIZE("io-reserve", GenPCIERootPort, io_reserve, -1),
110+
DEFINE_PROP_SIZE("mem-reserve", GenPCIERootPort, mem_reserve, -1),
111+
DEFINE_PROP_SIZE("pref32-reserve", GenPCIERootPort, pref32_reserve, -1),
112+
DEFINE_PROP_SIZE("pref64-reserve", GenPCIERootPort, pref64_reserve, -1),
81113
DEFINE_PROP_END_OF_LIST()
82114
};
83115

@@ -92,6 +124,10 @@ static void gen_rp_dev_class_init(ObjectClass *klass, void *data)
92124
dc->desc = "PCI Express Root Port";
93125
dc->vmsd = &vmstate_rp_dev;
94126
dc->props = gen_rp_props;
127+
128+
rpc->parent_realize = dc->realize;
129+
dc->realize = gen_rp_realize;
130+
95131
rpc->aer_vector = gen_rp_aer_vector;
96132
rpc->interrupts_init = gen_rp_interrupts_init;
97133
rpc->interrupts_uninit = gen_rp_interrupts_uninit;

include/hw/pci/pcie_port.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void pcie_chassis_del_slot(PCIESlot *s);
6565

6666
typedef struct PCIERootPortClass {
6767
PCIDeviceClass parent_class;
68+
DeviceRealize parent_realize;
6869

6970
uint8_t (*aer_vector)(const PCIDevice *dev);
7071
int (*interrupts_init)(PCIDevice *dev, Error **errp);

0 commit comments

Comments
 (0)