Skip to contentSkip to conversation

pcie port switch emulators

PATCH Applied Isaku Yamahata 4 participants 40 messages Oct 20, 2010 – Oct 27, 2010 Kbuild

v6 of 9 Applied Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover pcie port switch emulators

This patch series is v6 of the pcie switch emulators. Now the aer dependency has removed, so the patch 1-7 can be merged. And I cleaned up pcie_aer_write_config() in the aer patch.

new patches: 1
essentially updated patches: 2, 8

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 (12):
pcie: comment on hpev_intx
pci/bridge: fix pci_bridge_reset()
pcie port: define struct PCIEPort/PCIESlot and helper functions
ioh3420: pcie root port in X58 ioh
x3130: pcie upstream port
x3130: pcie downstream port
pcie/hotplug: introduce pushing attention button command pcie/aer: helper functions for pcie aer capability pcie/aer: glue aer error injection into qemu monitor
ioh3420: support aer
x3130/upstream: support aer
x3130/downstream: support aer.

 Makefile.objs           |    3 +-
 hw/ioh3420.c            |  228 +++++++++++++
 hw/ioh3420.h            |   10 +
 hw/pci_bridge.c         |   48 +++-
 hw/pci_bridge.h         |    1 +
 hw/pcie.h               |   24 ++-
 hw/pcie_aer.c           |  864 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcie_aer.h           |  105 ++++++
 hw/pcie_port.c          |  198 +++++++++++
 hw/pcie_port.h          |   51 +++
 hw/xio3130_downstream.c |  195 +++++++++++
 hw/xio3130_downstream.h |   11 +
 hw/xio3130_upstream.c   |  179 ++++++++++
 hw/xio3130_upstream.h   |   10 +
 qemu-common.h           |    5 +
 qemu-monitor.hx         |   36 ++
 sysemu.h                |    9 +
 17 files changed, 1969 insertions(+), 8 deletions(-)
 create mode 100644 hw/ioh3420.c
 create mode 100644 hw/ioh3420.h
 create mode 100644 hw/pcie_aer.c
 create mode 100644 hw/pcie_aer.h
 create mode 100644 hw/pcie_port.c
 create mode 100644 hw/pcie_port.h
 create mode 100644 hw/xio3130_downstream.c
 create mode 100644 hw/xio3130_downstream.h
 create mode 100644 hw/xio3130_upstream.c
 create mode 100644 hw/xio3130_upstream.h
#1 lore raw

PATCH v6 1/12 pcie: comment on hpev_intx

document hpev_intx.

---
 hw/pcie.h |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
hw/pcie.h +9 -1
index 68327d8..2871e27 100644
@@ -65,7 +65,15 @@ struct PCIExpressDevice {
     /* TODO FLR */
 
     /* SLOT */
-    unsigned int hpev_intx;     /* INTx for hot plug event */
+    unsigned int hpev_intx;     /* INTx for hot plug event (0-3:INT[A-D]#)
+                                 * 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 */
Signature · 1 line
1.7.1.1
#2 lore raw

PATCH v6 2/12 pci/bridge: fix pci_bridge_reset()

In reply to Isaku Yamahata

The default value of base/limit registers aren't specified in the spec. So pci_bridge_reset() shouldn't touch them.
Instead, introduced two functions to reset those registers in a way of typical implementation. zero base/limit registers or disable forwarding. They will be used later.

---
Changes v5 -> v6:
- pci_bridge_disable_base_limit()

Changes v4 -> v5:
- drop the lines in pci_bridge_reset()
- introduced two functions to reset base/limit registers.

---
 hw/pci_bridge.c |   48 ++++++++++++++++++++++++++++++++++++++++++------
 hw/pci_bridge.h |    1 +
 2 files changed, 43 insertions(+), 6 deletions(-)
hw/pci_bridge.c +42 -6
index 638e3b3..7e8488a 100644
@@ -151,6 +151,26 @@ void pci_bridge_write_config(PCIDevice *d,
     }
 }
 
