All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jamin Lin <jamin_lin@aspeedtech.com>
To: "Cédric Le Goater" <clg@kaod.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Kane Chen" <kane_chen@aspeedtech.com>,
	"open list:ASPEED BMCs" <qemu-arm@nongnu.org>,
	"open list:All patches CC here" <qemu-devel@nongnu.org>
Cc: Jamin Lin <jamin_lin@aspeedtech.com>, Troy Lee <troy_lee@aspeedtech.com>
Subject: [PATCH v1 1/3] hw/pci-host/aspeed_pcie: Fix lost INTx interrupts
Date: Wed, 25 Nov 2026 03:12:27 +0000	[thread overview]
Message-ID: <20261125031225.3810653-2-jamin_lin@aspeedtech.com> (raw)
In-Reply-To: <20261125031225.3810653-1-jamin_lin@aspeedtech.com>

The RC has one interrupt line for both INTx and MSI. It should be high
when (INT_STS & INT_EN) != 0 or an MSI is pending.

The model only updates the line when a device raises or lowers its
INTx. A write to INT_EN does not update it. The guest firmware masks an
INTx while the handler runs, so an INTx that comes in during the
handler is lost.

For example, with INTD (bit 3, 0x8):

  1. The device raises INTD.
  2. The guest firmware masks INTD.
  3. The device lowers INTD.
  4. The device raises INTD again.
  5. The guest firmware unmasks INTD.

  step  INT_EN  INT_STS  line
  1     0x8     0x8      1
  2     0x0     0x8      1
  3     0x0     0x0      0
  4     0x0     0x8      0
  5     0x8     0x8      0    (should be 1)

The guest never sees the interrupt from step 4.

INTx and MSI also overwrite each other on the line. If an MSI is
pending (MSI_STS0 = 0x1) and a device lowers INTD, the line drops to 0.
If INTD is pending (INT_STS = 0x8) and the guest clears the last MSI,
the line drops to 0 as well.

Compute the line in one place, aspeed_pcie_rc_update_irq(), and call
it on INTx changes, MSI changes and INT_EN writes.

Fixes: f002aa35f320 ("hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge")
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
 hw/pci-host/aspeed_pcie.c | 41 +++++++++++++++++++++++++++++----------
 hw/pci-host/trace-events  |  6 +++---
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/hw/pci-host/aspeed_pcie.c b/hw/pci-host/aspeed_pcie.c
index ceb010f213..2362409ab7 100644
--- a/hw/pci-host/aspeed_pcie.c
+++ b/hw/pci-host/aspeed_pcie.c
@@ -89,12 +89,29 @@ static void aspeed_pcie_root_port_class_init(ObjectClass *klass,
 
 #define ASPEED_PCIE_CFG_RC_MAX_MSI 64
 
+/*
+ * INTx and MSI share one RC interrupt line. Compute it from both, so one
+ * does not lower the line while the other is still pending.
+ */
+static void aspeed_pcie_rc_update_irq(AspeedPCIECfgState *cfg)
+{
+    uint32_t msi_sts0 = cfg->regs[cfg->rc_regs->msi_sts0_reg];
+    uint32_t msi_sts1 = cfg->regs[cfg->rc_regs->msi_sts1_reg];
+    uint32_t int_sts = cfg->regs[cfg->rc_regs->int_sts_reg];
+    uint32_t int_en = cfg->regs[cfg->rc_regs->int_en_reg];
+    bool level;
+
+    level = (int_sts & int_en) || msi_sts0 || msi_sts1;
+    trace_aspeed_pcie_rc_update_irq(cfg->id, int_sts, int_en, msi_sts0,
+                                    msi_sts1, level);
+    qemu_set_irq(cfg->rc.irq, level);
+}
+
 static void aspeed_pcie_rc_set_irq(void *opaque, int irq, int level)
 {
     AspeedPCIERcState *rc = (AspeedPCIERcState *) opaque;
     AspeedPCIECfgState *cfg =
         container_of(rc, AspeedPCIECfgState, rc);
-    bool intx;
 
     assert(irq < PCI_NUM_PINS);
 
@@ -104,10 +121,8 @@ static void aspeed_pcie_rc_set_irq(void *opaque, int irq, int level)
         cfg->regs[cfg->rc_regs->int_sts_reg] &= ~BIT(irq);
     }
 
-    intx = !!(cfg->regs[cfg->rc_regs->int_sts_reg] &
-              cfg->regs[cfg->rc_regs->int_en_reg]);
-    trace_aspeed_pcie_rc_intx_set_irq(cfg->id, irq, intx);
-    qemu_set_irq(rc->irq, intx);
+    trace_aspeed_pcie_rc_intx_set_irq(cfg->id, irq, level);
+    aspeed_pcie_rc_update_irq(cfg);
 }
 
 static int aspeed_pcie_rc_map_irq(PCIDevice *pci_dev, int irq_num)
