From c7c0a4c5d77c58efd048b34498110972bdac43ce Mon Sep 17 00:00:00 2001 From: Hou Zhiqiang Date: Tue, 2 Mar 2021 15:10:08 +0800 Subject: [PATCH] arm64: gic-v3-its: Clear the Pending table before enabling LPIs The GICv3 RM requires "The first 1KB of memory for the LPI Pending tables must contain only zeros on initial allocation, and this must be visible to the Redistributors, or else the effect is UNPREDICTABLE". And as the following statement, we here clear the whole Pending tables instead of the first 1KB. "An LPI Pending table that contains only zeros, including in the first 1KB, indicates that there are no pending LPIs. The first 1KB of the LPI Pending table is IMPLEMENTATION DEFINED. However, if the first 1KB of the LPI Pending table and the rest of the table contain only zeros, this must indicate that there are no pending LPIs." And there isn't any pending LPI under U-Boot, so it's unnecessary to loading the contents of the Pending table during the enablement, then set the GICR_PENDBASER.PTZ flag. Signed-off-by: Hou Zhiqiang Tested-by: Vladimir Oltean --- arch/arm/lib/gic-v3-its.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/arm/lib/gic-v3-its.c b/arch/arm/lib/gic-v3-its.c index 6ee22d2..e06a3bc 100644 --- a/arch/arm/lib/gic-v3-its.c +++ b/arch/arm/lib/gic-v3-its.c @@ -3,6 +3,7 @@ * Copyright 2019 Broadcom. */ #include +#include #include #include #include @@ -28,6 +29,8 @@ int gic_lpi_tables_init(u64 base, u32 num_redist) int i; u64 redist_lpi_base; u64 pend_base = GICR_BASE + GICR_PENDBASER; + ulong pend_tab_total_sz; + void *pend_tab_va; gicd_typer = readl(GICD_BASE + GICD_TYPER); @@ -76,12 +79,19 @@ int gic_lpi_tables_init(u64 base, u32 num_redist) redist_lpi_base = base + LPI_PROPBASE_SZ; + pend_tab_total_sz = num_redist * LPI_PENDBASE_SZ; + pend_tab_va = map_physmem(redist_lpi_base, pend_tab_total_sz, MAP_NOCACHE); + memset(pend_tab_va, 0, pend_tab_total_sz); + flush_cache((ulong)pend_tab_va, pend_tab_total_sz); + unmap_physmem(pend_tab_va, MAP_NOCACHE); + for (i = 0; i < num_redist; i++) { u32 offset = i * GIC_REDISTRIBUTOR_OFFSET; val = ((redist_lpi_base + (i * LPI_PENDBASE_SZ)) | GICR_PENDBASER_INNERSHAREABLE | - GICR_PENDBASER_RAWAWB); + GICR_PENDBASER_RAWAWB | + GICR_PENDBASER_PTZ); writeq(val, (uintptr_t)(pend_base + offset)); tmp = readq((uintptr_t)(pend_base + offset)); -- 1.9.1