Support GICv5
v2 cover Support GICv5
Small series adding GICv5 to the list of supported GIC versions. Minimal implementation, just enough for Fast Models.
Thanks!
Changelog:
v1 -> v2
- Assign SW_PPI to NS domain (per Sascha)
Vladimir Murzin (2):
Introduce --with-gic option
Add support for GICv5
Makefile.am | 15 +++-
arch/aarch64/include/asm/cpu.h | 11 +++
common/{gic.c => gic-v2.c} | 0
common/gic-v5.c | 134 +++++++++++++++++++++++++++++++++
configure.ac | 24 ++++--
scripts/FDT.pm | 16 ++++
scripts/findbase-by-regname.pl | 44 +++++++++++
7 files changed, 234 insertions(+), 10 deletions(-)
rename common/{gic.c => gic-v2.c} (100%)
create mode 100644 common/gic-v5.c
create mode 100755 scripts/findbase-by-regname.plSignature · 1 line
2.34.1
PATCH v2 1/2 Introduce --with-gic option
We are about adding support for another GIC version, so introduce a new --with-gic option to select the desired GIC version at configure time. The default remains v2, preserving existing behavior. Howevere, for GICv3, we replace the previous --enable-gicv3 option with --with-gic=v3 which is backward-incompatible change (yet I hope we can live with that).
---
Makefile.am | 8 +++++---
common/{gic.c => gic-v2.c} | 0
configure.ac | 23 ++++++++++++++++-------
3 files changed, 21 insertions(+), 10 deletions(-)
rename common/{gic.c => gic-v2.c} (100%)Makefile.am +5 -3
@@ -87,15 +87,17 @@ GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNE GIC_RDIST_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,gic-v3') DEFINES += -DGIC_DIST_BASE=$(GIC_DIST_BASE) DEFINES += -DGIC_RDIST_BASE=$(GIC_RDIST_BASE) -COMMON_OBJ += gic-v3.o -else +endif + +if GICV2 GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,cortex-a15-gic') GIC_CPU_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,cortex-a15-gic') DEFINES += -DGIC_CPU_BASE=$(GIC_CPU_BASE) DEFINES += -DGIC_DIST_BASE=$(GIC_DIST_BASE) -COMMON_OBJ += gic.o endif +COMMON_OBJ += gic-$(GIC_VERSION).o + if KERNEL_32 MBOX_OFFSET := 0x7ff8 TEXT_LIMIT := 0x3000
common/gic-v2.c renamed from common/gic.c +0 -0
configure.ac +16 -7
@@ -139,12 +139,21 @@ AC_ARG_WITH([xen-cmdline], [X_CMDLINE=$withval]) AC_SUBST([XEN_CMDLINE], [$X_CMDLINE]) -# Allow a user to pass --enable-gicv3 -AC_ARG_ENABLE([gicv3], - AS_HELP_STRING([--enable-gicv3], [enable GICv3 instead of GICv2]), - [USE_GICV3=$enableval]) -AM_CONDITIONAL([GICV3], [test "x$USE_GICV3" = "xyes"]) -AS_IF([test "x$USE_GICV3" = "xyes"], [], [USE_GICV3=no]) + +AC_ARG_WITH([gic], + AS_HELP_STRING([--with-gic={v2|v3}], [select GIC version]), + [GIC_VERSION=$withval], + [GIC_VERSION=v2]) + +AS_CASE([$GIC_VERSION], + [v2|v3], [], + [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2 or v3)])]) + +AC_SUBST([GIC_VERSION], [$GIC_VERSION]) + +AM_CONDITIONAL([GICV2], [test "x$GIC_VERSION" = "xv2"]) +AM_CONDITIONAL([GICV3], [test "x$GIC_VERSION" = "xv3"]) + # Ensure that we have all the needed programs AC_PROG_CC
@@ -174,7 +183,7 @@ echo " Device tree compiler: ${DTC}" echo " Linux kernel command line: ${CMDLINE}" echo " Embedded initrd: ${FILESYSTEM:-NONE}" echo " Use PSCI? ${USE_PSCI}" -echo " Use GICv3? ${USE_GICV3}" +echo " GIC version: ${GIC_VERSION}" echo " Boot-wrapper execution state: AArch${BOOTWRAPPER_ES}" echo " Kernel execution state: AArch${KERNEL_ES}" echo " Xen image ${XEN_IMAGE:-NONE}"
Signature · 1 line
2.34.1
Re: [BOOTWRAPPER PATCH v2 1/2] Introduce --with-gic option
Hi Vladimir,
Sorry for taking so long to get to this!
Quoted 1 line · Vladimir Murzin
We are about adding support for another GIC version, so introduce a
nit: We are about to add support
Quoted 3 lines
new --with-gic option to select the desired GIC version at configure time. The default remains v2, preserving existing behavior. Howevere,
nit: However
Aside from these nits, this looks good to me, so:
Thanks,
Sascha
Quoted 90 lines
for GICv3, we replace the previous --enable-gicv3 option with --with-gic=v3 which is backward-incompatible change (yet I hope we can
live with that).Signed-off-by Vladimir Murzin <[email protected]>---
Makefile.am | 8 +++++---common/{gic.c=>gic-v2.c} | 0
configure.ac | 23 ++++++++++++++++-------3 files changed, 21 insertions(+), 10 deletions(-)rename
common/{gic.c=>gic-v2.c} (100%)Makefile.am +0
-0@@ -87,15 +87,17 @@ GIC_DIST_BASE := $(shell perl -I$(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNE
GIC_RDIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,gic-v3')
DEFINES += -DGIC_DIST_BASE=$(GIC_DIST_BASE)
DEFINES += -DGIC_RDIST_BASE=$(GIC_RDIST_BASE)Makefile.am +3
-2-COMMON_OBJ += gic-v3.o -else +endif + +if GICV2GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,cortex-a15-gic')
GIC_CPU_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,cortex-a15-gic')
DEFINES += -DGIC_CPU_BASE=$(GIC_CPU_BASE)
DEFINES += -DGIC_DIST_BASE=$(GIC_DIST_BASE)
-COMMON_OBJ += gic.o
endifMakefile.am +2
-0+COMMON_OBJ += gic-$(GIC_VERSION).o +if
KERNEL_32
MBOX_OFFSET :=0x7ff8
TEXT_LIMIT :=0x3000common/gic-v2.c renamed from common/gic.c +0
-0configure.ac +0
-0@@ -139,12 +139,21 @@ AC_ARG_WITH([xen-cmdline], [X_CMDLINE=$withval]) AC_SUBST([XEN_CMDLINE], [$X_CMDLINE])configure.ac +0
-3-# Allow a user to pass --enable-gicv3 -AC_ARG_ENABLE([gicv3], - AS_HELP_STRING([--enable-gicv3], [enable GICv3 instead ofGICv2]),
configure.ac +9
-3- [USE_GICV3=$enableval]) -AM_CONDITIONAL([GICV3], [test "x$USE_GICV3" = "xyes"]) -AS_IF([test "x$USE_GICV3" = "xyes"], [], [USE_GICV3=no]) + +AC_ARG_WITH([gic], + AS_HELP_STRING([--with-gic={v2|v3}], [select GIC version]), + [GIC_VERSION=$withval], + [GIC_VERSION=v2]) + +AS_CASE([$GIC_VERSION], + [v2|v3], [], + [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2 orv3)])])
configure.ac +6
-0+ +AC_SUBST([GIC_VERSION], [$GIC_VERSION]) + +AM_CONDITIONAL([GICV2], [test "x$GIC_VERSION" = "xv2"]) +AM_CONDITIONAL([GICV3], [test "x$GIC_VERSION" = "xv3"]) +
# Ensure that we have all the needed programs
AC_PROG_CCconfigure.ac +0
-0@@ -174,7 +183,7 @@ echo " Device tree compiler:${DTC}"
echo " Linux kernel command line: ${CMDLINE}" echo " Embedded initrd: ${FILESYSTEM:-NONE}" echo " Use PSCI? ${USE_PSCI}"configure.ac +1
-1-echo " Use GICv3? ${USE_GICV3}" +echo " GIC version: ${GIC_VERSION}"echo " Boot-wrapper execution state: AArch${BOOTWRAPPER_ES}" echo " Kernel execution state: AArch${KERNEL_ES}" echo " Xen image ${XEN_IMAGE:-NONE}"
Re: [BOOTWRAPPER PATCH v2 1/2] Introduce --with-gic option
Quoted 11 lines · Sascha Bischoff
Hi Vladimir,
Sorry for taking so long to get to this!
Quoted 1 line · Vladimir Murzin
We are about adding support for another GIC version, so introduce a
nit: We are about to add support
Quoted 3 lines
new --with-gic option to select the desired GIC version at configure time. The default remains v2, preserving existing behavior. Howevere,
Quoted 7 lines
nit: However
Aside from these nits, this looks good to me, so:
Reviewed-by Sascha Bischoff <[email protected]>Thanks,
Sascha
Thanks Sascha, all fixed locally.
Cheers
Vladimir
PATCH v2 2/2 Add support for GICv5
In reply to Vladimir MurzinPerforms the minimal initialization required for GICv5 support. GICv5 support can be requested with --with-gic=v5.
--- Makefile.am | 7 ++ arch/aarch64/include/asm/cpu.h | 11 +++ common/gic-v5.c | 134 +++++++++++++++++++++++++++++++++ configure.ac | 7 +- scripts/FDT.pm | 16 ++++ scripts/findbase-by-regname.pl | 44 +++++++++++ 6 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 common/gic-v5.c create mode 100755 scripts/findbase-by-regname.pl
Makefile.am +7 -0
@@ -82,6 +82,13 @@ PSCI_NODE := CPU_NODES := endif +if GICV5 +GIC_IRS_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase-by-regname.pl $(KERNEL_DTB) "el3-config" 'arm,gic-v5-irs') +GIC_IWB_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v5-iwb') +DEFINES += -DGIC_IRS_BASE=$(GIC_IRS_BASE) +DEFINES += -DGIC_IWB_BASE=$(GIC_IWB_BASE) +endif + if GICV3 GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v3') GIC_RDIST_BASE := $(shell perl -I $(SCRIPT_DIR) $(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,gic-v3')
arch/aarch64/include/asm/cpu.h +11 -0
@@ -128,6 +128,7 @@#define ID_AA64PFR1_EL1_THE BITS(51, 48)#define ID_AA64PFR2_EL1 s3_0_c0_c4_2 +#define ID_AA64PFR2_EL1_GCIE BITS(15, 12)#define ID_AA64PFR2_EL1_FPMR BITS(35, 32)#define ID_AA64SMFR0_EL1 s3_0_c0_c4_5
@@ -169,6 +170,11 @@#define ICC_CTLR_EL3 S3_6_C12_C12_4#define ICC_PMR_EL1 S3_0_C4_C6_0 +#define ICC_PPI_DOMAINR0_EL3 S3_6_C12_C8_4 +#define ICC_PPI_DOMAINR1_EL3 S3_6_C12_C8_5 +#define ICC_PPI_DOMAINR2_EL3 S3_6_C12_C8_6 +#define ICC_PPI_DOMAINR3_EL3 S3_6_C12_C8_7 +#define VSTCR_EL2 s3_4_c2_c6_2#define VSCTLR_EL2 s3_4_c2_c0_0
@@ -245,6 +251,11 @@ static inline int has_gicv3_sysreg(void)return !!mrs_field (ID_AA64PFR0_EL1 ,GIC ); } +static inline int has_gicv5_sysreg (void ) +{ +return !!mrs_field (ID_AA64PFR2_EL1 ,GCIE ); +} +#endif /* !__ASSEMBLY__ */ #endif
common/gic-v5.c new file +134 -0
134 lines not on this page · raw message
configure.ac +4 -3
@@ -141,18 +141,19 @@ AC_SUBST([XEN_CMDLINE], [$X_CMDLINE]) AC_ARG_WITH([gic], - AS_HELP_STRING([--with-gic={v2|v3}], [select GIC version]), + AS_HELP_STRING([--with-gic={v2|v3|v5}], [select GIC version]), [GIC_VERSION=$withval], [GIC_VERSION=v2]) AS_CASE([$GIC_VERSION], - [v2|v3], [], - [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2 or v3)])]) + [v2|v3|v5], [], + [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2, v3, or v5)])]) AC_SUBST([GIC_VERSION], [$GIC_VERSION]) AM_CONDITIONAL([GICV2], [test "x$GIC_VERSION" = "xv2"]) AM_CONDITIONAL([GICV3], [test "x$GIC_VERSION" = "xv3"]) +AM_CONDITIONAL([GICV5], [test "x$GIC_VERSION" = "xv5"]) # Ensure that we have all the needed programs
scripts/FDT.pm +16 -0
@@ -322,6 +322,22 @@ sub get_num_reg_cells return ($ac, $sc); } +sub get_regname_idx +{ + my $self = shift; + my $regname = shift; + + my $prop = $self->get_property("reg-names"); + + return undef if (not defined($prop)); + + my @names = $prop->read_strings(); + + my ($idx) = grep { $names[$_] eq $regname } 0 .. $#names; + + return $idx; +} + sub translate_address { my $self = shift;
scripts/findbase-by-regname.pl new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [BOOTWRAPPER PATCH v2 2/2] Add support for GICv5
Hi Vladimir,
This looks good overall. There are a few nits around comments and one incorrect comment, but the code itself looks good to me and matches the spec as far as I can tell.
I've gone and tested this, and it works as advertised to boot Linux (and run KVM) on a GICv5-enabled FVP. Hence:
Quoted 118 lines · Vladimir Murzin
Performs the minimal initialization required for GICv5 support. GICv5 support can be requested with --with-gic=v5.
Signed-off-by Vladimir Murzin <[email protected]>---
Makefile.am | 7 ++
arch/aarch64/include/asm/cpu.h | 11 +++
common/gic-v5.c | 134
+++++++++++++++++++++++++++++++++
configure.ac | 7 +-
scripts/FDT.pm | 16 ++++
scripts/findbase-by-regname.pl | 44 +++++++++++6 files changed, 216 insertions(+), 3 deletions(-)create mode 100644
common/gic-v5.c
create mode 100755scripts/findbase-by-regname.plMakefile.am +0
-0@@ -82,6 +82,13 @@ PSCI_NODE :=CPU_NODES :=
endifMakefile.am +2
-0+if GICV5 +GIC_IRS_BASE := $(shell perl -I $(SCRIPT_DIR)$(SCRIPT_DIR)/findbase-by-regname.pl $(KERNEL_DTB) "el3-config" 'arm,gic-v5-irs')
+GIC_IWB_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v5-iwb')Makefile.am +4
-0+DEFINES += -DGIC_IRS_BASE=$(GIC_IRS_BASE) +DEFINES += -DGIC_IWB_BASE=$(GIC_IWB_BASE) +endif +if GICV3
GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v3')
GIC_RDIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,gic-v3')arch/aarch64/include/asm/cpu.h +0
-0@@ -128,6 +128,7 @@ #define ID_AA64PFR1_EL1_THE BITS(51, 48)
#defineID_AA64PFR2_EL1s3_0_c0_c4_2
+#defineID_AA64PFR2_EL1_GCIEBITS(15, 12)
#defineID_AA64PFR2_EL1_FPMRBITS(35, 32)
#defineID_AA64SMFR0_EL1s3_0_c0_c4_5arch/aarch64/include/asm/cpu.h +0
-0@@ -169,6 +170,11 @@ #define ICC_CTLR_EL3 S3_6_C12_C12_4 #define ICC_PMR_EL1 S3_0_C4_C6_0arch/aarch64/include/asm/cpu.h +5
-0+#define ICC_PPI_DOMAINR0_EL3 S3_6_C12_C8_4 +#define ICC_PPI_DOMAINR1_EL3 S3_6_C12_C8_5 +#define ICC_PPI_DOMAINR2_EL3 S3_6_C12_C8_6 +#define ICC_PPI_DOMAINR3_EL3 S3_6_C12_C8_7 +#define
VSTCR_EL2s3_4_c2_c6_2
#defineVSCTLR_EL2s3_4_c2_c0_0arch/aarch64/include/asm/cpu.h +0
-0@@ -245,6 +251,11 @@ static inline int has_gicv3_sysreg(void) return !!mrs_field(ID_AA64PFR0_EL1, GIC); }arch/aarch64/include/asm/cpu.h +5
-0+static inline int has_gicv5_sysreg (void ) +{ +return !!mrs_field (ID_AA64PFR2_EL1 ,GCIE ); +} +#endif /* !__ASSEMBLY__ */
#endifcommon/gic-v5.c new file +6
-0@@ -0,0 +1,134 @@ +/* +* gic-v5.c +* +* Copyright (C) 2025 ARM Limited. All rights reserved. +* +* Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE.txt file.
+ */common/gic-v5.c new file +27
-0+ +#include <stdint.h> + +#include <cpu.h> +#include <gic.h> +#include <asm/io.h> + +#define IWB_IDR0 0x0 +#define IWB_IDR0_IW_RANGE_SHIFT 0x0 +#define IWB_IDR0_IW_RANGE_MASK 0x7ff + +#define IWB_CR0 0x80 +#define IWB_CR0_IWBEN (1 << 0) +#define IWB_CR0_IDLE (1 << 1) + +#define IWB_WENABLE_STATUSR 0xc0 +#define IWB_WENABLE_STATUSR_IDLE (1 << 0) + +#define IWB_WDOMAIN_STATUSR 0xc4 +#define IWB_WDOMAIN_STATUSR_IDLE (1 << 0) + +#define IWB_WENABLER 0x2000 +#define IWB_WDOMAINR 0x8000 + +#define IRS_IDR6 0x0018 +#define IRS_IDR6_SPI_IRS_RANGE_MASK 0x1ffffff +
common/gic-v5.c line 45
Quoted 10 lines
common/gic-v5.c new file +10
-0+#define IRS_IDR7 0x001c +#define IRS_IDR7_SPI_BASE_MASK 0xffffff + +#define IRS_SPI_SELR 0x108 +#define IRS_SPI_DOMAINR 0x10c + +#define IRS_SPI_STATUSR 0x0118 +#define IRS_SPI_STATUSR_IDLE (1 << 0) + +
nit: extra newline
common/gic-v5.c line 51
Quoted 6 lines
common/gic-v5.c new file +6
-0+static void gic_iwb_init (void ) { +void *iwb_ptr = (void *)GIC_IWB_BASE ; +unsigned int num; +unsigned int i; + +/* Get number of implemented wires */
This comment is wrong. This isn't getting the number of wires. It is getting the number of wire control registers, which is number_of_wires/32.
common/gic-v5.c line 58
Quoted 8 lines
common/gic-v5.c new file +1
-0+ num = ((raw_readl(iwb_ptr + IWB_IDR0) >>
IWB_IDR0_IW_RANGE_SHIFT) &IWB_IDR0_IW_RANGE_MASK) + 1;common/gic-v5.c new file +6
-0+ +/* Disable all wires */ +for (i =0 ; i < num; i++) +raw_writel (0 , iwb_ptr +IWB_WENABLER + i *4 ); + +
Extra newline
common/gic-v5.c
Quoted 4 lines
common/gic-v5.c new file +1
-0+ while (!(raw_readl(iwb_ptr + IWB_WENABLE_STATUSR) &
IWB_WENABLE_STATUSR_IDLE));common/gic-v5.c new file +2
-0+ +/* Asign all wires to Non-Secure domain */
nit: Assign
Quoted 10 lines
common/gic-v5.c new file +2
-0+for (i =0 ; i < num *2 ; i++) + raw_writel(0x55555555, iwb_ptr + IWB_WDOMAINR + i *4);
common/gic-v5.c new file +2
-0+ + while (!(raw_readl(iwb_ptr + IWB_WDOMAIN_STATUSR) &
IWB_WDOMAIN_STATUSR_IDLE));common/gic-v5.c new file +4
-0+ +/* Enable IWB */ +raw_writel (IWB_CR0_IWBEN , iwb_ptr +IWB_CR0 ); +
common/gic-v5.c line 79
Quoted 10 lines
common/gic-v5.c new file +10
-0+while (!(raw_readl (iwb_ptr +IWB_CR0 ) &IWB_CR0_IDLE )); +} + +static void gic_irs_init (void ) { +void *irs_ptr = (void *)GIC_IRS_BASE ; +unsigned int range; +unsigned int base; +unsigned int i; + +/* Get the range of implemented SPI's ids */
nit: SPI IDs (or just SPIs)
Quoted 35 lines
common/gic-v5.c new file +1
-0+ base = raw_readl(irs_ptr + IRS_IDR7) &
IRS_IDR7_SPI_BASE_MASK;common/gic-v5.c new file +1
-0+ range = raw_readl(irs_ptr + IRS_IDR6) &
IRS_IDR6_SPI_IRS_RANGE_MASK;common/gic-v5.c new file +5
-0+ +for (i = base; i < base + range; i++) { +/* Select SPI */ +raw_writel (i, irs_ptr +IRS_SPI_SELR ); + while (!(raw_readl(irs_ptr + IRS_SPI_STATUSR) &
IRS_SPI_STATUSR_IDLE));common/gic-v5.c new file +4
-0+ +/* Asign SPI to Non-Secure domain */ +raw_writel (1 , irs_ptr +IRS_SPI_DOMAINR ); + while (!(raw_readl(irs_ptr + IRS_SPI_STATUSR) &
IRS_SPI_STATUSR_IDLE));common/gic-v5.c new file +13
-0+ } +} + +static void gic_ppi_init (void ) { +uint64_t val =0 ; + + val |=1UL << (2 *31 );// Trace Buffer Unit + val |=1UL << (2 *30 );// EL1 Physical Timer + val |=1UL << (2 *28 );// Non-secure EL2 Virtual Timer + val |=1UL << (2 *27 );// EL1 Virtual Timer + val |=1UL << (2 *26 );// Non-secure EL2 Physical Timer + val |=1UL << (2 *25 );// GIC maintenance interrupt + val |=1UL << (2 *24 );// Generic CTI interrupt trigger event
common/gic-v5.c new file +3
-0+ val |=1UL << (2 *23 );// PMU overflow interrupt request + val |=1UL << (2 *22 );// Debug communication channel + val |=1UL << (2 *21 );// Profiling Buffer management interrupt request
common/gic-v5.c new file +1
-0+ val |=1UL << (2 *15 );// Hardware accelerator for cleaning Dirty state interrupt
common/gic-v5.c line 110
Quoted 3 lines
common/gic-v5.c new file +3
-0+ val |= 1UL << (2 * 3); // Reserved for software usage + +/* Asign PPI to Non-Secure domain */
nit: Assign PPIs
Quoted 134 lines
common/gic-v5.c new file +8
-0+msr (ICC_PPI_DOMAINR0_EL3 , val); +isb (); +} + +void gic_secure_init (void ) +{ +/* +* If GICv5 is not available, skip initialisation. The OS will probably
common/gic-v5.c new file +1
-0+* fail with a warning, but this should be easier to debug than a
common/gic-v5.c new file +15
-0+* failure within the boot wrapper. +*/ +if (!has_gicv5_sysreg ()) +return ; + +if (this_cpu_logical_id () ==0 ) { +gic_iwb_init (); +gic_irs_init (); + } + +gic_ppi_init (); + +return ; +} +configure.ac +0
-0@@ -141,18 +141,19 @@ AC_SUBST([XEN_CMDLINE], [$X_CMDLINE])
AC_ARG_WITH([gic],
-AS_HELP_STRING([--with-gic={v2|v3}], [select GIC version]), +AS_HELP_STRING([--with-gic={v2|v3|v5}], [select GIC version]), [GIC_VERSION=$withval],
[GIC_VERSION=v2])
AS_CASE([$GIC_VERSION],
- [v2|v3], [],
- [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2 or v3)])])
+ [v2|v3|v5], [],
+ [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2, v3, or v5)])])
AC_SUBST([GIC_VERSION], [$GIC_VERSION])
AM_CONDITIONAL([GICV2], [test "x$GIC_VERSION" = "xv2"])AM_CONDITIONAL([GICV3], [test "x$GIC_VERSION" = "xv3"])+AM_CONDITIONAL([GICV5], [test "x$GIC_VERSION" = "xv5"])
# Ensure that we have all the needed programsscripts/FDT.pm +0
-0@@ -322,6 +322,22 @@ sub get_num_reg_cells return ($ac, $sc); }scripts/FDT.pm +16
-0+sub get_regname_idx +{ + my $self = shift; + my $regname = shift; + + my $prop = $self->get_property("reg-names"); + + return undef if (not defined($prop)); + + my @names = $prop->read_strings(); + + my ($idx) = grep { $names[$_] eq $regname } 0 .. $#names; + + return $idx; +} +sub
translate_address
{
my $self = shift;scripts/findbase-by- renamed from scripts/findbase-by-regname.pl +0
-0regname.pl
new file mode 100755
index 0000000..49cd0cescripts/findbase-by-regname.pl new file +8
-0@@ -0,0 +1,44 @@ +#!/usr/bin/perl -w +# Find device register base addresses. +# +# Usage: ./$0 <DTB> <regname> <compatible ...> +# +# Copyright (C) 2026 ARM Limited. All rights reserved. +# +# Use of this source code is governed by a BSD-style license thatcan be
scripts/findbase-by-regname.pl new file +16
-0+# found in the LICENSE.txt file. + +use warnings; +use strict; + +use FDT; + +my $filename = shift; +die("No filename provided") unless defined($filename); + +my $regname = shift; +die("no reg regname provided") unless defined($regname); + +my @compats = shift; + +open (my $fh, "<:raw", $filename) or die("Unable to open file'$filename'");
scripts/findbase-by-regname.pl new file +18
-0+ +my $fdt = FDT->parse($fh) or die("Unable to parse DTB"); + +my $root = $fdt->get_root(); + +my @devs = (); +for my $compat (@compats) { + push @devs, $root->find_compatible($compat); +} + +# We only care about finding the first matching device +my $dev = shift @devs; +die("No matching devices found") if (not defined($dev)); + +my $idx = $dev->get_regname_idx($regname); +die("Cannot find reg name $regname") if (not defined($idx)); +my ($addr, $size) = $dev->get_translated_reg($idx); +die("Cannot find reg entry $idx") if (not defined($addr) or notdefined($size));
scripts/findbase-by-regname.pl line 44
Quoted 2 lines
scripts/findbase-by-regname.pl new file +2
-0+ +printf("0x%016x\n", $addr);
Thanks,
Sascha
Re: [BOOTWRAPPER PATCH v2 2/2] Add support for GICv5
Hi Sascha,
Quoted 11 lines · Sascha Bischoff
Hi Vladimir,
This looks good overall. There are a few nits around comments and one incorrect comment, but the code itself looks good to me and matches the spec as far as I can tell.
I've gone and tested this, and it works as advertised to boot Linux (and run KVM) on a GICv5-enabled FVP. Hence:
Tested-by Sascha Bischoff <[email protected]>
Happy to hear it works not only in my setup :)
Quoted 349 lines · Vladimir Murzin
Quoted 118 lines
Performs the minimal initialization required for GICv5 support. GICv5 support can be requested with --with-gic=v5.
Signed-off-by Vladimir Murzin <[email protected]>---
Makefile.am | 7 ++
arch/aarch64/include/asm/cpu.h | 11 +++
common/gic-v5.c | 134
+++++++++++++++++++++++++++++++++
configure.ac | 7 +-
scripts/FDT.pm | 16 ++++
scripts/findbase-by-regname.pl | 44 +++++++++++6 files changed, 216 insertions(+), 3 deletions(-)create mode 100644
common/gic-v5.c
create mode 100755scripts/findbase-by-regname.plMakefile.am +0
-0@@ -82,6 +82,13 @@ PSCI_NODE :=CPU_NODES :=
endifMakefile.am +2
-0+if GICV5 +GIC_IRS_BASE := $(shell perl -I $(SCRIPT_DIR)$(SCRIPT_DIR)/findbase-by-regname.pl $(KERNEL_DTB) "el3-config" 'arm,gic-v5-irs')
+GIC_IWB_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v5-iwb')Makefile.am +4
-0+DEFINES += -DGIC_IRS_BASE=$(GIC_IRS_BASE) +DEFINES += -DGIC_IWB_BASE=$(GIC_IWB_BASE) +endif +if GICV3
GIC_DIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 0 'arm,gic-v3')
GIC_RDIST_BASE := $(shell perl -I $(SCRIPT_DIR)
$(SCRIPT_DIR)/findbase.pl $(KERNEL_DTB) 1 'arm,gic-v3')arch/aarch64/include/asm/cpu.h +0
-0@@ -128,6 +128,7 @@ #define ID_AA64PFR1_EL1_THE BITS(51, 48)
#defineID_AA64PFR2_EL1s3_0_c0_c4_2
+#defineID_AA64PFR2_EL1_GCIEBITS(15, 12)
#defineID_AA64PFR2_EL1_FPMRBITS(35, 32)
#defineID_AA64SMFR0_EL1s3_0_c0_c4_5arch/aarch64/include/asm/cpu.h +0
-0@@ -169,6 +170,11 @@ #define ICC_CTLR_EL3 S3_6_C12_C12_4 #define ICC_PMR_EL1 S3_0_C4_C6_0arch/aarch64/include/asm/cpu.h +5
-0+#define ICC_PPI_DOMAINR0_EL3 S3_6_C12_C8_4 +#define ICC_PPI_DOMAINR1_EL3 S3_6_C12_C8_5 +#define ICC_PPI_DOMAINR2_EL3 S3_6_C12_C8_6 +#define ICC_PPI_DOMAINR3_EL3 S3_6_C12_C8_7 +#define
VSTCR_EL2s3_4_c2_c6_2
#defineVSCTLR_EL2s3_4_c2_c0_0arch/aarch64/include/asm/cpu.h +0
-0@@ -245,6 +251,11 @@ static inline int has_gicv3_sysreg(void) return !!mrs_field(ID_AA64PFR0_EL1, GIC); }arch/aarch64/include/asm/cpu.h +5
-0+static inline int has_gicv5_sysreg (void ) +{ +return !!mrs_field (ID_AA64PFR2_EL1 ,GCIE ); +} +#endif /* !__ASSEMBLY__ */
#endifcommon/gic-v5.c new file +6
-0@@ -0,0 +1,134 @@ +/* +* gic-v5.c +* +* Copyright (C) 2025 ARM Limited. All rights reserved. +* +* Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE.txt file.
+ */common/gic-v5.c new file +27
-0+ +#include <stdint.h> + +#include <cpu.h> +#include <gic.h> +#include <asm/io.h> + +#define IWB_IDR0 0x0 +#define IWB_IDR0_IW_RANGE_SHIFT 0x0 +#define IWB_IDR0_IW_RANGE_MASK 0x7ff + +#define IWB_CR0 0x80 +#define IWB_CR0_IWBEN (1 << 0) +#define IWB_CR0_IDLE (1 << 1) + +#define IWB_WENABLE_STATUSR 0xc0 +#define IWB_WENABLE_STATUSR_IDLE (1 << 0) + +#define IWB_WDOMAIN_STATUSR 0xc4 +#define IWB_WDOMAIN_STATUSR_IDLE (1 << 0) + +#define IWB_WENABLER 0x2000 +#define IWB_WDOMAINR 0x8000 + +#define IRS_IDR6 0x0018 +#define IRS_IDR6_SPI_IRS_RANGE_MASK 0x1ffffff +common/gic-v5.c line 45
Quoted 10 lines
common/gic-v5.c new file +10
-0+#define IRS_IDR7 0x001c +#define IRS_IDR7_SPI_BASE_MASK 0xffffff + +#define IRS_SPI_SELR 0x108 +#define IRS_SPI_DOMAINR 0x10c + +#define IRS_SPI_STATUSR 0x0118 +#define IRS_SPI_STATUSR_IDLE (1 << 0) + +nit: extra newline
common/gic-v5.c line 51
Quoted 6 lines
common/gic-v5.c new file +6
-0+static void gic_iwb_init (void ) { +void *iwb_ptr = (void *)GIC_IWB_BASE ; +unsigned int num; +unsigned int i; + +/* Get number of implemented wires */ This comment is wrong. This isn't getting the number of wires. It is getting the number of wire control registers, which is number_of_wires/32.
common/gic-v5.c line 58
Quoted 8 lines
common/gic-v5.c new file +1
-0+ num = ((raw_readl(iwb_ptr + IWB_IDR0) >>
IWB_IDR0_IW_RANGE_SHIFT) &IWB_IDR0_IW_RANGE_MASK) + 1;common/gic-v5.c new file +6
-0+ +/* Disable all wires */ +for (i =0 ; i < num; i++) +raw_writel (0 , iwb_ptr +IWB_WENABLER + i *4 ); + +Extra newline
common/gic-v5.c
Quoted 4 lines
common/gic-v5.c new file +1
-0+ while (!(raw_readl(iwb_ptr + IWB_WENABLE_STATUSR) &
IWB_WENABLE_STATUSR_IDLE));common/gic-v5.c new file +2
-0+ +/* Asign all wires to Non-Secure domain */ nit: Assign
Quoted 10 lines
common/gic-v5.c new file +2
-0+for (i =0 ; i < num *2 ; i++) + raw_writel(0x55555555, iwb_ptr + IWB_WDOMAINR + i *4);
common/gic-v5.c new file +2
-0+ + while (!(raw_readl(iwb_ptr + IWB_WDOMAIN_STATUSR) &
IWB_WDOMAIN_STATUSR_IDLE));common/gic-v5.c new file +4
-0+ +/* Enable IWB */ +raw_writel (IWB_CR0_IWBEN , iwb_ptr +IWB_CR0 ); +common/gic-v5.c line 79
Quoted 10 lines
common/gic-v5.c new file +10
-0+while (!(raw_readl (iwb_ptr +IWB_CR0 ) &IWB_CR0_IDLE )); +} + +static void gic_irs_init (void ) { +void *irs_ptr = (void *)GIC_IRS_BASE ; +unsigned int range; +unsigned int base; +unsigned int i; + +/* Get the range of implemented SPI's ids */ nit: SPI IDs (or just SPIs)
Quoted 35 lines
common/gic-v5.c new file +1
-0+ base = raw_readl(irs_ptr + IRS_IDR7) &
IRS_IDR7_SPI_BASE_MASK;common/gic-v5.c new file +1
-0+ range = raw_readl(irs_ptr + IRS_IDR6) &
IRS_IDR6_SPI_IRS_RANGE_MASK;common/gic-v5.c new file +5
-0+ +for (i = base; i < base + range; i++) { +/* Select SPI */ +raw_writel (i, irs_ptr +IRS_SPI_SELR ); + while (!(raw_readl(irs_ptr + IRS_SPI_STATUSR) &
IRS_SPI_STATUSR_IDLE));common/gic-v5.c new file +4
-0+ +/* Asign SPI to Non-Secure domain */ +raw_writel (1 , irs_ptr +IRS_SPI_DOMAINR ); + while (!(raw_readl(irs_ptr + IRS_SPI_STATUSR) &
IRS_SPI_STATUSR_IDLE));common/gic-v5.c new file +13
-0+ } +} + +static void gic_ppi_init (void ) { +uint64_t val =0 ; + + val |=1UL << (2 *31 );// Trace Buffer Unit + val |=1UL << (2 *30 );// EL1 Physical Timer + val |=1UL << (2 *28 );// Non-secure EL2 Virtual Timer + val |=1UL << (2 *27 );// EL1 Virtual Timer + val |=1UL << (2 *26 );// Non-secure EL2 Physical Timer + val |=1UL << (2 *25 );// GIC maintenance interrupt + val |=1UL << (2 *24 );// Generic CTI interrupt trigger event
common/gic-v5.c new file +3
-0+ val |=1UL << (2 *23 );// PMU overflow interrupt request + val |=1UL << (2 *22 );// Debug communication channel + val |=1UL << (2 *21 );// Profiling Buffer management interrupt request
common/gic-v5.c new file +1
-0+ val |=1UL << (2 *15 );// Hardware accelerator for cleaning Dirty state interrupt
common/gic-v5.c line 110
Quoted 3 lines
common/gic-v5.c new file +3
-0+ val |= 1UL << (2 * 3); // Reserved for software usage + +/* Asign PPI to Non-Secure domain */ nit: Assign PPIs
Quoted 130 lines
common/gic-v5.c new file +8
-0+msr (ICC_PPI_DOMAINR0_EL3 , val); +isb (); +} + +void gic_secure_init (void ) +{ +/* +* If GICv5 is not available, skip initialisation. The OS will probably
common/gic-v5.c new file +1
-0+* fail with a warning, but this should be easier to debug than a
common/gic-v5.c new file +15
-0+* failure within the boot wrapper. +*/ +if (!has_gicv5_sysreg ()) +return ; + +if (this_cpu_logical_id () ==0 ) { +gic_iwb_init (); +gic_irs_init (); + } + +gic_ppi_init (); + +return ; +} +configure.ac +0
-0@@ -141,18 +141,19 @@ AC_SUBST([XEN_CMDLINE], [$X_CMDLINE])
AC_ARG_WITH([gic],
-AS_HELP_STRING([--with-gic={v2|v3}], [select GIC version]), +AS_HELP_STRING([--with-gic={v2|v3|v5}], [select GIC version]), [GIC_VERSION=$withval],
[GIC_VERSION=v2])
AS_CASE([$GIC_VERSION],
- [v2|v3], [],
- [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2 or v3)])])
+ [v2|v3|v5], [],
+ [AC_MSG_ERROR([Invalid GIC version: $GIC_VERSION (use v2, v3, or v5)])])
AC_SUBST([GIC_VERSION], [$GIC_VERSION])
AM_CONDITIONAL([GICV2], [test "x$GIC_VERSION" = "xv2"])AM_CONDITIONAL([GICV3], [test "x$GIC_VERSION" = "xv3"])+AM_CONDITIONAL([GICV5], [test "x$GIC_VERSION" = "xv5"])
# Ensure that we have all the needed programsscripts/FDT.pm +0
-0@@ -322,6 +322,22 @@ sub get_num_reg_cells return ($ac, $sc); }scripts/FDT.pm +16
-0+sub get_regname_idx +{ + my $self = shift; + my $regname = shift; + + my $prop = $self->get_property("reg-names"); + + return undef if (not defined($prop)); + + my @names = $prop->read_strings(); + + my ($idx) = grep { $names[$_] eq $regname } 0 .. $#names; + + return $idx; +} +sub
translate_address
{
my $self = shift;scripts/findbase-by- renamed from scripts/findbase-by-regname.pl +0
-0regname.pl
new file mode 100755
index 0000000..49cd0cescripts/findbase-by-regname.pl new file +8
-0@@ -0,0 +1,44 @@ +#!/usr/bin/perl -w +# Find device register base addresses. +# +# Usage: ./$0 <DTB> <regname> <compatible ...> +# +# Copyright (C) 2026 ARM Limited. All rights reserved. +# +# Use of this source code is governed by a BSD-style license thatcan be
scripts/findbase-by-regname.pl new file +16
-0+# found in the LICENSE.txt file. + +use warnings; +use strict; + +use FDT; + +my $filename = shift; +die("No filename provided") unless defined($filename); + +my $regname = shift; +die("no reg regname provided") unless defined($regname); + +my @compats = shift; + +open (my $fh, "<:raw", $filename) or die("Unable to open file'$filename'");
scripts/findbase-by-regname.pl new file +15
-0+ +my $fdt = FDT->parse($fh) or die("Unable to parse DTB"); + +my $root = $fdt->get_root(); + +my @devs = (); +for my $compat (@compats) { + push @devs, $root->find_compatible($compat); +} + +# We only care about finding the first matching device +my $dev = shift @devs; +die("No matching devices found") if (not defined($dev)); + +my $idx = $dev->get_regname_idx($regname);
Quoted 9 lines
scripts/findbase-by-regname.pl line 44
Quoted 6 lines
scripts/findbase-by-regname.pl new file +3
-0+die("Cannot find reg name $regname") if (not defined($idx)); +my ($addr, $size) = $dev->get_translated_reg($idx); +die("Cannot find reg entry $idx") if (not defined($addr) or notdefined($size));
scripts/findbase-by-regname.pl new file +2
-0+ +printf("0x%016x\n", $addr);Thanks,
Sascha
Thanks Sascha, all fixed locally.
Cheers
Vladimir