Skip to contentSkip to conversation

GICv3: add 32bit compatibility

PATCH Superseded Jean-Philippe Brucker 5 participants 14 messages Dec 11, 2014 – Dec 18, 2014

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover GICv3: add 32bit compatibility

This series adds 32bit compatibility to Marc's GICv3 driver. Only SGIs, PPIs and SPIs support is present. No ITS nor virtualisation.

It is based on 3.18.

Jean-Philippe Brucker (4):
arm64: GICv3: refactor the AArch64 specific parts
arm64: GICv3: change unsigned types for AArch32 compatibility
arm64: GICv3: Specialize readq and writeq accesses
ARM: add 32bit support to GICv3

 arch/arm/include/asm/arch_gicv3.h   | 182 ++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/arch_gicv3.h | 141 ++++++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3.c        |  69 ++++----------
 include/linux/irqchip/arm-gic-v3.h  |  95 +++----------------
 4 files changed, 356 insertions(+), 131 deletions(-)
 create mode 100644 arch/arm/include/asm/arch_gicv3.h
 create mode 100644 arch/arm64/include/asm/arch_gicv3.h
Signature · 1 line
2.2.0.rc1
#1 lore raw

PATCH 1/4 arm64: GICv3: refactor the AArch64 specific parts

This patch moves the GICv3 system register access helpers to arch/arm64/. Their 32bit counterparts will need to use mrc/mcr accesses instead of mrs_s/msr_s.

---
 arch/arm64/include/asm/arch_gicv3.h | 133 ++++++++++++++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3.c        |  38 +----------
 include/linux/irqchip/arm-gic-v3.h  |  77 ++-------------------
 3 files changed, 142 insertions(+), 106 deletions(-)
 create mode 100644 arch/arm64/include/asm/arch_gicv3.h
arch/arm64/include/asm/arch_gicv3.h new file +133 -0
new file mode 100644
index 0000000..28482d0
@@ -0,0 +1,133 @@
+/*
+ * arch/arm64/include/asm/arch_gicv3.h
+ *
+ * Copyright (C) 2014 ARM Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#include <asm/sysreg.h>
+
+#define ICC_EOIR1_EL1			sys_reg(3, 0, 12, 12, 1)
+#define ICC_IAR1_EL1			sys_reg(3, 0, 12, 12, 0)
+#define ICC_SGI1R_EL1			sys_reg(3, 0, 12, 11, 5)
+#define ICC_PMR_EL1			sys_reg(3, 0, 4, 6, 0)
+#define ICC_CTLR_EL1			sys_reg(3, 0, 12, 12, 4)
+#define ICC_SRE_EL1			sys_reg(3, 0, 12, 12, 5)
+#define ICC_GRPEN1_EL1			sys_reg(3, 0, 12, 12, 7)
+
+#define ICC_SRE_EL2			sys_reg(3, 4, 12, 9, 5)
+
+/*
+ * System register definitions
+ */
+#define ICH_VSEIR_EL2			sys_reg(3, 4, 12, 9, 4)
+#define ICH_HCR_EL2			sys_reg(3, 4, 12, 11, 0)
+#define ICH_VTR_EL2			sys_reg(3, 4, 12, 11, 1)
+#define ICH_MISR_EL2			sys_reg(3, 4, 12, 11, 2)
+#define ICH_EISR_EL2			sys_reg(3, 4, 12, 11, 3)
+#define ICH_ELSR_EL2			sys_reg(3, 4, 12, 11, 5)
+#define ICH_VMCR_EL2			sys_reg(3, 4, 12, 11, 7)
+
+#define __LR0_EL2(x)			sys_reg(3, 4, 12, 12, x)
+#define __LR8_EL2(x)			sys_reg(3, 4, 12, 13, x)
+
+#define ICH_LR0_EL2			__LR0_EL2(0)
+#define ICH_LR1_EL2			__LR0_EL2(1)
+#define ICH_LR2_EL2			__LR0_EL2(2)
+#define ICH_LR3_EL2			__LR0_EL2(3)
+#define ICH_LR4_EL2			__LR0_EL2(4)
+#define ICH_LR5_EL2			__LR0_EL2(5)
+#define ICH_LR6_EL2			__LR0_EL2(6)
+#define ICH_LR7_EL2			__LR0_EL2(7)
+#define ICH_LR8_EL2			__LR8_EL2(0)
+#define ICH_LR9_EL2			__LR8_EL2(1)
+#define ICH_LR10_EL2			__LR8_EL2(2)
+#define ICH_LR11_EL2			__LR8_EL2(3)
+#define ICH_LR12_EL2			__LR8_EL2(4)
+#define ICH_LR13_EL2			__LR8_EL2(5)
+#define ICH_LR14_EL2			__LR8_EL2(6)
+#define ICH_LR15_EL2			__LR8_EL2(7)
+
+#define __AP0Rx_EL2(x)			sys_reg(3, 4, 12, 8, x)
+#define ICH_AP0R0_EL2			__AP0Rx_EL2(0)
+#define ICH_AP0R1_EL2			__AP0Rx_EL2(1)
+#define ICH_AP0R2_EL2			__AP0Rx_EL2(2)
+#define ICH_AP0R3_EL2			__AP0Rx_EL2(3)
+
+#define __AP1Rx_EL2(x)			sys_reg(3, 4, 12, 9, x)
+#define ICH_AP1R0_EL2			__AP1Rx_EL2(0)
+#define ICH_AP1R1_EL2			__AP1Rx_EL2(1)
+#define ICH_AP1R2_EL2			__AP1Rx_EL2(2)
+#define ICH_AP1R3_EL2			__AP1Rx_EL2(3)
+
+#ifndef __ASSEMBLY__
+
+#include <linux/stringify.h>
+
+/* Low level accessors */
+
+static inline void gic_write_eoir(u64 irq)
+{
+	asm volatile("msr_s " __stringify(ICC_EOIR1_EL1) ", %0" : : "r" (irq));
+	isb();
+}
+
+static inline u64 __maybe_unused gic_read_iar(void)
+{
+	u64 irqstat;
+
+	asm volatile("mrs_s %0, " __stringify(ICC_IAR1_EL1) : "=r" (irqstat));
+	return irqstat;
+}
+
+static inline void __maybe_unused gic_write_pmr(u64 val)
+{
+	asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" (val));
+}
+
+static inline void __maybe_unused gic_write_ctlr(u64 val)
+{
+	asm volatile("msr_s " __stringify(ICC_CTLR_EL1) ", %0" : : "r" (val));
+	isb();
+}
+
+static inline void __maybe_unused gic_write_grpen1(u64 val)
+{
+	asm volatile("msr_s " __stringify(ICC_GRPEN1_EL1) ", %0" : : "r" (val));
+	isb();
+}
+
+static inline void __maybe_unused gic_write_sgi1r(u64 val)
+{
+	asm volatile("msr_s " __stringify(ICC_SGI1R_EL1) ", %0" : : "r" (val));
+}
+
+static inline u64 __maybe_unused gic_read_sre(void)
+{
+	u64 val;
+
+	asm volatile("mrs_s %0, " __stringify(ICC_SRE_EL1) : "=r" (val));
+	return val;
+}
+
+static inline void __maybe_unused gic_write_sre(u64 val)
+{
+	asm volatile("msr_s " __stringify(ICC_SRE_EL1) ", %0" : : "r" (val));
+	isb();
+}
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ASM_ARCH_GICV3_H */
drivers/irqchip/irq-gic-v3.c +3 -35
index aa17ae8..b85d6b6 100644
@@ -104,45 +104,13 @@ static void gic_redist_wait_for_rwp(void)
 	gic_do_wait_for_rwp(gic_data_rdist_rd_base());
 }
 
-/* Low level accessors */
-static u64 __maybe_unused gic_read_iar(void)
-{
-	u64 irqstat;
-
-	asm volatile("mrs_s %0, " __stringify(ICC_IAR1_EL1) : "=r" (irqstat));
-	return irqstat;
-}
-
-static void __maybe_unused gic_write_pmr(u64 val)
-{
-	asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" (val));
-}
-
-static void __maybe_unused gic_write_ctlr(u64 val)
-{
-	asm volatile("msr_s " __stringify(ICC_CTLR_EL1) ", %0" : : "r" (val));
-	isb();
-}
-
-static void __maybe_unused gic_write_grpen1(u64 val)
-{
-	asm volatile("msr_s " __stringify(ICC_GRPEN1_EL1) ", %0" : : "r" (val));
-	isb();
-}
-
-static void __maybe_unused gic_write_sgi1r(u64 val)
-{
-	asm volatile("msr_s " __stringify(ICC_SGI1R_EL1) ", %0" : : "r" (val));
-}
-
 static void gic_enable_sre(void)
 {
 	u64 val;
 
-	asm volatile("mrs_s %0, " __stringify(ICC_SRE_EL1) : "=r" (val));
+	val = gic_read_sre();
 	val |= ICC_SRE_EL1_SRE;
-	asm volatile("msr_s " __stringify(ICC_SRE_EL1) ", %0" : : "r" (val));
-	isb();
+	gic_write_sre(val);
 
 	/*
 	 * Need to check that the SRE bit has actually been set. If
@@ -151,7 +119,7 @@ static void gic_enable_sre(void)
 	 *
 	 * Kindly inform the luser.
 	 */
-	asm volatile("mrs_s %0, " __stringify(ICC_SRE_EL1) : "=r" (val));
+	val = gic_read_sre();
 	if (!(val & ICC_SRE_EL1_SRE))
 		pr_err("GIC: unable to set SRE (disabled at EL2), panic ahead\n");
 }
include/linux/irqchip/arm-gic-v3.h +6 -71

94 lines not on this page · raw message

Signature · 1 line
2.2.0.rc1
#2 lore raw

PATCH 2/4 arm64: GICv3: change unsigned types for AArch32 compatibility

In reply to Jean-Philippe Brucker

This patch does a few simple compatibility-related changes:
- change the system register access prototypes to their actual size,
- homogenise mpidr accesses with unsigned long,
- force the 64bit register values to unsigned long long.

