pcie port switch emulators
v8 cover pcie port switch emulators
Here is v8 of the pcie switch emulators patch.
This is for qemu main tree.
Patch description:
The patch series adds pcie/aer functionality to the pcie port emulators and adds new qemu command to inject aer into the guest.
Changes v7 -> v8:
- Added command to the forward declaration.
- revise pci command/status register initialization
- various changes to follow the review
- use domain:slot.func:slot.func..:slot.func to specify pci function instead of domain:bus:slot.func
- allow symbolic name for aer error name in addition to 32 bit value
Changes v6 -> v7:
- the glue patch for pushing attention button is dropped for now. This will be addressed later.
- various clean up of aer helper functions.
changes v5 -> v6:
- dropped already merged patches.
- add comment on hpev_intx
- updated the bridge fix patch
- update the aer patch.
- reordered the patch series to remove the aer dependency.
change v4 -> v5:
- introduced pci_xxx_test_and_clear/set_mask
- eliminated xxx_notify(msi_trigger, int_level)
- eliminated FLR bits.
FLR will be addressed at the next phase.
changes v3 -> v4:
- introduced new pci config helper functions.(clear set bit)
- various clean up and some bug fixes.
- dropped pci_shift_xxx().
- dropped function pointerin pcie_aer.h
- dropped pci_exp_cap(), pcie_aer_cap().
- file rename (pcie_{root, upstream, downsatrem} => ioh33420, x3130).
changes v2 -> v3:
- msi: improved commant and simplified shift/ffs dance
- pci w1c config register framework
- split pcie.[ch] into pcie_regs.h, pcie.[ch] and pcie_aer.[ch]
- pcie, aer: many changes by following reviews.
changes v1 -> v2:
- update msi
- dropped already pushed out patches.
- added msix patches.
Isaku Yamahata (11):
pci: revise pci command register initialization
pci: clean up pci command register io/memory bit initialization
pci: fix accesses to pci status register
pci: clean up of pci status register
pcie_regs.h: more constants
pcie/aer: helper functions for pcie aer capability
pci: introduce a parser for pci device path
pcie/aer: glue aer error injection into qemu monitor
ioh3420: support aer
x3130/upstream: support aer
x3130/downstream: support aer.
Makefile.objs | 2 +- hmp-commands.hx | 23 + hw/ioh3420.c | 51 ++- hw/pci.c | 207 +++++++++- hw/pci.h | 1 + hw/pcie.h | 14 + hw/pcie_aer.c | 1045 +++++++++++++++++++++++++++++++++++++++++++++++ hw/pcie_aer.h | 106 +++++ hw/pcie_regs.h | 2 + hw/xio3130_downstream.c | 13 +- hw/xio3130_upstream.c | 12 +- qemu-common.h | 3 + sysemu.h | 5 + 13 files changed, 1456 insertions(+), 28 deletions(-) create mode 100644 hw/pcie_aer.c create mode 100644 hw/pcie_aer.h
PATCH v8 1/11 pci: revise pci command register initialization
This patch cleans up command register initialization with comments.
--- hw/pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)
hw/pci.c +42 -0
@@ -544,8 +544,50 @@ static void pci_init_wmask(PCIDevice *dev) dev->wmask[PCI_CACHE_LINE_SIZE ] =0xff ; dev->wmask[PCI_INTERRUPT_LINE ] =0xff ; + +/* +* bit 0: PCI_COMMAND_IO +* type 0: if IO BAR is used, RW +* type 1: RW +* bit 1: PCI_COMMAND_MEMORY +* type 0: if IO BAR is used, RW +* type 1: RW +* bit 2: PCI_COMMAND_MASTER +* type 0: RW if bus master +* type 1: RW +* bit 3: PCI_COMMAND_SPECIAL +* RO=0, optionally RW: Such device should set this bit itself +* bit 4: PCI_COMMAND_INVALIDATE +* RO=0, optionally RW: Such device should set this bit itself +* bit 5: PCI_COMMAND_VGA_PALETTE +* RO=0, optionally RW: Such device should set this bit itself +* bit 6: PCI_COMMAND_PARITY +* RW with exceptions: Such device should clear this bit itself +* Given that qemu doesn't emulate pci bus cycles, so that there +* is no place to generate parity error. So just making this +* register RW is okay because there is no place which refers +* this bit. +* TODO: When device assignment tried to inject PERR# into qemu, +* some extra work would be needed. +* bit 7: PCI_COMMAND_WAIT: reserved (PCI 3.0) +* RO=0 +* bit 8: PCI_COMMAND_SERR +* RW with exceptions: Such device should clear this bit itself +* Given that qemu doesn't emulate pci bus cycles, so that there +* is no place to generate system error. So just making this +* register RW is okay because there is no place which refers +* this bit. +* TODO: When device assignment tried to inject SERR# into qemu, +* some extra work would be needed. +* bit 9: PCI_COMMAND_FAST_BACK +* RO=0, optionally RW: Such device should set this bit itself +* bit 10: PCI_COMMAND_INTX_DISABLE +* RW +* bit 11-15: reserved +*/ pci_set_word (dev->wmask +PCI_COMMAND ,PCI_COMMAND_IO |PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER | +PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,
Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH v8 01/11] pci: revise pci command register initialization
Quoted 4 lines · Isaku Yamahata
This patch cleans up command register initialization with comments.
Signed-off-by Isaku Yamahata <[email protected]>
Probably just fold with the next patch.
Quoted 61 lines
--- hw/pci.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)hw/pci.c +42
-0@@ -544,8 +544,50 @@ static void pci_init_wmask(PCIDevice *dev) dev->wmask[PCI_CACHE_LINE_SIZE ] =0xff ; dev->wmask[PCI_INTERRUPT_LINE ] =0xff ; + +/* +* bit 0: PCI_COMMAND_IO +* type 0: if IO BAR is used, RW +* type 1: RW +* bit 1: PCI_COMMAND_MEMORY +* type 0: if IO BAR is used, RW +* type 1: RW +* bit 2: PCI_COMMAND_MASTER +* type 0: RW if bus master +* type 1: RW +* bit 3: PCI_COMMAND_SPECIAL +* RO=0, optionally RW: Such device should set this bit itself +* bit 4: PCI_COMMAND_INVALIDATE +* RO=0, optionally RW: Such device should set this bit itself +* bit 5: PCI_COMMAND_VGA_PALETTE +* RO=0, optionally RW: Such device should set this bit itself +* bit 6: PCI_COMMAND_PARITY +* RW with exceptions: Such device should clear this bit itself +* Given that qemu doesn't emulate pci bus cycles, so that there +* is no place to generate parity error. So just making this +* register RW is okay because there is no place which refers +* this bit. +* TODO: When device assignment tried to inject PERR# into qemu, +* some extra work would be needed. +* bit 7: PCI_COMMAND_WAIT: reserved (PCI 3.0) +* RO=0 +* bit 8: PCI_COMMAND_SERR +* RW with exceptions: Such device should clear this bit itself +* Given that qemu doesn't emulate pci bus cycles, so that there +* is no place to generate system error. So just making this +* register RW is okay because there is no place which refers +* this bit. +* TODO: When device assignment tried to inject SERR# into qemu, +* some extra work would be needed. +* bit 9: PCI_COMMAND_FAST_BACK +* RO=0, optionally RW: Such device should set this bit itself +* bit 10: PCI_COMMAND_INTX_DISABLE +* RW +* bit 11-15: reserved +*/ pci_set_word (dev->wmask +PCI_COMMAND ,PCI_COMMAND_IO |PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER | +PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,Signature · 1 line
1.7.1.1
PATCH v8 2/11 pci: clean up pci command register io/memory bit initialization
In reply to Isaku YamahataThis patch fixes the initialization of io/memory bit of command register. Those bits for type 1 device is RW.
Those bits for type 0 device is
RO = 0 if it has no io/memory BAR
RW if it has io/memory BAR
--- hw/pci.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
hw/pci.c +17 -3
@@ -548,10 +548,14 @@ static void pci_init_wmask(PCIDevice *dev)/* * bit 0: PCI_COMMAND_IO * type 0: if IO BAR is used, RW -* type 1: RW +* This is handled by pci_register_bar() +* type 1: RW: +* This is fixed by pci_init_wmask_bridge() * bit 1: PCI_COMMAND_MEMORY * type 0: if IO BAR is used, RW +* This is handled by pci_register_bar() * type 1: RW +* This is fixed by pci_init_wmask_bridge() * bit 2: PCI_COMMAND_MASTER * type 0: RW if bus master * type 1: RW
@@ -586,8 +590,7 @@ static void pci_init_wmask(PCIDevice *dev)* bit 11-15: reserved */ pci_set_word (dev->wmask +PCI_COMMAND , -PCI_COMMAND_IO |PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER | -PCI_COMMAND_PARITY |PCI_COMMAND_SERR | +PCI_COMMAND_MASTER |PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,
@@ -596,6 +599,9 @@ static void pci_init_wmask(PCIDevice *dev)static void pci_init_wmask_bridge (PCIDevice *d) { +pci_word_test_and_set_mask (d->wmask +PCI_COMMAND , +PCI_COMMAND_IO |PCI_COMMAND_MEMORY ); +/* PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS and PCI_SEC_LETENCY_TIMER */ memset (d->wmask +PCI_PRIMARY_BUS ,0xff ,4 );
@@ -833,6 +839,14 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,if (region_num ==PCI_ROM_SLOT ) {/* ROM enable bit is writeable */ wmask |=PCI_ROM_ADDRESS_ENABLE ; + }else { +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { +pci_word_test_and_set_mask (pci_dev->wmask +PCI_COMMAND , +PCI_COMMAND_IO ); + }else { +pci_word_test_and_set_mask (pci_dev->wmask +PCI_COMMAND , +PCI_COMMAND_MEMORY ); + } }pci_set_long (pci_dev->config + addr, type); if (!(r->type & PCI_BASE_ADDRESS_SPACE_IO) &&
Signature · 1 line
1.7.1.1
PATCH v8 3/11 pci: fix accesses to pci status register
In reply to Isaku Yamahatapci status register is 16 bit, not 8 bit.
So use helper function to manipulate status register.
--- hw/pci.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-)
hw/pci.c +13 -8
@@ -127,9 +127,11 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)static void pci_update_irq_status (PCIDevice *dev) {if (dev->irq_state) { - dev->config[PCI_STATUS ] |=PCI_STATUS_INTERRUPT ; +pci_word_test_and_set_mask (dev->config +PCI_STATUS , +PCI_STATUS_INTERRUPT ); }else { - dev->config[PCI_STATUS ] &= ~PCI_STATUS_INTERRUPT ; +pci_word_test_and_clear_mask (dev->config +PCI_STATUS , +PCI_STATUS_INTERRUPT ); } }
@@ -404,7 +406,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)* in irq_state which we are saving. * This makes us compatible with old devices * which never set or clear this bit. */ - s->config[PCI_STATUS ] &= ~PCI_STATUS_INTERRUPT ; +pci_word_test_and_clear_mask (s->config +PCI_STATUS ,PCI_STATUS_INTERRUPT );vmstate_save_state (f,pci_get_vmstate (s), s);/* Restore the interrupt status bit. */ pci_update_irq_status (s);
@@ -530,7 +532,7 @@ static void pci_init_cmask(PCIDevice *dev) {pci_set_word (dev->cmask +PCI_VENDOR_ID ,0xffff );pci_set_word (dev->cmask +PCI_DEVICE_ID ,0xffff ); - dev->cmask[PCI_STATUS ] =PCI_STATUS_CAP_LIST ; +pci_set_word (dev->cmask +PCI_STATUS ,PCI_STATUS_CAP_LIST ); dev->cmask[PCI_REVISION_ID ] =0xff ; dev->cmask[PCI_CLASS_PROG ] =0xff ;pci_set_word (dev->cmask +PCI_CLASS_DEVICE ,0xffff );
@@ -1697,8 +1699,9 @@ static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id, {uint8_t next, prev; -if (!(pdev->config[PCI_STATUS ] &PCI_STATUS_CAP_LIST )) +if (!(pci_get_word (pdev->config +PCI_STATUS ) &PCI_STATUS_CAP_LIST )) {return 0 ; + }for (prev =PCI_CAPABILITY_LIST ; (next = pdev->config[prev]); prev = next +PCI_CAP_LIST_NEXT )
@@ -1804,7 +1807,7 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, config[PCI_CAP_LIST_ID ] = cap_id; config[PCI_CAP_LIST_NEXT ] = pdev->config[PCI_CAPABILITY_LIST ]; pdev->config[PCI_CAPABILITY_LIST ] = offset; - pdev->config[PCI_STATUS ] |=PCI_STATUS_CAP_LIST ; +pci_word_test_and_set_mask (pdev->config +PCI_STATUS ,PCI_STATUS_CAP_LIST );memset (pdev->used + offset,0xFF , size);/* Make capability read-only by default */ memset (pdev->wmask + offset,0 , size);
@@ -1827,8 +1830,10 @@ void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)memset (pdev->cmask + offset,0 , size);memset (pdev->used + offset,0 , size); -if (!pdev->config[PCI_CAPABILITY_LIST ]) - pdev->config[PCI_STATUS ] &= ~PCI_STATUS_CAP_LIST ; +if (!pdev->config[PCI_CAPABILITY_LIST ]) { +pci_word_test_and_clear_mask (pdev->config +PCI_STATUS , +PCI_STATUS_CAP_LIST ); + } }/* Reserve space for capability at a known offset (to call after load). */
Signature · 1 line
1.7.1.1
PATCH v8 4/11 pci: clean up of pci status register
In reply to Isaku YamahataThis patch refine the initialization/reset of
pci status registers.
--- hw/pci.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-)
hw/pci.c +39 -2
@@ -145,6 +145,9 @@ static void pci_device_reset(PCIDevice *dev)pci_word_test_and_clear_mask (dev->config +PCI_COMMAND ,pci_get_word (dev->wmask +PCI_COMMAND ) |pci_get_word (dev->w1cmask +PCI_COMMAND )); +pci_word_test_and_clear_mask (dev->config +PCI_STATUS , +pci_get_word (dev->wmask +PCI_STATUS ) | +pci_get_word (dev->w1cmask +PCI_STATUS )); dev->config[PCI_CACHE_LINE_SIZE ] =0x0 ; dev->config[PCI_INTERRUPT_LINE ] =0x0 ;for (r =0 ; r <PCI_NUM_REGIONS ; ++r) {
@@ -540,7 +543,7 @@ static void pci_init_cmask(PCIDevice *dev) dev->cmask[PCI_CAPABILITY_LIST ] =0xff ; } -static void pci_init_wmask (PCIDevice *dev) +static void pci_init_wmask_w1cmask (PCIDevice *dev) {int config_size =pci_config_size (dev);
@@ -595,6 +598,40 @@ static void pci_init_wmask(PCIDevice *dev)PCI_COMMAND_MASTER |PCI_COMMAND_PARITY |PCI_COMMAND_SERR | PCI_COMMAND_INTX_DISABLE); +/* +* bit 0-2: reserved +* bit 3: PCI_STATUS_INTERRUPT: RO +* bit 4: PCI_STATUS_CAP_LIST: RO +* bit 5: PCI_STATUS_66MHZ: RO +* bit 6: PCI_STATUS_UDF: reserved (PCI 2.2-) +* bit 7: PCI_STATUS_FAST_BACK: RO +* bit 8: PCI_STATUS_PARITY +* type 0: RW for bus master +* type 1: RW1C +* bit 9-10: PCI_STATUS_DEVSEL: RO +* bit 11: PCI_STATUS_SIG_TARGET_ABORT +* type 0: RW1C for targets that is capable of terminating +* a transaction. +* type 1: RW1C +* bit 12: PCI_STATUS_REC_TARGET_ABORT +* type 0: RW1C for masters +* type 1: RW1C +* bit 13: PCI_STATUS_REC_MASTER_ABORT +* type 0: RW1C for masters +* type 1: RW1C +* bit 14: PCI_STATUS_SIG_SYSTEM_ERROR +* type 0: RW1C with execptions +* type 1: RW1C +* bit : PCI_STATUS_DETECTED_PARITY: RW1C +* +* It's okay to set w1mask even for RO=0(i.e. reserved) because +* writing value 1 to w1c bit whose value is 0 has no effect. +*/ +pci_set_word (dev->w1cmask +PCI_STATUS , +PCI_STATUS_PARITY |PCI_STATUS_SIG_TARGET_ABORT | +PCI_STATUS_REC_TARGET_ABORT |PCI_STATUS_REC_MASTER_ABORT | +PCI_STATUS_SIG_SYSTEM_ERROR |PCI_STATUS_DETECTED_PARITY ); +memset (dev->wmask +PCI_CONFIG_HEADER_SIZE ,0xff , config_size -PCI_CONFIG_HEADER_SIZE ); }
@@ -725,7 +762,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,pci_set_default_subsystem_id (pci_dev); }pci_init_cmask (pci_dev); -pci_init_wmask (pci_dev); +pci_init_wmask_w1cmask (pci_dev);if (is_bridge) {pci_init_wmask_bridge (pci_dev); }
Signature · 1 line
1.7.1.1
PATCH v8 5/11 pcie_regs.h: more constants
In reply to Isaku Yamahataremove unnecessary sizeof.
--- hw/pcie_regs.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/pcie_regs.h +2 -0
@@ -94,7 +94,9 @@#define PCI_ERR_CAP_MHRE 0x00000400#define PCI_ERR_CAP_TLP 0x00000800 +#define PCI_ERR_HEADER_LOG_SIZE 16#define PCI_ERR_TLP_PREFIX_LOG 0x38 +#define PCI_ERR_TLP_PREFIX_LOG_SIZE 16#define PCI_SEC_STATUS_RCV_SYSTEM_ERROR 0x4000
Signature · 1 line
1.7.1.1
PATCH v8 6/11 pcie/aer: helper functions for pcie aer capability
In reply to Isaku YamahataThis patch implements helper functions for pcie aer capability which will be used later.
---
Changes v7 -> v8:
- various changes to follow the review.
- s/TLP_PRESENT/TLP_PREFIX_PRESENT/g
Changes v6 -> v7:
- make error log buffer non-ringed buffer
- refactor pcie_aer_error_inject()
- clean up of pcie_aer_write_config()
- make pcie_aer_inject_error() return error
- remove AERMsgResult
- remove PCIEAERSeverity
- reduce forward declarations
- style clean ups
- remove paren for sizeof.
Chnages v5 -> v6:
- cleaned up pcie_aer_write_config().
- enum definition.
Changes v4 -> v5:
- use pci_xxx_test_and_xxx_mask()
- rewrote PCIDevice::written bits.
- eliminated pcie_aer_notify()
- introduced PCIExpressDevice::aer_intx
Changes v3 -> v4:
- various naming fixes.
- use pci bit operation helper function
- eliminate errmsg function pointer
- replace pci_shift_xxx() with PCIDevice::written
- uncorrect error status register.
- dropped pcie_aer_cap()
Changes v2 -> v3:
- split out from pcie.[ch] to pcie_aer.[ch] to make the files sorter.
- embeded PCIExpressDevice into PCIDevice.
- CodingStyle fix
--- Makefile.objs | 2 +- hw/pcie.h | 14 + hw/pcie_aer.c | 826 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pcie_aer.h | 106 ++++++++ qemu-common.h | 3 + 5 files changed, 950 insertions(+), 1 deletions(-) create mode 100644 hw/pcie_aer.c create mode 100644 hw/pcie_aer.h
Makefile.objs +1 -1
@@ -208,7 +208,7 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o # PCI watchdog devices hw-obj-y += wdt_i6300esb.o -hw-obj-y += pcie.o pcie_port.o +hw-obj-y += pcie.o pcie_aer.o pcie_port.o hw-obj-y += msix.o msi.o # PCI network cards
hw/pcie.h +14 -0
@@ -24,6 +24,7 @@#include "hw.h" #include "pci_regs.h" #include "pcie_regs.h" +#include "pcie_aer.h" typedef enum { /* for attention and power indicator */
@@ -79,6 +80,19 @@ struct PCIExpressDevice {Software Notification of Hot-Plug Events, an interrupt is sent whenever the logical and of these conditions transitions from false to true. */ + +/* AER */ +uint16_t aer_cap; +PCIEAERLog aer_log; +unsigned int aer_intx;/* INTx for error reporting +* default is 0 = INTA# +* If the chip wants to use other interrupt +* line, initialize this member with the +* desired number. +* If the chip dynamically changes this member, +* also initialize it when loaded as +* appropreately. +*/ };/* PCI express capability helper functions */
hw/pcie_aer.c new file +826 -0
826 lines not on this page · raw message
hw/pcie_aer.h new file +106 -0
106 lines not on this page · raw message
qemu-common.h +3 -0
@@ -240,6 +240,9 @@ typedef struct PCIBus PCIBus;typedef struct PCIDevice PCIDevice ;typedef struct PCIExpressDevice PCIExpressDevice ;typedef struct PCIBridge PCIBridge ; +typedef struct PCIEAERMsg PCIEAERMsg ; +typedef struct PCIEAERLog PCIEAERLog ; +typedef struct PCIEAERErr PCIEAERErr ;typedef struct PCIEPort PCIEPort ;typedef struct PCIESlot PCIESlot ;typedef struct SerialState SerialState ;
Signature · 1 line
1.7.1.1
PATCH v8 7/11 pci: introduce a parser for pci device path
In reply to Isaku Yamahataintroduce a function to parse pci device path of
the format, [Domain:]Slot.Function:Slot.Function....:Slot.Function.
--- hw/pci.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci.h | 1 + 2 files changed, 88 insertions(+), 0 deletions(-)
hw/pci.c +87 -0
@@ -433,6 +433,93 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev) }/* +* Parse format [Domain:]Slot.Function:Slot.Function....:Slot.Function +* and get PCIDevice +* return 0 on success +* -1 on error: format is invalid or device isn't found. +*/ +int pci_parse_dev_path (const char *addr,PCIDevice **pdev) +{ +unsigned long domain; +unsigned long slot; +unsigned long func; +const char *p; +char *e; +unsigned long val; +PCIBus *bus; +PCIBus *child_bus; +PCIDevice *d; + + p = addr; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } +if (*e ==':' ) { + domain = val; + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + }else if (*e =='.' ){ + domain =0 ; + }else { +return -1 ; + } +if (domain >0xffff ) { +return -1 ; + } + + bus =pci_find_root_bus (domain); +if (!bus) { +return -1 ; + } + +for (;;) { + slot = val; +if (*e !='.' ) { +return -1 ; + } + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + func = val; +if (slot >0x1f || func >=PCI_FUNC_MAX ) { +return -1 ; + } + d = bus->devices[PCI_DEVFN (slot, func)]; +if (!d) { +return -1 ; + } +if (*e =='\0' ) { +break ; + } + +if (*e !=':' ) { +return -1 ; + } + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + QLIST_FOREACH(child_bus, &bus->child, sibling) { +if (child_bus->parent_dev == d) { + bus = child_bus; +continue ; + } + } +return -1 ; + } + + *pdev = d; +return 0 ; +} + +/* * Parse [[<domain>:]<bus>:]<slot>, return -1 on error if funcp == NULL * [[<domain>:]<bus>:]<slot>.<func>, return -1 on error */
hw/pci.h +1 -0
@@ -239,6 +239,7 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,int slot,int function);PCIBus *pci_get_bus_devfn (int *devfnp,const char *devaddr); +int pci_parse_dev_path (const char *addr,PCIDevice **pdev);int pci_parse_devaddr (const char *addr,int *domp,int *busp,unsigned int *slotp,unsigned int *funcp); int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH v8 07/11] pci: introduce a parser for pci device path
Quoted 4 lines · Isaku Yamahata
introduce a function to parse pci device path of
the format, [Domain:]Slot.Function:Slot.Function....:Slot.Function.Signed-off-by Isaku Yamahata <[email protected]>
Hmm.
How about we use openfirmware path like what Gleb's patch does, with a fallback to bus:dev.fn for when it's unambiguous?
Quoted 117 lines
--- hw/pci.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci.h | 1 + 2 files changed, 88 insertions(+), 0 deletions(-)hw/pci.c +87
-0@@ -433,6 +433,93 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev) }/* +* Parse format [Domain:]Slot.Function:Slot.Function....:Slot.Function +* and get PCIDevice +* return 0 on success +* -1 on error: format is invalid or device isn't found. +*/ +int pci_parse_dev_path (const char *addr,PCIDevice **pdev) +{ +unsigned long domain; +unsigned long slot; +unsigned long func; +const char *p; +char *e; +unsigned long val; +PCIBus *bus; +PCIBus *child_bus; +PCIDevice *d; + + p = addr; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } +if (*e ==':' ) { + domain = val; + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + }else if (*e =='.' ){ + domain =0 ; + }else { +return -1 ; + } +if (domain >0xffff ) { +return -1 ; + } + + bus =pci_find_root_bus (domain); +if (!bus) { +return -1 ; + } + +for (;;) { + slot = val; +if (*e !='.' ) { +return -1 ; + } + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + func = val; +if (slot >0x1f || func >=PCI_FUNC_MAX ) { +return -1 ; + } + d = bus->devices[PCI_DEVFN (slot, func)]; +if (!d) { +return -1 ; + } +if (*e =='\0' ) { +break ; + } + +if (*e !=':' ) { +return -1 ; + } + p = e +1 ; + val =strtoul (p, &e,0 ); +if (e == p) { +return -1 ; + } + QLIST_FOREACH(child_bus, &bus->child, sibling) { +if (child_bus->parent_dev == d) { + bus = child_bus; +continue ; + } + } +return -1 ; + } + + *pdev = d; +return 0 ; +} + +/* * Parse [[<domain>:]<bus>:]<slot>, return -1 on error if funcp == NULL * [[<domain>:]<bus>:]<slot>.<func>, return -1 on error */ hw/pci.h +1
-0@@ -239,6 +239,7 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,int slot,int function);PCIBus *pci_get_bus_devfn (int *devfnp,const char *devaddr); +int pci_parse_dev_path (const char *addr,PCIDevice **pdev);int pci_parse_devaddr (const char *addr,int *domp,int *busp,unsigned int *slotp,unsigned int *funcp); int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH v8 07/11] pci: introduce a parser for pci device path
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata
introduce a function to parse pci device path of
the format, [Domain:]Slot.Function:Slot.Function....:Slot.Function.Signed-off-by Isaku Yamahata <[email protected]>Hmm.
How about we use openfirmware path like what Gleb's patch does, with a fallback to bus:dev.fn for when it's unambiguous?
Okay, let me check my understanding of the format.
The openfirmware path in pci case looks like /pci@<ioport>/<device name>@<slot>,<func>/.../<device name>@<slot>,<func>
"pci@<ioport>" corresponds to pci domain. So <mmio address> should be also supported in addition to <ioport>.
Maybe we'd like "<device name>@" to be optional. So the parser would accept something like /{<ioport>, <mmio addr>}/<slot>,<func>/.../<slot>,<func>
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH v8 07/11] pci: introduce a parser for pci device path
Quoted 11 lines · Isaku Yamahata
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata
introduce a function to parse pci device path of
the format, [Domain:]Slot.Function:Slot.Function....:Slot.Function.Signed-off-by Isaku Yamahata <[email protected]>Hmm.
How about we use openfirmware path like what Gleb's patch does, with a fallback to bus:dev.fn for when it's unambiguous?
Quoted 8 lines
Okay, let me check my understanding of the format.
The openfirmware path in pci case looks like /pci@<ioport>/<device name>@<slot>,<func>/.../<device name>@<slot>,<func>
"pci@<ioport>" corresponds to pci domain. So <mmio address> should be also supported in addition to <ioport>.
Correct.
Quoted 3 lines
Maybe we'd like "<device name>@" to be optional. So the parser would accept something like /{<ioport>, <mmio addr>}/<slot>,<func>/.../<slot>,<func>
My patch series has pci_dev_fw_name() function that fills in <device name> for you, so no reason to make it optional. If you still want to make it optional @ should stay, so it should be /@ioport/@slot.func/
--
Gleb.
PATCH v8 8/11 pcie/aer: glue aer error injection into qemu monitor
In reply to Isaku Yamahataintroduce pcie_aer_inject_error command.
---
Changes v7 -> v8:
- use domain:slot.func:slot.func...:slot.func instead of domain:bus:slot.func
- allow symbolic aer error name in addition to 32bit value
Changes v6 -> v7:
- check return value.
Changes v3 -> v4:
- s/PCIE_AER/PCIEAER/g for structure names.
- compilation adjustment.
Changes v2 -> v3:
- compilation adjustment.
pcie/aer/qmp: glue update
glue update.
pcie/aer: update glue function
update glue function.
--- hmp-commands.hx | 23 ++++++ hw/pcie_aer.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ sysemu.h | 5 + 3 files changed, 247 insertions(+), 0 deletions(-)
hmp-commands.hx +23 -0
@@ -836,6 +836,29 @@ Hot remove PCI device. ETEXI { + .name = "pcie_aer_inject_error", + .args_type = "advisory_non_fatal:-a,correctable:-c," + "pci_dev_path:s,error_status:s," + "header0:i?,header1:i?,header2:i?,header3:i?," + "prefix0:i?,prefix1:i?,prefix2:i?,prefix3:i?", + .params = "[-a] [-c] [[<domain>:]<slot>.<func>:...:<slot>.<func> " + "<error status: error string or 32bit> " + "[<tlp header:(32bit x 4)>] " + "[<tlp header prefix:(32bit x 4)>]", + .help = "inject pcie aer error " + "(use -a for advisory non fatal error) " + "(use -c for correctable error)", + .user_print = pcie_aer_inject_error_print, + .mhandler.cmd_new = do_pcie_aer_inejct_error, + }, + +STEXI +@item pcie_aer_inject_error +@findex pcie_aer_inject_error +Inject PCIe AER error +ETEXI + + { .name = "host_net_add", .args_type = "device:s,opts:s?", .params = "tap|user|socket|vde|dump [options]",
hw/pcie_aer.c +219 -0
228 lines not on this page · raw message
sysemu.h +5 -0
@@ -151,6 +151,11 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict);void drive_hot_add (Monitor *mon,const QDict *qdict);void do_pci_device_hot_remove (Monitor *mon,const QDict *qdict); +/* pcie aer error injection */ +void pcie_aer_inject_error_print (Monitor *mon,const QObject *data); +int do_pcie_aer_inejct_error (Monitor *mon, +const QDict *qdict,QObject **ret_data); +/* serial ports */ #define MAX_SERIAL_PORTS 4
Signature · 1 line
1.7.1.1
PATCH v8 9/11 ioh3420: support aer
In reply to Isaku YamahataAdd aer support.
--- hw/ioh3420.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 45 insertions(+), 6 deletions(-)
hw/ioh3420.c +45 -6
@@ -36,25 +36,59 @@#define IOH_EP_EXP_OFFSET 0x90#define IOH_EP_AER_OFFSET 0x100 +/* +* If two MSI vector are allocated, Advanced Error Interrupt Message Number +* is 1. otherwise 0. +* 17.12.5.10 RPERRSTS, 32:27 bit Advanced Error Interrupt Message Number. +*/ +static uint8_t ioh3420_aer_vector (const PCIDevice *d) +{ +switch (msi_nr_vectors_allocated (d)) { +case 1 : +return 0 ; +case 2 : +return 1 ; +case 4 : +case 8 : +case 16 : +case 32 : +default : +break ; + } +abort (); +return 0 ; +} + +static void ioh3420_aer_vector_update (PCIDevice *d) +{ +pcie_aer_root_set_vector (d,ioh3420_aer_vector (d)); +} +static void ioh3420_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len) { +uint32_t root_cmd = +pci_get_long (d->config + d->exp.aer_cap +PCI_ERR_ROOT_COMMAND ); +pci_bridge_write_config (d, address, val, len);msi_write_config (d, address, val, len); +ioh3420_aer_vector_update (d);pcie_cap_slot_write_config (d, address, val, len); -/* TODO: AER */ +pcie_aer_write_config (d, address, val, len); +pcie_aer_root_write_config (d, address, val, len, root_cmd); }static void ioh3420_reset (DeviceState *qdev) {PCIDevice *d =DO_UPCAST (PCIDevice, qdev, qdev);msi_reset (d); +ioh3420_aer_vector_update (d);pcie_cap_root_reset (d);pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d); +pcie_aer_root_reset (d);pci_bridge_reset (qdev);pci_bridge_disable_base_limit (d); -/* TODO: AER */ }static int ioh3420_initfn (PCIDevice *d)
@@ -98,13 +132,15 @@ static int ioh3420_initfn(PCIDevice *d)return rc; }pcie_cap_root_init (d); -/* TODO: AER */ +pcie_aer_init (d,IOH_EP_AER_OFFSET ); +pcie_aer_root_init (d); +ioh3420_aer_vector_update (d);return 0 ; }static int ioh3420_exitfn (PCIDevice *d) { -/* TODO: AER */ +pcie_aer_exit (d);msi_uninit (d);pcie_cap_exit (d);return pci_bridge_exitfn (d);
@@ -142,7 +178,8 @@ static const VMStateDescription vmstate_ioh3420 = { .post_load = pcie_cap_slot_post_load, .fields = (VMStateField []) {VMSTATE_PCIE_DEVICE (port.br.dev, PCIESlot), -/* TODO: AER */ +VMSTATE_STRUCT (port.br.dev.exp.aer_log, PCIESlot,0 , + vmstate_pcie_aer_log, PCIEAERLog),VMSTATE_END_OF_LIST () } };
@@ -164,7 +201,9 @@ static PCIDeviceInfo ioh3420_info = { DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0), DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0), DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0), -/* TODO: AER */ + DEFINE_PROP_UINT16("aer_log_max", PCIESlot, + port.br.dev.exp.aer_log.log_max, + PCIE_AER_LOG_MAX_DEFAULT), DEFINE_PROP_END_OF_LIST(), } };
Signature · 1 line
1.7.1.1
PATCH v8 10/11 x3130/upstream: support aer
In reply to Isaku Yamahataadd aer support.
--- hw/xio3130_upstream.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
hw/xio3130_upstream.c +7 -5
@@ -41,7 +41,7 @@ static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,pci_bridge_write_config (d, address, val, len);pcie_cap_flr_write_config (d, address, val, len);msi_write_config (d, address, val, len); -/* TODO: AER */ +pcie_aer_write_config (d, address, val, len); }static void xio3130_upstream_reset (DeviceState *qdev)
@@ -89,14 +89,14 @@ static int xio3130_upstream_initfn(PCIDevice *d)pcie_cap_flr_init (d);pcie_cap_deverr_init (d); -/* TODO: AER */ +pcie_aer_init (d,XIO3130_AER_OFFSET );return 0 ; }static int xio3130_upstream_exitfn (PCIDevice *d) { -/* TODO: AER */ +pcie_aer_exit (d);msi_uninit (d);pcie_cap_exit (d);return pci_bridge_exitfn (d);
@@ -131,7 +131,8 @@ static const VMStateDescription vmstate_xio3130_upstream = { .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_PCIE_DEVICE (br.dev, PCIEPort), -/* TODO: AER */ +VMSTATE_STRUCT (br.dev.exp.aer_log, PCIEPort,0 , vmstate_pcie_aer_log, + PCIEAERLog),VMSTATE_END_OF_LIST () } };
@@ -151,7 +152,8 @@ static PCIDeviceInfo xio3130_upstream_info = { .qdev.props = (Property[]) {DEFINE_PROP_UINT8 ("port" , PCIEPort, port,0 ), -/* TODO: AER */ +DEFINE_PROP_UINT16 ("aer_log_max" , PCIEPort, br.dev.exp.aer_log.log_max, +PCIE_AER_LOG_MAX_DEFAULT ),DEFINE_PROP_END_OF_LIST (), } };
Signature · 1 line
1.7.1.1
PATCH v8 11/11 x3130/downstream: support aer.
In reply to Isaku Yamahataadd aer support.
--- hw/xio3130_downstream.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
hw/xio3130_downstream.c +8 -5
@@ -42,7 +42,7 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,pcie_cap_flr_write_config (d, address, val, len);pcie_cap_slot_write_config (d, address, val, len);msi_write_config (d, address, val, len); -/* TODO: AER */ +pcie_aer_write_config (d, address, val, len); }static void xio3130_downstream_reset (DeviceState *qdev)
@@ -97,14 +97,14 @@ static int xio3130_downstream_initfn(PCIDevice *d)return rc; }pcie_cap_ari_init (d); -/* TODO: AER */ +pcie_aer_init (d,XIO3130_AER_OFFSET );return 0 ; }static int xio3130_downstream_exitfn (PCIDevice *d) { -/* TODO: AER */ +pcie_aer_exit (d);msi_uninit (d);pcie_cap_exit (d);return pci_bridge_exitfn (d);
@@ -144,7 +144,8 @@ static const VMStateDescription vmstate_xio3130_downstream = { .post_load = pcie_cap_slot_post_load, .fields = (VMStateField []) {VMSTATE_PCIE_DEVICE (port.br.dev, PCIESlot), -/* TODO: AER */ +VMSTATE_STRUCT (port.br.dev.exp.aer_log, PCIESlot,0 , + vmstate_pcie_aer_log, PCIEAERLog),VMSTATE_END_OF_LIST () } };
@@ -166,7 +167,9 @@ static PCIDeviceInfo xio3130_downstream_info = { DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0), DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0), DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0), -/* TODO: AER */ + DEFINE_PROP_UINT16("aer_log_max", PCIESlot, + port.br.dev.exp.aer_log.log_max, + PCIE_AER_LOG_MAX_DEFAULT), DEFINE_PROP_END_OF_LIST(), } };
Signature · 1 line
1.7.1.1