Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3276019imm; Fri, 25 May 2018 02:55:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqzZfHpNAZDYTulWd5RNlLJ9xdkzX33La/e/g5EzG923r0BPimE2oH3dNY6RhJoDfSu24dd X-Received: by 2002:a63:715d:: with SMTP id b29-v6mr1351136pgn.325.1527242125983; Fri, 25 May 2018 02:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527242125; cv=none; d=google.com; s=arc-20160816; b=QWN0RwlZWY/PHwqGyVlZabTr43frAauzgnuu7r+2yosLDM7U9ChttTR4Q7aFJ4Acdy +6eXF3baWhEz0QVcOjEtbGTDTT353prfgl8UQhPfd1ZzSLMkjijDLBI9eIkHrp0kwgEJ Q9S6YhuftaQkmtxqSZIsXmOw/F060R/0S5wGcPBuBuRMXODsJNsF1g2oPPiccGUwkC4X a91ZtljGfgQhfyAkjY9fzLSsG3S6z81KaBLayY44mpI089donnddKm29OSdiW70ERhps yDZpmgUytPVkELymxYFL4bd6Fqsp4+DwToKat/rMzU7HlM4VZkzjddfXbL1MNpBwzmOb CCpw== 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=qVVejGZsP4SkHY6dbOuSyM8wbrkKKqVszCNWn66pcEk=; b=okyqaXP6eczkw3SonEzrvDoQPTlLi1FBgL7F01sTc/CXAuMZ2ay0YoIhPz1tydmTg3 NA+Y/YRknJY/AT8hUD7lkhds9wjYiVvC9BWeGayVpfD2iX2ias6vy3b4z/crDGlVblLi d+rNo39EqIpIHhHoPllqfm/a30AdLcCzf4gtZWwWh4SuEBgxQATD7T7XIHA7er2hPcB1 uBroLn5TPNVqR9pJDNAT16TVnlTQV7Ijn/I2UQytPSBVsBodJFYdpPHXL1ea02Hflkhx hMJbN5UcuwJrY8MqEV7w94FmNGCju6JK0tFWT0K9dp2Am+D/gguUyeD1tJXUY77FCZXc Gy4A== 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 x63-v6si23216320pfi.162.2018.05.25.02.55.11; Fri, 25 May 2018 02:55:25 -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 S966199AbeEYJuq (ORCPT + 99 others); Fri, 25 May 2018 05:50:46 -0400 Received: from foss.arm.com ([217.140.101.70]:57584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966133AbeEYJuh (ORCPT ); Fri, 25 May 2018 05:50:37 -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 3A689168F; Fri, 25 May 2018 02:50:37 -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 E3CAB3F25D; Fri, 25 May 2018 02:50:34 -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 v4 17/26] irqchip/gic-v3: Factor group0 detection into functions Date: Fri, 25 May 2018 10:49:23 +0100 Message-Id: <1527241772-48007-18-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527241772-48007-1-git-send-email-julien.thierry@arm.com> References: <1527241772-48007-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. 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 0c58db3..13d283d 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -389,6 +389,39 @@ static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs } } +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; @@ -530,7 +563,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 @@ -542,25 +575,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