PCIe Root complex event collector
cover PCIe Root complex event collector
Hi All,
This is a first attempt to add PCIe Root Complex Event Collector emulation support to Qemu. This patch is created on Qemu commit:88afdc92b6 and tested using Qemu Risc V virt machine and the PCIe aer error injection module in the Linux kernel(v 5.14).
Thanks,
Mayuresh.
Mayuresh Chitale (3):
hw/pci/pcie.c: modify PCIe Express capability for RCiEP and RCEC hw/pci: Add PCIe RCEC support
docs: pcie: RCEC
docs/pcie.txt | 16 +++-- hw/pci/meson.build | 2 +- hw/pci/pcie.c | 40 ++++++++++--- hw/pci/pcie_aer.c | 9 +++ hw/pci/pcie_rcec.c | 119 +++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/hw/pci/pci_ids.h | 1 + include/hw/pci/pcie.h | 3 + include/hw/pci/pcie_regs.h | 3 + 9 files changed, 180 insertions(+), 14 deletions(-) create mode 100644 hw/pci/pcie_rcec.c
Signature · 1 line
2.17.1
RFC PATCH 3/3 docs: pcie: RCEC
Update root bus section to include information on how to enable PCIe RCEC for any given machine.
--- docs/pcie.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
docs/pcie.txt +11 -5
@@ -57,12 +57,14 @@ Place only the following kinds of devices directly on the Root Complex: (4) Extra Root Complexes (pxb-pcie), if multiple PCI Express Root Buses are needed. + (5) Root complex event collector (pcie-rcec). + pcie.0 bus - ---------------------------------------------------------------------------- - | | | | - ----------- ------------------ ------------------- -------------- - | PCI Dev | | PCIe Root Port | | PCIe-PCI Bridge | | pxb-pcie | - ----------- ------------------ ------------------- -------------- + ------------------------------------------------------------------------------------ + | | | | | + ----------- ------------------ ------------------- -------------- ------------- + | PCI Dev | | PCIe Root Port | | PCIe-PCI Bridge | | pxb-pcie | | PCIe RCEC | + ----------- ------------------ ------------------- -------------- ------------- 2.1.1 To plug a device into pcie.0 as a Root Complex Integrated Endpoint use: -device <dev>[,bus=pcie.0]
@@ -72,6 +74,10 @@ Place only the following kinds of devices directly on the Root Complex: connected to the pcie.1 bus: -device ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \ -device pcie-pci-bridge,id=pcie_pci_bridge1,bus=pcie.1 +2.1.3 To plug a PCIe RCEC into pcie.0 use: + -device pcie-rcec + PCIe RCEC must always be the first device on the root bus, pcie.0. So any RCiEP + devices plugged into pcie.0 must appear after the rcec in the command line. 2.2 PCI Express only hierarchy
Signature · 1 line
2.17.1
RFC PATCH 1/3 hw/pci/pcie.c: modify PCIe Express capability for RCiEP and RCEC
In reply to Mayuresh ChitaleSkip the link and slot capabilities' configuration for PCIe RCiEP and PCIe RCEC.
--- hw/pci/pcie.c | 22 ++++++++++++++-------- include/hw/pci/pcie.h | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-)
hw/pci/pcie.c +14 -8
@@ -64,6 +64,8 @@ pcie_cap_v1_fill(PCIDevice *dev, uint8_t port, uint8_t type, uint8_t version)* Specification revisions. */ pci_set_long (exp_cap +PCI_EXP_DEVCAP ,PCI_EXP_DEVCAP_RBER ); +if (type ==PCI_EXP_TYPE_RC_EC || type ==PCI_EXP_TYPE_RC_END ) +return ; pci_set_long(exp_cap + PCI_EXP_LNKCAP, (port << PCI_EXP_LNKCAP_PN_SHIFT) |
@@ -172,8 +174,9 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset,/* Filling values common with v1 */ pcie_cap_v1_fill (dev, port, type,PCI_EXP_FLAGS_VER2 ); -/* Fill link speed and width options */ -pcie_cap_fill_slot_lnk (dev); +if (type !=PCI_EXP_TYPE_RC_EC && type !=PCI_EXP_TYPE_RC_END ) +/* Fill link speed and width options */ +pcie_cap_fill_slot_lnk (dev);/* Filling v2 specific values */ pci_set_long(exp_cap + PCI_EXP_DEVCAP2,
@@ -211,10 +214,10 @@ int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, uint8_t type,return pos; } -static int -pcie_endpoint_cap_common_init (PCIDevice *dev,uint8_t offset,uint8_t cap_size) +int +pcie_endpoint_cap_common_init (PCIDevice *dev,uint8_t offset,uint8_t cap_size, +uint8_t type) { -uint8_t type =PCI_EXP_TYPE_ENDPOINT ;Error *local_err =NULL ;int ret;
@@ -224,7 +227,8 @@ pcie_endpoint_cap_common_init(PCIDevice *dev, uint8_t offset, uint8_t cap_size)* should instead be Root Complex Integrated Endpoints. */ if (pci_bus_is_express (pci_get_bus (dev)) - &&pci_bus_is_root (pci_get_bus (dev))) { + &&pci_bus_is_root (pci_get_bus (dev)) + && type !=PCI_EXP_TYPE_RC_EC ) { type =PCI_EXP_TYPE_RC_END ; }
@@ -243,12 +247,14 @@ pcie_endpoint_cap_common_init(PCIDevice *dev, uint8_t offset, uint8_t cap_size)int pcie_endpoint_cap_init (PCIDevice *dev,uint8_t offset) { -return pcie_endpoint_cap_common_init (dev, offset,PCI_EXP_VER2_SIZEOF ); +return pcie_endpoint_cap_common_init (dev, offset, +PCI_EXP_VER2_SIZEOF ,PCI_EXP_TYPE_ENDPOINT ); }int pcie_endpoint_cap_v1_init (PCIDevice *dev,uint8_t offset) { -return pcie_endpoint_cap_common_init (dev, offset,PCI_EXP_VER1_SIZEOF ); +return pcie_endpoint_cap_common_init (dev, offset, +PCI_EXP_VER1_SIZEOF ,PCI_EXP_TYPE_ENDPOINT ); }void pcie_cap_exit (PCIDevice *dev)
include/hw/pci/pcie.h +2 -0
@@ -147,4 +147,6 @@ void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp);void pcie_cap_slot_unplug_request_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp); +int pcie_endpoint_cap_common_init (PCIDevice *dev,uint8_t offset, +uint8_t cap_size,uint8_t type);#endif /* QEMU_PCIE_H */
Signature · 1 line
2.17.1
RFC PATCH 2/3 hw/pci: Add PCIe RCEC support
In reply to Mayuresh ChitaleThis patch adds support for PCIe Root Complex Event Collector (RCEC) emulation. Further, if a RCiEP supports AER capability then a mapping is created for that RCiEP in the RCEC's endpoint association capability.
--- hw/pci/meson.build | 2 +- hw/pci/pcie.c | 18 ++++++ hw/pci/pcie_aer.c | 9 +++ hw/pci/pcie_rcec.c | 119 +++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/hw/pci/pci_ids.h | 1 + include/hw/pci/pcie.h | 1 + include/hw/pci/pcie_regs.h | 3 + 8 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 hw/pci/pcie_rcec.c
hw/pci/meson.build +1 -1
@@ -11,7 +11,7 @@ pci_ss.add(files( # The functions in these modules can be used by devices too. Since we # allow plugging PCIe devices into PCI buses, include them even if # CONFIG_PCI_EXPRESS=n. -pci_ss.add(files('pcie.c', 'pcie_aer.c')) +pci_ss.add(files('pcie.c', 'pcie_aer.c', 'pcie_rcec.c')) softmmu_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c')) softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)
hw/pci/pcie.c +18 -0
@@ -747,6 +747,24 @@ void pcie_cap_slot_push_attention_button(PCIDevice *dev)pcie_cap_slot_event (dev,PCI_EXP_HP_EV_ABP ); } +void pcie_rcec_ep_map (PCIDevice *dev) +{ +int devnum =PCI_SLOT (dev->devfn); +uint32_t ep_bitmap; +PCIDevice *rcec; +uint16_t cap; + +/* RCEC is always expected to be at 00:01.0 */ + rcec =pci_find_device (pci_get_bus (dev),0 ,PCI_DEVFN (1 ,0 )); +if (!rcec) +return ; + +pcie_cap_deverr_init (dev); + cap =pcie_find_capability (rcec,PCI_EXT_CAP_ID_RCEC ); + ep_bitmap =pci_get_long (rcec->config + cap +0x4 ); +pci_set_long (rcec->config + cap +0x4 , ep_bitmap |1 << devnum); +} +/* root control/capabilities/status. PME isn't emulated for now */ void pcie_cap_root_init (PCIDevice *dev) {
hw/pci/pcie_aer.c +9 -0
@@ -166,6 +166,15 @@ int pcie_aer_init(PCIDevice *dev, uint8_t cap_ver, uint16_t offset,/* nothing */ break ; } + +/* +* If this is a RCiEP, map it into the RCEC's endpoint association bitmap +* capability +*/ +if (pci_bus_is_express (pci_get_bus (dev)) + &&pci_bus_is_root (pci_get_bus (dev))) +pcie_rcec_ep_map (dev); +return 0 ; }
hw/pci/pcie_rcec.c new file +119 -0
119 lines not on this page · raw message
include/hw/pci/pci.h +1 -0
@@ -109,6 +109,7 @@ extern bool pci_available;#define PCI_DEVICE_ID_REDHAT_NVME 0x0010#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0011#define PCI_DEVICE_ID_REDHAT_QXL 0x0100 +#define PCI_DEVICE_ID_REDHAT_RCEC 0x0101#define FMT_PCIBUS PRIx64
include/hw/pci/pci_ids.h +1 -0
@@ -88,6 +88,7 @@#define PCI_CLASS_SYSTEM_RTC 0x0803#define PCI_CLASS_SYSTEM_PCI_HOTPLUG 0x0804#define PCI_CLASS_SYSTEM_SDHCI 0x0805 +#define PCI_CLASS_SYSTEM_RCEC 0x0807#define PCI_CLASS_SYSTEM_OTHER 0x0880#define PCI_BASE_CLASS_INPUT 0x09
include/hw/pci/pcie.h +1 -0
@@ -149,4 +149,5 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp);int pcie_endpoint_cap_common_init (PCIDevice *dev,uint8_t offset,uint8_t cap_size,uint8_t type); +void pcie_rcec_ep_map (PCIDevice *dev);#endif /* QEMU_PCIE_H */
include/hw/pci/pcie_regs.h +3 -0
@@ -179,4 +179,7 @@ typedef enum PCIExpLinkWidth {#define PCI_ACS_VER 0x1#define PCI_ACS_SIZEOF 8 +#define PCI_RCEC_EP_VER 1 +#define PCI_RCEC_EP_SIZEOF 0x8 +#endif /* QEMU_PCIE_REGS_H */
Signature · 1 line
2.17.1