@@ -129,7 +144,7 @@ static void aspeed_pcie_rc_msi_notify(AspeedPCIERcState *rc, uint64_t data)
     cfg->regs[reg] |= BIT(data % 32);
 
     trace_aspeed_pcie_rc_msi_set_irq(cfg->id, data, 1);
-    qemu_set_irq(rc->irq, 1);
+    aspeed_pcie_rc_update_irq(cfg);
 }
 
 static void aspeed_pcie_rc_msi_write(void *opaque, hwaddr addr, uint64_t data,
@@ -541,6 +556,10 @@ static void aspeed_pcie_cfg_write(void *opaque, hwaddr addr, uint64_t data,
             s->regs[R_H2X_TX_STS] |= R_H2X_TX_STS_IDLE_MASK;
         }
         break;
+    case R_H2X_RC_H_INT_EN:
+        s->regs[reg] = data;
+        aspeed_pcie_rc_update_irq(s);
+        break;
     /* preserve INTx status */
     case R_H2X_RC_H_INT_STS:
         if (data & H2X_RC_INT_INTDONE_MASK) {
@@ -567,8 +586,7 @@ static void aspeed_pcie_cfg_write(void *opaque, hwaddr addr, uint64_t data,
 
         if (!s->regs[R_H2X_RC_H_MSI_STS0] &&
             !s->regs[R_H2X_RC_H_MSI_STS1]) {
-            trace_aspeed_pcie_rc_msi_clear_irq(s->id, 0);
-            qemu_set_irq(s->rc.irq, 0);
+            aspeed_pcie_rc_update_irq(s);
         }
         break;
     default:
@@ -718,6 +736,10 @@ static void aspeed_2700_pcie_cfg_write(void *opaque, hwaddr addr,
         }
         break;
 
+    case R_H2X_INT_EN:
+        s->regs[reg] = data;
+        aspeed_pcie_rc_update_irq(s);
+        break;
     case R_H2X_INT_STS:
         s->regs[reg] &= ~data | R_H2X_INT_STS_INTX_MASK;
         break;
@@ -740,8 +762,7 @@ static void aspeed_2700_pcie_cfg_write(void *opaque, hwaddr addr,
 
         if (!s->regs[R_H2X_MSI_STS0] &&
             !s->regs[R_H2X_MSI_STS1]) {
-            trace_aspeed_pcie_rc_msi_clear_irq(s->id, 0);
-            qemu_set_irq(s->rc.irq, 0);
+            aspeed_pcie_rc_update_irq(s);
         }
         break;
     default:
diff --git a/hw/pci-host/trace-events b/hw/pci-host/trace-events
index a6fd88c2c4..26730beafc 100644
--- a/hw/pci-host/trace-events
+++ b/hw/pci-host/trace-events
@@ -1,10 +1,10 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
 # aspeed_pcie.c
-aspeed_pcie_rc_intx_set_irq(uint32_t id, int num, int level) "%d: num %d set IRQ leve %d"
+aspeed_pcie_rc_update_irq(uint32_t id, uint32_t int_sts, uint32_t int_en, uint32_t msi_sts0, uint32_t msi_sts1, int level) "%d: INT_STS 0x%x INT_EN 0x%x MSI_STS0 0x%x MSI_STS1 0x%x level %d"
+aspeed_pcie_rc_intx_set_irq(uint32_t id, int num, int level) "%d: INTx %d level %d"
 aspeed_pcie_rc_msi_notify(uint32_t id, uint64_t addr, uint64_t data) "%d: 0x%" PRIx64 " data 0x%" PRIx64
-aspeed_pcie_rc_msi_set_irq(uint32_t id, uint64_t unm, int level) "%d: num 0x%" PRIx64 " set IRQ level %d"
-aspeed_pcie_rc_msi_clear_irq(uint32_t id, int level) "%d: clear IRQ level %d"
+aspeed_pcie_rc_msi_set_irq(uint32_t id, uint64_t num, int level) "%d: num 0x%" PRIx64 " set IRQ level %d"
 aspeed_pcie_cfg_read(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32
 aspeed_pcie_cfg_write(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32
 aspeed_pcie_cfg_rw(uint32_t id, const char *dir, uint8_t bus, uint8_t devfn, uint64_t addr, uint64_t data) "%d: %s bus:0x%x devfn:0x%x addr 0x%" PRIx64 " data 0x%" PRIx64
-- 
2.53.0


  reply	other threads:[~2026-11-25  3:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  3:12 [PATCH v1 0/3] Add the AST2700 PCIe EHCI Jamin Lin
2026-11-25  3:12 ` Jamin Lin [this message]
2026-11-25  3:12 ` [PATCH v1 2/3] hw/usb/hcd-ehci-pci: Use DEFINE_TYPES Jamin Lin
2026-11-25  3:12 ` [PATCH v1 3/3] hw/usb/hcd-ehci-pci-aspeed: Add the AST2700 PCIe EHCI Jamin Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125031225.3810653-2-jamin_lin@aspeedtech.com \
    --to=jamin_lin@aspeedtech.com \
    --cc=clg@kaod.org \
    --cc=kane_chen@aspeedtech.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=troy_lee@aspeedtech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.