Note: the list registers are 64bit on GICv3, but the AArch32 vGIC driver will need to split their values into two 32bit registers: LRn and LRCn.

---
 arch/arm64/include/asm/arch_gicv3.h | 31 ++++++++++++++++++-------------
 drivers/irqchip/irq-gic-v3.c        | 25 ++++++++++++-------------
 include/linux/irqchip/arm-gic-v3.h  | 18 +++++++++---------
 3 files changed, 39 insertions(+), 35 deletions(-)
arch/arm64/include/asm/arch_gicv3.h +18 -13
index 28482d0..a0ea9de 100644
@@ -77,15 +77,20 @@
 
 #include <linux/stringify.h>
 
-/* Low level accessors */
+/*
+ * Low-level accessors
+ *
+ * These system registers are 32 bits, but we make sure that the compiler
+ * sets the GP register's most significant bits to 0 with an explicit cast.
+ */
 
-static inline void gic_write_eoir(u64 irq)
+static inline void gic_write_eoir(u32 irq)
 {
-	asm volatile("msr_s " __stringify(ICC_EOIR1_EL1) ", %0" : : "r" (irq));
+	asm volatile("msr_s " __stringify(ICC_EOIR1_EL1) ", %0" : : "r" ((u64)irq));
 	isb();
 }
 
-static inline u64 __maybe_unused gic_read_iar(void)
+static inline u32 __maybe_unused gic_read_iar(void)
 {
 	u64 irqstat;
 
@@ -93,20 +98,20 @@ static inline u64 __maybe_unused gic_read_iar(void)
 	return irqstat;
 }
 
-static inline void __maybe_unused gic_write_pmr(u64 val)
+static inline void __maybe_unused gic_write_pmr(u32 val)
 {
-	asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" (val));
+	asm volatile("msr_s " __stringify(ICC_PMR_EL1) ", %0" : : "r" ((u64)val));
 }
 
-static inline void __maybe_unused gic_write_ctlr(u64 val)
+static inline void __maybe_unused gic_write_ctlr(u32 val)
 {
-	asm volatile("msr_s " __stringify(ICC_CTLR_EL1) ", %0" : : "r" (val));
+	asm volatile("msr_s " __stringify(ICC_CTLR_EL1) ", %0" : : "r" ((u64)val));
 	isb();
 }
 
-static inline void __maybe_unused gic_write_grpen1(u64 val)
+static inline void __maybe_unused gic_write_grpen1(u32 val)
 {
-	asm volatile("msr_s " __stringify(ICC_GRPEN1_EL1) ", %0" : : "r" (val));
+	asm volatile("msr_s " __stringify(ICC_GRPEN1_EL1) ", %0" : : "r" ((u64)val));
 	isb();
 }
 
@@ -115,7 +120,7 @@ static inline void __maybe_unused gic_write_sgi1r(u64 val)
 	asm volatile("msr_s " __stringify(ICC_SGI1R_EL1) ", %0" : : "r" (val));
 }
 
-static inline u64 __maybe_unused gic_read_sre(void)
+static inline u32 __maybe_unused gic_read_sre(void)
 {
 	u64 val;
 
@@ -123,9 +128,9 @@ static inline u64 __maybe_unused gic_read_sre(void)
 	return val;
 }
 
-static inline void __maybe_unused gic_write_sre(u64 val)
+static inline void __maybe_unused gic_write_sre(u32 val)
 {
-	asm volatile("msr_s " __stringify(ICC_SRE_EL1) ", %0" : : "r" (val));
+	asm volatile("msr_s " __stringify(ICC_SRE_EL1) ", %0" : : "r" ((u64)val));
 	isb();
 }
 
drivers/irqchip/irq-gic-v3.c +12 -13
index b85d6b6..e2cd5ac 100644
@@ -220,11 +220,11 @@ static int gic_set_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
-static u64 gic_mpidr_to_affinity(u64 mpidr)
+static u64 gic_mpidr_to_affinity(unsigned long mpidr)
 {
 	u64 aff;
 
-	aff = (MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 |
+	aff = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 32 |
 	       MPIDR_AFFINITY_LEVEL(mpidr, 2) << 16 |
 	       MPIDR_AFFINITY_LEVEL(mpidr, 1) << 8  |
 	       MPIDR_AFFINITY_LEVEL(mpidr, 0));
@@ -234,7 +234,7 @@ static u64 gic_mpidr_to_affinity(u64 mpidr)
 
 static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
 {
-	u64 irqnr;
+	u32 irqnr;
 
 	do {
 		irqnr = gic_read_iar();
@@ -285,9 +285,9 @@ static void __init gic_dist_init(void)
 		writeq_relaxed(affinity, base + GICD_IROUTER + i * 8);
 }
 
-static int gic_populate_rdist(void)
+static int __init gic_populate_rdist(void)
 {
-	u64 mpidr = cpu_logical_map(smp_processor_id());
+	unsigned long mpidr = cpu_logical_map(smp_processor_id());
 	u64 typer;
 	u32 aff;
 	int i;
@@ -316,9 +316,8 @@ static int gic_populate_rdist(void)
 			typer = readq_relaxed(ptr + GICR_TYPER);
 			if ((typer >> 32) == aff) {
 				gic_data_rdist_rd_base() = ptr;
-				pr_info("CPU%d: found redistributor %llx @%p\n",
-					smp_processor_id(),
-					(unsigned long long)mpidr, ptr);
+				pr_info("CPU%d: found redistributor %lx @%p\n",
+					smp_processor_id(), mpidr, ptr);
 				return 0;
 			}
 
@@ -333,8 +332,8 @@ static int gic_populate_rdist(void)
 	}
 
 	/* We couldn't even deal with ourselves... */
-	WARN(true, "CPU%d: mpidr %llx has no re-distributor!\n",
-	     smp_processor_id(), (unsigned long long)mpidr);
+	WARN(true, "CPU%d: mpidr %lx has no re-distributor!\n",
+	     smp_processor_id(), mpidr);
 	return -ENODEV;
 }
 
@@ -403,10 +402,10 @@ static struct notifier_block gic_cpu_notifier = {
 };
 
 static u16 gic_compute_target_list(int *base_cpu, const struct cpumask *mask,
-				   u64 cluster_id)
+				   unsigned long cluster_id)
 {
 	int cpu = *base_cpu;
-	u64 mpidr = cpu_logical_map(cpu);
+	unsigned long mpidr = cpu_logical_map(cpu);
 	u16 tlist = 0;
 
 	while (cpu < nr_cpu_ids) {
@@ -463,7 +462,7 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
 	smp_wmb();
 
 	for_each_cpu_mask(cpu, *mask) {
-		u64 cluster_id = cpu_logical_map(cpu) & ~0xffUL;
+		unsigned long cluster_id = cpu_logical_map(cpu) & ~0xffUL;
 		u16 tlist;
 
 		tlist = gic_compute_target_list(&cpu, mask, cluster_id);
include/linux/irqchip/arm-gic-v3.h +9 -9
index e70b56f..95171d1 100644
@@ -39,7 +39,7 @@
 #define GICD_ICACTIVER			0x0380
 #define GICD_IPRIORITYR			0x0400
 #define GICD_ICFGR			0x0C00
-#define GICD_IROUTER			0x6000
+#define GICD_IROUTER			0x6000		/* 64bit */
 #define GICD_PIDR2			0xFFE8
 
 #define GICD_CTLR_RWP			(1U << 31)
@@ -61,7 +61,7 @@
 #define GICR_IIDR			0x0004
 #define GICR_TYPER			0x0008
 #define GICR_STATUSR			GICD_STATUSR
-#define GICR_WAKER			0x0014
+#define GICR_WAKER			0x0014		/* 32bit */
 #define GICR_SETLPIR			0x0040
 #define GICR_CLRLPIR			0x0048
 #define GICR_SEIR			GICD_SEIR
@@ -69,7 +69,7 @@
 #define GICR_PENDBASER			0x0078
 #define GICR_INVLPIR			0x00A0
 #define GICR_INVALLR			0x00B0
-#define GICR_SYNCR			0x00C0
+#define GICR_SYNCR			0x00C0		/* 32bit */
 #define GICR_MOVLPIR			0x0100
 #define GICR_MOVALLR			0x0110
 #define GICR_PIDR2			GICD_PIDR2
@@ -107,13 +107,13 @@
 /*
  * Hypervisor interface registers (SRE only)
  */
-#define ICH_LR_VIRTUAL_ID_MASK		((1UL << 32) - 1)
+#define ICH_LR_VIRTUAL_ID_MASK		((1ULL << 32) - 1)
 
-#define ICH_LR_EOI			(1UL << 41)
-#define ICH_LR_GROUP			(1UL << 60)
-#define ICH_LR_STATE			(3UL << 62)
-#define ICH_LR_PENDING_BIT		(1UL << 62)
-#define ICH_LR_ACTIVE_BIT		(1UL << 63)
+#define ICH_LR_EOI			(1ULL << 41)
+#define ICH_LR_GROUP			(1ULL << 60)
+#define ICH_LR_STATE			(3ULL << 62)
+#define ICH_LR_PENDING_BIT		(1ULL << 62)
+#define ICH_LR_ACTIVE_BIT		(1ULL << 63)
 
 #define ICH_MISR_EOI			(1 << 0)
 #define ICH_MISR_U			(1 << 1)
Signature · 1 line
2.2.0.rc1
#3 lore raw

PATCH 2/4 arm64: GICv3: change unsigned types for AArch32 compatibility

Hi Jean,

drivers/irqchip/irq-gic-v3.c static void __init gic_dist_init(void) · line 288

Quoted 2 lines · Jean-Philippe Brucker
drivers/irqchip/irq-gic-v3.c +1 -1
-static int gic_populate_rdist(void)
+static int __init gic_populate_rdist(void)
              ^^^^^^

This change breaks cpu hotplug. Is it intentional?

Vladimir

drivers/irqchip/irq-gic-v3.c static void __init gic_dist_init(void) · line 291

Quoted 4 lines

{

drivers/irqchip/irq-gic-v3.c +1 -1
-     u64 mpidr = cpu_logical_map(smp_processor_id());
+     unsigned long mpidr = cpu_logical_map(smp_processor_id());
      u64 typer;

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590 ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2548782

#4 lore raw

PATCH 2/4 arm64: GICv3: change unsigned types for AArch32 compatibility

Quoted 8 lines · Vladimir Murzin

Hi Jean,

drivers/irqchip/irq-gic-v3.c static void __init gic_dist_init(void) · line 288

Quoted 2 lines · Jean-Philippe Brucker
drivers/irqchip/irq-gic-v3.c +1 -1
-static int gic_populate_rdist(void)
+static int __init gic_populate_rdist(void)
              ^^^^^^

This change breaks cpu hotplug. Is it intentional?

No, that must be a rebase mistake.

Thanks,
Jean

#5 lore raw

PATCH 3/4 arm64: GICv3: Specialize readq and writeq accesses

In reply to Jean-Philippe Brucker

On 32bit platforms, we cannot assure that an I/O ldrd or strd will be done atomically. Besides, an hypervisor would be unable to emulate such accesses.
In order to allow the AArch32 version of the driver to split them into two 32bit accesses while keeping the requirement for atomic writes, this patch specializes the IROUTER and TYPER accesses.
Since the latter is an ID register, it won't need to be read atomically, but we still avoid future confusion by using gic_read_typer instead of a generic gic_readq.

---
 arch/arm64/include/asm/arch_gicv3.h | 3 +++
 drivers/irqchip/irq-gic-v3.c        | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm64/include/asm/arch_gicv3.h +3 -0
index a0ea9de..622f08a 100644
@@ -134,5 +134,8 @@ static inline void __maybe_unused gic_write_sre(u32 val)
 	isb();
 }
 
+#define gic_read_typer(c)		readq_relaxed(c)
+#define gic_write_irouter(v, c)		writeq_relaxed(v, c)
+
 #endif /* __ASSEMBLY__ */
 #endif /* __ASM_ARCH_GICV3_H */
drivers/irqchip/irq-gic-v3.c +3 -3
index e2cd5ac..d8f30ee 100644
@@ -282,7 +282,7 @@ static void __init gic_dist_init(void)
 	 */
 	affinity = gic_mpidr_to_affinity(cpu_logical_map(smp_processor_id()));
 	for (i = 32; i < gic_data.irq_nr; i++)
-		writeq_relaxed(affinity, base + GICD_IROUTER + i * 8);
+		gic_write_irouter(affinity, base + GICD_IROUTER + i * 8);
 }
 
 static int __init gic_populate_rdist(void)
@@ -313,7 +313,7 @@ static int __init gic_populate_rdist(void)
 		}
 
 		do {
-			typer = readq_relaxed(ptr + GICR_TYPER);
+			typer = gic_read_typer(ptr + GICR_TYPER);
 			if ((typer >> 32) == aff) {
 				gic_data_rdist_rd_base() = ptr;
 				pr_info("CPU%d: found redistributor %lx @%p\n",
@@ -498,7 +498,7 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
 	reg = gic_dist_base(d) + GICD_IROUTER + (gic_irq(d) * 8);
 	val = gic_mpidr_to_affinity(cpu_logical_map(cpu));
 
-	writeq_relaxed(val, reg);
+	gic_write_irouter(val, reg);
 
 	/*
 	 * If the interrupt was enabled, enabled it again. Otherwise,
Signature · 1 line
2.2.0.rc1
#6 lore raw

PATCH 4/4 ARM: add 32bit support to GICv3

In reply to Jean-Philippe Brucker

Implement the system and memory-mapped register accesses in asm/arch_gicv3.h for 32bit architectures.

This patch is a straightforward translation of the arm64 header. 64bit accesses are done in two times and don't need atomicity: TYPER is read-only, and the upper-word of IROUTER is always zero on 32bit architectures.

---
 arch/arm/include/asm/arch_gicv3.h | 182 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 182 insertions(+)
 create mode 100644 arch/arm/include/asm/arch_gicv3.h
arch/arm/include/asm/arch_gicv3.h new file +182 -0
new file mode 100644
index 0000000..de285aa
@@ -0,0 +1,182 @@
+/*
+ * arch/arm/include/asm/arch_gicv3.h
+ *
+ * Copyright (C) 2014 ARM Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/io.h>
+
+#define __ACCESS_CP15(CRn, Op1, CRm, Op2)	p15, Op1, %0, CRn, CRm, Op2
+#define __ACCESS_CP15_64(Op1, CRm)		p15, Op1, %Q0, %R0, CRm
+
+#define ICC_EOIR1			__ACCESS_CP15(c12, 0, c12, 1)
+#define ICC_IAR1			__ACCESS_CP15(c12, 0, c12, 0)
+#define ICC_SGI1R			__ACCESS_CP15_64(0, c12)
+#define ICC_PMR				__ACCESS_CP15(c4, 0, c6, 0)
+#define ICC_CTLR			__ACCESS_CP15(c12, 0, c12, 4)
+#define ICC_SRE				__ACCESS_CP15(c12, 0, c12, 5)
+#define ICC_IGRPEN1			__ACCESS_CP15(c12, 0, c12, 7)
+
+#define ICC_HSRE			__ACCESS_CP15(c12, 4, c9, 5)
+
+#define ICH_VSEIR			__ACCESS_CP15(c12, 4, c9, 4)
+#define ICH_HCR				__ACCESS_CP15(c12, 4, c11, 0)
+#define ICH_VTR				__ACCESS_CP15(c12, 4, c11, 1)
+#define ICH_MISR			__ACCESS_CP15(c12, 4, c11, 2)
+#define ICH_EISR			__ACCESS_CP15(c12, 4, c11, 3)
+#define ICH_ELSR			__ACCESS_CP15(c12, 4, c11, 5)
+#define ICH_VMCR			__ACCESS_CP15(c12, 4, c11, 7)
+
+#define __LR0(x)			__ACCESS_CP15(c12, 4, c12, x)
+#define __LR8(x)			__ACCESS_CP15(c12, 4, c13, x)
+
+#define ICH_LR0				__LR0(0)
+#define ICH_LR1				__LR0(1)
+#define ICH_LR2				__LR0(2)
+#define ICH_LR3				__LR0(3)
+#define ICH_LR4				__LR0(4)
+#define ICH_LR5				__LR0(5)
+#define ICH_LR6				__LR0(6)
+#define ICH_LR7				__LR0(7)
+#define ICH_LR8				__LR8(0)
+#define ICH_LR9				__LR8(1)
+#define ICH_LR10			__LR8(2)
+#define ICH_LR11			__LR8(3)
+#define ICH_LR12			__LR8(4)
+#define ICH_LR13			__LR8(5)
+#define ICH_LR14			__LR8(6)
+#define ICH_LR15			__LR8(7)
+
+/* LR top half */
+#define __LRC0(x)			__ACCESS_CP15(c12, 4, c14, x)
+#define __LRC8(x)			__ACCESS_CP15(c12, 4, c15, x)
+
+#define ICH_LRC0			__LRC0(0)
+#define ICH_LRC1			__LRC0(1)
+#define ICH_LRC2			__LRC0(2)
+#define ICH_LRC3			__LRC0(3)
+#define ICH_LRC4			__LRC0(4)
+#define ICH_LRC5			__LRC0(5)
+#define ICH_LRC6			__LRC0(6)
+#define ICH_LRC7			__LRC0(7)
+#define ICH_LRC8			__LRC8(0)
+#define ICH_LRC9			__LRC8(1)
+#define ICH_LRC10			__LRC8(2)
+#define ICH_LRC11			__LRC8(3)
+#define ICH_LRC12			__LRC8(4)
+#define ICH_LRC13			__LRC8(5)
+#define ICH_LRC14			__LRC8(6)
+#define ICH_LRC15			__LRC8(7)
+
+#define __AP0Rx(x)			__ACCESS_CP15(c12, 4, c8, x)
+#define ICH_AP0R0			__AP0Rx(0)
+#define ICH_AP0R1			__AP0Rx(1)
+#define ICH_AP0R2			__AP0Rx(2)
+#define ICH_AP0R3			__AP0Rx(3)
+
+#define __AP1Rx(x)			__ACCESS_CP15(c12, 4, c9, x)
+#define ICH_AP1R0			__AP1Rx(0)
+#define ICH_AP1R1			__AP1Rx(1)
+#define ICH_AP1R2			__AP1Rx(2)
+#define ICH_AP1R3			__AP1Rx(3)
+
+/* Low-level accessors */
+
+static inline void __maybe_unused gic_write_eoir(u32 irq)
+{
+	asm volatile("mcr " __stringify(ICC_EOIR1) : : "r" (irq));
+	isb();
+}
+
+static inline u32 __maybe_unused gic_read_iar(void)
+{
+	u32 irqstat;
+
+	asm volatile("mrc " __stringify(ICC_IAR1) : "=r" (irqstat));
+	return irqstat;
+}
+
+static inline void __maybe_unused gic_write_pmr(u32 val)
+{
+	asm volatile("mcr " __stringify(ICC_PMR) : : "r" (val));
+	isb();
+}
+
+static inline void __maybe_unused gic_write_ctlr(u32 val)
+{
+	asm volatile("mcr " __stringify(ICC_CTLR) : : "r" (val));
+	isb();
+}
+
+static inline void __maybe_unused gic_write_grpen1(u32 val)
+{
+	asm volatile("mcr " __stringify(ICC_IGRPEN1) : : "r" (val));
+	isb();
+}
+
+static inline void __maybe_unused gic_write_sgi1r(u64 val)
+{
+	asm volatile("mcrr " __stringify(ICC_SGI1R) : : "r" (val));
+}
+
+static inline u32 __maybe_unused gic_read_sre(void)
+{
+	u32 val;
+
+	asm volatile("mrc " __stringify(ICC_SRE) : "=r" (val));
+	return val;
+}
+
+static inline void __maybe_unused gic_write_sre(u32 val)
+{
+	asm volatile("mcr " __stringify(ICC_SRE) : : "r" (val));
+	isb();
+}
+
+/*
+ * Even in 32bit systems that use LPAE, there is no guarantee that the I/O
+ * interface provides true 64bit atomic accesses, so using strd/ldrd doesn't
+ * make much sense.
+ * Moreover, 64bit I/O emulation is extremely difficult to implement on
+ * AArch32, since the syndrome register doesn't provide any information for
+ * them.
+ * Consequently, the following IO helpers use 32bit accesses.
+ *
+ * There are only two registers that need 64bit accesses in this driver:
+ * - GICD_IROUTERn, contain the affinity values associated to each interrupt.
+ *   The upper-word (aff3) will always be 0, so there is no need for a lock.
+ * - GICR_TYPER is an ID register and doesn't need atomicity.
+ */
+static void gic_write_irouter(u64 val, volatile void __iomem *addr)
+{
+	writel_relaxed((u32)val, addr);
+	writel_relaxed((u32)(val >> 32), addr + 4);
+}
+
+static inline u64 gic_read_typer(const volatile void __iomem *addr)
+{
+	u64 val;
+
+	val = readl_relaxed(addr);
+	val |= (u64)readl_relaxed(addr + 4) << 32;
+	return val;
+}
+
+#endif /* !__ASSEMBLY__ */
+#endif /* !__ASM_ARCH_GICV3_H */
Signature · 1 line
2.2.0.rc1
#7 lore raw

PATCH 4/4 ARM: add 32bit support to GICv3

arch/arm/include/asm/arch_gicv3.h line 23

Quoted 6 lines · Jean-Philippe Brucker
arch/arm/include/asm/arch_gicv3.h new file +6 -0
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/io.h>

This should be linux/io.h

arch/arm/include/asm/arch_gicv3.h line 101

Quoted 3 lines
arch/arm/include/asm/arch_gicv3.h new file +3 -0
+/* Low-level accessors */
+
+static inline void __maybe_unused gic_write_eoir(u32 irq)

No need for __maybe_unused with static inline.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
#8 lore raw

PATCH 4/4 ARM: add 32bit support to GICv3

Quoted 9 lines · Russell King - ARM Linux

arch/arm/include/asm/arch_gicv3.h line 23

Quoted 6 lines · Jean-Philippe Brucker
arch/arm/include/asm/arch_gicv3.h new file +6 -0
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/io.h>

This should be linux/io.h

Also, you should probably move the #ifndef down to the level of the inline functions. The #defines are perfectly usable in assembly context.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#9 lore raw

PATCH 4/4 ARM: add 32bit support to GICv3

Quoted 11 lines · Marc Zyngier
Quoted 9 lines · Russell King - ARM Linux

arch/arm/include/asm/arch_gicv3.h line 23

Quoted 6 lines · Jean-Philippe Brucker
arch/arm/include/asm/arch_gicv3.h new file +6 -0
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/io.h>

This should be linux/io.h

Quoted 3 lines

Also, you should probably move the #ifndef down to the level of the inline functions. The #defines are perfectly usable in assembly context.

This would require a change in the definition of __ACCESS_CP15, in order to distinguish between inlined parameter '%0' and explicit registers. I don't see any pleasant ways to do this, apart from adding a 'reg' argument to all those #defines.
Furthermore, all other cp15 accesses from assembly on the arm/ side seem to use raw opcodes, instead of macro names.

Thanks,
Jean

#10 lore raw

PATCH 4/4 ARM: add 32bit support to GICv3

Quoted 16 lines · Jean-Philippe Brucker
Quoted 11 lines · Marc Zyngier
Quoted 9 lines · Russell King - ARM Linux

arch/arm/include/asm/arch_gicv3.h line 23

Quoted 6 lines · Jean-Philippe Brucker
arch/arm/include/asm/arch_gicv3.h new file +6 -0
+#ifndef __ASM_ARCH_GICV3_H
+#define __ASM_ARCH_GICV3_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/io.h>

This should be linux/io.h

Quoted 3 lines

Also, you should probably move the #ifndef down to the level of the inline functions. The #defines are perfectly usable in assembly context.

Quoted 6 lines

This would require a change in the definition of __ACCESS_CP15, in order to distinguish between inlined parameter '%0' and explicit registers. I don't see any pleasant ways to do this, apart from adding a 'reg' argument to all those #defines.
Furthermore, all other cp15 accesses from assembly on the arm/ side seem to use raw opcodes, instead of macro names.

Ah, fair enough. I guess we can rework that part, should we ever support KVM on 32bit ARMv8 CPUs...

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#11 lore raw

cover GICv3: add 32bit compatibility

In reply to Jean-Philippe Brucker

On 11/12/14 14:23, Jean-Philippe Brucker wrote:

Hi Jean-Philippe,

Quoted 11 lines

This series adds 32bit compatibility to Marc's GICv3 driver. Only SGIs, PPIs and SPIs support is present. No ITS nor virtualisation.

It is based on 3.18.

Jean-Philippe Brucker (4):
arm64: GICv3: refactor the AArch64 specific parts
arm64: GICv3: change unsigned types for AArch32 compatibility
arm64: GICv3: Specialize readq and writeq accesses
ARM: add 32bit support to GICv3

Quoted 8 lines
 arch/arm/include/asm/arch_gicv3.h   | 182 ++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/arch_gicv3.h | 141 ++++++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3.c        |  69 ++++----------
 include/linux/irqchip/arm-gic-v3.h  |  95 +++----------------
 4 files changed, 356 insertions(+), 131 deletions(-)
 create mode 100644 arch/arm/include/asm/arch_gicv3.h
 create mode 100644 arch/arm64/include/asm/arch_gicv3.h

Overall, this looks good to me (once you've sorted the nits spotted by Russell). It is going to conflict quite badly with what is going to be merged in 3.19 though. Any chance you could rebase it on top of -rc1 once it is out?

Also, I don't see an obvious way to select CONFIG_ARM_GIC_V3 for ARM (arm64 selects it automatically). What about selecting it from ARCH_VIRT, which is likely to be the primary user of this?

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#12 lore raw

cover GICv3: add 32bit compatibility

In reply to Jean-Philippe Brucker

Hi Jean-Philippe,

Quoted 11 lines · Jean-Philippe Brucker

This series adds 32bit compatibility to Marc's GICv3 driver. Only SGIs, PPIs and SPIs support is present. No ITS nor virtualisation.

It is based on 3.18.

Jean-Philippe Brucker (4):
arm64: GICv3: refactor the AArch64 specific parts
arm64: GICv3: change unsigned types for AArch32 compatibility
arm64: GICv3: Specialize readq and writeq accesses
ARM: add 32bit support to GICv3

Quoted 7 lines
 arch/arm/include/asm/arch_gicv3.h   | 182 ++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/arch_gicv3.h | 141 ++++++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3.c        |  69 ++++----------
 include/linux/irqchip/arm-gic-v3.h  |  95 +++----------------
 4 files changed, 356 insertions(+), 131 deletions(-)
 create mode 100644 arch/arm/include/asm/arch_gicv3.h
 create mode 100644 arch/arm64/include/asm/arch_gicv3.h

so if I compile this with CONFIG_KVM_ARM_VGIC on, I get a compilation error:
LD init/built-in.o
arch/arm/kvm/built-in.o: In function `svc_die_str':
arch_timer.c:(.rodata+0xf7c): undefined reference to `vgic_v3_probe' make[2]: *** [vmlinux] Error 1

The svc_die_str reference is probably bogus, but if I protect the vgic_v3_probe reference in virt/kvm/arm/vgic.c with "#ifdef ARM64" it compiles fine. Disabling CONFIG_KVM_ARM_VGIC in the .config also fixes this also.
I leave it up to you whether you want to take your "no virtualisation" statement above serious and fix Kconfig accordingly or use the ifdef solution.

After fixing that, adding CONFIG_ARM_GIC_V3 as Marc suggested (and adding AArch32 support for the ICC_SGI1R trap in my patches ;-) I could run a 32-bit GICv3 guest with your patches on a GICv3 64-bit host.

Cheers,
Andre.

#13 lore raw

cover GICv3: add 32bit compatibility

Quoted 28 lines · Andre Przywara

Hi Jean-Philippe,

Quoted 11 lines · Jean-Philippe Brucker

This series adds 32bit compatibility to Marc's GICv3 driver. Only SGIs, PPIs and SPIs support is present. No ITS nor virtualisation.

It is based on 3.18.

Jean-Philippe Brucker (4):
arm64: GICv3: refactor the AArch64 specific parts
arm64: GICv3: change unsigned types for AArch32 compatibility
arm64: GICv3: Specialize readq and writeq accesses
ARM: add 32bit support to GICv3

Quoted 7 lines
 arch/arm/include/asm/arch_gicv3.h   | 182 ++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/arch_gicv3.h | 141 ++++++++++++++++++++++++++++
 drivers/irqchip/irq-gic-v3.c        |  69 ++++----------
 include/linux/irqchip/arm-gic-v3.h  |  95 +++----------------
 4 files changed, 356 insertions(+), 131 deletions(-)
 create mode 100644 arch/arm/include/asm/arch_gicv3.h
 create mode 100644 arch/arm64/include/asm/arch_gicv3.h

so if I compile this with CONFIG_KVM_ARM_VGIC on, I get a compilation error:
LD init/built-in.o
arch/arm/kvm/built-in.o: In function `svc_die_str':
arch_timer.c:(.rodata+0xf7c): undefined reference to `vgic_v3_probe' make[2]: *** [vmlinux] Error 1

Quoted 4 lines

The svc_die_str reference is probably bogus, but if I protect the vgic_v3_probe reference in virt/kvm/arm/vgic.c with "#ifdef ARM64" it compiles fine. Disabling CONFIG_KVM_ARM_VGIC in the .config also fixes this also.

That's an absolute no-no. I want to be able to run the exact same kernel as a KVM host *and* a guest. So disabling the vgic can never be the right solution.

Either wrapping the vgic_v3_probe reference with CONFIG_ARM64 or having a non "static inline" vgic_v3_probe for 32bit are acceptable solutions.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...