pcie port switch emulators
v9 cover pcie port switch emulators
Now v9 of pcie aer patch series.
I dropped qmp patch to inject aer error because it will depends on Gleb's openfirmware path patches.
Once his patches are merged, the glue patch will be respined.
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.
Change v8 -> v9:
- dropped qmp glue aer error injection.
- folded pci command register initialization patches
- make pcie_aer_init() return error
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 (8):
pci: revise pci command register 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
ioh3420: support aer
x3130/upstream: support aer x3130/downstream: support aer.
Makefile.objs | 2 +- hw/ioh3420.c | 80 ++++- hw/pci.c | 120 +++++++- hw/pcie.h | 14 + hw/pcie_aer.c | 827 +++++++++++++++++++++++++++++++++++++++++++++++ hw/pcie_aer.h | 106 ++++++ hw/pcie_regs.h | 2 + hw/xio3130_downstream.c | 43 ++- hw/xio3130_upstream.c | 33 ++- qemu-common.h | 3 + 10 files changed, 1189 insertions(+), 41 deletions(-) create mode 100644 hw/pcie_aer.c create mode 100644 hw/pcie_aer.h
PATCH v9 1/8 pci: revise pci command register initialization
This patch cleans up command register initialization with
comments. It also 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
---
Changes v8 -> v9
- patch squash
--- hw/pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 57 insertions(+), 1 deletions(-)
hw/pci.c +57 -1
@@ -544,8 +544,53 @@ 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 +* 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 +* 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_MASTER |PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,
@@ -554,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 );
@@ -791,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
[Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Quoted 8 lines · Isaku Yamahata
This patch cleans up command register initialization with
comments. It also 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 BARSigned-off-by Isaku Yamahata <[email protected]>
There's a bug here: you can not assume that device that has no io BAR claims no io transactions.
Another bug is that migrating from qemu where a bit is writeable to one where it's RO creates a situation where a RW bit becomes RO, or the reverse, which might confuse guests. So we will need a compatibility flag and set it for old machine types.
Quoted 50 lines
---
Changes v8 -> v9
- patch squash--- hw/pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 57 insertions(+), 1 deletions(-)hw/pci.c +35
-0@@ -544,8 +544,53 @@ 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 +* 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 +* 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
hw/pci.c static void pci_init_wmask(PCIDevice *dev) · line 591
Quoted 10 lines
hw/pci.c +10
-0+* 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 +*/
Let's document non-obvious things, like maybe COMMAND_PARITY/COMMAND_SERR. I don't cherish writing each bit up in two places.
Quoted 33 lines
hw/pci.c +12
-1pci_set_word (dev->wmask +PCI_COMMAND , -PCI_COMMAND_IO |PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER | +PCI_COMMAND_MASTER |PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,@@ -554,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 );@@ -791,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
[Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata
This patch cleans up command register initialization with
comments. It also 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
Quoted 4 lines
Quoted 1 line
Signed-off-by Isaku Yamahata <[email protected]>There's a bug here: you can not assume that device that has no io BAR claims no io transactions.
Which device are you mentioning?
Such device should set the bit by itself, not by pci generic layer.
Quoted 4 lines
Another bug is that migrating from qemu where a bit is writeable to one where it's RO creates a situation where a RW bit becomes RO, or the reverse, which might confuse guests. So we will need a compatibility flag and set it for old machine types.
We needs to keep compatibility. Which way do you prefer?
- don't care: no way
- introduce global property to indicate compat qemu version or flags something like if (compat version <= 0.13) old behaviour... or if (flags & ...)
- introduce global-pci property
- introduce pci bus property
Users needs to specify this property for all pci devices.
- Don't change common code(pci.c), and provide a helper function. Each device which needs new behavior like pcie calls it. Probably each device may provide property to specify compat behavior
- any other?
Quoted 99 lines
Quoted 51 lines
---
Changes v8 -> v9
- patch squash--- hw/pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 57 insertions(+), 1 deletions(-)hw/pci.c +35
-0@@ -544,8 +544,53 @@ 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 +* 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 +* 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 hw/pci.c static void pci_init_wmask(PCIDevice *dev) · line 591
Quoted 10 lines
hw/pci.c +10
-0+* 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 +*/ Let's document non-obvious things, like maybe COMMAND_PARITY/COMMAND_SERR. I don't cherish writing each bit up in two places.
Quoted 33 lines
hw/pci.c +12
-1pci_set_word (dev->wmask +PCI_COMMAND , -PCI_COMMAND_IO |PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER | +PCI_COMMAND_MASTER |PCI_COMMAND_PARITY |PCI_COMMAND_SERR |PCI_COMMAND_INTX_DISABLE ); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff,@@ -554,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 );@@ -791,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
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Quoted 9 lines · Isaku Yamahata
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata
This patch cleans up command register initialization with
comments. It also 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
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Isaku Yamahata <[email protected]>There's a bug here: you can not assume that device that has no io BAR claims no io transactions.
Which device are you mentioning?
Look at appendix D in PCI spec. There are many programming classes like display controllers that claim specific addresses without using a BAR. We could code it all up with a huge table. But what we have is much simpler and works well AFAIK.
Quoted 1 line
Such device should set the bit by itself, not by pci generic layer.
Since this is PCI spec specified behaviour, I think it's better to have it in a common place. Devices are sure to get it wrong.
Quoted 15 lines
Quoted 4 lines
Another bug is that migrating from qemu where a bit is writeable to one where it's RO creates a situation where a RW bit becomes RO, or the reverse, which might confuse guests. So we will need a compatibility flag and set it for old machine types.
We needs to keep compatibility. Which way do you prefer?
- don't care: no way
- introduce global property to indicate compat qemu version or flags something like if (compat version <= 0.13) old behaviour... or if (flags & ...)
- introduce global-pci property
Quoted 8 lines
- introduce pci bus property
Users needs to specify this property for all pci devices.- Don't change common code(pci.c), and provide a helper function. Each device which needs new behavior like pcie calls it. Probably each device may provide property to specify compat behavior
- any other?
- Don't change behaviour at all.
What is the motivation for the change? Why do we bother? What we have is spec compliant, I think, so it's hard for me to believe pcie *needs* the new behaviour.
[Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Quoted 22 lines · Michael S. Tsirkin
Quoted 22 lines
Quoted 4 lines
Another bug is that migrating from qemu where a bit is writeable to one where it's RO creates a situation where a RW bit becomes RO, or the reverse, which might confuse guests. So we will need a compatibility flag and set it for old machine types.
We needs to keep compatibility. Which way do you prefer?
- don't care: no way
- introduce global property to indicate compat qemu version or flags something like if (compat version <= 0.13) old behaviour... or if (flags & ...)
- introduce global-pci property
- introduce pci bus property
Users needs to specify this property for all pci devices.- Don't change common code(pci.c), and provide a helper function. Each device which needs new behavior like pcie calls it. Probably each device may provide property to specify compat behavior
Quoted 7 lines
Quoted 1 line
- any other?
- Don't change behaviour at all.
What is the motivation for the change? Why do we bother? What we have is spec compliant, I think, so it's hard for me to believe pcie *needs* the new behaviour.
AER wants SERR bit to be writable and you requested it as below. I thought, you wanted me to revise PCI_COMMAND and PCI_STATUS initialization. If I misunderstood, can you please elaborate on it?
If you accept the following PCI_COMMAND line,
I'm fine with dropping this clean up patch.
http://lists.nongnu.org/archive/html/qemu-devel/2010-11/msg00131.html
Quoted 16 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+void pcie_aer_init(PCIDevice *dev, uint16_t offset) +{ + PCIExpressDevice *exp; + + pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); + pci_word_test_and_set_mask(dev->w1cmask + PCI_STATUS, + PCI_STATUS_SIG_SYSTEM_ERROR); +I would say we should just set these for all devices.
But if we do my concern is that guest might write 1 to this register, then we migrate to an old guest and that one can not clear this bit. Thoughts? Let's add a flag so old machine types can disable this?Also - what about other bits in the status register?
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH v9 1/8] pci: revise pci command register initialization
Quoted 31 lines · Isaku Yamahata
Quoted 22 lines · Michael S. Tsirkin
Quoted 22 lines
Quoted 4 lines
Another bug is that migrating from qemu where a bit is writeable to one where it's RO creates a situation where a RW bit becomes RO, or the reverse, which might confuse guests. So we will need a compatibility flag and set it for old machine types.
We needs to keep compatibility. Which way do you prefer?
- don't care: no way
- introduce global property to indicate compat qemu version or flags something like if (compat version <= 0.13) old behaviour... or if (flags & ...)
- introduce global-pci property
- introduce pci bus property
Users needs to specify this property for all pci devices.- Don't change common code(pci.c), and provide a helper function. Each device which needs new behavior like pcie calls it. Probably each device may provide property to specify compat behavior
Quoted 7 lines
Quoted 1 line
- any other?
- Don't change behaviour at all.
What is the motivation for the change? Why do we bother? What we have is spec compliant, I think, so it's hard for me to believe pcie *needs* the new behaviour.
Quoted 23 lines
AER wants SERR bit to be writable and you requested it as below. I thought, you wanted me to revise
PCI_COMMANDandPCI_STATUSinitialization. If I misunderstood, can you please elaborate on it?
If you accept the followingPCI_COMMANDline,
I'm fine with dropping this clean up patch.http://lists.nongnu.org/archive/html/qemu-devel/2010-11/msg00131.html
Quoted 16 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+void pcie_aer_init(PCIDevice *dev, uint16_t offset) +{ + PCIExpressDevice *exp; + + pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); + pci_word_test_and_set_mask(dev->w1cmask + PCI_STATUS, + PCI_STATUS_SIG_SYSTEM_ERROR); +I would say we should just set these for all devices.
But if we do my concern is that guest might write 1 to this register, then we migrate to an old guest and that one can not clear this bit. Thoughts? Let's add a flag so old machine types can disable this?Also - what about other bits in the status register?
I think what you did for PCI_STATUS addressed this comment. Thanks!
Yes, for AER we need to enable SERR, and just for SERR, I think a global property or a bus property will be the simplest (I think properties are inherited from bus to device, right?) Something like pci_command_serr_enable, should be a bit property. Default to on and disable for 0.13 and back. Hmm?
Also, need to check this and fail aer initialization if not there. Maybe simply don't add aer capability if aer_init fails? Or make it yet another property ...
Signature · 1 line
MST
PATCH v9 2/8 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
[Qemu-devel] Re: [PATCH v9 2/8] pci: fix accesses to pci status register
Quoted 4 lines · Isaku Yamahata
pci status register is 16 bit, not 8 bit.
So use helper function to manipulate status register.Signed-off-by Isaku Yamahata <[email protected]>
At least the subject is wrong: the relevant bit is in the low byte. So the code is correct as written on BE machines.
Quoted 75 lines
--- 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
[Qemu-devel] Re: [PATCH v9 2/8] pci: fix accesses to pci status register
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata
pci status register is 16 bit, not 8 bit.
So use helper function to manipulate status register.Signed-off-by Isaku Yamahata <[email protected]>At least the subject is wrong: the relevant bit is in the low byte. So the code is correct as written on BE machines.
The code is correct, but also inconsistent and prone to errors. Except the commit message, are you objecting the patch contents itself? How about the following commit log?
pci: make accesses to pci status register consistent
pci status register is 16 bits, not 8 bits.
It is inconsistent to access 16 bits register as uint8_t. So use pci config space functions to manipulate status register for consistency.
Quoted 77 lines
Quoted 76 lines
--- 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
Signature · 1 line
yamahata
PATCH v9 3/8 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
[Qemu-devel] Re: [PATCH v9 3/8] pci: clean up of pci status register
Quoted 4 lines · Isaku Yamahata
This patch refine the initialization/reset of
pci status registers.Signed-off-by Isaku Yamahata <[email protected]>
This one seems good. Applied with some tweaks: I cut down the comment:
we don't really need to repeat what code does IMO, rather why it does it, and clarified the comment text. Also split init_w1c out to a function so that each function does one thing.
Quoted 79 lines
--- 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 v9 4/8 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 v9 5/8 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 v8 -> v9:
- make pcie_aer_init() return error
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 | 827 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pcie_aer.h | 106 ++++++++ qemu-common.h | 3 + 5 files changed, 951 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 +827 -0
827 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
[Qemu-devel] [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability
Quoted 4 lines · Isaku Yamahata
This patch implements helper functions for pcie aer capability which will be used later.
Signed-off-by Isaku Yamahata <[email protected]>
OK, I applied this and tried to get rid of recursion, and clean up some whitespace and english mistakes.
Patcheset attached, pls review.
I'll push the patches out on pci branch so we can make progress more easily.
Please, try to address the TODO: I think the case of PCIE device behind a pci bridge is not covered properly.
Michael S. Tsirkin (2):
pcie_aer: get rid of recursion
pcie_aer: complete unwinding recursion
hw/pcie_aer.c | 72 +++++++++++++++++++++++--------------------------------- 1 files changed, 30 insertions(+), 42 deletions(-)
Signature · 1 line
1.7.3.2.91.g446ac
PATCH 1/2 pcie_aer: get rid of recursion
Added some TODOs: they are trivial but omitted here to make the patch logic as transparent as possible.
--- hw/pcie_aer.c | 48 +++++++++++++++++++++++++++++++----------------- 1 files changed, 31 insertions(+), 17 deletions(-)
hw/pcie_aer.c +31 -17
@@ -176,14 +176,8 @@ static void pcie_aer_update_uncor_status(PCIDevice *dev) }/* -* pcie_aer_msg() is called recursively by -* pcie_aer_msg_alldev(), pci_aer_msg_vbridge() and pcie_aer_msg_root_port() -*/ -static void pcie_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg); - -/* * return value: -* true: error message is sent up +* true: error message needs to be sent up * false: error message is masked * * 6.2.6 Error Message Control
@@ -193,8 +187,6 @@ static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg);static bool pcie_aer_msg_alldev (PCIDevice *dev,const PCIEAERMsg *msg) { -PCIDevice *parent_port; -if (!(pcie_aer_msg_is_uncor (msg) && (pci_get_word (dev->config +PCI_COMMAND ) &PCI_COMMAND_SERR ))) {return false;
@@ -220,13 +212,21 @@ pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg) }/* send up error message */ +return true; +} + +/* Get parent port to send up error message on. +* TODO: clean up and open-code this logic */ +static PCIDevice *pcie_aer_parent_port (PCIDevice *dev) +{ +PCIDevice *parent_port;if (pci_is_express (dev) &&pcie_cap_get_type (dev) ==PCI_EXP_TYPE_ROOT_PORT ) { -/* Root port notify system itself, +/* Root port can notify system itself, or send the error message to root complex event collector. */ /* -* if root port is associated to event collector, set -* parent_port = root complex event collector +* if root port is associated with an event collector, +* return the root complex event collector here. * For now root complex event collector isn't supported. */ parent_port =NULL ;
@@ -236,11 +236,10 @@ pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg)if (parent_port) {if (!pci_is_express (parent_port)) {/* just ignore it */ -return false; +return NULL ; } -pcie_aer_msg (parent_port, msg); } -return true; +return parent_port; }/*
@@ -381,8 +380,12 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)/* * 6.2.6 Error Message Control Figure 6-3 +* +* Returns true in case the error needs to +* be propagated up. +* TODO: open-code. */ -static void pcie_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) +static bool pcie_send_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) {uint8_t type;bool msg_sent;
@@ -402,6 +405,18 @@ static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)if (type ==PCI_EXP_TYPE_ROOT_PORT && msg_sent) {pcie_aer_msg_root_port (dev, msg); } +return msg_sent; +} + +static void pcie_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) +{ +bool send_to_parent; +while (dev) { +if (!pcie_send_aer_msg (dev, msg)) { +return ; + } + dev =pcie_aer_parent_port (dev); + } }static void pcie_aer_update_log (PCIDevice *dev,const PCIEAERErr *err)
@@ -824,4 +839,3 @@ const VMStateDescription vmstate_pcie_aer_log = { VMSTATE_END_OF_LIST() } }; -
Signature · 1 line
1.7.3.2.91.g446ac
PATCH 2/2 pcie_aer: complete unwinding recursion
In reply to Michael S. TsirkinOpen-code functions created in the previous patch, to make code more compact and clear.
Detcted and documented what looks like a bug in code that becomes apparent from this refactoring.
--- hw/pcie_aer.c | 80 +++++++++++++++++++------------------------------------- 1 files changed, 27 insertions(+), 53 deletions(-)
hw/pcie_aer.c +27 -53
@@ -215,33 +215,6 @@ pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg)return true; } -/* Get parent port to send up error message on. -* TODO: clean up and open-code this logic */ -static PCIDevice *pcie_aer_parent_port (PCIDevice *dev) -{ -PCIDevice *parent_port; -if (pci_is_express (dev) && -pcie_cap_get_type (dev) ==PCI_EXP_TYPE_ROOT_PORT ) { -/* Root port can notify system itself, -or send the error message to root complex event collector. */ -/* -* if root port is associated with an event collector, -* return the root complex event collector here. -* For now root complex event collector isn't supported. -*/ - parent_port =NULL ; - }else { - parent_port =pci_bridge_get_device (dev->bus); - } -if (parent_port) { -if (!pci_is_express (parent_port)) { -/* just ignore it */ -return NULL ; - } - } -return parent_port; -} -/* * return value: * true: error message is sent up
@@ -381,41 +354,42 @@ static bool pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)/* * 6.2.6 Error Message Control Figure 6-3 * -* Returns true in case the error needs to -* be propagated up. -* TODO: open-code. +* Walk up the bus tree from the device, propagate the error message. */ -static bool pcie_send_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) +static void pcie_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) {uint8_t type; -bool msg_sent; - -assert (pci_is_express (dev)); - type =pcie_cap_get_type (dev); -if (type ==PCI_EXP_TYPE_ROOT_PORT || - type ==PCI_EXP_TYPE_UPSTREAM || - type ==PCI_EXP_TYPE_DOWNSTREAM ) { - msg_sent =pcie_aer_msg_vbridge (dev, msg); -if (!msg_sent) { +while (dev) { +if (!pci_is_express (parent_port)) { +/* just ignore it */ +/* TODO: Shouldn't we set PCI_STATUS_SIG_SYSTEM_ERROR? +* Consider e.g. a PCI bridge above a PCI Express device. */ return ; } - } - msg_sent =pcie_aer_msg_alldev (dev, msg); -if (type ==PCI_EXP_TYPE_ROOT_PORT && msg_sent) { -pcie_aer_msg_root_port (dev, msg); - } -return msg_sent; -} -static void pcie_aer_msg (PCIDevice *dev,const PCIEAERMsg *msg) -{ -bool send_to_parent; -while (dev) { -if (!pcie_send_aer_msg (dev, msg)) { + type =pcie_cap_get_type (dev); +if ((type ==PCI_EXP_TYPE_ROOT_PORT || + type ==PCI_EXP_TYPE_UPSTREAM || + type ==PCI_EXP_TYPE_DOWNSTREAM ) && + !pcie_aer_msg_vbridge (dev, msg)) { +return ; + } +if (!pcie_aer_msg_alldev (dev, msg)) { +return ; + } +if (type ==PCI_EXP_TYPE_ROOT_PORT ) { +pcie_aer_msg_root_port (dev, msg); +/* Root port can notify system itself, +or send the error message to root complex event collector. */ +/* +* if root port is associated with an event collector, +* return the root complex event collector here. +* For now root complex event collector isn't supported. +*/ return ; } - dev =pcie_aer_parent_port (dev); + dev =pci_bridge_get_device (dev->bus); } }
Signature · 1 line
1.7.3.2.91.g446ac
[Qemu-devel] Re: [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability
In reply to Michael S. TsirkinQuoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata
This patch implements helper functions for pcie aer capability which will be used later.
Signed-off-by Isaku Yamahata <[email protected]>
Quoted 7 lines
OK, I applied this and tried to get rid of recursion, and clean up some whitespace and english mistakes.
Patcheset attached, pls review.
I'll push the patches out on pci branch so we can make progress more easily.
Thank you for cleaning it up.
Basically looks good. Except the following patch.
Quoted 2 lines
Please, try to address the TODO: I think the case of PCIE device behind a pci bridge is not covered properly.
Will do.
Quoted 1 line
From
166886f7f3e423812f4f3f467e2071c53e9dde01Mon Sep 17 00:00:00 2001
Message-Id: <166886f7f3e423812f4f3f467e2071c53e9dde01.1290067665.git.yamahata@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Thu, 18 Nov 2010 17:03:23 +0900
Subject: [PATCH] pcie/aer: typo
Compilation fix.
--- hw/pcie_aer.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/pcie_aer.c +1 -1
@@ -363,7 +363,7 @@ static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)uint8_t type;while (dev) { -if (!pci_is_express (parent_port)) { +if (!pci_is_express (dev)) {/* just ignore it */ /* TODO: Shouldn't we set PCI_STATUS_SIG_SYSTEM_ERROR? * Consider e.g. a PCI bridge above a PCI Express device. */
Signature · 5 lines
1.7.1.1 -- yamahata
[Qemu-devel] Re: [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability
Quoted 10 lines · Isaku Yamahata
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata
This patch implements helper functions for pcie aer capability which will be used later.
Signed-off-by Isaku Yamahata <[email protected]>OK, I applied this and tried to get rid of recursion, and clean up some whitespace and english mistakes.
Quoted 7 lines
Quoted 4 lines
Patcheset attached, pls review.
I'll push the patches out on pci branch so we can make progress more easily.
Thank you for cleaning it up.
Basically looks good. Except the following patch.
Right. Fixed up, thanks!
Quoted 41 lines
Quoted 3 lines
Please, try to address the TODO: I think the case of PCIE device behind a pci bridge is not covered properly.
Will do.
Quoted 1 line
From
166886f7f3e423812f4f3f467e2071c53e9dde01Mon Sep 17 00:00:00 2001Message-Id: <166886f7f3e423812f4f3f467e2071c53e9dde01.1290067665.git.yamahata@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Thu, 18 Nov 2010 17:03:23 +0900
Subject: [PATCH] pcie/aer: typoCompilation fix.
Signed-off-by Isaku Yamahata <[email protected]>--- hw/pcie_aer.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)hw/pcie_aer.c +1
-1@@ -363,7 +363,7 @@ static void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)uint8_t type;while (dev) { -if (!pci_is_express (parent_port)) { +if (!pci_is_express (dev)) {/* just ignore it */ /* TODO: Shouldn't we set PCI_STATUS_SIG_SYSTEM_ERROR? * Consider e.g. a PCI bridge above a PCI Express device. */ Signature · 5 lines
1.7.1.1 -- yamahata
[Qemu-devel] Re: [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability
In reply to Michael S. TsirkinQuoted 2 lines · Michael S. Tsirkin
Please, try to address the TODO: I think the case of PCIE device behind a pci bridge is not covered properly.
Right, pci-to-pcie bridge case isn't covered.
Although SERR bit can be set, the error can't be propagated up further because qemu doesn't emulate PERR#/SERR#.
There is no use case of pci-to-pcie bridge in qemu, I think. If good error handling is wanted, express should be used. So it isn't worthwhile to implement pci-to-pcie bridge.
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH 0/2] Re: [PATCH v9 5/8] pcie/aer: helper functions for pcie aer capability
Quoted 9 lines · Isaku Yamahata
Quoted 2 lines · Michael S. Tsirkin
Please, try to address the TODO: I think the case of PCIE device behind a pci bridge is not covered properly.
Right, pci-to-pcie bridge case isn't covered.
Although SERR bit can be set, the error can't be propagated up further because qemu doesn't emulate PERR#/SERR#.There is no use case of pci-to-pcie bridge in qemu, I think.
I think it's useful to put an express device behind a pci bridge in qemu, because pci bridges are tested and supported by more guests.
Quoted 2 lines
If good error handling is wanted, express should be used. So it isn't worthwhile to implement pci-to-pcie bridge.
Okay, we can look into this later.
Quoted 2 lines
Signature · 1 line
yamahata
PATCH v9 6/8 ioh3420: support aer
In reply to Isaku YamahataAdd aer support.
---
Changes v8 -> v9:
- error path in initialization
--- hw/ioh3420.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 70 insertions(+), 10 deletions(-)
hw/ioh3420.c +70 -10
@@ -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)
@@ -63,6 +97,7 @@ static int ioh3420_initfn(PCIDevice *d)PCIEPort *p =DO_UPCAST (PCIEPort, br, br);PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; +int tmp; rc =pci_bridge_initfn (d);if (rc <0 ) {
@@ -78,35 +113,57 @@ static int ioh3420_initfn(PCIDevice *d) rc =pci_bridge_ssvid_init (d,IOH_EP_SSVID_OFFSET ,IOH_EP_SSVID_SVID ,IOH_EP_SSVID_SSID );if (rc <0 ) { -return rc; + goto err_bridge; } rc =msi_init (d,IOH_EP_MSI_OFFSET ,IOH_EP_MSI_NR_VECTOR ,IOH_EP_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT ,IOH_EP_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_MASKBIT );if (rc <0 ) { -return rc; + goto err_bridge; } rc =pcie_cap_init (d,IOH_EP_EXP_OFFSET ,PCI_EXP_TYPE_ROOT_PORT , p->port);if (rc <0 ) { -return rc; + goto err_msi; }pcie_cap_deverr_init (d);pcie_cap_slot_init (d, s->slot);pcie_chassis_create (s->chassis); rc =pcie_chassis_add_slot (s);if (rc <0 ) { + goto err_pcie_cap;return rc; }pcie_cap_root_init (d); -/* TODO: AER */ + rc =pcie_aer_init (d,IOH_EP_AER_OFFSET ); +if (rc <0 ) { + goto err; + } +pcie_aer_root_init (d); +ioh3420_aer_vector_update (d);return 0 ; + +err: +pcie_chassis_del_slot (s); +err_pcie_cap: +pcie_cap_exit (d); +err_msi: +msi_uninit (d); +err_bridge: + tmp =pci_bridge_exitfn (d); +assert (!tmp); +return rc; }static int ioh3420_exitfn (PCIDevice *d) { -/* TODO: AER */ -msi_uninit (d); +PCIBridge * br =DO_UPCAST (PCIBridge, dev, d); +PCIEPort *p =DO_UPCAST (PCIEPort, br, br); +PCIESlot *s =DO_UPCAST (PCIESlot, port, p); + +pcie_aer_exit (d); +pcie_chassis_del_slot (s);pcie_cap_exit (d); +msi_uninit (d);return pci_bridge_exitfn (d); }
@@ -142,7 +199,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 +222,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 v9 7/8 x3130/upstream: support aer
In reply to Isaku Yamahataadd aer support.
---
Changes v8 -> v9
- error path in initialization.
--- hw/xio3130_upstream.c | 33 ++++++++++++++++++++++++--------- 1 files changed, 24 insertions(+), 9 deletions(-)
hw/xio3130_upstream.c +24 -9
@@ -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)
@@ -57,6 +57,7 @@ static int xio3130_upstream_initfn(PCIDevice *d)PCIBridge * br =DO_UPCAST (PCIBridge, dev, d);PCIEPort *p =DO_UPCAST (PCIEPort, br, br);int rc; +int tmp; rc =pci_bridge_initfn (d);if (rc <0 ) {
@@ -72,33 +73,45 @@ static int xio3130_upstream_initfn(PCIDevice *d)XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT , XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);if (rc <0 ) { -return rc; + goto err_bridge; } rc =pci_bridge_ssvid_init (d,XIO3130_SSVID_OFFSET ,XIO3130_SSVID_SVID ,XIO3130_SSVID_SSID );if (rc <0 ) { -return rc; + goto err_bridge; } rc =pcie_cap_init (d,XIO3130_EXP_OFFSET ,PCI_EXP_TYPE_UPSTREAM , p->port);if (rc <0 ) { -return rc; + goto err_msi; }/* TODO: implement FLR */ pcie_cap_flr_init (d);pcie_cap_deverr_init (d); -/* TODO: AER */ + rc =pcie_aer_init (d,XIO3130_AER_OFFSET ); +if (rc <0 ) { + goto err; + }return 0 ; + +err: +pcie_cap_exit (d); +err_msi: +msi_uninit (d); +err_bridge: + tmp =pci_bridge_exitfn (d); +assert (!tmp); +return rc; }static int xio3130_upstream_exitfn (PCIDevice *d) { -/* TODO: AER */ -msi_uninit (d); +pcie_aer_exit (d);pcie_cap_exit (d); +msi_uninit (d);return pci_bridge_exitfn (d); }
@@ -131,7 +144,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 +165,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 v9 8/8 x3130/downstream: support aer.
In reply to Isaku Yamahataadd aer support.
---
Changes v8 -> v9:
- error path in initialization
--- hw/xio3130_downstream.c | 43 +++++++++++++++++++++++++++++++++---------- 1 files changed, 33 insertions(+), 10 deletions(-)
hw/xio3130_downstream.c +33 -10
@@ -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)
@@ -61,6 +61,7 @@ static int xio3130_downstream_initfn(PCIDevice *d)PCIEPort *p =DO_UPCAST (PCIEPort, br, br);PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; +int tmp; rc =pci_bridge_initfn (d);if (rc <0 ) {
@@ -76,17 +77,17 @@ static int xio3130_downstream_initfn(PCIDevice *d)XIO3130_MSI_SUPPORTED_FLAGS &PCI_MSI_FLAGS_64BIT , XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT);if (rc <0 ) { -return rc; + goto err_bridge; } rc =pci_bridge_ssvid_init (d,XIO3130_SSVID_OFFSET ,XIO3130_SSVID_SVID ,XIO3130_SSVID_SSID );if (rc <0 ) { -return rc; + goto err_bridge; } rc =pcie_cap_init (d,XIO3130_EXP_OFFSET ,PCI_EXP_TYPE_DOWNSTREAM , p->port);if (rc <0 ) { -return rc; + goto err_msi; }pcie_cap_flr_init (d);/* TODO: implement FLR */ pcie_cap_deverr_init (d);
@@ -94,19 +95,38 @@ static int xio3130_downstream_initfn(PCIDevice *d)pcie_chassis_create (s->chassis); rc =pcie_chassis_add_slot (s);if (rc <0 ) { -return rc; + goto err_pcie_cap; }pcie_cap_ari_init (d); -/* TODO: AER */ + rc =pcie_aer_init (d,XIO3130_AER_OFFSET ); +if (rc <0 ) { + goto err; + }return 0 ; + +err: +pcie_chassis_del_slot (s); +err_pcie_cap: +pcie_cap_exit (d); +err_msi: +msi_uninit (d); +err_bridge: + tmp =pci_bridge_exitfn (d); +assert (!tmp); +return rc; }static int xio3130_downstream_exitfn (PCIDevice *d) { -/* TODO: AER */ -msi_uninit (d); +PCIBridge * br =DO_UPCAST (PCIBridge, dev, d); +PCIEPort *p =DO_UPCAST (PCIEPort, br, br); +PCIESlot *s =DO_UPCAST (PCIESlot, port, p); + +pcie_aer_exit (d); +pcie_chassis_del_slot (s);pcie_cap_exit (d); +msi_uninit (d);return pci_bridge_exitfn (d); }
@@ -144,7 +164,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 +187,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
A message that is not in the archive (sent off-list or not yet received): 1289930315.27724.18.camel@etmartin-lnx
[Qemu-devel] Re: [PATCH v9 8/8] x3130/downstream: support aer.
Quoted 3 lines · Isaku Yamahata
add aer support.
Signed-off-by Isaku Yamahata <[email protected]>
I'm actually working on a scheme to provide support to handle PCI errors related to assigned devices. The goal is to notify the coresponding driver so that all his I/O access are stop quickly and to provide that same driver a chance to get back in sync with the device.
I'm just wondering how can I make use of your aer support in Q35?
As you already know, error detection and error recovery phases are driven by a state machine where the next state depends on the returned value from the current callback. Also only the host can performed the link recovery sequence for assigned devices.
Because of such it seems like the only way to maintain consistency between the assigned device and it's corresponding driver is to perform the error detection/recovery phase in lockstep with the host?
thanks,
-Etienne
[Qemu-devel] Re: [PATCH v9 8/8] x3130/downstream: support aer.
Quoted 13 lines · Etienne Martineau
Quoted 3 lines · Isaku Yamahata
add aer support.
Signed-off-by Isaku Yamahata <[email protected]>I'm actually working on a scheme to provide support to handle PCI errors related to assigned devices. The goal is to notify the coresponding driver so that all his I/O access are stop quickly and to provide that same driver a chance to get back in sync with the device.
I'm just wondering how can I make use of your aer support in Q35?
Quoted 8 lines
As you already know, error detection and error recovery phases are driven by a state machine where the next state depends on the returned value from the current callback. Also only the host can performed the link recovery sequence for assigned devices.
Because of such it seems like the only way to maintain consistency between the assigned device and it's corresponding driver is to perform the error detection/recovery phase in lockstep with the host?
Maybe. At least at the first implementation, I suppose.
Then we would learn from its experience, then move on to next generation implementation.
To be honest, what I have in my mind very vaguely is
- something like pcie aer fd driver.
or enhancement to vfio
qemu polls the fd.
- error recovery in host will be directed by qemu
in concert with guest recovery action.
For latency necessary information would be shared by qemu and host kernel, so that the aer driver in host kernel could take responsibility to eliminate the latency caused by qemu process.
I suppose there is no single right way for recovery action in host/guest. So there should be room for recovery policies.
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH v9 8/8] x3130/downstream: support aer.
Quoted 4 lines · Isaku Yamahata
Quoted 3 lines
Because of such it seems like the only way to maintain consistency between the assigned device and it's corresponding driver is to perform the error detection/recovery phase in lockstep with the host?
Quoted 8 lines
Maybe. At least at the first implementation, I suppose.
Then we would learn from its experience, then move on to next generation implementation.To be honest, what I have in my mind very vaguely is
- something like pcie aer fd driver.
or enhancement to vfio
qemu polls the fd.
I'm currently working on a pcie aer driver. Few weeks ago I sent some rfc patches. I'm about to send another version.
It's basically a simple UIO based pci-stub driver for AER and PM. Notification goes through eventfd and error code / error result are mmap directly over a 'logical' BAR. Qemu consume the eventfd or it goes directly to the guest with irqfd.
Quoted 2 lines
- error recovery in host will be directed by qemu
in concert with guest recovery action.
To my view, this is the tricky part. Error recovery can be directed by qemu indeed but how do you get the information about the guest recovery action for every error callback?
I think that because aer handling effectively 'merge' callback return code from multiple source it's hard to discriminate what value should be given back to the host for the corresponding assigned device (at least from the qemu side)
Quoted 4 lines
For latency necessary information would be shared by qemu and host kernel, so that the aer driver in host kernel could take responsibility to eliminate the latency caused by qemu process.
I'm sorry but I'm not sure to follow here. Can you elaborate more on this topic?
Quoted 3 lines
I suppose there is no single right way for recovery action in host/guest. So there should be room for recovery policies.
Yes I agree. There is already a policy argument part of the uio pci_stub driver that I'm working on.
-Etienne
[Qemu-devel] Re: [PATCH v9 8/8] x3130/downstream: support aer.
Quoted 16 lines · Etienne Martineau
Quoted 4 lines · Isaku Yamahata
Quoted 3 lines
Because of such it seems like the only way to maintain consistency between the assigned device and it's corresponding driver is to perform the error detection/recovery phase in lockstep with the host?
Quoted 8 lines
Maybe. At least at the first implementation, I suppose.
Then we would learn from its experience, then move on to next generation implementation.To be honest, what I have in my mind very vaguely is
- something like pcie aer fd driver.
or enhancement to vfio
qemu polls the fd.
Quoted 7 lines
I'm currently working on a pcie aer driver. Few weeks ago I sent some rfc patches. I'm about to send another version.
It's basically a simple UIO based pci-stub driver for AER and PM. Notification goes through eventfd and error code / error result are mmap directly over a 'logical' BAR. Qemu consume the eventfd or it goes directly to the guest with irqfd.
You mean '[RFC PATCH] kvm: BSimple stub driver with AER capabilities'. Yes, that is exactly what I've thought.
Can you please add me to CC?
Quoted 11 lines
Quoted 2 lines
- error recovery in host will be directed by qemu
in concert with guest recovery action.To my view, this is the tricky part. Error recovery can be directed by qemu indeed but how do you get the information about the guest recovery action for every error callback?
I think that because aer handling effectively 'merge' callback return code from multiple source it's hard to discriminate what value should be given back to the host for the corresponding assigned device (at least from the qemu side)
I don't have any clear idea yet. I've just figured it would be tricky like you.
Maybe listing what kind of aer recovery we want would help, I suppose.
Quoted 6 lines
Quoted 4 lines
For latency necessary information would be shared by qemu and host kernel, so that the aer driver in host kernel could take responsibility to eliminate the latency caused by qemu process.
I'm sorry but I'm not sure to follow here. Can you elaborate more on this topic?
I mean that we might want to move the code in qemu aer recovery into kvm host kernel for latency. something like in-kernel pic emulator.
Quoted 5 lines
Quoted 2 lines
I suppose there is no single right way for recovery action in host/guest. So there should be room for recovery policies.
Yes I agree. There is already a policy argument part of the uio
pci_stubdriver that I'm working on.
Great.
Signature · 1 line
yamahata
Michael S. Tsirkin
AppliedQuoted 54 lines · Isaku Yamahata
Now v9 of pcie aer patch series.
I dropped qmp patch to inject aer error because it will depends on Gleb's openfirmware path patches.
Once his patches are merged, the glue patch will be respined.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.Change v8 -> v9:
- dropped qmp glue aer error injection.
- folded pci command register initialization patches
- makepcie_aer_init()return errorChanges 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 valueChanges 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 onhpev_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
- eliminatedxxx_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.
- droppedpci_shift_xxx().
- dropped function pointerinpcie_aer.h
- droppedpci_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] intopcie_regs.h, pcie.[ch] and pcie_aer.[ch]
- pcie, aer: many changes by following reviews.
Quoted 8 lines
changes v1 -> v2:
- update msi
- dropped already pushed out patches.
- added msix patches.Isaku Yamahata (8):
pci: revise pci command register initialization
pci: fix accesses to pci status register
I dropped these for now. Maybe for AER we'll need a small patch to make SERR enable writeable + a compatibility flag set in machine description for 0.13 and back?
If yes let's do just this, leave IO/MEMORY alone.
Quoted 1 line
pci: clean up of pci status register
Applied a minimal subset for AER.
Quoted 1 line
pcie_regs.h: more constants
Applied after fixing up the comment.
Quoted 1 line
pcie/aer: helper functions for pcie aer capability
Applied, added cleanup patches on top to remove recursion
Quoted 3 lines
ioh3420: support aer
x3130/upstream: support aer
x3130/downstream: support aer.
Applied.
Quoted 14 lines
Makefile.objs | 2 +- hw/ioh3420.c | 80 ++++- hw/pci.c | 120 +++++++- hw/pcie.h | 14 + hw/pcie_aer.c | 827 +++++++++++++++++++++++++++++++++++++++++++++++ hw/pcie_aer.h | 106 ++++++ hw/pcie_regs.h | 2 + hw/xio3130_downstream.c | 43 ++- hw/xio3130_upstream.c | 33 ++- qemu-common.h | 3 + 10 files changed, 1189 insertions(+), 41 deletions(-) create mode 100644 hw/pcie_aer.c create mode 100644 hw/pcie_aer.h