feat(allwinner): adjust H616 L2 cache size in DTB

The Allwinner H616 and its siblings come in different die revisions,
some have 256 KB of L2 cache, some have 1 MB. This prevents a single
static cache description in the devicetree.

Use the cache size ID register (CCSIDR_EL1) to query the topology of the
L2 cache, and adjust the cache-sets and cache-size properties in the L2
cache DT node accordingly.

The ARM ARM does not promise (anymore) that the cache size can be derived
*architecturally* from this register, but the reading is definitely
correct for the Arm Cortex-A53 core used.

Change-Id: Id7dc324d783b8319fe5df6164be2f941d4cac82d
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
Andre Przywara 2024-05-01 14:05:24 +01:00 committed by André Przywara
parent 646d06b237
commit ee5b26fd00
4 changed files with 84 additions and 1 deletions

View file

@ -58,4 +58,12 @@ static inline void sunxi_prepare_dtb(void *fdt)
} }
#endif #endif
#ifdef PLAT_sun50i_h616
void sunxi_soc_fdt_fixup(void *dtb);
#else
static inline void sunxi_soc_fdt_fixup(void *dtb)
{
}
#endif
#endif /* SUNXI_PRIVATE_H */ #endif /* SUNXI_PRIVATE_H */

View file

@ -34,6 +34,8 @@ void sunxi_prepare_dtb(void *fdt)
} }
#endif #endif
sunxi_soc_fdt_fixup(fdt);
if (sunxi_psci_is_scpi()) { if (sunxi_psci_is_scpi()) {
ret = fdt_add_cpu_idle_states(fdt, sunxi_idle_states); ret = fdt_add_cpu_idle_states(fdt, sunxi_idle_states);
if (ret < 0) { if (ret < 0) {

View file

@ -21,4 +21,5 @@ endif
BL31_SOURCES += common/fdt_wrappers.c \ BL31_SOURCES += common/fdt_wrappers.c \
drivers/allwinner/axp/axp805.c \ drivers/allwinner/axp/axp805.c \
drivers/allwinner/sunxi_rsb.c \ drivers/allwinner/sunxi_rsb.c \
drivers/mentor/i2c/mi2cv.c drivers/mentor/i2c/mi2cv.c \
${AW_PLAT}/${PLAT}/sunxi_h616_dtb.c

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2024, ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Amend the device tree to adjust the L2 cache size, which is different
* between the revisions of the H616 chips: earlier versions have 256 KB of L2,
* later versions 1 MB.
* Read the cache ID registers and adjust the size and number of sets entries
* in the L2 cache DT node.
*/
#include <common/fdt_wrappers.h>
#include <lib/utils_def.h>
#include <libfdt.h>
#define CACHE_L1D 0x0
#define CACHE_L1I 0x1
#define CACHE_L2U 0x2
#define CCSIDR_SETS_SHIFT 13
#define CCSIDR_SETS_MASK GENMASK(14, 0)
#define CCSIDR_ASSOC_SHIFT 3
#define CCSIDR_ASSOC_MASK GENMASK(9, 0)
#define CCSIDR_LSIZE_SHIFT 0
#define CCSIDR_LSIZE_MASK GENMASK(2, 0)
static uint32_t armv8_get_ccsidr(unsigned int sel)
{
uint32_t reg;
__asm__ volatile ("msr CSSELR_EL1, %0\n" :: "r" (sel));
__asm__ volatile ("mrs %0, CCSIDR_EL1\n" : "=r" (reg));
return reg;
}
void sunxi_soc_fdt_fixup(void *dtb)
{
int node = fdt_path_offset(dtb, "/cpus/cpu@0");
uint32_t phandle, ccsidr, cell;
int sets, line_size, assoc;
int ret;
if (node < 0) {
return;
}
ret = fdt_read_uint32(dtb, node, "next-level-cache", &phandle);
if (ret != 0) {
return;
}
node = fdt_node_offset_by_phandle(dtb, phandle);
if (ret != 0) {
return;
}
ccsidr = armv8_get_ccsidr(CACHE_L2U);
sets = ((ccsidr >> CCSIDR_SETS_SHIFT) & CCSIDR_SETS_MASK) + 1;
line_size = 16U << ((ccsidr >> CCSIDR_LSIZE_SHIFT) & CCSIDR_LSIZE_MASK);
assoc = ((ccsidr >> CCSIDR_ASSOC_SHIFT) & CCSIDR_ASSOC_MASK) + 1;
cell = cpu_to_fdt32(sets);
fdt_setprop(dtb, node, "cache-sets", &cell, sizeof(cell));
cell = cpu_to_fdt32(line_size);
fdt_setprop(dtb, node, "cache-line-size", &cell, sizeof(cell));
cell = cpu_to_fdt32(sets * assoc * line_size);
fdt_setprop(dtb, node, "cache-size", &cell, sizeof(cell));
}