Skip to content

Instantly share code, notes, and snippets.

@apritzel
Created January 13, 2025 21:27
Show Gist options
  • Save apritzel/dec15f1324ae77e182315eba4e625bcd to your computer and use it in GitHub Desktop.
Save apritzel/dec15f1324ae77e182315eba4e625bcd to your computer and use it in GitHub Desktop.
Hack to switch TF-A Allwinner to modern MPIDR encoding
diff --git a/plat/allwinner/common/include/platform_def.h b/plat/allwinner/common/include/platform_def.h
index c9d075ac8..9543dbeaa 100644
--- a/plat/allwinner/common/include/platform_def.h
+++ b/plat/allwinner/common/include/platform_def.h
@@ -72,7 +72,7 @@
#define PLATFORM_CLUSTER_COUNT U(1)
#define PLATFORM_CORE_COUNT (PLATFORM_CLUSTER_COUNT * \
PLATFORM_MAX_CPUS_PER_CLUSTER)
-#define PLATFORM_MAX_CPUS_PER_CLUSTER U(4)
+#define PLATFORM_MAX_CPUS_PER_CLUSTER U(8)
#define PLATFORM_STACK_SIZE (0x1000 / PLATFORM_CORE_COUNT)
#ifndef SPD_none
diff --git a/plat/allwinner/common/plat_helpers.S b/plat/allwinner/common/plat_helpers.S
index b00c7aefd..3f7d68d0b 100644
--- a/plat/allwinner/common/plat_helpers.S
+++ b/plat/allwinner/common/plat_helpers.S
@@ -34,9 +34,9 @@ endfunc plat_crash_console_flush
func plat_my_core_pos
mrs x0, mpidr_el1
- and x1, x0, #MPIDR_CLUSTER_MASK
- and x0, x0, #MPIDR_CPU_MASK
- add x0, x0, x1, LSR #6
+ and x1, x0, #0xff0000
+ ubfx x0, x0, #8, #3
+ add x0, x0, x1, LSR #13
ret
endfunc plat_my_core_pos
diff --git a/plat/allwinner/common/sunxi_topology.c b/plat/allwinner/common/sunxi_topology.c
index 45be1e03d..7247e6bca 100644
--- a/plat/allwinner/common/sunxi_topology.c
+++ b/plat/allwinner/common/sunxi_topology.c
@@ -20,11 +20,10 @@ static const unsigned char plat_power_domain_tree_desc[PLAT_MAX_PWR_LVL + 1] = {
int plat_core_pos_by_mpidr(u_register_t mpidr)
{
- unsigned int cluster = MPIDR_AFFLVL1_VAL(mpidr);
- unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
+ unsigned int cluster = MPIDR_AFFLVL2_VAL(mpidr);
+ unsigned int core = MPIDR_AFFLVL1_VAL(mpidr);
if (MPIDR_AFFLVL3_VAL(mpidr) > 0 ||
- MPIDR_AFFLVL2_VAL(mpidr) > 0 ||
cluster >= PLATFORM_CLUSTER_COUNT ||
core >= PLATFORM_MAX_CPUS_PER_CLUSTER) {
return -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment