Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7258016imm; Tue, 28 Aug 2018 08:54:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ4EV48tLbZ3B34Ex/apYdIqYTBWKUXc9iFVe9FGMtHNaZDXLbOfD8LS3gqkkU2R1Y5KiOw X-Received: by 2002:a63:231c:: with SMTP id j28-v6mr2104324pgj.332.1535471650521; Tue, 28 Aug 2018 08:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535471650; cv=none; d=google.com; s=arc-20160816; b=RkSQbHRvflvd8OCeE083I89KlKgYEx7wtvanuoxJaaLCr3atqhqIwlTUAwEWIWArah orFJSu173xShkJi5PXJtTTQwoOBgqgLoHbGEQwOTPLSklxE68CI37Uh2ngJSSW6t2f2t 5BGijmL4l58j/QrRr7UrCaOsjW4vmSp+vyLnfXrFr+dJey08qFj5EVdIu88cBfdEH952 ziDb2MoQ1jCKiCeFpptDX3DbJrLeNN2CTWuOmyF5Xzcofqcp6Bta3UDeGHOUoF2s+Sdp Bf8B5MXS9fTKXDlZlKPtqAbbpyBrSoxdHtivUFhdy5Cmq5R0JNSkea3e87274O97m5P2 k7iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=3KVi1emgZjv+hnVEltA2JgohkRL8zD03WdubIPrevhY=; b=vKMKTkR5TXLZiOtbb1anbMKGPb8WveqVo6FDQPGX0jBdBEYb8AHkPEDVUKPGZ9X8va Ilor8eZuI0JyqkGOjGCoYxuWObjiYh0WloVNAyNx68uQBkc/mahPI0GFeuvX+7FfHlbN hzlJGP2vzzJR2VxVt6fcviiQAlIk4y8cUuV/fVLGJyyKafC2VSk6xANpjnQ/MngtWlc7 j1e9cKziqeOReV132hvBdFzwuJ04zr0Dt55k7adfIHTfNt4OHLMX//SMxd/GZqAkwKwK XNCG0gMTly++wbwYkHXBhcbviGpyOlkOs/0Z05apL9JOg9j+SOGs7f3vAHiCHEHzdIQQ MVuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be11-v6si1240396plb.347.2018.08.28.08.53.55; Tue, 28 Aug 2018 08:54:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbeH1Top (ORCPT + 99 others); Tue, 28 Aug 2018 15:44:45 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41092 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbeH1Too (ORCPT ); Tue, 28 Aug 2018 15:44:44 -0400 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 4C9B980D; Tue, 28 Aug 2018 08:52:28 -0700 (PDT) Received: from e112298-lin.Emea.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 17EFC3F557; Tue, 28 Aug 2018 08:52:25 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, Julien Thierry , Thomas Gleixner , Jason Cooper Subject: [PATCH v5 17/27] irqchip/gic-v3: Factor group0 detection into functions Date: Tue, 28 Aug 2018 16:51:27 +0100 Message-Id: <1535471497-38854-18-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> References: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code to detect whether Linux has access to group0 interrupts can prove useful in other parts of the driver. Provide a separate function to do this. Tested-by: Daniel Thompson Signed-off-by: Julien Thierry Cc: Thomas Gleixner Cc: Jason Cooper Cc: Marc Zyngier --- drivers/irqchip/irq-gic-v3.c | 55 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index d5912f1..fef6688 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -392,6 +392,39 @@ static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs } while (irqnr != ICC_IAR1_EL1_SPURIOUS); } +static u32 gic_get_pribits(void) +{ + u32 pribits; + + pribits = gic_read_ctlr(); + pribits &= ICC_CTLR_EL1_PRI_BITS_MASK; + pribits >>= ICC_CTLR_EL1_PRI_BITS_SHIFT; + pribits++; + + return pribits; +} + +static bool gic_has_group0(void) +{ + u32 val; + + /* + * Let's find out if Group0 is under control of EL3 or not by + * setting the highest possible, non-zero priority in PMR. + * + * If SCR_EL3.FIQ is set, the priority gets shifted down in + * order for the CPU interface to set bit 7, and keep the + * actual priority in the non-secure range. In the process, it + * looses the least significant bit and the actual priority + * becomes 0x80. Reading it back returns 0, indicating that + * we're don't have access to Group0. + */ + gic_write_pmr(BIT(8 - gic_get_pribits())); + val = gic_read_pmr(); + + return val != 0; +} + static void __init gic_dist_init(void) { unsigned int i; @@ -533,7 +566,7 @@ static void gic_cpu_sys_reg_init(void) u64 mpidr = cpu_logical_map(cpu); u64 need_rss = MPIDR_RS(mpidr); bool group0; - u32 val, pribits; + u32 pribits; /* * Need to check that the SRE bit has actually been set. If @@ -545,25 +578,9 @@ static void gic_cpu_sys_reg_init(void) if (!gic_enable_sre()) pr_err("GIC: unable to set SRE (disabled at EL2), panic ahead\n"); - pribits = gic_read_ctlr(); - pribits &= ICC_CTLR_EL1_PRI_BITS_MASK; - pribits >>= ICC_CTLR_EL1_PRI_BITS_SHIFT; - pribits++; + pribits = gic_get_pribits(); - /* - * Let's find out if Group0 is under control of EL3 or not by - * setting the highest possible, non-zero priority in PMR. - * - * If SCR_EL3.FIQ is set, the priority gets shifted down in - * order for the CPU interface to set bit 7, and keep the - * actual priority in the non-secure range. In the process, it - * looses the least significant bit and the actual priority - * becomes 0x80. Reading it back returns 0, indicating that - * we're don't have access to Group0. - */ - write_gicreg(BIT(8 - pribits), ICC_PMR_EL1); - val = read_gicreg(ICC_PMR_EL1); - group0 = val != 0; + group0 = gic_has_group0(); /* Set priority mask register */ write_gicreg(DEFAULT_PMR_VALUE, ICC_PMR_EL1); -- 1.9.1