From patchwork Wed Oct 11 13:01:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 9999591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9BEB96037F for ; Wed, 11 Oct 2017 13:04:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B7F328A16 for ; Wed, 11 Oct 2017 13:04:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 805C128A18; Wed, 11 Oct 2017 13:04:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A61B28A16 for ; Wed, 11 Oct 2017 13:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wyGzXxBouGRXLV2/owX5K41J1Zn0QufwLuOcUOeinBk=; b=LcfpxUQnmgbGMaMgb+vJNRDEbG cD4vCHFq5DKBZoO1LNnVOkRdOSBGYoo810qxLXlvzUyWsmTD3zQQS9KTEfweHfP+WY+4WIXctPfKy ANWnrAK8l61qfomIXGTUgKXlVwzQ4mZj0AEFPzIMG+Afn2qTuQ2/89Mr37Jn5+RCsZo0jvz6tr1I+ RO7gcV8/QJIMcHyXoWN/QunpWJVjJ0knnTx6ZOkm47GlRVKQHMvYGA/2yFjQT6H34//NprEIHZ/BG DtPxkwmkQELssd9/tCHivLgjY+kXHPuqphSWRiRkQI9ejJ4W6zeOEvSO2uLUawVYd0+lN8USPSUL4 bYPmM06g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2Gg9-0007ed-9N; Wed, 11 Oct 2017 13:04:05 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2Ge0-0005hV-Bv for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2017 13:02:04 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31460164F; Wed, 11 Oct 2017 06:01:27 -0700 (PDT) Received: from e112298-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AC32B3F483; Wed, 11 Oct 2017 06:01:25 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org, daniel.thompson@linaro.org, marc.zyngier@arm.com, mark.rutland@arm.com Subject: [RFC 6/7] arm64: Detect current view of GIC priorities Date: Wed, 11 Oct 2017 14:01:01 +0100 Message-Id: <1507726862-11944-7-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507726862-11944-1-git-send-email-julien.thierry@arm.com> References: <1507726862-11944-1-git-send-email-julien.thierry@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171011_060152_960674_9DADEED8 X-CRM114-Status: GOOD ( 17.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Thomas Gleixner , Will Deacon , Jason Cooper , Julien Thierry MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The values non secure EL1 needs to use for priority registers depends on the value of SCR_EL3.FIQ. Since we don't have access to SCR_EL3, we fake an interrupt and compare the GIC priority with the one present in the [re]distributor. Also, add firmware requirements related to SCR_EL3. Signed-off-by: Julien Thierry Cc: Catalin Marinas Cc: Will Deacon Cc: Thomas Gleixner Cc: Jason Cooper Cc: Marc Zyngier --- Documentation/arm64/booting.txt | 5 +++ arch/arm64/include/asm/arch_gicv3.h | 5 +++ arch/arm64/include/asm/irqflags.h | 6 +++ arch/arm64/include/asm/sysreg.h | 1 + drivers/irqchip/irq-gic-v3.c | 83 +++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) -- 1.9.1 diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt index 8d0df62..e387938 100644 --- a/Documentation/arm64/booting.txt +++ b/Documentation/arm64/booting.txt @@ -188,6 +188,11 @@ Before jumping into the kernel, the following conditions must be met: the kernel image will be entered must be initialised by software at a higher exception level to prevent execution in an UNKNOWN state. + - SCR_EL3.FIQ must have the same value across all CPUs the kernel is + executing on. + - The value of SCR_EL3.FIQ must be the same as the one present at boot + time whenever the kernel is executing. + For systems with a GICv3 interrupt controller to be used in v3 mode: - If EL3 is present: ICC_SRE_EL3.Enable (bit 3) must be initialiased to 0b1. diff --git a/arch/arm64/include/asm/arch_gicv3.h b/arch/arm64/include/asm/arch_gicv3.h index b6b430c..90a3dc3 100644 --- a/arch/arm64/include/asm/arch_gicv3.h +++ b/arch/arm64/include/asm/arch_gicv3.h @@ -114,6 +114,11 @@ static inline void gic_write_bpr1(u32 val) write_sysreg_s(val, SYS_ICC_BPR1_EL1); } +static inline u32 gic_read_rpr(void) +{ + return read_sysreg_s(SYS_ICC_RPR_EL1); +} + #define gic_read_typer(c) readq_relaxed(c) #define gic_write_irouter(v, c) writeq_relaxed(v, c) #define gic_read_lpir(c) readq_relaxed(c) diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h index 1c69ebb..4718ca3f 100644 --- a/arch/arm64/include/asm/irqflags.h +++ b/arch/arm64/include/asm/irqflags.h @@ -205,6 +205,12 @@ static inline int arch_irqs_disabled_flags(unsigned long flags) !(ARCH_FLAGS_GET_PMR(flags) & ICC_PMR_EL1_EN_BIT); } +/* Mask IRQs at CPU level instead of GIC level */ +static inline void arch_irqs_daif_disable(void) +{ + asm volatile ("msr daifset, #2" : : : "memory"); +} + void maybe_switch_to_sysreg_gic_cpuif(void); #endif /* CONFIG_IRQFLAGS_GIC_MASKING */ diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index f707fed..e71bc81 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -205,6 +205,7 @@ #define SYS_ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5) #define SYS_ICC_IGRPEN0_EL1 sys_reg(3, 0, 12, 12, 6) #define SYS_ICC_IGRPEN1_EL1 sys_reg(3, 0, 12, 12, 7) +#define SYS_ICC_RPR_EL1 sys_reg(3, 0, 12, 11, 3) #define SYS_CONTEXTIDR_EL1 sys_reg(3, 0, 13, 0, 1) #define SYS_TPIDR_EL1 sys_reg(3, 0, 13, 0, 4) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 1cdf495..e0b235f 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -62,6 +62,10 @@ struct gic_chip_data { static struct gic_chip_data gic_data __read_mostly; static struct static_key supports_deactivate = STATIC_KEY_INIT_TRUE; +#ifdef CONFIG_USE_ICC_SYSREGS_FOR_IRQFLAGS +DEFINE_STATIC_KEY_FALSE(have_non_secure_prio_view); +#endif + static struct gic_kvm_info gic_v3_kvm_info; #define gic_data_rdist() (this_cpu_ptr(gic_data.rdists.rdist)) @@ -969,6 +973,81 @@ static int partition_domain_translate(struct irq_domain *d, .select = gic_irq_domain_select, }; +#ifdef CONFIG_USE_ICC_SYSREGS_FOR_IRQFLAGS +/* + * The behaviours of RPR and PMR registers differ depending on the value of + * SCR_EL3.FIQ, while the behaviour of priority registers of the distributor + * and redistributors is always the same. + * + * If SCR_EL3.FIQ == 1, the values used for RPR and PMR are the same as the ones + * programmed in the distributor and redistributors registers. + * + * Otherwise, the value presented by RPR as well as the value which will be + * compared against PMR is: (GIC_(R)DIST_PRI[irq] >> 1) | 0x80; + * + * see GICv3/GICv4 Architecture Specification (IHI0069D): + * - section 4.8.1 Non-secure accesses to register fields for Secure interrupt + * priorities. + * - Figure 4-7 Secure read of the priority field for a Non-secure Group 1 + * interrupt. + */ +static void __init gic_detect_prio_view(void) +{ + /* + * Randomly picked SGI, must be <= 8 as other SGIs might be + * used by the firmware. + */ + const u32 fake_irqnr = 7; + const u32 fake_irqmask = BIT(fake_irqnr); + void __iomem * const rdist_base = gic_data_rdist_sgi_base(); + unsigned long irq_flags; + u32 acked_irqnr; + bool was_enabled; + + irq_flags = arch_local_save_flags(); + + arch_irqs_daif_disable(); + + was_enabled = !!(readl_relaxed(rdist_base + GICD_ISENABLER) & + fake_irqmask); + + if (!was_enabled) + writel_relaxed(fake_irqmask, rdist_base + GICD_ISENABLER); + + /* Need to unmask to acknowledge the IRQ */ + gic_write_pmr(ICC_PMR_EL1_UNMASKED); + dsb(sy); + + /* Fake a pending SGI */ + writel_relaxed(fake_irqmask, rdist_base + GICD_ISPENDR); + dsb(sy); + + acked_irqnr = gic_read_iar(); + + if (acked_irqnr == fake_irqnr) { + if (gic_read_rpr() == gic_get_irq_prio(acked_irqnr, rdist_base)) + static_branch_enable(&have_non_secure_prio_view); + } else { + pr_warn("Unexpected IRQ for priority detection: %u\n", + acked_irqnr); + } + + if (acked_irqnr < 1020) { + gic_write_eoir(acked_irqnr); + if (static_key_true(&supports_deactivate)) + gic_write_dir(acked_irqnr); + } + + /* Restore enabled state */ + if (!was_enabled) { + writel_relaxed(fake_irqmask, rdist_base + GICD_ICENABLER); + gic_redist_wait_for_rwp(); + } + + arch_local_irq_restore(irq_flags); +} +#endif + static int __init gic_init_bases(void __iomem *dist_base, struct redist_region *rdist_regs, u32 nr_redist_regions, @@ -1025,6 +1104,10 @@ static int __init gic_init_bases(void __iomem *dist_base, gic_cpu_init(); gic_cpu_pm_init(); +#ifdef CONFIG_USE_ICC_SYSREGS_FOR_IRQFLAGS + gic_detect_prio_view(); +#endif + return 0; out_free: