From patchwork Wed Jan 17 11:54:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 10169211 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 9F787603ED for ; Wed, 17 Jan 2018 11:57:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF1E2856D for ; Wed, 17 Jan 2018 11:57:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8279928578; Wed, 17 Jan 2018 11:57:47 +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=unavailable 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 CE3A62856D for ; Wed, 17 Jan 2018 11:57:46 +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=FBqjURTNw/ISV98JEo5ERUMWiTdTWdFX8HBrc2/lB8o=; b=MDsvMg9/j4O7kX0bPmBAgsUUYS XEUmQytvK9eQBSAUv4DSpKXDPQXhygiZSbtEcM/NsY9WObdoayVCzjQjclU4OGrn3v32u1/qrvE6q 0LwNNmNf72VPVwIR5zM23S8ld12f1j1cBfALSoqxiBl5RLXaLMQPZlf8SGoU4VQSyNbxUO7tJlaVk nCXBjyTQZ+mypJMaEDlnKbNwY8alrY/babDf4ncKeFiROgidr9X2iLNXhiiQxhFLg0othybNf5FP9 l/IDEv7utYSonhPo4PHJdiio4ePd4PAYrVJgGWjeDrPyYB9p+cBnROT4Rn8+9PBAV1Ogbo5wsGzII fGBMXQBw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ebmLf-0007KR-3f; Wed, 17 Jan 2018 11:57:43 +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.89 #1 (Red Hat Linux)) id 1ebmJb-0004aV-5M for linux-arm-kernel@lists.infradead.org; Wed, 17 Jan 2018 11:55:37 +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 39E1A165C; Wed, 17 Jan 2018 03:55:21 -0800 (PST) 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 6DDCD3F53D; Wed, 17 Jan 2018 03:55:19 -0800 (PST) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] arm64: Detect current view of GIC priorities Date: Wed, 17 Jan 2018 11:54:43 +0000 Message-Id: <1516190084-18978-6-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516190084-18978-1-git-send-email-julien.thierry@arm.com> References: <1516190084-18978-1-git-send-email-julien.thierry@arm.com> 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: mark.rutland@arm.com, daniel.thompson@linaro.org, Jason Cooper , Julien Thierry , marc.zyngier@arm.com, Catalin Marinas , Will Deacon , james.morse@arm.com, Thomas Gleixner 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 | 86 +++++++++++++++++++++++++++++++++++++ 5 files changed, 103 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 490bb3a..ac7b7f6 100644 --- a/arch/arm64/include/asm/arch_gicv3.h +++ b/arch/arm64/include/asm/arch_gicv3.h @@ -124,6 +124,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 3d5d443..d25e7ee 100644 --- a/arch/arm64/include/asm/irqflags.h +++ b/arch/arm64/include/asm/irqflags.h @@ -217,6 +217,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 08cc885..46fa869 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -304,6 +304,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 df51d96..58b5e89 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -63,6 +63,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; static DEFINE_PER_CPU(bool, has_rss); @@ -997,6 +1001,84 @@ 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); + + do { + 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); + } + } while (acked_irqnr == ICC_IAR1_EL1_SPURIOUS); + + /* 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, @@ -1057,6 +1139,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: