From 30524ff80a7b8a77393622349df9041cc786c96f Mon Sep 17 00:00:00 2001 From: Heyi Guo Date: Wed, 20 Jan 2021 18:50:16 +0800 Subject: [PATCH] refactor(gicv3): add helper function to get the limit of ESPI INTID Add helper function gicv3_get_espi_limit() to get the value of (maximum extended SPI INTID + 1), so that some duplicated code can be removed later. Signed-off-by: Heyi Guo Change-Id: I0355ca2647f872e8189add259f6c47d415494cce --- drivers/arm/gic/v3/gicv3_helpers.c | 22 ++++++++++++++++++++++ drivers/arm/gic/v3/gicv3_private.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/arm/gic/v3/gicv3_helpers.c b/drivers/arm/gic/v3/gicv3_helpers.c index 23a1dfaec..ad7ff22d5 100644 --- a/drivers/arm/gic/v3/gicv3_helpers.c +++ b/drivers/arm/gic/v3/gicv3_helpers.c @@ -110,6 +110,28 @@ unsigned int gicv3_get_spi_limit(uintptr_t gicd_base) return spi_limit; } +#if GIC_EXT_INTID +/******************************************************************************* + * Helper function to get the maximum ESPI INTID + 1. + ******************************************************************************/ +unsigned int gicv3_get_espi_limit(uintptr_t gicd_base) +{ + unsigned int typer_reg = gicd_read_typer(gicd_base); + + /* Check if extended SPI range is implemented */ + if ((typer_reg & TYPER_ESPI) != 0U) { + /* + * (maximum ESPI INTID + 1) is equal to + * 32 * (GICD_TYPER.ESPI_range + 1) + 4096 + */ + return ((((typer_reg >> TYPER_ESPI_RANGE_SHIFT) & + TYPER_ESPI_RANGE_MASK) + 1U) << 5) + MIN_ESPI_ID; + } + + return 0U; +} +#endif /* GIC_EXT_INTID */ + /******************************************************************************* * Helper function to configure the default attributes of (E)SPIs. ******************************************************************************/ diff --git a/drivers/arm/gic/v3/gicv3_private.h b/drivers/arm/gic/v3/gicv3_private.h index 7965f4091..93ee1a18d 100644 --- a/drivers/arm/gic/v3/gicv3_private.h +++ b/drivers/arm/gic/v3/gicv3_private.h @@ -234,6 +234,7 @@ void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg); * Private GICv3 helper function prototypes ******************************************************************************/ unsigned int gicv3_get_spi_limit(uintptr_t gicd_base); +unsigned int gicv3_get_espi_limit(uintptr_t gicd_base); void gicv3_spis_config_defaults(uintptr_t gicd_base); void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base); unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,