From nobody Thu Nov 14 17:56:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1708438487; cv=none; d=zohomail.com; s=zohoarc; b=RKd8KnwWa9us+1WhAnmfTmbAwBAtqhsSDBUMOn51CGJBpzpbqyOIgb4qBfM6GeK1pnI5uI4DMx9Xmm5N+LvzMh0HG4wn61ZVB+9MviTvtLuj05BEziAJJYMWdGqEWVIKKf/58lKcAt1lcBgmFrvNkrDnkfcNPhHEMLdNzPcw428= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708438487; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=UNMMjOlj7WoK7k8K+tO+SVR5jAbIvP5YUVWHn5tnEXY=; b=K8nGTWeptTwFVSsZrvHovfq4XYKfhtzl8nEm2wHnq/sVoP7nMzg58Uh7hxkOEDeR/reiflXynb/EGZuPn51hwpTglIR4OpehtAUfycfuYhVjNbCEHSjIq9vLtgKpZqmQu4zdyI261XV4aU3SpL6q77cbNGfWa6UmjVl7i5UZ0aw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708438487554316.16642813908925; Tue, 20 Feb 2024 06:14:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcQsG-00027f-Fv; Tue, 20 Feb 2024 09:13:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcP5j-00009A-A0; Tue, 20 Feb 2024 07:19:21 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcP5b-0004MS-Em; Tue, 20 Feb 2024 07:19:18 -0500 Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TfJLF6gQgz2Bd4t; Tue, 20 Feb 2024 20:16:53 +0800 (CST) Received: from kwepemi500008.china.huawei.com (unknown [7.221.188.139]) by mail.maildlp.com (Postfix) with ESMTPS id EE37618001A; Tue, 20 Feb 2024 20:19:01 +0800 (CST) Received: from huawei.com (10.67.174.55) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 20 Feb 2024 20:19:01 +0800 To: , , , , , , CC: Subject: [RFC PATCH 3/3] hw/intc/arm_gicv3: Implement FEAT_GICv3_NMI feature to support FEAT_NMI Date: Tue, 20 Feb 2024 12:17:52 +0000 Message-ID: <20240220121752.490665-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220121752.490665-1-ruanjinjie@huawei.com> References: <20240220121752.490665-1-ruanjinjie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.67.174.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500008.china.huawei.com (7.221.188.139) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=ruanjinjie@huawei.com; helo=szxga04-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 20 Feb 2024 09:13:26 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Jinjie Ruan From: Jinjie Ruan via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708438489337100003 Content-Type: text/plain; charset="utf-8" Connect NMI wire from GICv3 to every Arm PE. +-------------------------------------------------+ | Distributor | +-------------------------------------------------+ | NMI | NMI \ / \ / +--------+ +-------+ | redist | | redist| +--------+ +-------+ | NMI | NMI \ / \ / +-------------+ +---------------+ |CPU interface| ... | CPU interface | +-------------+ +---------------+ | NMI | NMI \ / \ / +-----+ +-----+ | PE | | PE | +-----+ +-----+ Support the superpriority property for SPI/SGI/PPI interrupt and these interrupts with a NMI high priority. Also support configure a interrupt with superpriority property with GICR_INMIR0 or GICD_INMIR register. Support ack a NMI interrupt with ICC_NMIAR1_EL1 register. and support PE to distinguish IRQ from FIQ for a NMI. Signed-off-by: Jinjie Ruan --- hw/arm/virt.c | 2 + hw/intc/arm_gicv3.c | 61 ++++++++++++++++++++++++++---- hw/intc/arm_gicv3_common.c | 4 ++ hw/intc/arm_gicv3_cpuif.c | 57 ++++++++++++++++++++++++++-- hw/intc/arm_gicv3_dist.c | 39 +++++++++++++++++++ hw/intc/arm_gicv3_redist.c | 23 +++++++++++ hw/intc/gicv3_internal.h | 5 +++ include/hw/core/cpu.h | 1 + include/hw/intc/arm_gic_common.h | 1 + include/hw/intc/arm_gicv3_common.h | 6 +++ target/arm/helper.c | 5 ++- 11 files changed, 191 insertions(+), 13 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0af1943697..5f2683a553 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -848,6 +848,8 @@ static void create_gic(VirtMachineState *vms, MemoryReg= ion *mem) qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); sysbus_connect_irq(gicbusdev, i + 3 * smp_cpus, qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); + sysbus_connect_irq(gicbusdev, i + 4 * smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_NMI)); } =20 fdt_add_gic_node(vms); diff --git a/hw/intc/arm_gicv3.c b/hw/intc/arm_gicv3.c index 0b8f79a122..e3281cffdc 100644 --- a/hw/intc/arm_gicv3.c +++ b/hw/intc/arm_gicv3.c @@ -21,7 +21,7 @@ #include "hw/intc/arm_gicv3.h" #include "gicv3_internal.h" =20 -static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio) +static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio, bool is_nm= i) { /* Return true if this IRQ at this priority should take * precedence over the current recorded highest priority @@ -33,11 +33,21 @@ static bool irqbetter(GICv3CPUState *cs, int irq, uint8= _t prio) if (prio < cs->hppi.prio) { return true; } + + /* + * Current highest prioirity pending interrupt is not a NMI + * and the new IRQ is a NMI with same priority. + */ + if (prio =3D=3D cs->hppi.prio && !cs->hppi.superprio && is_nmi) { + return true; + } + /* If multiple pending interrupts have the same priority then it is an * IMPDEF choice which of them to signal to the CPU. We choose to * signal the one with the lowest interrupt number. */ - if (prio =3D=3D cs->hppi.prio && irq <=3D cs->hppi.irq) { + if (prio =3D=3D cs->hppi.prio && !cs->hppi.superprio && + !is_nmi && irq <=3D cs->hppi.irq) { return true; } return false; @@ -141,6 +151,8 @@ static void gicv3_redist_update_noirqset(GICv3CPUState = *cs) uint8_t prio; int i; uint32_t pend; + bool is_nmi =3D 0; + uint32_t superprio =3D 0; =20 /* Find out which redistributor interrupts are eligible to be * signaled to the CPU interface. @@ -152,10 +164,26 @@ static void gicv3_redist_update_noirqset(GICv3CPUStat= e *cs) if (!(pend & (1 << i))) { continue; } - prio =3D cs->gicr_ipriorityr[i]; - if (irqbetter(cs, i, prio)) { + superprio =3D extract32(cs->gicr_isuperprio, i, 1); + + /* NMI */ + if (superprio) { + is_nmi =3D 1; + + /* DS =3D 0 & Non-secure NMI */ + if ((!(cs->gic->gicd_ctlr & GICD_CTLR_DS)) && + extract32(cs->gicr_igroupr0, i, 1)) + prio =3D 0x80; + else + prio =3D 0x0; + } else { + is_nmi =3D 0; + prio =3D cs->gicr_ipriorityr[i]; + } + if (irqbetter(cs, i, prio, is_nmi)) { cs->hppi.irq =3D i; cs->hppi.prio =3D prio; + cs->hppi.superprio =3D is_nmi; seenbetter =3D true; } } @@ -168,7 +196,7 @@ static void gicv3_redist_update_noirqset(GICv3CPUState = *cs) if ((cs->gicr_ctlr & GICR_CTLR_ENABLE_LPIS) && cs->gic->lpi_enable && (cs->gic->gicd_ctlr & GICD_CTLR_EN_GRP1NS) && (cs->hpplpi.prio !=3D 0xff)) { - if (irqbetter(cs, cs->hpplpi.irq, cs->hpplpi.prio)) { + if (irqbetter(cs, cs->hpplpi.irq, cs->hpplpi.prio, false)) { cs->hppi.irq =3D cs->hpplpi.irq; cs->hppi.prio =3D cs->hpplpi.prio; cs->hppi.grp =3D cs->hpplpi.grp; @@ -212,7 +240,9 @@ static void gicv3_update_noirqset(GICv3State *s, int st= art, int len) { int i; uint8_t prio; + bool is_nmi =3D 0; uint32_t pend =3D 0; + uint32_t superprio =3D 0; =20 assert(start >=3D GIC_INTERNAL); assert(len > 0); @@ -240,10 +270,27 @@ static void gicv3_update_noirqset(GICv3State *s, int = start, int len) */ continue; } - prio =3D s->gicd_ipriority[i]; - if (irqbetter(cs, i, prio)) { + + superprio =3D *gic_bmp_ptr32(s->superprio, i); + /* NMI */ + if (superprio & (1 << (i & 0x1f))) { + is_nmi =3D 1; + + /* DS =3D 0 & Non-secure NMI */ + if ((!(s->gicd_ctlr & GICD_CTLR_DS)) && + gicv3_gicd_group_test(s, i)) + prio =3D 0x80; + else + prio =3D 0x0; + } else { + is_nmi =3D 0; + prio =3D s->gicd_ipriority[i]; + } + + if (irqbetter(cs, i, prio, is_nmi)) { cs->hppi.irq =3D i; cs->hppi.prio =3D prio; + cs->hppi.superprio =3D is_nmi; cs->seenbetter =3D true; } } diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index cb55c72681..4a56140f4c 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -299,6 +299,9 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_h= andler handler, for (i =3D 0; i < s->num_cpu; i++) { sysbus_init_irq(sbd, &s->cpu[i].parent_vfiq); } + for (i =3D 0; i < s->num_cpu; i++) { + sysbus_init_irq(sbd, &s->cpu[i].parent_nmi); + } =20 memory_region_init_io(&s->iomem_dist, OBJECT(s), ops, s, "gicv3_dist", 0x10000); @@ -563,6 +566,7 @@ static Property arm_gicv3_common_properties[] =3D { DEFINE_PROP_UINT32("num-irq", GICv3State, num_irq, 32), DEFINE_PROP_UINT32("revision", GICv3State, revision, 3), DEFINE_PROP_BOOL("has-lpi", GICv3State, lpi_enable, 0), + DEFINE_PROP_BOOL("has-nmi", GICv3State, nmi_support, 1), DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn,= 0), /* * Compatibility property: force 8 bits of physical priority, even diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c index e1a60d8c15..9b0ee0cfec 100644 --- a/hw/intc/arm_gicv3_cpuif.c +++ b/hw/intc/arm_gicv3_cpuif.c @@ -931,6 +931,7 @@ void gicv3_cpuif_update(GICv3CPUState *cs) /* Tell the CPU about its highest priority pending interrupt */ int irqlevel =3D 0; int fiqlevel =3D 0; + int nmilevel =3D 0; ARMCPU *cpu =3D ARM_CPU(cs->cpu); CPUARMState *env =3D &cpu->env; =20 @@ -967,7 +968,14 @@ void gicv3_cpuif_update(GICv3CPUState *cs) g_assert_not_reached(); } =20 - if (isfiq) { + if (cs->hppi.superprio) { + nmilevel =3D 1; + if (isfiq) { + cs->cpu->nmi_irq =3D false; + } else { + cs->cpu->nmi_irq =3D true; + } + } else if (isfiq) { fiqlevel =3D 1; } else { irqlevel =3D 1; @@ -978,6 +986,7 @@ void gicv3_cpuif_update(GICv3CPUState *cs) =20 qemu_set_irq(cs->parent_fiq, fiqlevel); qemu_set_irq(cs->parent_irq, irqlevel); + qemu_set_irq(cs->parent_nmi, nmilevel); } =20 static uint64_t icc_pmr_read(CPUARMState *env, const ARMCPRegInfo *ri) @@ -1097,7 +1106,8 @@ static uint64_t icc_hppir0_value(GICv3CPUState *cs, C= PUARMState *env) return cs->hppi.irq; } =20 -static uint64_t icc_hppir1_value(GICv3CPUState *cs, CPUARMState *env) +static uint64_t icc_hppir1_value(GICv3CPUState *cs, CPUARMState *env, + bool is_nmi, bool is_hppi) { /* Return the highest priority pending interrupt register value * for group 1. @@ -1108,6 +1118,16 @@ static uint64_t icc_hppir1_value(GICv3CPUState *cs, = CPUARMState *env) return INTID_SPURIOUS; } =20 + if (!is_hppi) { + if (is_nmi && (!cs->hppi.superprio)) { + return INTID_SPURIOUS; + } + + if ((!is_nmi) && cs->hppi.superprio) { + return INTID_NMI; + } + } + /* Check whether we can return the interrupt or if we should return * a special identifier, as per the CheckGroup1ForSpecialIdentifiers * pseudocode. (We can simplify a little because for us ICC_SRE_EL1.RM @@ -1168,7 +1188,30 @@ static uint64_t icc_iar1_read(CPUARMState *env, cons= t ARMCPRegInfo *ri) if (!icc_hppi_can_preempt(cs)) { intid =3D INTID_SPURIOUS; } else { - intid =3D icc_hppir1_value(cs, env); + intid =3D icc_hppir1_value(cs, env, false, false); + } + + if (!gicv3_intid_is_special(intid)) { + icc_activate_irq(cs, intid); + } + + trace_gicv3_icc_iar1_read(gicv3_redist_affid(cs), intid); + return intid; +} + +static uint64_t icc_nmiar1_read(CPUARMState *env, const ARMCPRegInfo *ri) +{ + GICv3CPUState *cs =3D icc_cs_from_env(env); + uint64_t intid; + + if (icv_access(env, HCR_IMO)) { + return icv_iar_read(env, ri); + } + + if (!icc_hppi_can_preempt(cs)) { + intid =3D INTID_SPURIOUS; + } else { + intid =3D icc_hppir1_value(cs, env, true, false); } =20 if (!gicv3_intid_is_special(intid)) { @@ -1555,7 +1598,7 @@ static uint64_t icc_hppir1_read(CPUARMState *env, con= st ARMCPRegInfo *ri) return icv_hppir_read(env, ri); } =20 - value =3D icc_hppir1_value(cs, env); + value =3D icc_hppir1_value(cs, env, false, true); trace_gicv3_icc_hppir1_read(gicv3_redist_affid(cs), value); return value; } @@ -2344,6 +2387,12 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] =3D { .access =3D PL1_R, .accessfn =3D gicv3_irq_access, .readfn =3D icc_iar1_read, }, + { .name =3D "ICC_NMIAR1_EL1", .state =3D ARM_CP_STATE_BOTH, + .opc0 =3D 3, .opc1 =3D 0, .crn =3D 12, .crm =3D 9, .opc2 =3D 5, + .type =3D ARM_CP_IO | ARM_CP_NO_RAW, + .access =3D PL1_R, .accessfn =3D gicv3_irq_access, + .readfn =3D icc_nmiar1_read, + }, { .name =3D "ICC_EOIR1_EL1", .state =3D ARM_CP_STATE_BOTH, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 12, .crm =3D 12, .opc2 =3D 1, .type =3D ARM_CP_IO | ARM_CP_NO_RAW, diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c index 35e850685c..a234df44dd 100644 --- a/hw/intc/arm_gicv3_dist.c +++ b/hw/intc/arm_gicv3_dist.c @@ -89,6 +89,29 @@ static int gicd_ns_access(GICv3State *s, int irq) return extract32(s->gicd_nsacr[irq / 16], (irq % 16) * 2, 2); } =20 +static void gicd_write_bitmap_reg(GICv3State *s, MemTxAttrs attrs, + uint32_t *bmp, maskfn *maskfn, + int offset, uint32_t val) +{ + /* + * Helper routine to implement writing to a "set" register + * (GICD_INMIR, etc). + * Semantics implemented here: + * RAZ/WI for SGIs, PPIs, unimplemented IRQs + * Bits corresponding to Group 0 or Secure Group 1 interrupts RAZ/WI. + * offset should be the offset in bytes of the register from the start + * of its group. + */ + int irq =3D offset * 8; + + if (irq < GIC_INTERNAL || irq >=3D s->num_irq) { + return; + } + val &=3D mask_group_and_nsacr(s, attrs, maskfn, irq); + *gic_bmp_ptr32(bmp, irq) =3D val; + gicv3_update(s, irq, 32); +} + static void gicd_write_set_bitmap_reg(GICv3State *s, MemTxAttrs attrs, uint32_t *bmp, maskfn *maskfn, @@ -402,6 +425,7 @@ static bool gicd_readl(GICv3State *s, hwaddr offset, bool dvis =3D s->revision >=3D 4; =20 *data =3D (1 << 25) | (1 << 24) | (dvis << 18) | (sec_extn << 10) | + (s->nmi_support << GICD_TYPER_NMI_SHIFT) | (s->lpi_enable << GICD_TYPER_LPIS_SHIFT) | (0xf << 19) | itlinesnumber; return true; @@ -543,6 +567,14 @@ static bool gicd_readl(GICv3State *s, hwaddr offset, /* RAZ/WI since affinity routing is always enabled */ *data =3D 0; return true; + case GICD_INMIR ... GICD_INMIR + 0x7f: + if (!s->nmi_support) { + *data =3D 0; + return true; + } + *data =3D gicd_read_bitmap_reg(s, attrs, s->superprio, NULL, + offset - GICD_INMIR); + return true; case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: { uint64_t r; @@ -752,6 +784,13 @@ static bool gicd_writel(GICv3State *s, hwaddr offset, case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: /* RAZ/WI since affinity routing is always enabled */ return true; + case GICD_INMIR ... GICD_INMIR + 0x7f: + if (!s->nmi_support) { + return true; + } + gicd_write_bitmap_reg(s, attrs, s->superprio, NULL, + offset - GICD_INMIR, value); + return true; case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: { uint64_t r; diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c index 8153525849..87e7823f34 100644 --- a/hw/intc/arm_gicv3_redist.c +++ b/hw/intc/arm_gicv3_redist.c @@ -35,6 +35,15 @@ static int gicr_ns_access(GICv3CPUState *cs, int irq) return extract32(cs->gicr_nsacr, irq * 2, 2); } =20 +static void gicr_write_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs, + uint32_t *reg, uint32_t val) +{ + /* Helper routine to implement writing to a "set" register */ + val &=3D mask_group(cs, attrs); + *reg =3D val; + gicv3_redist_update(cs); +} + static void gicr_write_set_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs, uint32_t *reg, uint32_t val) { @@ -406,6 +415,13 @@ static MemTxResult gicr_readl(GICv3CPUState *cs, hwadd= r offset, *data =3D value; return MEMTX_OK; } + case GICR_INMIR0: + if (!cs->gic->nmi_support) { + *data =3D 0; + return MEMTX_OK; + } + *data =3D gicr_read_bitmap_reg(cs, attrs, cs->gicr_isuperprio); + return MEMTX_OK; case GICR_ICFGR0: case GICR_ICFGR1: { @@ -555,6 +571,13 @@ static MemTxResult gicr_writel(GICv3CPUState *cs, hwad= dr offset, gicv3_redist_update(cs); return MEMTX_OK; } + case GICR_INMIR0: + if (!cs->gic->nmi_support) { + return MEMTX_OK; + } + gicr_write_bitmap_reg(cs, attrs, &cs->gicr_isuperprio, value); + return MEMTX_OK; + case GICR_ICFGR0: /* Register is all RAZ/WI or RAO/WI bits */ return MEMTX_OK; diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h index 29d5cdc1b6..93e56b3726 100644 --- a/hw/intc/gicv3_internal.h +++ b/hw/intc/gicv3_internal.h @@ -52,6 +52,8 @@ #define GICD_SGIR 0x0F00 #define GICD_CPENDSGIR 0x0F10 #define GICD_SPENDSGIR 0x0F20 +#define GICD_INMIR 0x0F80 +#define GICD_INMIRnE 0x3B00 #define GICD_IROUTER 0x6000 #define GICD_IDREGS 0xFFD0 =20 @@ -68,6 +70,7 @@ #define GICD_CTLR_E1NWF (1U << 7) #define GICD_CTLR_RWP (1U << 31) =20 +#define GICD_TYPER_NMI_SHIFT 9 #define GICD_TYPER_LPIS_SHIFT 17 =20 /* 16 bits EventId */ @@ -109,6 +112,7 @@ #define GICR_ICFGR1 (GICR_SGI_OFFSET + 0x0C04) #define GICR_IGRPMODR0 (GICR_SGI_OFFSET + 0x0D00) #define GICR_NSACR (GICR_SGI_OFFSET + 0x0E00) +#define GICR_INMIR0 (GICR_SGI_OFFSET + 0x0F80) =20 /* VLPI redistributor registers, offsets from VLPI_base */ #define GICR_VPROPBASER (GICR_VLPI_OFFSET + 0x70) @@ -507,6 +511,7 @@ FIELD(VTE, RDBASE, 42, RDBASE_PROCNUM_LENGTH) /* Special interrupt IDs */ #define INTID_SECURE 1020 #define INTID_NONSECURE 1021 +#define INTID_NMI 1022 #define INTID_SPURIOUS 1023 =20 /* Functions internal to the emulated GICv3 */ diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 4385ce54c9..6c9dc25e5b 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -541,6 +541,7 @@ struct CPUState { uint32_t tcg_cflags; uint32_t halted; int32_t exception_index; + bool nmi_irq; =20 AccelCPUState *accel; /* shared by kvm and hvf */ diff --git a/include/hw/intc/arm_gic_common.h b/include/hw/intc/arm_gic_com= mon.h index 7080375008..140f531758 100644 --- a/include/hw/intc/arm_gic_common.h +++ b/include/hw/intc/arm_gic_common.h @@ -69,6 +69,7 @@ struct GICState { =20 qemu_irq parent_irq[GIC_NCPU]; qemu_irq parent_fiq[GIC_NCPU]; + qemu_irq parent_nmi[GIC_NCPU]; qemu_irq parent_virq[GIC_NCPU]; qemu_irq parent_vfiq[GIC_NCPU]; qemu_irq maintenance_irq[GIC_NCPU]; diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3= _common.h index 4e2fb518e7..8f9bcdfac9 100644 --- a/include/hw/intc/arm_gicv3_common.h +++ b/include/hw/intc/arm_gicv3_common.h @@ -146,6 +146,7 @@ typedef struct { int irq; uint8_t prio; int grp; + bool superprio; } PendingIrq; =20 struct GICv3CPUState { @@ -155,6 +156,7 @@ struct GICv3CPUState { qemu_irq parent_fiq; qemu_irq parent_virq; qemu_irq parent_vfiq; + qemu_irq parent_nmi; =20 /* Redistributor */ uint32_t level; /* Current IRQ level */ @@ -170,6 +172,7 @@ struct GICv3CPUState { uint32_t gicr_ienabler0; uint32_t gicr_ipendr0; uint32_t gicr_iactiver0; + uint32_t gicr_isuperprio; uint32_t edge_trigger; /* ICFGR0 and ICFGR1 even bits */ uint32_t gicr_igrpmodr0; uint32_t gicr_nsacr; @@ -247,6 +250,7 @@ struct GICv3State { uint32_t num_irq; uint32_t revision; bool lpi_enable; + bool nmi_support; bool security_extn; bool force_8bit_prio; bool irq_reset_nonsecure; @@ -272,6 +276,7 @@ struct GICv3State { GIC_DECLARE_BITMAP(active); /* GICD_ISACTIVER */ GIC_DECLARE_BITMAP(level); /* Current level */ GIC_DECLARE_BITMAP(edge_trigger); /* GICD_ICFGR even bits */ + GIC_DECLARE_BITMAP(superprio); /* GICD_INMIR */ uint8_t gicd_ipriority[GICV3_MAXIRQ]; uint64_t gicd_irouter[GICV3_MAXIRQ]; /* Cached information: pointer to the cpu i/f for the CPUs specified @@ -311,6 +316,7 @@ GICV3_BITMAP_ACCESSORS(pending) GICV3_BITMAP_ACCESSORS(active) GICV3_BITMAP_ACCESSORS(level) GICV3_BITMAP_ACCESSORS(edge_trigger) +GICV3_BITMAP_ACCESSORS(superprio) =20 #define TYPE_ARM_GICV3_COMMON "arm-gicv3-common" typedef struct ARMGICv3CommonClass ARMGICv3CommonClass; diff --git a/target/arm/helper.c b/target/arm/helper.c index 8d525c6b82..9bf0073840 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2023,7 +2023,7 @@ static uint64_t isr_read(CPUARMState *env, const ARMC= PRegInfo *ri) ret |=3D CPSR_I; } =20 - if (cs->interrupt_request & CPU_INTERRUPT_NMI) { + if ((cs->interrupt_request & CPU_INTERRUPT_NMI) && cs->nmi_irq) { ret |=3D ISR_IS; } } @@ -2037,7 +2037,7 @@ static uint64_t isr_read(CPUARMState *env, const ARMC= PRegInfo *ri) ret |=3D CPSR_F; } =20 - if (cs->interrupt_request & CPU_INTERRUPT_NMI) { + if ((cs->interrupt_request & CPU_INTERRUPT_NMI) && !cs->nmi_irq) { ret |=3D ISR_FS; } } @@ -11452,6 +11452,7 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *= cs) break; case EXCP_IRQ: case EXCP_VIRQ: + case EXCP_NMI: addr +=3D 0x80; break; case EXCP_FIQ: --=20 2.34.1