+void pci_bridge_disable_base_limit(PCIDevice *dev)
+{
+    uint8_t *conf = dev->config;
+
+    pci_byte_test_and_set_mask(conf + PCI_IO_BASE,
+                               PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_set_mask(conf + PCI_MEMORY_BASE,
+                               PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_set_mask(conf + PCI_PREF_MEMORY_BASE,
+                               PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
+    pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
+}
+
 /* reset bridge specific configuration registers */
 void pci_bridge_reset_reg(PCIDevice *dev)
 {
@@ -161,12 +181,28 @@ void pci_bridge_reset_reg(PCIDevice *dev)
     conf[PCI_SUBORDINATE_BUS] = 0;
     conf[PCI_SEC_LATENCY_TIMER] = 0;
 
-    conf[PCI_IO_BASE] = 0;
-    conf[PCI_IO_LIMIT] = 0;
-    pci_set_word(conf + PCI_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
+    /*
+     * the default values for base/limit registers aren't specified
+     * in the PCI-to-PCI-bridge spec. So we don't thouch them here.
+     * Each implementation can override it.
+     * typical implementation does
+     * zero base/limit registers or
+     * disable forwarding: pci_bridge_disable_base_limit()
+     * If disable forwarding is wanted, call pci_bridge_disable_base_limit()
+     * after this function.
+     */
+    pci_byte_test_and_clear_mask(conf + PCI_IO_BASE,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_BASE,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_BASE,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
     pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
     pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
 
hw/pci_bridge.h +1 -0
index f6fade0..84411a6 100644
@@ -39,6 +39,7 @@ pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
 
 void pci_bridge_write_config(PCIDevice *d,
                              uint32_t address, uint32_t val, int len);
+void pci_bridge_disable_base_limit(PCIDevice *dev);
 void pci_bridge_reset_reg(PCIDevice *dev);
 void pci_bridge_reset(DeviceState *qdev);
 
Signature · 1 line
1.7.1.1
#3 lore raw

[Qemu-devel] Re: [PATCH v6 02/12] pci/bridge: fix pci_bridge_reset()

Quoted 7 lines · Isaku Yamahata

The default value of base/limit registers aren't specified in the spec. So pci_bridge_reset() shouldn't touch them.
Instead, introduced two functions to reset those registers in a way of typical implementation. zero base/limit registers or disable forwarding. They will be used later.

The commit message seems to be out of date?

Quoted 92 lines

---
Changes v5 -> v6:
- pci_bridge_disable_base_limit()

Changes v4 -> v5:
- drop the lines in pci_bridge_reset()
- introduced two functions to reset base/limit registers.

---
 hw/pci_bridge.c |   48 ++++++++++++++++++++++++++++++++++++++++++------
 hw/pci_bridge.h |    1 +
 2 files changed, 43 insertions(+), 6 deletions(-)
hw/pci_bridge.c +42 -6
index 638e3b3..7e8488a 100644
@@ -151,6 +151,26 @@ void pci_bridge_write_config(PCIDevice *d,
     }
 }
 
+void pci_bridge_disable_base_limit(PCIDevice *dev)
+{
+    uint8_t *conf = dev->config;
+
+    pci_byte_test_and_set_mask(conf + PCI_IO_BASE,
+                               PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_set_mask(conf + PCI_MEMORY_BASE,
+                               PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_set_mask(conf + PCI_PREF_MEMORY_BASE,
+                               PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
+    pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
+}
+
 /* reset bridge specific configuration registers */
 void pci_bridge_reset_reg(PCIDevice *dev)
 {
@@ -161,12 +181,28 @@ void pci_bridge_reset_reg(PCIDevice *dev)
     conf[PCI_SUBORDINATE_BUS] = 0;
     conf[PCI_SEC_LATENCY_TIMER] = 0;
 
-    conf[PCI_IO_BASE] = 0;
-    conf[PCI_IO_LIMIT] = 0;
-    pci_set_word(conf + PCI_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
+    /*
+     * the default values for base/limit registers aren't specified
+     * in the PCI-to-PCI-bridge spec. So we don't thouch them here.
+     * Each implementation can override it.
+     * typical implementation does
+     * zero base/limit registers or
+     * disable forwarding: pci_bridge_disable_base_limit()
+     * If disable forwarding is wanted, call pci_bridge_disable_base_limit()
+     * after this function.
+     */
+    pci_byte_test_and_clear_mask(conf + PCI_IO_BASE,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_BASE,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_BASE,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
     pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
     pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
 
hw/pci_bridge.h +1 -0
index f6fade0..84411a6 100644
@@ -39,6 +39,7 @@ pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
 
 void pci_bridge_write_config(PCIDevice *d,
                              uint32_t address, uint32_t val, int len);
+void pci_bridge_disable_base_limit(PCIDevice *dev);
 void pci_bridge_reset_reg(PCIDevice *dev);
 void pci_bridge_reset(DeviceState *qdev);
 
Signature · 1 line
1.7.1.1
#4 lore raw

[Qemu-devel] Re: [PATCH v6 02/12] pci/bridge: fix pci_bridge_reset()

Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata

The default value of base/limit registers aren't specified in the spec. So pci_bridge_reset() shouldn't touch them.
Instead, introduced two functions to reset those registers in a way of typical implementation. zero base/limit registers or disable forwarding. They will be used later.

The commit message seems to be out of date?

Oops. Here's the update one. Only the commit log change. Should I resend the whole series?

Quoted 1 line

From a3e0fd4d19879156d40f87228d09c660fc512b16 Mon Sep 17 00:00:00 2001

Message-Id: <a3e0fd4d19879156d40f87228d09c660fc512b16.1287565438.git.yamahata@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Fri, 15 Oct 2010 19:33:50 +0900
Subject: [PATCH v6 02/12] pci/bridge: fix pci_bridge_reset()

The lower bits of base/limit registers is RO and shouldn't be zero cleared on reset. This patch fixes it.
In fact, the default value of base/limit registers aren't specified in the spec. And some bridges disable forwarding on reset instead of zeroing base/limit registers.
So introduce one function to disable bridge forwarding so that such bridges can use it. It will be used later.

---
Changes v5 -> v6:
- pci_bridge_disable_base_limit()

Changes v4 -> v5:
- drop the lines in pci_bridge_reset()
- introduced two functions to reset base/limit registers.

---
 hw/pci_bridge.c |   48 ++++++++++++++++++++++++++++++++++++++++++------
 hw/pci_bridge.h |    1 +
 2 files changed, 43 insertions(+), 6 deletions(-)
hw/pci_bridge.c +42 -6
index 638e3b3..7e8488a 100644
@@ -151,6 +151,26 @@ void pci_bridge_write_config(PCIDevice *d,
     }
 }
 
+void pci_bridge_disable_base_limit(PCIDevice *dev)
+{
+    uint8_t *conf = dev->config;
+
+    pci_byte_test_and_set_mask(conf + PCI_IO_BASE,
+                               PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_set_mask(conf + PCI_MEMORY_BASE,
+                               PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_set_mask(conf + PCI_PREF_MEMORY_BASE,
+                               PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
+    pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
+}
+
 /* reset bridge specific configuration registers */
 void pci_bridge_reset_reg(PCIDevice *dev)
 {
@@ -161,12 +181,28 @@ void pci_bridge_reset_reg(PCIDevice *dev)
     conf[PCI_SUBORDINATE_BUS] = 0;
     conf[PCI_SEC_LATENCY_TIMER] = 0;
 
-    conf[PCI_IO_BASE] = 0;
-    conf[PCI_IO_LIMIT] = 0;
-    pci_set_word(conf + PCI_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
-    pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
+    /*
+     * the default values for base/limit registers aren't specified
+     * in the PCI-to-PCI-bridge spec. So we don't thouch them here.
+     * Each implementation can override it.
+     * typical implementation does
+     * zero base/limit registers or
+     * disable forwarding: pci_bridge_disable_base_limit()
+     * If disable forwarding is wanted, call pci_bridge_disable_base_limit()
+     * after this function.
+     */
+    pci_byte_test_and_clear_mask(conf + PCI_IO_BASE,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT,
+                                 PCI_IO_RANGE_MASK & 0xff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_BASE,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT,
+                                 PCI_MEMORY_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_BASE,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
+    pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT,
+                                 PCI_PREF_RANGE_MASK & 0xffff);
     pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
     pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
 
hw/pci_bridge.h +1 -0
index f6fade0..84411a6 100644
@@ -39,6 +39,7 @@ pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type);
 
 void pci_bridge_write_config(PCIDevice *d,
                              uint32_t address, uint32_t val, int len);
+void pci_bridge_disable_base_limit(PCIDevice *dev);
 void pci_bridge_reset_reg(PCIDevice *dev);
 void pci_bridge_reset(DeviceState *qdev);
 
Signature · 6 lines
1.7.1.1



-- 
yamahata
#5 lore raw

[Qemu-devel] Re: [PATCH v6 02/12] pci/bridge: fix pci_bridge_reset()

Quoted 8 lines · Isaku Yamahata
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Isaku Yamahata

The default value of base/limit registers aren't specified in the spec. So pci_bridge_reset() shouldn't touch them.
Instead, introduced two functions to reset those registers in a way of typical implementation. zero base/limit registers or disable forwarding. They will be used later.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

The commit message seems to be out of date?

Oops. Here's the update one. Only the commit log change. Should I resend the whole series?

No, I can handle that.

#6 lore raw

PATCH v6 3/12 pcie port: define struct PCIEPort/PCIESlot and helper functions

In reply to Isaku Yamahata

define struct PCIEPort which represents common part
of pci express port.(root, upstream and downstream.) add a helper function for pcie port which can be used commonly by root/upstream/downstream port.
define struct PCIESlot which represents common part of pcie slot.(root and downstream.) and helper functions for it. helper functions for chassis, slot -> PCIESlot conversion.

---
Changes v4 -> v5:
- use pci_xxx_test_and_xxx_mask()

Changes v3 -> v4:
- Initialize prefetchable memory base/limit registers correctly. They must support 64bit.
- compilation adjustment.

Changes v2 -> v3:
- static'fy chassis.
- compilation adjustment.

---
 Makefile.objs  |    2 +-
 hw/pcie_port.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcie_port.h |   51 ++++++++++++++++++++++++
 qemu-common.h  |    2 +
 4 files changed, 170 insertions(+), 1 deletions(-)
 create mode 100644 hw/pcie_port.c
 create mode 100644 hw/pcie_port.h
Makefile.objs +1 -1
index eeb5134..c73d12b 100644
@@ -186,7 +186,7 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o
 # PCI watchdog devices
 hw-obj-y += wdt_i6300esb.o
 
-hw-obj-y += pcie.o
+hw-obj-y += pcie.o pcie_port.o
 hw-obj-y += msix.o msi.o
 
 # PCI network cards
hw/pcie_port.c new file +116 -0

116 lines not on this page · raw message

hw/pcie_port.h new file +51 -0

51 lines not on this page · raw message

qemu-common.h +2 -0
index 6d9ee26..b97b16e 100644
@@ -221,6 +221,8 @@ typedef struct PCIBus PCIBus;
 typedef struct PCIDevice PCIDevice;
 typedef struct PCIExpressDevice PCIExpressDevice;
 typedef struct PCIBridge PCIBridge;
+typedef struct PCIEPort PCIEPort;
+typedef struct PCIESlot PCIESlot;
 typedef struct SerialState SerialState;
 typedef struct IRQState *qemu_irq;
 typedef struct PCMCIACardState PCMCIACardState;
Signature · 1 line
1.7.1.1
#7 lore raw

PATCH v6 4/12 ioh3420: pcie root port in X58 ioh

In reply to Isaku Yamahata

Implements pcie root port switch in intel X58 ioh whose device id is 0x3420.

---
Changes v5 -> v6:
- compilation adjustment.
- eliminated aer bits.

Changes v4 -> v5:
- use pci_xxx_test_and_xxx_mask()

Changes v3 -> v4:
- rename pcie_root -> ioh3420
- compilation adjustment.

Changes v2 -> v3:
- compilation adjustment.

---
 Makefile.objs |    1 +
 hw/ioh3420.c  |  188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/ioh3420.h  |   10 +++
 3 files changed, 199 insertions(+), 0 deletions(-)
 create mode 100644 hw/ioh3420.c
 create mode 100644 hw/ioh3420.h
Makefile.objs +1 -0
index c73d12b..3a05322 100644
@@ -140,6 +140,7 @@ hw-obj-y =
 hw-obj-y += vl.o loader.o
 hw-obj-y += virtio.o virtio-console.o
 hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o pci_bridge.o
+hw-obj-y += ioh3420.o
 hw-obj-y += watchdog.o
 hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 hw-obj-$(CONFIG_ECC) += ecc.o
hw/ioh3420.c new file +188 -0

188 lines not on this page · raw message

hw/ioh3420.h new file +10 -0
new file mode 100644
index 0000000..68c523a
@@ -0,0 +1,10 @@
+#ifndef QEMU_IOH3420_H
+#define QEMU_IOH3420_H
+
+#include "pcie_port.h"
+
+PCIESlot *ioh3420_init(PCIBus *bus, int devfn, bool multifunction,
+                       const char *bus_name, pci_map_irq_fn map_irq,
+                       uint8_t port, uint8_t chassis, uint16_t slot);
+
+#endif /* QEMU_IOH3420_H */
Signature · 1 line
1.7.1.1
#8 lore raw

PATCH v6 5/12 x3130: pcie upstream port

In reply to Isaku Yamahata

Implement TI x3130 pcie upstream port switch.

---
Changes v5 -> v6:
- compilation adjustment.
- delete aer bits.

Changes v4 -> v5:
- remove flr related stuff.
This will be addressed at the next phase.
- use pci_xxx_test_and_xxx_mask().

Chnages v3 -> v4:
- rename pcie_upstream -> x3130_upstream.
- compilation adjustment.

Changes v2 -> v3:
- compilation adjustment.

---
 Makefile.objs         |    2 +-
 hw/xio3130_upstream.c |  174 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xio3130_upstream.h |   10 +++
 3 files changed, 185 insertions(+), 1 deletions(-)
 create mode 100644 hw/xio3130_upstream.c
 create mode 100644 hw/xio3130_upstream.h
Makefile.objs +1 -1
index 3a05322..b1ef2bb 100644
@@ -140,7 +140,7 @@ hw-obj-y =
 hw-obj-y += vl.o loader.o
 hw-obj-y += virtio.o virtio-console.o
 hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o pci_bridge.o
-hw-obj-y += ioh3420.o
+hw-obj-y += ioh3420.o xio3130_upstream.o
 hw-obj-y += watchdog.o
 hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 hw-obj-$(CONFIG_ECC) += ecc.o
hw/xio3130_upstream.c new file +174 -0

174 lines not on this page · raw message

hw/xio3130_upstream.h new file +10 -0
new file mode 100644
index 0000000..e996997
@@ -0,0 +1,10 @@
+#ifndef QEMU_XIO3130_UPSTREAM_H
+#define QEMU_XIO3130_UPSTREAM_H
+
+#include "pcie_port.h"
+
+PCIEPort *xio3130_upstream_init(PCIBus *bus, int devfn, bool multifunction,
+                                const char *bus_name, pci_map_irq_fn map_irq,
+                                uint8_t port);
+
+#endif /* QEMU_XIO3130_H */
Signature · 1 line
1.7.1.1
#9 lore raw

PATCH v6 6/12 x3130: pcie downstream port

In reply to Isaku Yamahata

Implement TI x3130 pcie downstream port switch.

---
Changes v5 -> v6:
- compilation adjustment.
- eliminate aer bits.

Changes v4 -> v5:
- use pci_xxx_test_and_xxx_mask().
- removed flr related stuff.

Changes v3 -> v4:
- rename: pcie_downstream -> x3130_downstream
- compilation adjustment.

Changes v2 -> v3:
- compilation adjustment.

---
 Makefile.objs           |    2 +-
 hw/xio3130_downstream.c |  190 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/xio3130_downstream.h |   11 +++
 3 files changed, 202 insertions(+), 1 deletions(-)
 create mode 100644 hw/xio3130_downstream.c
 create mode 100644 hw/xio3130_downstream.h
Makefile.objs +1 -1
index b1ef2bb..138e545 100644
@@ -140,7 +140,7 @@ hw-obj-y =
 hw-obj-y += vl.o loader.o
 hw-obj-y += virtio.o virtio-console.o
 hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o pci_bridge.o
-hw-obj-y += ioh3420.o xio3130_upstream.o
+hw-obj-y += ioh3420.o xio3130_upstream.o xio3130_downstream.o
 hw-obj-y += watchdog.o
 hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 hw-obj-$(CONFIG_ECC) += ecc.o
hw/xio3130_downstream.c new file +190 -0

190 lines not on this page · raw message

hw/xio3130_downstream.h new file +11 -0
new file mode 100644
index 0000000..010487f
@@ -0,0 +1,11 @@
+#ifndef QEMU_XIO3130_DOWNSTREAM_H
+#define QEMU_XIO3130_DOWNSTREAM_H
+
+#include "pcie_port.h"
+
+PCIESlot *xio3130_downstream_init(PCIBus *bus, int devfn, bool multifunction,
+                                  const char *bus_name, pci_map_irq_fn map_irq,
+                                  uint8_t port, uint8_t chassis,
+                                  uint16_t slot);
+
+#endif /* QEMU_XIO3130_DOWNSTREAM_H */
Signature · 1 line
1.7.1.1
#10 lore raw

PATCH v6 7/12 pcie/hotplug: introduce pushing attention button command

In reply to Isaku Yamahata

glue pcie_push_attention_button command.

---
 hw/pcie_port.c  |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx |   14 +++++++++
 sysemu.h        |    4 +++
 3 files changed, 100 insertions(+), 0 deletions(-)
hw/pcie_port.c +82 -0
index 117de61..f43a1c7 100644
@@ -18,6 +18,10 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu-objects.h"
+#include "sysemu.h"
+#include "monitor.h"
+#include "pcie.h"
 #include "pcie_port.h"
 
 void pcie_port_init_reg(PCIDevice *d)
@@ -114,3 +118,81 @@ void pcie_chassis_del_slot(PCIESlot *s)
 {
     QLIST_REMOVE(s, next);
 }
+
+/**************************************************************************
+ * glue for qemu monitor
+ */
+
+/* Parse [<chassis>.]<slot>, return -1 on error */
+static int pcie_parse_slot_addr(const char* slot_addr,
+                                uint8_t *chassisp, uint16_t *slotp)
+{
+    const char *p;
+    char *e;
+    unsigned long val;
+    unsigned long chassis = 0;
+    unsigned long slot;
+
+    p = slot_addr;
+    val = strtoul(p, &e, 0);
+    if (e == p) {
+        return -1;
+    }
+    if (*e == '.') {
+        chassis = val;
+        p = e + 1;
+        val = strtoul(p, &e, 0);
+        if (e == p) {
+            return -1;
+        }
+    }
+    slot = val;
+
+    if (*e) {
+        return -1;
+    }
+
+    if (chassis > 0xff || slot > 0xffff) {
+        return -1;
+    }
+
+    *chassisp = chassis;
+    *slotp = slot;
+    return 0;
+}
+
+void pcie_attention_button_push_print(Monitor *mon, const QObject *data)
+{
+    QDict *qdict;
+
+    assert(qobject_type(data) == QTYPE_QDICT);
+    qdict = qobject_to_qdict(data);
+
+    monitor_printf(mon, "OK chassis %d, slot %d\n",
+                   (int) qdict_get_int(qdict, "chassis"),
+                   (int) qdict_get_int(qdict, "slot"));
+}
+
+int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
+                               QObject **ret_data)
+{
+    const char* pcie_slot = qdict_get_str(qdict, "pcie_slot");
+    uint8_t chassis;
+    uint16_t slot;
+    PCIESlot *s;
+
+    if (pcie_parse_slot_addr(pcie_slot, &chassis, &slot) < 0) {
+        monitor_printf(mon, "invalid pcie slot address %s\n", pcie_slot);
+        return -1;
+    }
+    s = pcie_chassis_find_slot(chassis, slot);
+    if (!s) {
+        monitor_printf(mon, "slot is not found. %s\n", pcie_slot);
+        return -1;
+    }
+    pcie_cap_slot_push_attention_button(&s->port.br.dev);
+    *ret_data = qobject_from_jsonf("{ 'chassis': %d, 'slot': %d}",
+                                   chassis, slot);
+    assert(*ret_data);
+    return 0;
+}
qemu-monitor.hx +14 -0
index 2af3de6..965c754 100644
@@ -1154,6 +1154,20 @@ Hot remove PCI device.
 ETEXI
 
     {
+        .name       = "pcie_push_attention_button",
+        .args_type  = "pcie_slot:s",
+        .params     = "[<chassis>.]<slot>",
+        .help       = "push pci express attention button",
+        .user_print  = pcie_attention_button_push_print,
+        .mhandler.cmd_new = pcie_attention_button_push,
+    },
+
+STEXI
+@item pcie_abp
+Push PCI express attention button
+ETEXI
+
+    {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
         .params     = "tap|user|socket|vde|dump [options]",
sysemu.h +4 -0
index 9c988bb..cca411d 100644
@@ -150,6 +150,10 @@ extern unsigned int nb_prom_envs;
 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 hotplug */
+void pcie_attention_button_push_print(Monitor *mon, const QObject *data);
+int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
+                               QObject **ret_data);
 
 /* serial ports */
 
Signature · 1 line
1.7.1.1
#11 lore raw

[Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to think about how to tie this into pci_add/pci_del. Right?
As a low level command, this is not really useful unless there is an event on LED status change and a way to get info on LED status.
Right?

Quoted 145 lines
---
 hw/pcie_port.c  |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx |   14 +++++++++
 sysemu.h        |    4 +++
 3 files changed, 100 insertions(+), 0 deletions(-)
hw/pcie_port.c +82 -0
index 117de61..f43a1c7 100644
@@ -18,6 +18,10 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu-objects.h"
+#include "sysemu.h"
+#include "monitor.h"
+#include "pcie.h"
 #include "pcie_port.h"
 
 void pcie_port_init_reg(PCIDevice *d)
@@ -114,3 +118,81 @@ void pcie_chassis_del_slot(PCIESlot *s)
 {
     QLIST_REMOVE(s, next);
 }
+
+/**************************************************************************
+ * glue for qemu monitor
+ */
+
+/* Parse [<chassis>.]<slot>, return -1 on error */
+static int pcie_parse_slot_addr(const char* slot_addr,
+                                uint8_t *chassisp, uint16_t *slotp)
+{
+    const char *p;
+    char *e;
+    unsigned long val;
+    unsigned long chassis = 0;
+    unsigned long slot;
+
+    p = slot_addr;
+    val = strtoul(p, &e, 0);
+    if (e == p) {
+        return -1;
+    }
+    if (*e == '.') {
+        chassis = val;
+        p = e + 1;
+        val = strtoul(p, &e, 0);
+        if (e == p) {
+            return -1;
+        }
+    }
+    slot = val;
+
+    if (*e) {
+        return -1;
+    }
+
+    if (chassis > 0xff || slot > 0xffff) {
+        return -1;
+    }
+
+    *chassisp = chassis;
+    *slotp = slot;
+    return 0;
+}
+
+void pcie_attention_button_push_print(Monitor *mon, const QObject *data)
+{
+    QDict *qdict;
+
+    assert(qobject_type(data) == QTYPE_QDICT);
+    qdict = qobject_to_qdict(data);
+
+    monitor_printf(mon, "OK chassis %d, slot %d\n",
+                   (int) qdict_get_int(qdict, "chassis"),
+                   (int) qdict_get_int(qdict, "slot"));
+}
+
+int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
+                               QObject **ret_data)
+{
+    const char* pcie_slot = qdict_get_str(qdict, "pcie_slot");
+    uint8_t chassis;
+    uint16_t slot;
+    PCIESlot *s;
+
+    if (pcie_parse_slot_addr(pcie_slot, &chassis, &slot) < 0) {
+        monitor_printf(mon, "invalid pcie slot address %s\n", pcie_slot);
+        return -1;
+    }
+    s = pcie_chassis_find_slot(chassis, slot);
+    if (!s) {
+        monitor_printf(mon, "slot is not found. %s\n", pcie_slot);
+        return -1;
+    }
+    pcie_cap_slot_push_attention_button(&s->port.br.dev);
+    *ret_data = qobject_from_jsonf("{ 'chassis': %d, 'slot': %d}",
+                                   chassis, slot);
+    assert(*ret_data);
+    return 0;
+}
qemu-monitor.hx +14 -0
index 2af3de6..965c754 100644
@@ -1154,6 +1154,20 @@ Hot remove PCI device.
 ETEXI
 
     {
+        .name       = "pcie_push_attention_button",
+        .args_type  = "pcie_slot:s",
+        .params     = "[<chassis>.]<slot>",
+        .help       = "push pci express attention button",
+        .user_print  = pcie_attention_button_push_print,
+        .mhandler.cmd_new = pcie_attention_button_push,
+    },
+
+STEXI
+@item pcie_abp
+Push PCI express attention button
+ETEXI
+
+    {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
         .params     = "tap|user|socket|vde|dump [options]",
sysemu.h +4 -0
index 9c988bb..cca411d 100644
@@ -150,6 +150,10 @@ extern unsigned int nb_prom_envs;
 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 hotplug */
+void pcie_attention_button_push_print(Monitor *mon, const QObject *data);
+int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
+                               QObject **ret_data);
 
 /* serial ports */
 
Signature · 1 line
1.7.1.1
#12 lore raw

[Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to think about how to tie this into pci_add/pci_del. Right?

Maybe or maybe not.
I'm not sure it's a good idea to tie it to pci_add/pci_del in the first place.
The specification says only that pushing the button is just to initiate the hot-plug operation. It means only a notification. The spec says nothing about the concrete action from OS when the button is pushed. It's up to OS.

For example.
OS may start to probe the slot.
OS may start to quiescence the device.
OS is allowed to ignore the notification.
OS may propagate the notification to the management software, and it would pop up the dialog to the user for further operation.

Quoted 4 lines

As a low level command, this is not really useful unless there is an event on LED status change and a way to get info on LED status.
Right?

No. Guest OS can provide users those infos, and Linux does via sysfs. So there already is a way to know LED status. This is the reason why LED status change event stuff has low priority in my TODO list.

Signature · 1 line
yamahata
#13 lore raw

[Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 18 lines · Isaku Yamahata
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to think about how to tie this into pci_add/pci_del. Right?

Maybe or maybe not.
I'm not sure it's a good idea to tie it to pci_add/pci_del in the first place.
The specification says only that pushing the button is just to initiate the hot-plug operation. It means only a notification. The spec says nothing about the concrete action from OS when the button is pushed. It's up to OS.

Quoted 7 lines

For example.
OS may start to probe the slot.
OS may start to quiescence the device.
OS is allowed to ignore the notification.
OS may propagate the notification to the management software, and it would pop up the dialog to the user for further operation.

pci_add/pci_del really behave in the same way. There's no way to force the OS to respond. We only use ACPI for now, but for express I expect standard interfaces will work better long term.

Quoted 9 lines
Quoted 4 lines

As a low level command, this is not really useful unless there is an event on LED status change and a way to get info on LED status.
Right?

No. Guest OS can provide users those infos, and Linux does via sysfs. So there already is a way to know LED status. This is the reason why LED status change event stuff has low priority in my TODO list.

But that's in the guest.

Signature · 1 line
MST
#14 lore raw

[Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 27 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

Maybe or maybe not.
I'm not sure it's a good idea to tie it to pci_add/pci_del in the first place.
The specification says only that pushing the button is just to initiate the hot-plug operation. It means only a notification. The spec says nothing about the concrete action from OS when the button is pushed. It's up to OS.

Quoted 7 lines

For example.
OS may start to probe the slot.
OS may start to quiescence the device.
OS is allowed to ignore the notification.
OS may propagate the notification to the management software, and it would pop up the dialog to the user for further operation.

Quoted 3 lines

pci_add/pci_del really behave in the same way. There's no way to force the OS to respond. We only use ACPI for now, but for express I expect standard interfaces will work better long term.

The current qemu pci hot plug requires guest OS intervention as you said. On the other hand, The express hot plug doesn't requires the intervention. pci_add/pci_del for express simply populates/deletes PCIDvice (+ interrupt). No guest OS intervention. It really corresponds to physical insertion/removal of the pcie card into/from the slot.

Probably I don't understand what you mean by "tie it to pci_add/pci_del". The command shouldn't be express specific, but more generic? or something else?

Signature · 1 line
yamahata
#15 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

#16 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

Quoted 8 lines
Quoted 3 lines

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
#17 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 10 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Quoted 9 lines
Quoted 4 lines

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack

Is it a guest ack? I thought it was actually an eject that can be initiated without the notification being sent to the guest.

If so, polling doesn't really make much sense.

Regards,

Anthony Liguori

Quoted 10 lines

- way to poll status: did guest ack last command?

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

#18 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Markus Armbruster
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 4 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack

Is it a guest ack? I thought it was actually an eject that can be initiated without the notification being sent to the guest.

Yes.

Quoted 1 line

If so, polling doesn't really make much sense.

Who said something about polling?

Quoted 13 lines

Regards,

Anthony Liguori

Quoted 9 lines

- way to poll status: did guest ack last command?

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

#19 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

In reply to Michael S. Tsirkin
Quoted 17 lines · Michael S. Tsirkin
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

Quoted 8 lines
Quoted 3 lines

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding. The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
#20 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 18 lines · Isaku Yamahata
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding.

Your understanding is correct.

Quoted 39 lines

The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

Quoted 4 lines

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

Right. So what is suggested is that we have
A. a single command to push the attention button
B. a single command to remove pci card without guest OS interaction C. a way to interact with the guest
management tools or human monitor will be able to tie A,B,C together in various interesting ways

What I am also saying is that the same command should be able to work for pci and express I think.

Quoted 19 lines

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
#21 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 74 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding.

Your understanding is correct.

Quoted 39 lines

The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

Quoted 4 lines

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

Quoted 7 lines

Right. So what is suggested is that we have
A. a single command to push the attention button
B. a single command to remove pci card without guest OS interaction C. a way to interact with the guest
management tools or human monitor will be able to tie A,B,C together in various interesting ways

Makes sense. How about the following?

For A. => pci_push_attention_button command
qemu pci hot plug case: device_del/pci_del is internally aliased to
this command for compatibility.
pci express native hot plug case: this command is exposed to
the user as is.

For B. => pci_unplug command (or other better name?)
qemu pci hot plug case: -ENOSYS. (until someone implements it.) pci express native hot plug case: device_del/pci_del is internally
aliased to this command.

For C. => I'm not sure what kind of command is wanted. Any comments?
- new QMP/HMP command
enhance info pci command? or info pci-slot command? Probably we want to allow hot-plug controller specific infos.

- new QMP event
- LED change status
power led: on, off, blinking
attention led: on, off, blinking
- slot status change?
card: inserted, removed
electromechanical lock: engaged, un-engaged
Probably we want to allow events specific to the hot-plug controller.

- any other?

Quoted 2 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed. More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

thanks,

Quoted 20 lines
Quoted 19 lines

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
Signature · 1 line
yamahata
#22 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 95 lines · Isaku Yamahata
Quoted 74 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding.

Your understanding is correct.

Quoted 39 lines

The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

Quoted 4 lines

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

Quoted 7 lines

Right. So what is suggested is that we have
A. a single command to push the attention button
B. a single command to remove pci card without guest OS interaction C. a way to interact with the guest
management tools or human monitor will be able to tie A,B,C together in various interesting ways

Makes sense. How about the following?

For A. => pci_push_attention_button command
qemu pci hot plug case: device_del/pci_del is internally aliased to
this command for compatibility.
pci express native hot plug case: this command is exposed to
the user as is.

For B. => pci_unplug command (or other better name?)
qemu pci hot plug case: -ENOSYS. (until someone implements it.) pci express native hot plug case: device_del/pci_del is internally
aliased to this command.

Quoted 4 lines

For C. => I'm not sure what kind of command is wanted. Any comments?
- new QMP/HMP command
enhance info pci command? or info pci-slot command? Probably we want to allow hot-plug controller specific infos.

Yes. It probably does not matter which command this is.

Quoted 11 lines

- new QMP event
- LED change status
power led: on, off, blinking
attention led: on, off, blinking
- slot status change?
card: inserted, removed
electromechanical lock: engaged, un-engaged
Probably we want to allow events specific to the hot-plug controller.

- any other?

I am really interested in high level QMP event that tells us guest ejected the device.
This should work for pci and for express.
Low level stuff for led status etc is noce for a debugging, not really sure about value for users.

Quoted 6 lines
Quoted 4 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed.

Yes.

Quoted 14 lines

More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

Quoted 1 line

thanks,

Can we just use the topological address everywhere? Bus numbers are guest assigned, so we can not always rely on them. They are nice for human monitor though and should be way to get from them to topology and back.
And for bus 0 they are equivalent.

Quoted 23 lines
Quoted 20 lines
Quoted 19 lines

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
Signature · 1 line
yamahata
#23 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 113 lines · Michael S. Tsirkin
Quoted 95 lines · Isaku Yamahata
Quoted 74 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding.

Your understanding is correct.

Quoted 39 lines

The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

Quoted 4 lines

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

Quoted 7 lines

Right. So what is suggested is that we have
A. a single command to push the attention button
B. a single command to remove pci card without guest OS interaction C. a way to interact with the guest
management tools or human monitor will be able to tie A,B,C together in various interesting ways

Makes sense. How about the following?

For A. => pci_push_attention_button command
qemu pci hot plug case: device_del/pci_del is internally aliased to
this command for compatibility.
pci express native hot plug case: this command is exposed to
the user as is.

For B. => pci_unplug command (or other better name?)
qemu pci hot plug case: -ENOSYS. (until someone implements it.) pci express native hot plug case: device_del/pci_del is internally
aliased to this command.

Quoted 4 lines

For C. => I'm not sure what kind of command is wanted. Any comments?
- new QMP/HMP command
enhance info pci command? or info pci-slot command? Probably we want to allow hot-plug controller specific infos.

Yes. It probably does not matter which command this is.

Quoted 10 lines

- new QMP event
- LED change status
power led: on, off, blinking
attention led: on, off, blinking
- slot status change?
card: inserted, removed
electromechanical lock: engaged, un-engaged
Probably we want to allow events specific to the hot-plug controller.

Quoted 6 lines
Quoted 1 line

- any other?

I am really interested in high level QMP event that tells us guest ejected the device.
This should work for pci and for express.

Express doesn't have a way for OS to eject the device. Neither Standard pci hot plug.
So ejecting the device would be a event specific to qemu pci hot plug.

Quoted 26 lines

Low level stuff for led status etc is noce for a debugging, not really sure about value for users.

Quoted 6 lines
Quoted 4 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed.

Yes.

Quoted 14 lines

More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

Quoted 8 lines
Quoted 1 line

thanks,

Can we just use the topological address everywhere? Bus numbers are guest assigned, so we can not always rely on them. They are nice for human monitor though and should be way to get from them to topology and back.
And for bus 0 they are equivalent.

Yes, with some kind of conversion.
We could go with whichever addressing with (slight?) effort to implement conversion.
The point is what users(libvirt? virt-manager?) want.

thanks,

Quoted 24 lines
Quoted 23 lines
Quoted 20 lines
Quoted 19 lines

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
Signature · 1 line
yamahata
Signature · 1 line
yamahata
#24 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 117 lines · Isaku Yamahata
Quoted 116 lines · Michael S. Tsirkin
Quoted 95 lines · Isaku Yamahata
Quoted 74 lines · Michael S. Tsirkin
Quoted 18 lines · Isaku Yamahata
Quoted 17 lines · Michael S. Tsirkin
Quoted 15 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Isaku Yamahata

glue pcie_push_attention_button command.

So as a high level command, I think we need to
think about how to tie this into pci_add/pci_del.
Right?

[...]

Do we have consensus how our set of commands for hot plug should look like? We talked about it, but did we reach consensus? If yes, did we write it down somewhere?

Quoted 7 lines
Quoted 5 lines

I think for simple things yes:
- command to send hotplug notification to the guest
- command to immediately add/remove the device
- event to notify about guest ack
- way to poll status: did guest ack last command?

I'm not sure about guest ack. Let me check my understanding.

Your understanding is correct.

Quoted 39 lines

The current qemu pci hot plug has its own hot plug controler, PIIX4_PM, which relies on ACPI.

- command to add the device into the slot
This corresponds to physically inserting the device into the slot.
- qemu pci hot plug case: device_add/pci_add command.
The qemu pci hot plug controller, PIIX4_PM, detects the insertion, then notify the guest OS of the event via ACPI, _L01. The guest OS would start to probe the device.

- pci express native hot plug case: device_add/pci_add command. The pcie hot plug controller detects the the insertion, then notify the guest OS of the event via interrupt. The guest OS would start to probe the device.

- command to remove the device from the slot
This corresponds to physically removing the device from the slot.
- qemu pci hot plug case: No corresponding command. There is no way to remove the pci card forcibly from the slot.

- pci express native hot plug case: device_del/pci_del After the removal of the card, the hot plug controller notifies the guest OS via interrupt.

- command to send hotplug notification to the guest
command to push attention button.
This corresponds to pushing the button near the slot.
- qemu pci hot plug case: device_del/pci_del command
Maybe the button is called an eject button.
When the button is pushed, the hot plug controller notifies the guest OS via ACPI, _L01.
Then, guest OS reacts the event by calling ACPI \_SB.PCI0.S<n>._EJ0 method. It program the hot plug controller to eject the device in the given slot. As a result, the device is removed from the slot. If the guest OS doesn't call _EJ0 (nor programs the controller directly), the device stays there.
There is no way to remove the pci card without the guest OS intervention.

Quoted 4 lines

- pci express native hot plug case:
pcie_push_attention_button command with my patch series. The hot plug controller raise the interrupt to the guest OS. There is no specified action from the OS.

Quoted 7 lines

Right. So what is suggested is that we have
A. a single command to push the attention button
B. a single command to remove pci card without guest OS interaction C. a way to interact with the guest
management tools or human monitor will be able to tie A,B,C together in various interesting ways

Makes sense. How about the following?

For A. => pci_push_attention_button command
qemu pci hot plug case: device_del/pci_del is internally aliased to
this command for compatibility.
pci express native hot plug case: this command is exposed to
the user as is.

For B. => pci_unplug command (or other better name?)
qemu pci hot plug case: -ENOSYS. (until someone implements it.) pci express native hot plug case: device_del/pci_del is internally
aliased to this command.

Quoted 4 lines

For C. => I'm not sure what kind of command is wanted. Any comments?
- new QMP/HMP command
enhance info pci command? or info pci-slot command? Probably we want to allow hot-plug controller specific infos.

Yes. It probably does not matter which command this is.

Quoted 11 lines

- new QMP event
- LED change status
power led: on, off, blinking
attention led: on, off, blinking
- slot status change?
card: inserted, removed
electromechanical lock: engaged, un-engaged
Probably we want to allow events specific to the hot-plug controller.

- any other?

Quoted 7 lines
Quoted 3 lines

I am really interested in high level QMP event that tells us guest ejected the device.
This should work for pci and for express.

Express doesn't have a way for OS to eject the device. Neither Standard pci hot plug.
So ejecting the device would be a event specific to qemu pci hot plug.

Isn't this what LED is used for?

Quoted 69 lines
Quoted 26 lines

Low level stuff for led status etc is noce for a debugging, not really sure about value for users.

Quoted 6 lines
Quoted 4 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed.

Yes.

Quoted 14 lines

More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

Quoted 8 lines
Quoted 1 line

thanks,

Can we just use the topological address everywhere? Bus numbers are guest assigned, so we can not always rely on them. They are nice for human monitor though and should be way to get from them to topology and back.
And for bus 0 they are equivalent.

Yes, with some kind of conversion.
We could go with whichever addressing with (slight?) effort to implement conversion.
The point is what users(libvirt? virt-manager?) want.

thanks,

Quoted 24 lines
Quoted 23 lines
Quoted 20 lines
Quoted 19 lines

- a way to get the slot status
new command for QMP/HMP? or enhance info pci?

- QMP event for qemu to notify the slot status change e.g. when LED status is changed, qmp event will be sent.

Quoted 10 lines

Existing ones will keep function:
- send notification and when acked remove device
- add device and send notification
These are useful for human monitor but maybe not
for management.

Signature · 1 line
MST
Signature · 1 line
yamahata
Signature · 1 line
yamahata
Signature · 1 line
yamahata
#25 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

In reply to Isaku Yamahata
Quoted 30 lines · Isaku Yamahata
Quoted 21 lines
Quoted 4 lines
Quoted 2 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed.

Yes.

Quoted 14 lines

More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

Quoted 8 lines
Quoted 1 line

thanks,

Can we just use the topological address everywhere? Bus numbers are guest assigned, so we can not always rely on them. They are nice for human monitor though and should be way to get from them to topology and back.
And for bus 0 they are equivalent.

Quoted 4 lines

Yes, with some kind of conversion.
We could go with whichever addressing with (slight?) effort to implement conversion.
The point is what users(libvirt? virt-manager?) want.

When pushing the attention button, we are talking to the hot plug controller, not the device in the slot.
The button can be pushed even when the slot is empty.

In qemu pci hot plug case the button is used only for device ejection, so (segment, bus, device) triplet (or any address to specify the device in the slot) works.
But such address doesn't work for pcie case. (nor for standard pci hot plug case)
Address that will be used should be able to specify the slot itself without the device.

Signature · 1 line
yamahata
#26 lore raw

Re: [Qemu-devel] Re: [PATCH v6 07/12] pcie/hotplug: introduce pushing attention button command

Quoted 40 lines · Isaku Yamahata
Quoted 30 lines · Isaku Yamahata
Quoted 21 lines
Quoted 4 lines
Quoted 2 lines

What I am also saying is that the same command should be able to work for pci and express I think.

I see. Then, I think that the slot numbering needs to be discussed.

Yes.

Quoted 14 lines

More concretely, it's what type of argument is passed for push attention button command.
Here the slot number in general means that the number that is printed near the physical slot. Not pci (segment, bus, device) triplets.

The current qemu pci hot plug abuses the triplets as the slot number with the assumption of (segment = 0, bus = 0, device = slot number). On the other hand, pcie hot plug has its own scheme to number the slots. The correspondence between the triplets and the slot is provided to the OS. (The standard pci hot plug has its own too which is different from the pcie one.)
So users may want to operate with the slot number.
User's opinions are needed. Any comments?

Quoted 8 lines
Quoted 1 line

thanks,

Can we just use the topological address everywhere? Bus numbers are guest assigned, so we can not always rely on them. They are nice for human monitor though and should be way to get from them to topology and back.
And for bus 0 they are equivalent.

Quoted 4 lines

Yes, with some kind of conversion.
We could go with whichever addressing with (slight?) effort to implement conversion.
The point is what users(libvirt? virt-manager?) want.

When pushing the attention button, we are talking to the hot plug controller, not the device in the slot.
The button can be pushed even when the slot is empty.

Quoted 7 lines

In qemu pci hot plug case the button is used only for device ejection, so (segment, bus, device) triplet (or any address to specify the device in the slot) works.
But such address doesn't work for pcie case. (nor for standard pci hot plug case)
Address that will be used should be able to specify the slot itself without the device.

Not sure I understand. The device number is the number of the slot on the bus anyway, isn't it? The only issue is that the bus must be specified by the topology used to reach it, not bus number since that is guest assigned expect for the root which is always 0.

Quoted 2 lines
Signature · 1 line
yamahata
#27 lore raw

PATCH v6 8/12 pcie/aer: helper functions for pcie aer capability

In reply to Isaku Yamahata

This patch implements helper functions for pcie aer capability which will be used later.

---
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 |  780 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcie_aer.h |  105 ++++++++
 qemu-common.h |    3 +
 5 files changed, 903 insertions(+), 1 deletions(-)
 create mode 100644 hw/pcie_aer.c
 create mode 100644 hw/pcie_aer.h
Makefile.objs +1 -1
index 138e545..48f98f3 100644
@@ -187,7 +187,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
index 2871e27..415a680 100644
@@ -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 */
@@ -74,6 +75,19 @@ struct PCIExpressDevice {
                                  * also initialize it when loaded as
                                  * appropreately.
                                  */
+
+    /* 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 +780 -0

780 lines not on this page · raw message

hw/pcie_aer.h new file +105 -0

105 lines not on this page · raw message

qemu-common.h +3 -0
index b97b16e..63ee8c3 100644
@@ -221,6 +221,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
#28 lore raw

[Qemu-devel] Re: [PATCH v6 08/12] 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.

Some style comments and a couple of minor bugs.

Quoted 120 lines

---
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 |  780 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcie_aer.h |  105 ++++++++
 qemu-common.h |    3 +
 5 files changed, 903 insertions(+), 1 deletions(-)
 create mode 100644 hw/pcie_aer.c
 create mode 100644 hw/pcie_aer.h
Makefile.objs +1 -1
index 138e545..48f98f3 100644
@@ -187,7 +187,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
index 2871e27..415a680 100644
@@ -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 */
@@ -74,6 +75,19 @@ struct PCIExpressDevice {
                                  * also initialize it when loaded as
                                  * appropreately.
                                  */
+
+    /* 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 +36 -0
new file mode 100644
index 0000000..b8cede3
@@ -0,0 +1,780 @@
+/*
+ * pcie_aer.c
+ *
+ * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
+ *                    VA Linux Systems Japan K.K.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "sysemu.h"
+#include "pci_bridge.h"
+#include "pcie.h"
+#include "msix.h"
+#include "msi.h"
+#include "pci_internals.h"
+#include "pcie_regs.h"
+
+//#define DEBUG_PCIE
+#ifdef DEBUG_PCIE
+# define PCIE_DPRINTF(fmt, ...)                                         \
+    fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__)
+#else
+# define PCIE_DPRINTF(fmt, ...) do {} while (0)
+#endif
+#define PCIE_DEV_PRINTF(dev, fmt, ...)                                  \

hw/pcie_aer.c line 46

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__)
+
+static void pcie_aer_clear_error(PCIDevice *dev);
+static uint8_t pcie_aer_root_get_vector(PCIDevice *dev);
+static AERMsgResult
+pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg);
+static AERMsgResult
+pcie_aer_msg_vbridge(PCIDevice *dev, const PCIEAERMsg *msg);
+static AERMsgResult
+pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg);

Just make the above bool, e.g. true if sent?

Also don't forward declare static functions. Just order them properly in the file.

Quoted 25 lines
hw/pcie_aer.c new file +25 -0
+
+/* From 6.2.7 Error Listing and Rules. Table 6-2, 6-3 and 6-4 */
+static PCIEAERSeverity pcie_aer_uncor_default_severity(uint32_t status)
+{
+    switch (status) {
+    case PCI_ERR_UNC_INTN:
+    case PCI_ERR_UNC_DLP:
+    case PCI_ERR_UNC_SDN:
+    case PCI_ERR_UNC_RX_OVER:
+    case PCI_ERR_UNC_FCP:
+    case PCI_ERR_UNC_MALF_TLP:
+        return AER_ERR_FATAL;
+    case PCI_ERR_UNC_POISON_TLP:
+    case PCI_ERR_UNC_ECRC:
+    case PCI_ERR_UNC_UNSUP:
+    case PCI_ERR_UNC_COMP_TIME:
+    case PCI_ERR_UNC_COMP_ABORT:
+    case PCI_ERR_UNC_UNX_COMP:
+    case PCI_ERR_UNC_ACSV:
+    case PCI_ERR_UNC_MCBTLP:
+    case PCI_ERR_UNC_ATOP_EBLOCKED:
+    case PCI_ERR_UNC_TLP_PRF_BLOCKED:
+        return AER_ERR_NONFATAL;
+    default:
+        break;

hw/pcie_aer.c line 81

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    }
+    abort();
+    return AER_ERR_FATAL;
+}
+
+static uint32_t aer_log_next(uint32_t i, uint32_t max)
+{
+    return (i + 1) % max;
+}
+

Pass in PCIEAERLog* as 1st parameter instead of max. This way we get it right.

hw/pcie_aer.c line 86

Quoted 5 lines
hw/pcie_aer.c new file +5 -0
+static bool aer_log_empty_index(uint32_t producer, uint32_t consumer)
+{
+    return producer == consumer;
+}
+

This one is better opencoded.

Quoted 14 lines
hw/pcie_aer.c new file +14 -0
+static bool aer_log_empty(PCIEAERLog *aer_log)
+{
+    return aer_log_empty_index(aer_log->producer, aer_log->consumer);
+}
+
+static bool aer_log_full(PCIEAERLog *aer_log)
+{
+    return aer_log_next(aer_log->producer, aer_log->log_max) ==
+        aer_log->consumer;
+}
+
+static uint32_t aer_log_add(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->producer;

hw/pcie_aer.c line 110

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    aer_log->producer = aer_log_next(aer_log->producer, aer_log->log_max);
+    return i;
+}
+
+static uint32_t aer_log_del(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->consumer;
+    aer_log->consumer = aer_log_next(aer_log->consumer, aer_log->log_max);
+    return i;
+}

Please just use 'int' or 'unsigned' instead of uint32_t if you simply want to say 'a number'. Using specific length makes it impossible to say where you *really* want a value.

hw/pcie_aer.c line 119

Quoted 9 lines
hw/pcie_aer.c new file +9 -0
+
+static int aer_log_add_err(PCIEAERLog *aer_log, const PCIEAERErr *err)
+{
+    uint32_t i;
+    if (aer_log_full(aer_log)) {
+        return -1;
+    }
+    i = aer_log_add(aer_log);
+    memcpy(&aer_log->log[i], err, sizeof(*err));

sizeof is not a function, you don't need ()

Quoted 90 lines
hw/pcie_aer.c new file +90 -0
+    return 0;
+}
+
+static const PCIEAERErr* aer_log_del_err(PCIEAERLog *aer_log)
+{
+    uint32_t i;
+    assert(!aer_log_empty(aer_log));
+    i = aer_log_del(aer_log);
+    return &aer_log->log[i];
+}
+
+static void aer_log_clear_all_err(PCIEAERLog *aer_log)
+{
+    aer_log->producer = 0;
+    aer_log->consumer = 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);
+
+    pcie_add_capability(dev, PCI_EXT_CAP_ID_ERR, PCI_ERR_VER,
+                        offset, PCI_ERR_SIZEOF);
+    exp = &dev->exp;
+    exp->aer_cap = offset;
+    if (dev->exp.aer_log.log_max == PCIE_AER_LOG_MAX_UNSET) {
+        dev->exp.aer_log.log_max = PCIE_AER_LOG_MAX_DEFAULT;
+    }
+    if (dev->exp.aer_log.log_max > PCIE_AER_LOG_MAX_MAX) {
+        dev->exp.aer_log.log_max = PCIE_AER_LOG_MAX_MAX;
+    }
+    dev->exp.aer_log.log = qemu_mallocz(sizeof(dev->exp.aer_log.log[0]) *
+                                        dev->exp.aer_log.log_max);
+
+    /* On reset PCI_ERR_CAP_MHRE is disabled
+     * PCI_ERR_CAP_MHRE is RWS so that reset doesn't affect related
+     * registers
+     */
+    pci_set_long(dev->w1cmask + offset + PCI_ERR_UNCOR_STATUS,
+                 PCI_ERR_UNC_SUPPORTED);
+
+    pci_set_long(dev->config + offset + PCI_ERR_UNCOR_SEVER,
+                 PCI_ERR_UNC_SEVERITY_DEFAULT);
+    pci_set_long(dev->wmask + offset + PCI_ERR_UNCOR_SEVER,
+                 PCI_ERR_UNC_SUPPORTED);
+
+    pci_long_test_and_set_mask(dev->w1cmask + offset + PCI_ERR_COR_STATUS,
+                               PCI_ERR_COR_STATUS);
+
+    pci_set_long(dev->config + offset + PCI_ERR_COR_MASK,
+                 PCI_ERR_COR_MASK_DEFAULT);
+    pci_set_long(dev->wmask + offset + PCI_ERR_COR_MASK,
+                 PCI_ERR_COR_SUPPORTED);
+
+    /* capabilities and control. multiple header logging is supported */
+    if (dev->exp.aer_log.log_max > 0) {
+        pci_set_long(dev->config + offset + PCI_ERR_CAP,
+                     PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC |
+                     PCI_ERR_CAP_MHRC);
+        pci_set_long(dev->wmask + offset + PCI_ERR_CAP,
+                     PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE |
+                     PCI_ERR_CAP_MHRE);
+    } else {
+        pci_set_long(dev->config + offset + PCI_ERR_CAP,
+                     PCI_ERR_CAP_ECRC_GENC | PCI_ERR_CAP_ECRC_CHKC);
+        pci_set_long(dev->wmask + offset + PCI_ERR_CAP,
+                     PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
+    }
+
+    switch (pcie_cap_get_type(dev)) {
+    case PCI_EXP_TYPE_ROOT_PORT:
+        /* this case will be set by pcie_aer_root_init() */
+        /* fallthrough */
+    case PCI_EXP_TYPE_DOWNSTREAM:
+    case PCI_EXP_TYPE_UPSTREAM:
+        pci_word_test_and_set_mask(dev->wmask + PCI_BRIDGE_CONTROL,
+                                   PCI_BRIDGE_CTL_SERR);
+        pci_long_test_and_set_mask(dev->w1cmask + PCI_STATUS,
+                                   PCI_SEC_STATUS_RCV_SYSTEM_ERROR);
+        break;
+    default:
+        /* nothing */
+        break;
+    }
+}
+

hw/pcie_aer.c line 219

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+void pcie_aer_exit(PCIDevice *dev)
+{
+    qemu_free(dev->exp.aer_log.log);
+}
+
+void pcie_aer_write_config(PCIDevice *dev,
+                           uint32_t addr, uint32_t val, int len,
+                           uint32_t uncorsta_old)
+{
+    uint32_t pos = dev->exp.aer_cap;

dev->config + pos would be a better variable to use.

hw/pcie_aer.c line 227

Quoted 8 lines
hw/pcie_aer.c new file +8 -0
+    uint32_t errcap = pci_get_long(dev->config + pos + PCI_ERR_CAP);
+    uint32_t first_error = 1U << PCI_ERR_CAP_FEP(errcap);
+    uint32_t uncorsta = pci_get_long(dev->config + pos + PCI_ERR_UNCOR_STATUS);
+
+    /* uncorrectable error */
+    if ((uncorsta_old & first_error) && !(uncorsta & first_error)) {
+        /* the bit that corresponds to the first error is cleared */
+        pcie_aer_clear_error(dev);

So why not just call this unconditionally?

hw/pcie_aer.c line 233

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+    } else if (errcap & PCI_ERR_CAP_MHRE) {
+        /* When PCI_ERR_CAP_MHRE is enabled and the first error isn't cleared
+         * nothing should happen. So we have to revert the modification to
+         * the register.
+         */
+        pci_set_long(dev->config + pos + PCI_ERR_UNCOR_STATUS, uncorsta_old);

Why do we need uncorsta_old? Why can't we get the info from the log?

hw/pcie_aer.c line 237

Quoted 4 lines
hw/pcie_aer.c new file +4 -0
+    }
+
+    /* capability & control */
+    if (ranges_overlap(addr, len, pos + PCI_ERR_CAP, 4)) {

I can not figure this out. What does this range check do? And why use capability number as offset?

hw/pcie_aer.c line 238

Quoted 1 line
hw/pcie_aer.c new file +1 -0
+        if (!(errcap & PCI_ERR_CAP_MHRE)) {

also checking twise is ugly.

Quoted 25 lines
hw/pcie_aer.c new file +25 -0
+            aer_log_clear_all_err(&dev->exp.aer_log);
+        }
+    }
+}
+
+static inline void pcie_aer_msg(PCIDevice *dev, const PCIEAERMsg *msg)
+{
+    uint8_t type;
+    AERMsgResult result;
+
+    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) {
+        result = pcie_aer_msg_vbridge(dev, msg);
+        if (result != AER_MSG_SENT) {
+            return;
+        }
+    }
+    result = pcie_aer_msg_alldev(dev, msg);
+    if (type == PCI_EXP_TYPE_ROOT_PORT && result == AER_MSG_SENT) {
+        pcie_aer_msg_root_port(dev, msg);
+    }

hw/pcie_aer.c line 273

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+}
+
+static AERMsgResult
+pcie_aer_msg_alldev(PCIDevice *dev, const PCIEAERMsg *msg)
+{
+    uint16_t cmd = pci_get_word(dev->config + PCI_COMMAND);
+    bool transmit1 =
+        pcie_aer_msg_is_uncor(msg) && (cmd & PCI_COMMAND_SERR);
+    uint32_t devctl = pci_get_word(dev->config +
+                                   dev->exp.exp_cap + PCI_EXP_DEVCTL);

Word is uint16, so devctl should be too.

Quoted 125 lines
hw/pcie_aer.c new file +125 -0
+    bool transmit2 = msg->severity & devctl;
+    PCIDevice *parent_port;
+
+    if (transmit1) {
+        if (pcie_aer_msg_is_uncor(msg)) {
+            /* Signaled System Error */
+            pci_word_test_and_set_mask(dev->config + PCI_STATUS,
+                                       PCI_STATUS_SIG_SYSTEM_ERROR);
+        }
+    }
+
+    if (!(transmit1 || transmit2)) {
+        return AER_MSG_MASKED;
+    }
+
+    /* send up error message */
+    if (pci_is_express(dev) &&
+        pcie_cap_get_type(dev) == PCI_EXP_TYPE_ROOT_PORT) {
+        /* Root port 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
+         * 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)) {
+            /* What to do? */
+            return AER_MSG_MASKED;
+        }
+        pcie_aer_msg(parent_port, msg);
+    }
+    return AER_MSG_SENT;
+}
+
+static AERMsgResult
+pcie_aer_msg_vbridge(PCIDevice *dev, const PCIEAERMsg *msg)
+{
+    uint16_t bridge_control = pci_get_word(dev->config + PCI_BRIDGE_CONTROL);
+
+    if (pcie_aer_msg_is_uncor(msg)) {
+        /* Received System Error */
+        pci_word_test_and_set_mask(dev->config + PCI_SEC_STATUS,
+                                   PCI_SEC_STATUS_RCV_SYSTEM_ERROR);
+    }
+
+    if (!(bridge_control & PCI_BRIDGE_CTL_SERR)) {
+        return AER_MSG_MASKED;
+    }
+    return AER_MSG_SENT;
+}
+
+static AERMsgResult
+pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)
+{
+    AERMsgResult ret;
+    uint16_t cmd;
+    uint8_t *aer_cap;
+    uint32_t root_cmd;
+    uint32_t root_sta;
+    bool msi_trigger;
+
+    ret = AER_MSG_MASKED;
+    cmd = pci_get_word(dev->config + PCI_COMMAND);
+    aer_cap = dev->config + dev->exp.aer_cap;
+    root_cmd = pci_get_long(aer_cap + PCI_ERR_ROOT_COMMAND);
+    root_sta = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS);
+    msi_trigger = false;
+
+    if (cmd & PCI_COMMAND_SERR) {
+        /* System Error. Platform Specific */
+        /* ret = AER_MSG_SENT; */
+    }
+
+    /* Errro Message Received: Root Error Status register */
+    switch (msg->severity) {
+    case AER_ERR_COR:
+        if (root_sta & PCI_ERR_ROOT_COR_RCV) {
+            root_sta |= PCI_ERR_ROOT_MULTI_COR_RCV;
+        } else {
+            if (root_cmd & PCI_ERR_ROOT_CMD_COR_EN) {
+                msi_trigger = true;
+            }
+            pci_set_word(aer_cap + PCI_ERR_ROOT_COR_SRC, msg->source_id);
+        }
+        root_sta |= PCI_ERR_ROOT_COR_RCV;
+        break;
+    case AER_ERR_NONFATAL:
+        if (!(root_sta & PCI_ERR_ROOT_NONFATAL_RCV) &&
+            root_cmd & PCI_ERR_ROOT_CMD_NONFATAL_EN) {
+            msi_trigger = true;
+        }
+        root_sta |= PCI_ERR_ROOT_NONFATAL_RCV;
+        break;
+    case AER_ERR_FATAL:
+        if (!(root_sta & PCI_ERR_ROOT_FATAL_RCV) &&
+            root_cmd & PCI_ERR_ROOT_CMD_FATAL_EN) {
+            msi_trigger = true;
+        }
+        if (!(root_sta & PCI_ERR_ROOT_UNCOR_RCV)) {
+            root_sta |= PCI_ERR_ROOT_FIRST_FATAL;
+        }
+        root_sta |= PCI_ERR_ROOT_FATAL_RCV;
+        break;
+    }
+    if (pcie_aer_msg_is_uncor(msg)) {
+        if (root_sta & PCI_ERR_ROOT_UNCOR_RCV) {
+            root_sta |= PCI_ERR_ROOT_MULTI_UNCOR_RCV;
+        } else {
+            pci_set_word(aer_cap + PCI_ERR_ROOT_SRC, msg->source_id);
+        }
+        root_sta |= PCI_ERR_ROOT_UNCOR_RCV;
+    }
+    pci_set_long(aer_cap + PCI_ERR_ROOT_STATUS, root_sta);
+
+    if (root_cmd & msg->severity) {
+        /* 6.2.4.1.2 Interrupt Generation */
+        if (pci_msi_enabled(dev)) {
+            pci_msi_notify(dev, pcie_aer_root_get_vector(dev));
+        } else {
+            qemu_set_irq(dev->irq[dev->exp.aer_intx], 1);

hw/pcie_aer.c line 408

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+        }
+        ret = AER_MSG_SENT;
+    }
+    return ret;
+}
+
+static void pcie_aer_update_log(PCIDevice *dev, const PCIEAERErr *err)
+{
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+    uint8_t first_bit = ffsl(err->status) - 1;

What guarantees err->status is not 0 here?

hw/pcie_aer.c line 421

Quoted 13 lines
hw/pcie_aer.c new file +13 -0
+    uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP);
+    int i;
+    uint32_t dw;
+
+    errcap &= ~(PCI_ERR_CAP_FEP_MASK | PCI_ERR_CAP_TLP);
+    errcap |= PCI_ERR_CAP_FEP(first_bit);
+
+    if (err->flags & PCIE_AER_ERR_HEADER_VALID) {
+        for (i = 0; i < ARRAY_SIZE(err->header); ++i) {
+            /* 7.10.8 Header Log Register */
+            cpu_to_be32wu(&dw, err->header[i]);
+            memcpy(aer_cap + PCI_ERR_HEADER_LOG + sizeof(err->header[0]) * i,
+                   &dw, sizeof(dw));

memcpy into config space is almost sure to be wrong on BE hosts. Please fill all fields with appropriate pci_ macros.
This also ensures you don't depend on specific layout for correctness.

sizeof(err->header) is confusing here. Please just use a macro.

hw/pcie_aer.c line 425

Quoted 4 lines
hw/pcie_aer.c new file +4 -0
+        }
+    } else {
+        assert(!(err->flags & PCIE_AER_ERR_TLP_PRESENT));
+        memset(aer_cap + PCI_ERR_HEADER_LOG, 0, sizeof(err->header));

sizeof(err->header) is confusing here. Please just use a macro.

hw/pcie_aer.c line 435

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    }
+
+    if ((err->flags & PCIE_AER_ERR_TLP_PRESENT) &&
+        (pci_get_long(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2) &
+         PCI_EXP_DEVCAP2_EETLPP)) {
+        for (i = 0; i < ARRAY_SIZE(err->prefix); ++i) {
+            /* 7.10.12 tlp prefix log register */
+            cpu_to_be32wu(&dw, err->prefix[i]);
+            memcpy(aer_cap + PCI_ERR_TLP_PREFIX_LOG +
+                   sizeof(err->prefix[0]) * i, &dw, sizeof(dw));

as above

Quoted 8 lines
hw/pcie_aer.c new file +8 -0
+        }
+        errcap |= PCI_ERR_CAP_TLP;
+    } else {
+        memset(aer_cap + PCI_ERR_TLP_PREFIX_LOG, 0, sizeof(err->prefix));
+    }
+    pci_set_long(aer_cap + PCI_ERR_CAP, errcap);
+}
+

hw/pcie_aer.c line 453

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+static void pcie_aer_clear_log(PCIDevice *dev)
+{
+    PCIEAERErr *err;
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+
+    pci_long_test_and_clear_mask(aer_cap + PCI_ERR_CAP,
+                                 PCI_ERR_CAP_FEP_MASK | PCI_ERR_CAP_TLP);
+
+    memset(aer_cap + PCI_ERR_HEADER_LOG, 0, sizeof(err->header));
+    memset(aer_cap + PCI_ERR_TLP_PREFIX_LOG, 0, sizeof(err->prefix));

So err is in fact unused?

This assumes that layout for PCIEAERErr matches config space. This will lead with time to attempts to copy structure directly. This is wrong e.g. because of endianness. Please don't do these tricks: just a macro defining size will be enough.

hw/pcie_aer.c line 464

Quoted 11 lines
hw/pcie_aer.c new file +11 -0
+}
+
+static int pcie_aer_record_error(PCIDevice *dev,
+                                 const PCIEAERErr *err)
+{
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+    uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP);
+    int fep = PCI_ERR_CAP_FEP(errcap);
+
+    if (errcap & PCI_ERR_CAP_MHRE &&
+        (pci_get_long(aer_cap + PCI_ERR_UNCOR_STATUS) & (1ULL << fep))) {

get_long returns 32 bit
1ULL gives you 64 bit
So why bother with it?
Looking at code fep is 0 to 31, so 1U would be what you want.

Quoted 19 lines
hw/pcie_aer.c new file +19 -0
+        /*  Not first error. queue error */
+        if (aer_log_add_err(&dev->exp.aer_log, err) < 0) {
+            /* overflow */
+            return -1;
+        }
+        return 0;
+    }
+
+    pcie_aer_update_log(dev, err);
+    return 0;
+}
+
+static void pcie_aer_clear_error(PCIDevice *dev)
+{
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+    uint32_t errcap = pci_get_long(aer_cap + PCI_ERR_CAP);
+    PCIEAERLog *aer_log = &dev->exp.aer_log;
+    const PCIEAERErr *err;
+    uint32_t consumer;

hw/pcie_aer.c line 493

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+
+    if (!(errcap & PCI_ERR_CAP_MHRE) || aer_log_empty(aer_log)) {
+        pcie_aer_clear_log(dev);
+        return;
+    }
+
+    /*
+     * If more errors are queued, set corresponding bits in uncorrectable
+     * error status.
+     * We emulates uncorrectable error status register as W1CS.

We emulate

Quoted 14 lines
hw/pcie_aer.c new file +14 -0
+     * So set bit in uncorrectable error status here again for multiple
+     * error recording support.
+     *
+     * 6.2.4.2 Multiple Error Handling(Advanced Error Reporting Capability)
+     */
+    for (consumer = dev->exp.aer_log.consumer;
+         !aer_log_empty_index(dev->exp.aer_log.producer, consumer);
+         consumer = aer_log_next(consumer, dev->exp.aer_log.log_max)) {
+        pci_long_test_and_set_mask(aer_cap + PCI_ERR_UNCOR_STATUS,
+                                   dev->exp.aer_log.log[consumer].status);
+    }
+
+    err = aer_log_del_err(aer_log);
+    pcie_aer_update_log(dev, err);

hw/pcie_aer.c line 517

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+}
+
+/*
+ * non-Function specific error must be recorded in all functions.
+ * It is the responsibility of the caller of this function.
+ * It is also caller's responsiblity to determine which function should
+ * report the rerror.
+ *
+ * 6.2.4 Error Logging
+ * 6.2.5 Sqeucne of Device Error Signaling and Logging Operations

typo?

hw/pcie_aer.c line 522

Quoted 5 lines
hw/pcie_aer.c new file +5 -0
+ * table 6-2: Flowchard Showing Sequence of Device Error Signaling and Logging
+ *            Operations
+ *
+ * Although this implementation can be shortened/optimized, this is kept
+ * parallel to table 6-2.

Yes but this does not mean this can not be split up into subfunctions.

Quoted 9 lines
hw/pcie_aer.c new file +9 -0
+ */
+void pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err)
+{
+    uint8_t *exp_cap;
+    uint8_t *aer_cap = NULL;
+    uint32_t devctl = 0;
+    uint32_t devsta = 0;
+    uint32_t status = err->status;
+    uint32_t mask;

hw/pcie_aer.c line 541

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    bool is_unsupported_request =
+        (!(err->flags & PCIE_AER_ERR_IS_CORRECTABLE) &&
+         err->status == PCI_ERR_UNC_UNSUP);
+    bool is_advisory_nonfatal = false;  /* for advisory non-fatal error */
+    uint32_t uncor_status = 0;          /* for advisory non-fatal error */
+    PCIEAERMsg msg;
+    int is_header_log_overflowed = 0;
+
+    if (!pci_is_express(dev)) {
+        /* What to do? */

This is used from command, right?
So return error?

hw/pcie_aer.c line 550

Quoted 9 lines
hw/pcie_aer.c new file +9 -0
+        return;
+    }
+
+    if (err->flags & PCIE_AER_ERR_IS_CORRECTABLE) {
+        status &= PCI_ERR_COR_SUPPORTED;
+    } else {
+        status &= PCI_ERR_UNC_SUPPORTED;
+    }
+    if (!status || status & (status - 1)) {

So you want to rely on & being higher precedence than && or not? I prefer when we do, use less (), but the rest of the file seems to use (). Let's be consistent.

hw/pcie_aer.c line 551

Quoted 1 line
hw/pcie_aer.c new file +1 -0
+        /* invalid status bit. one and only one bit must be set */

Pls put comments on same or above lines as the code, not after :)

hw/pcie_aer.c line 552

Quoted 1 line
hw/pcie_aer.c new file +1 -0
+        return;

So return error?

hw/pcie_aer.c line 562

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    }
+
+    exp_cap = dev->config + dev->exp.exp_cap;
+    if (dev->exp.aer_cap) {
+        aer_cap = dev->config + dev->exp.aer_cap;
+        devctl = pci_get_long(exp_cap + PCI_EXP_DEVCTL);
+        devsta = pci_get_long(exp_cap + PCI_EXP_DEVSTA);
+    }
+    if (err->flags & PCIE_AER_ERR_IS_CORRECTABLE) {
+    correctable_error:

Please, don't use goto to implement logic.
Split correctable/uncorrectable into subfunctions and call them any number of times.

Quoted 23 lines
hw/pcie_aer.c new file +23 -0
+        devsta |= PCI_EXP_DEVSTA_CED;
+        if (is_unsupported_request) {
+            devsta |= PCI_EXP_DEVSTA_URD;
+        }
+        pci_set_word(exp_cap + PCI_EXP_DEVSTA, devsta);
+
+        if (aer_cap) {
+            pci_long_test_and_set_mask(aer_cap + PCI_ERR_COR_STATUS, status);
+            mask = pci_get_long(aer_cap + PCI_ERR_COR_MASK);
+            if (mask & status) {
+                return;
+            }
+            if (is_advisory_nonfatal) {
+                uint32_t uncor_mask =
+                    pci_get_long(aer_cap + PCI_ERR_UNCOR_MASK);
+                if (!(uncor_mask & uncor_status)) {
+                    is_header_log_overflowed = pcie_aer_record_error(dev, err);
+                }
+                pci_long_test_and_set_mask(aer_cap + PCI_ERR_UNCOR_STATUS,
+                                           uncor_status);
+            }
+        }
+

hw/pcie_aer.c line 595

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+        if (is_unsupported_request && !(devctl & PCI_EXP_DEVCTL_URRE)) {
+            return;
+        }
+        if (!(devctl & PCI_EXP_DEVCTL_CERE)) {
+            return;
+        }
+        msg.severity = AER_ERR_COR;
+    } else {
+        bool is_fatal =
+            (pcie_aer_uncor_default_severity(status) == AER_ERR_FATAL);

Don't need (); also

Quoted 53 lines
hw/pcie_aer.c new file +53 -0
+        uint16_t cmd;
+
+        if (aer_cap) {
+            is_fatal = status & pci_get_long(aer_cap + PCI_ERR_UNCOR_SEVER);
+        }
+        if (!is_fatal && (err->flags & PCIE_AER_ERR_MAYBE_ADVISORY)) {
+            is_advisory_nonfatal = true;
+            uncor_status = status;
+            status = PCI_ERR_COR_ADV_NONFATAL;
+            goto correctable_error;
+        }
+        if (is_fatal) {
+            devsta |= PCI_EXP_DEVSTA_FED;
+        } else {
+            devsta |= PCI_EXP_DEVSTA_NFED;
+        }
+        if (is_unsupported_request) {
+            devsta |= PCI_EXP_DEVSTA_URD;
+        }
+        pci_set_long(exp_cap + PCI_EXP_DEVSTA, devsta);
+
+        if (aer_cap) {
+            mask = pci_get_long(aer_cap + PCI_ERR_UNCOR_MASK);
+            if (mask & status) {
+                pci_long_test_and_set_mask(aer_cap + PCI_ERR_UNCOR_STATUS,
+                                           status);
+                return;
+            }
+
+            is_header_log_overflowed = pcie_aer_record_error(dev, err);
+            pci_long_test_and_set_mask(aer_cap + PCI_ERR_UNCOR_STATUS, status);
+        }
+
+        cmd = pci_get_word(dev->config + PCI_COMMAND);
+        if (is_unsupported_request &&
+            !(devctl & PCI_EXP_DEVCTL_URRE) && !(cmd & PCI_COMMAND_SERR)) {
+            return;
+        }
+        if (is_fatal) {
+            if (!((cmd & PCI_COMMAND_SERR) ||
+                  (devctl & PCI_EXP_DEVCTL_FERE))) {
+                return;
+            }
+            msg.severity = AER_ERR_FATAL;
+        } else {
+            if (!((cmd & PCI_COMMAND_SERR) ||
+                  (devctl & PCI_EXP_DEVCTL_NFERE))) {
+                return;
+            }
+            msg.severity = AER_ERR_NONFATAL;
+        }
+    }
+

hw/pcie_aer.c line 658

Quoted 10 lines
hw/pcie_aer.c new file +10 -0
+    /* send up error message */
+    msg.source_id = err->source_id;
+    pcie_aer_msg(dev, &msg);
+
+    if (is_header_log_overflowed) {
+        PCIEAERErr header_log_overflow = {
+            .status = PCI_ERR_COR_HL_OVERFLOW,
+            .flags = PCIE_AER_ERR_IS_CORRECTABLE,
+            .header = {0, 0, 0, 0},
+            .prefix = {0, 0, 0, 0},

You don't need the 0,0,0 thing. Whatever you don't specify is 0.

hw/pcie_aer.c line 664

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+        };
+        pcie_aer_inject_error(dev, &header_log_overflow);
+    }
+}
+
+void pcie_aer_root_set_vector(PCIDevice *dev, uint8_t vector)

Just get vector as unsigned, you won't have to cast it down below.

Quoted 142 lines
hw/pcie_aer.c new file +116 -0
+{
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+    assert(vector < PCI_ERR_ROOT_IRQ_MAX);
+    pci_long_test_and_clear_mask(aer_cap + PCI_ERR_ROOT_STATUS,
+                                 PCI_ERR_ROOT_IRQ);
+    pci_long_test_and_set_mask(aer_cap + PCI_ERR_ROOT_STATUS,
+                               ((uint32_t)vector) << PCI_ERR_ROOT_IRQ_SHIFT);
+}
+
+static uint8_t pcie_aer_root_get_vector(PCIDevice *dev)
+{
+    uint8_t *aer_cap = dev->config + dev->exp.aer_cap;
+    uint32_t root_status = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS);
+    return (root_status & PCI_ERR_ROOT_IRQ) >> PCI_ERR_ROOT_IRQ_SHIFT;
+}
+
+void pcie_aer_root_init(PCIDevice *dev)
+{
+    uint16_t pos = dev->exp.aer_cap;
+
+    pci_set_long(dev->wmask + pos + PCI_ERR_ROOT_COMMAND,
+                 PCI_ERR_ROOT_CMD_EN_MASK);
+    pci_set_long(dev->w1cmask + pos + PCI_ERR_ROOT_STATUS,
+                 PCI_ERR_ROOT_STATUS_REPORT_MASK);
+}
+
+void pcie_aer_root_reset(PCIDevice *dev)
+{
+    uint8_t* aer_cap = dev->config + dev->exp.aer_cap;
+
+    pci_set_long(aer_cap + PCI_ERR_ROOT_COMMAND, 0);
+
+    /*
+     * Advanced Error Interrupt Message Number in Root Error Status Register
+     * must be updated by chip dependent code because it's chip dependent
+     * which number is used.
+     */
+}
+
+static bool pcie_aer_root_does_trigger(uint32_t cmd, uint32_t status)
+{
+    return
+        ((cmd & PCI_ERR_ROOT_CMD_COR_EN) && (status & PCI_ERR_ROOT_COR_RCV)) ||
+        ((cmd & PCI_ERR_ROOT_CMD_NONFATAL_EN) &&
+         (status & PCI_ERR_ROOT_NONFATAL_RCV)) ||
+        ((cmd & PCI_ERR_ROOT_CMD_FATAL_EN) &&
+         (status & PCI_ERR_ROOT_FATAL_RCV));
+}
+
+void pcie_aer_root_write_config(PCIDevice *dev,
+                                uint32_t addr, uint32_t val, int len,
+                                uint32_t root_cmd_prev)
+{
+    uint16_t pos = dev->exp.aer_cap;
+    uint8_t *aer_cap = dev->config + pos;
+
+    /* root command register */
+    uint32_t root_cmd = pci_get_long(aer_cap + PCI_ERR_ROOT_COMMAND);
+    if (root_cmd & PCI_ERR_ROOT_CMD_EN_MASK) {
+        /* 6.2.4.1.2 Interrupt Generation */
+
+        /* 0 -> 1 */
+        uint32_t root_cmd_set = (root_cmd_prev ^ root_cmd) & root_cmd;
+        uint32_t root_status = pci_get_long(aer_cap + PCI_ERR_ROOT_STATUS);
+
+        if (pci_msi_enabled(dev)) {
+            if (pcie_aer_root_does_trigger(root_cmd_set, root_status)) {
+                pci_msi_notify(dev, pcie_aer_root_get_vector(dev));
+            }
+        } else {
+            int int_level = pcie_aer_root_does_trigger(root_cmd, root_status);
+            qemu_set_irq(dev->irq[dev->exp.aer_intx], int_level);
+        }
+    }
+}
+
+static const VMStateDescription vmstate_pcie_aer_err = {
+    .name = "PCIE_AER_ERROR",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields     = (VMStateField[]) {
+        VMSTATE_UINT32(status, PCIEAERErr),
+        VMSTATE_UINT16(source_id, PCIEAERErr),
+        VMSTATE_UINT16(flags, PCIEAERErr),
+        VMSTATE_UINT32_ARRAY(header, PCIEAERErr, 4),
+        VMSTATE_UINT32_ARRAY(prefix, PCIEAERErr, 4),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+#define VMSTATE_PCIE_AER_ERRS(_field, _state, _field_num, _vmsd, _type) { \
+    .name       = (stringify(_field)),                                    \
+    .version_id = 0,                                                      \
+    .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),     \
+    .size       = sizeof(_type),                                          \
+    .vmsd       = &(_vmsd),                                               \
+    .flags      = VMS_POINTER | VMS_VARRAY_UINT16 | VMS_STRUCT,           \
+    .offset     = vmstate_offset_pointer(_state, _field, _type),          \
+}
+
+const VMStateDescription vmstate_pcie_aer_log = {
+    .name = "PCIE_AER_ERROR_LOG",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields     = (VMStateField[]) {
+        VMSTATE_UINT32(producer, PCIEAERLog),
+        VMSTATE_UINT32(consumer, PCIEAERLog),
+        VMSTATE_UINT16(log_max, PCIEAERLog),
+        VMSTATE_PCIE_AER_ERRS(log, PCIEAERLog, log_max,
+                              vmstate_pcie_aer_err, PCIEAERErr),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
hw/pcie_aer.h new file +20 -0
new file mode 100644
index 0000000..db9f87c
@@ -0,0 +1,105 @@
+/*
+ * pcie_aer.h
+ *
+ * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
+ *                    VA Linux Systems Japan K.K.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+

hw/pcie_aer.h line 30

Quoted 10 lines
hw/pcie_aer.h new file +10 -0
+#ifndef QEMU_PCIE_AER_H
+#define QEMU_PCIE_AER_H
+
+#include "hw.h"
+
+/* definitions which PCIExpressDevice uses */
+typedef enum {
+    AER_MSG_MASKED,
+    AER_MSG_SENT,
+} AERMsgResult;

We don't really need this, especially not in an external header.

Quoted 17 lines
hw/pcie_aer.h new file +17 -0
+
+/* AER log */
+struct PCIEAERLog {
+    /* This structure is saved/loaded.
+       So explicitly size them instead of unsigned int */
+    uint32_t producer;
+    uint32_t consumer;
+
+#define PCIE_AER_LOG_MAX_DEFAULT        8
+#define PCIE_AER_LOG_MAX_MAX            128 /* what is appropriate? */
+#define PCIE_AER_LOG_MAX_UNSET          0xffff
+    uint16_t log_max;
+
+    PCIEAERErr *log;    /* ringed buffer */
+};
+
+/* aer error severity */

hw/pcie_aer.h line 57

Quoted 10 lines
hw/pcie_aer.h new file +10 -0
+typedef enum {
+    /* those value are same as
+     * Root error command register in aer extended cap and
+     * root control register in pci express cap.
+     */
+    AER_ERR_COR         = PCI_ERR_ROOT_CMD_COR_EN,
+    AER_ERR_NONFATAL    = PCI_ERR_ROOT_CMD_NONFATAL_EN,
+    AER_ERR_FATAL       = PCI_ERR_ROOT_CMD_FATAL_EN,
+} PCIEAERSeverity;
+

I think we are better off without the enum above. It just adds 2 ways to get the same value and thre will always be confusion.
And C compiler does not give us type checking anyway.

Quoted 64 lines
hw/pcie_aer.h new file +48 -0
+/* aer error message: error signaling message has only error sevirity and
+   source id. See 2.2.8.3 error signaling messages */
+struct PCIEAERMsg {
+    PCIEAERSeverity severity;
+    uint16_t source_id; /* bdf */
+};
+
+static inline bool
+pcie_aer_msg_is_uncor(const PCIEAERMsg *msg)
+{
+    return msg->severity == AER_ERR_NONFATAL || msg->severity == AER_ERR_FATAL;
+}
+
+/* error */
+struct PCIEAERErr {
+    uint32_t status;    /* error status bits */
+    uint16_t source_id; /* bdf */
+
+#define PCIE_AER_ERR_IS_CORRECTABLE     0x1     /* correctable/uncorrectable */
+#define PCIE_AER_ERR_MAYBE_ADVISORY     0x2     /* maybe advisory non-fatal */
+#define PCIE_AER_ERR_HEADER_VALID       0x4     /* TLP header is logged */
+#define PCIE_AER_ERR_TLP_PRESENT        0x8     /* TLP Prefix is logged */
+    uint16_t flags;
+
+    uint32_t header[4]; /* TLP header */
+    uint32_t prefix[4]; /* TLP header prefix */
+};
+
+extern const VMStateDescription vmstate_pcie_aer_log;
+
+void pcie_aer_init(PCIDevice *dev, uint16_t offset);
+void pcie_aer_exit(PCIDevice *dev);
+void pcie_aer_write_config(PCIDevice *dev,
+                           uint32_t addr, uint32_t val, int len,
+                           uint32_t uncorsta_prev);
+
+/* aer root port */
+void pcie_aer_root_set_vector(PCIDevice *dev, uint8_t vector);
+void pcie_aer_root_init(PCIDevice *dev);
+void pcie_aer_root_reset(PCIDevice *dev);
+void pcie_aer_root_write_config(PCIDevice *dev,
+                                uint32_t addr, uint32_t val, int len,
+                                uint32_t root_cmd_prev);
+
+/* error injection */
+void pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err);
+
+#endif /* QEMU_PCIE_AER_H */
qemu-common.h +3 -0
index b97b16e..63ee8c3 100644
@@ -221,6 +221,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
#29 lore raw

[Qemu-devel] Re: [PATCH v6 08/12] pcie/aer: helper functions for pcie aer capability

Thank you for detailed review.

Quoted 11 lines · Michael S. Tsirkin

hw/pcie_aer.c line 110

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+static uint32_t aer_log_del(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->consumer;
+    aer_log->consumer = aer_log_next(aer_log->consumer, aer_log->log_max);
+    return i;
+}

Please just use 'int' or 'unsigned' instead of uint32_t if you simply want to say 'a number'. Using specific length makes it impossible to say where you *really* want a value.

PCIEAERLog is saved/loaded. So explicit sized number is chosen.

Signature · 1 line
yamahata
#30 lore raw

[Qemu-devel] Re: [PATCH v6 08/12] pcie/aer: helper functions for pcie aer capability

Quoted 15 lines · Isaku Yamahata

Thank you for detailed review.

Quoted 11 lines · Michael S. Tsirkin

hw/pcie_aer.c line 110

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+static uint32_t aer_log_del(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->consumer;
+    aer_log->consumer = aer_log_next(aer_log->consumer, aer_log->log_max);
+    return i;
+}

Please just use 'int' or 'unsigned' instead of uint32_t if you simply want to say 'a number'. Using specific length makes it impossible to say where you *really* want a value.

Quoted 1 line

PCIEAERLog is saved/loaded. So explicit sized number is chosen.

I didn't notice. But consumer/producer are not guest visible, are they? If yes I think it's a mistake to save/load them, tying us to a specific implementation: just calculate and save the # of valid entries in the log.

Also I put the comment here but it is a general one: pls go over the code, and just take a look at what types you use all over and think whether size really matters. In most places it does not, it just must be big enough, so use int or unsigned there. It will be much harder for others to do so later.

Quoted 2 lines
Signature · 1 line
yamahata
#31 lore raw

[Qemu-devel] Re: [PATCH v6 08/12] pcie/aer: helper functions for pcie aer capability

Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Isaku Yamahata

Thank you for detailed review.

Quoted 11 lines · Michael S. Tsirkin

hw/pcie_aer.c line 110

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+static uint32_t aer_log_del(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->consumer;
+    aer_log->consumer = aer_log_next(aer_log->consumer, aer_log->log_max);
+    return i;
+}

Please just use 'int' or 'unsigned' instead of uint32_t if you simply want to say 'a number'. Using specific length makes it impossible to say where you *really* want a value.

Quoted 6 lines
Quoted 1 line

PCIEAERLog is saved/loaded. So explicit sized number is chosen.

I didn't notice. But consumer/producer are not guest visible, are they? If yes I think it's a mistake to save/load them, tying us to a specific implementation: just calculate and save the # of valid entries in the log.

ACIEAERLog and PCIEAERErr themselves are the implementation specific internal states which is not visible to guest.
So there is no point of arguing that consumer/producer are specific to implementation.

Quoted 5 lines

Also I put the comment here but it is a general one: pls go over the code, and just take a look at what types you use all over and think whether size really matters. In most places it does not, it just must be big enough, so use int or unsigned there. It will be much harder for others to do so later.

Will do.

Signature · 1 line
yamahata
#32 lore raw

[Qemu-devel] Re: [PATCH v6 08/12] pcie/aer: helper functions for pcie aer capability

Quoted 24 lines · Isaku Yamahata
Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Isaku Yamahata

Thank you for detailed review.

Quoted 11 lines · Michael S. Tsirkin

hw/pcie_aer.c line 110

Quoted 6 lines
hw/pcie_aer.c new file +6 -0
+static uint32_t aer_log_del(PCIEAERLog *aer_log)
+{
+    uint32_t i = aer_log->consumer;
+    aer_log->consumer = aer_log_next(aer_log->consumer, aer_log->log_max);
+    return i;
+}

Please just use 'int' or 'unsigned' instead of uint32_t if you simply want to say 'a number'. Using specific length makes it impossible to say where you *really* want a value.

Quoted 6 lines
Quoted 1 line

PCIEAERLog is saved/loaded. So explicit sized number is chosen.

I didn't notice. But consumer/producer are not guest visible, are they? If yes I think it's a mistake to save/load them, tying us to a specific implementation: just calculate and save the # of valid entries in the log.

Quoted 4 lines

ACIEAERLog and PCIEAERErr themselves are the implementation specific internal states which is not visible to guest.
So there is no point of arguing that consumer/producer are specific to implementation.

Well the errors can be read out by the guest, so they are potentially guest visible. Thus I think the only thing we want to migrate is the list of errors logged.

Quoted 9 lines
Quoted 5 lines

Also I put the comment here but it is a general one: pls go over the code, and just take a look at what types you use all over and think whether size really matters. In most places it does not, it just must be big enough, so use int or unsigned there. It will be much harder for others to do so later.

Will do.

Signature · 1 line
yamahata
#33 lore raw

Re: [Qemu-devel] Re: [PATCH v6 08/12] pcie/aer: helper functions for pcie aer capability

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

This patch implements helper functions for pcie aer capability which will be used later.

Some style comments and a couple of minor bugs.

[...]

Quoted 11 lines

hw/pcie_aer.c line 119

Quoted 9 lines
hw/pcie_aer.c new file +9 -0
+
+static int aer_log_add_err(PCIEAERLog *aer_log, const PCIEAERErr *err)
+{
+    uint32_t i;
+    if (aer_log_full(aer_log)) {
+        return -1;
+    }
+    i = aer_log_add(aer_log);
+    memcpy(&aer_log->log[i], err, sizeof(*err));

sizeof is not a function, you don't need ()

Matter of taste. Yes, it's an operator, but it's as function-like as operators get.

For what it's worth, grep says roughly 98% of our sizeof uses are followed by '('. I doubt the parenthesis are required for grouping that often.

[...]

#34 lore raw

PATCH v6 9/12 pcie/aer: glue aer error injection into qemu monitor

In reply to Isaku Yamahata

introduce pcie_aer_inject_error command.

---
Changes v3 -> v4:
- s/PCIE_AER/PCIEAER/g for structure names.
- compilation adjustment.

Changes v2 -> v3:
- compilation adjustment.

---
 hw/pcie_aer.c   |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx |   22 ++++++++++++++
 sysemu.h        |    5 +++
 3 files changed, 111 insertions(+), 0 deletions(-)
hw/pcie_aer.c +84 -0
index b8cede3..459e0d7 100644
@@ -19,6 +19,8 @@
  */
 
 #include "sysemu.h"
+#include "qemu-objects.h"
+#include "monitor.h"
 #include "pci_bridge.h"
 #include "pcie.h"
 #include "msix.h"
@@ -778,3 +780,85 @@ const VMStateDescription vmstate_pcie_aer_log = {
     }
 };
 
+void pcie_aer_inject_error_print(Monitor *mon, const QObject *data)
+{
+    QDict *qdict;
+    int devfn;
+    assert(qobject_type(data) == QTYPE_QDICT);
+    qdict = qobject_to_qdict(data);
+
+    devfn = (int)qdict_get_int(qdict, "devfn");
+    monitor_printf(mon, "OK domain: %x, bus: %x devfn: %x.%x\n",
+                   (int) qdict_get_int(qdict, "domain"),
+                   (int) qdict_get_int(qdict, "bus"),
+                   PCI_SLOT(devfn), PCI_FUNC(devfn));
+}
+
+int do_pcie_aer_inejct_error(Monitor *mon,
+                             const QDict *qdict, QObject **ret_data)
+{
+    const char *pci_addr = qdict_get_str(qdict, "pci_addr");
+    int dom;
+    int bus;
+    unsigned int slot;
+    unsigned int func;
+    PCIDevice *dev;
+    PCIEAERErr err;
+
+    /* Ideally qdev device path should be used.
+     * However at the moment there is no reliable way to determine
+     * wheher a given qdev is pci device or not.
+     * so pci_addr is used.
+     */
+    if (pci_parse_devaddr(pci_addr, &dom, &bus, &slot, &func)) {
+        monitor_printf(mon, "invalid pci address %s\n", pci_addr);
+        return -1;
+    }
+    dev = pci_find_device(pci_find_root_bus(dom), bus, slot, func);
+    if (!dev) {
+        monitor_printf(mon, "device is not found. 0x%x:0x%x.0x%x\n",
+                       bus, slot, func);
+        return -1;
+    }
+    if (!pci_is_express(dev)) {
+        monitor_printf(mon, "the device doesn't support pci express. "
+                       "0x%x:0x%x.0x%x\n",
+                       bus, slot, func);
+        return -1;
+    }
+
+    err.status = qdict_get_int(qdict, "error_status");
+    err.source_id = (pci_bus_num(dev->bus) << 8) | dev->devfn;
+
+    err.flags = 0;
+    if (qdict_get_int(qdict, "is_correctable")) {
+        err.flags |= PCIE_AER_ERR_IS_CORRECTABLE;
+    }
+    if (qdict_get_int(qdict, "advisory_non_fatal")) {
+        err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY;
+    }
+    if (qdict_haskey(qdict, "tlph0")) {
+        err.flags |= PCIE_AER_ERR_HEADER_VALID;
+    }
+    if (qdict_haskey(qdict, "hpfx0")) {
+        err.flags |= PCIE_AER_ERR_TLP_PRESENT;
+    }
+
+    err.header[0] = qdict_get_try_int(qdict, "tlph0", 0);
+    err.header[1] = qdict_get_try_int(qdict, "tlph1", 0);
+    err.header[2] = qdict_get_try_int(qdict, "tlph2", 0);
+    err.header[3] = qdict_get_try_int(qdict, "tlph3", 0);
+
+    err.prefix[0] = qdict_get_try_int(qdict, "hpfx0", 0);
+    err.prefix[1] = qdict_get_try_int(qdict, "hpfx1", 0);
+    err.prefix[2] = qdict_get_try_int(qdict, "hpfx2", 0);
+    err.prefix[3] = qdict_get_try_int(qdict, "hpfx3", 0);
+
+    pcie_aer_inject_error(dev, &err);
+    *ret_data = qobject_from_jsonf("{ 'domain': %d, 'bus': %d, 'devfn': %d }",
+                                   pci_find_domain(dev->bus),
+                                   pci_bus_num(dev->bus), dev->devfn);
+    assert(*ret_data);
+
+    return 0;
+}
qemu-monitor.hx +22 -0
index 965c754..ccb3d0e 100644
@@ -1168,6 +1168,28 @@ Push PCI express attention button
 ETEXI
 
     {
+        .name       = "pcie_aer_inject_error",
+        .args_type  = "advisory_non_fatal:-a,is_correctable:-c,"
+	              "pci_addr:s,error_status:i,"
+	              "tlph0:i?,tlph1:i?,tlph2:i?,tlph3:i?,"
+	              "hpfx0:i?,hpfx1:i?,hpfx2:i?,hpfx3:i?",
+        .params     = "[-a] [-c] [[<domain>:]<bus>:]<slot>.<func> "
+	              "<error status: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 correctrable error)",
+        .user_print  = pcie_aer_inject_error_print,
+        .mhandler.cmd_new = do_pcie_aer_inejct_error,
+    },
+
+STEXI
+@item pcie_abp
+Push PCI express attention button
+ETEXI
+
+    {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
         .params     = "tap|user|socket|vde|dump [options]",
sysemu.h +5 -0
index cca411d..2f7157c 100644
@@ -155,6 +155,11 @@ void pcie_attention_button_push_print(Monitor *mon, const QObject *data);
 int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
                                QObject **ret_data);
 
+/* 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
#35 lore raw

[Qemu-devel] Re: [PATCH v6 09/12] pcie/aer: glue aer error injection into qemu monitor

Quoted 96 lines · Isaku Yamahata

introduce pcie_aer_inject_error command.

---
Changes v3 -> v4:
- s/PCIE_AER/PCIEAER/g for structure names.
- compilation adjustment.

Changes v2 -> v3:
- compilation adjustment.

---
 hw/pcie_aer.c   |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx |   22 ++++++++++++++
 sysemu.h        |    5 +++
 3 files changed, 111 insertions(+), 0 deletions(-)
hw/pcie_aer.c +65 -0
index b8cede3..459e0d7 100644
@@ -19,6 +19,8 @@
  */
 
 #include "sysemu.h"
+#include "qemu-objects.h"
+#include "monitor.h"
 #include "pci_bridge.h"
 #include "pcie.h"
 #include "msix.h"
@@ -778,3 +780,85 @@ const VMStateDescription vmstate_pcie_aer_log = {
     }
 };
 
+void pcie_aer_inject_error_print(Monitor *mon, const QObject *data)
+{
+    QDict *qdict;
+    int devfn;
+    assert(qobject_type(data) == QTYPE_QDICT);
+    qdict = qobject_to_qdict(data);
+
+    devfn = (int)qdict_get_int(qdict, "devfn");
+    monitor_printf(mon, "OK domain: %x, bus: %x devfn: %x.%x\n",
+                   (int) qdict_get_int(qdict, "domain"),
+                   (int) qdict_get_int(qdict, "bus"),
+                   PCI_SLOT(devfn), PCI_FUNC(devfn));
+}
+
+int do_pcie_aer_inejct_error(Monitor *mon,
+                             const QDict *qdict, QObject **ret_data)
+{
+    const char *pci_addr = qdict_get_str(qdict, "pci_addr");
+    int dom;
+    int bus;
+    unsigned int slot;
+    unsigned int func;
+    PCIDevice *dev;
+    PCIEAERErr err;
+
+    /* Ideally qdev device path should be used.
+     * However at the moment there is no reliable way to determine
+     * wheher a given qdev is pci device or not.
+     * so pci_addr is used.
+     */
+    if (pci_parse_devaddr(pci_addr, &dom, &bus, &slot, &func)) {
+        monitor_printf(mon, "invalid pci address %s\n", pci_addr);
+        return -1;
+    }
+    dev = pci_find_device(pci_find_root_bus(dom), bus, slot, func);
+    if (!dev) {
+        monitor_printf(mon, "device is not found. 0x%x:0x%x.0x%x\n",
+                       bus, slot, func);
+        return -1;
+    }
+    if (!pci_is_express(dev)) {
+        monitor_printf(mon, "the device doesn't support pci express. "
+                       "0x%x:0x%x.0x%x\n",
+                       bus, slot, func);
+        return -1;
+    }
+
+    err.status = qdict_get_int(qdict, "error_status");
+    err.source_id = (pci_bus_num(dev->bus) << 8) | dev->devfn;
+
+    err.flags = 0;
+    if (qdict_get_int(qdict, "is_correctable")) {
+        err.flags |= PCIE_AER_ERR_IS_CORRECTABLE;
+    }
+    if (qdict_get_int(qdict, "advisory_non_fatal")) {
+        err.flags |= PCIE_AER_ERR_MAYBE_ADVISORY;
+    }
+    if (qdict_haskey(qdict, "tlph0")) {
+        err.flags |= PCIE_AER_ERR_HEADER_VALID;
+    }
+    if (qdict_haskey(qdict, "hpfx0")) {
+        err.flags |= PCIE_AER_ERR_TLP_PRESENT;
+    }

hw/pcie_aer.c const VMStateDescription vmstate_pcie_aer_log = { · line 855

Quoted 10 lines
hw/pcie_aer.c +10 -0
+
+    err.header[0] = qdict_get_try_int(qdict, "tlph0", 0);
+    err.header[1] = qdict_get_try_int(qdict, "tlph1", 0);
+    err.header[2] = qdict_get_try_int(qdict, "tlph2", 0);
+    err.header[3] = qdict_get_try_int(qdict, "tlph3", 0);
+
+    err.prefix[0] = qdict_get_try_int(qdict, "hpfx0", 0);
+    err.prefix[1] = qdict_get_try_int(qdict, "hpfx1", 0);
+    err.prefix[2] = qdict_get_try_int(qdict, "hpfx2", 0);
+    err.prefix[3] = qdict_get_try_int(qdict, "hpfx3", 0);

Can't we use a list or something? Sticking index in key name in this way seems ugly.

Quoted 59 lines
hw/pcie_aer.c +8 -0
+    pcie_aer_inject_error(dev, &err);
+    *ret_data = qobject_from_jsonf("{ 'domain': %d, 'bus': %d, 'devfn': %d }",
+                                   pci_find_domain(dev->bus),
+                                   pci_bus_num(dev->bus), dev->devfn);
+    assert(*ret_data);
+
+    return 0;
+}
qemu-monitor.hx +22 -0
index 965c754..ccb3d0e 100644
@@ -1168,6 +1168,28 @@ Push PCI express attention button
 ETEXI
 
     {
+        .name       = "pcie_aer_inject_error",
+        .args_type  = "advisory_non_fatal:-a,is_correctable:-c,"
+	              "pci_addr:s,error_status:i,"
+	              "tlph0:i?,tlph1:i?,tlph2:i?,tlph3:i?,"
+	              "hpfx0:i?,hpfx1:i?,hpfx2:i?,hpfx3:i?",
+        .params     = "[-a] [-c] [[<domain>:]<bus>:]<slot>.<func> "
+	              "<error status: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 correctrable error)",
+        .user_print  = pcie_aer_inject_error_print,
+        .mhandler.cmd_new = do_pcie_aer_inejct_error,
+    },
+
+STEXI
+@item pcie_abp
+Push PCI express attention button
+ETEXI
+
+    {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
         .params     = "tap|user|socket|vde|dump [options]",
sysemu.h +5 -0
index cca411d..2f7157c 100644
@@ -155,6 +155,11 @@ void pcie_attention_button_push_print(Monitor *mon, const QObject *data);
 int pcie_attention_button_push(Monitor *mon, const QDict *qdict,
                                QObject **ret_data);
 
+/* 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
#36 lore raw

PATCH v6 10/12 ioh3420: support aer

In reply to Isaku Yamahata

Add aer support.

---
 hw/ioh3420.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 deletions(-)
hw/ioh3420.c +46 -6
index 1f340d3..09c94f9 100644
@@ -36,28 +36,63 @@
 #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)
 {
     uint16_t sltctl =
         pci_get_word(d->config + d->exp.exp_cap + PCI_EXP_SLTCTL);
+    uint32_t uncorsta =
+        pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_UNCOR_STATUS);
+    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, sltctl);
-    /* TODO: AER */
+    pcie_aer_write_config(d, address, val, len, uncorsta);
+    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)
@@ -101,13 +136,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);
@@ -144,7 +181,8 @@ static const VMStateDescription vmstate_ioh3420 = {
     .minimum_version_id_old = 1,
     .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 +204,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
#37 lore raw

PATCH v6 11/12 x3130/upstream: support aer

In reply to Isaku Yamahata

add aer support.

---
 hw/xio3130_upstream.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
hw/xio3130_upstream.c +10 -5
index d9d637f..36ed4b1 100644
@@ -38,10 +38,13 @@
 static void xio3130_upstream_write_config(PCIDevice *d, uint32_t address,
                                           uint32_t val, int len)
 {
+    uint32_t uncorsta =
+        pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_UNCOR_STATUS);
+
     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, uncorsta);
 }
 
 static void xio3130_upstream_reset(DeviceState *qdev)
@@ -89,14 +92,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 +134,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 +155,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
#38 lore raw

PATCH v6 12/12 x3130/downstream: support aer.

In reply to Isaku Yamahata

add aer support.

---
 hw/xio3130_downstream.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
hw/xio3130_downstream.c +10 -5
index a44e188..9087c0b 100644
@@ -40,12 +40,14 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
 {
     uint16_t sltctl =
         pci_get_word(d->config + d->exp.exp_cap + PCI_EXP_SLTCTL);
+    uint32_t uncorsta =
+        pci_get_long(d->config + d->exp.aer_cap + PCI_ERR_UNCOR_STATUS);
 
     pci_bridge_write_config(d, address, val, len);
     pcie_cap_flr_write_config(d, address, val, len);
     pcie_cap_slot_write_config(d, address, val, len, sltctl);
     msi_write_config(d, address, val, len);
-    /* TODO: AER */
+    pcie_aer_write_config(d, address, val, len, uncorsta);
 }
 
 static void xio3130_downstream_reset(DeviceState *qdev)
@@ -100,14 +102,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);
@@ -146,7 +148,8 @@ static const VMStateDescription vmstate_xio3130_downstream = {
     .minimum_version_id_old = 1,
     .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()
     }
 };
@@ -168,7 +171,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
#39 lore raw
In reply to Isaku Yamahata
Quoted 7 lines · Isaku Yamahata

Isaku Yamahata (12):
pcie: comment on hpev_intx
pci/bridge: fix pci_bridge_reset()
pcie port: define struct PCIEPort/PCIESlot and helper functions
ioh3420: pcie root port in X58 ioh
x3130: pcie upstream port
x3130: pcie downstream port

Applied patched 1-6 on my branch.
I'll give people a chance to comment and then we can merge.