aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Turner <andrew@FreeBSD.org>2022-08-25 08:28:28 +0000
committerAndrew Turner <andrew@FreeBSD.org>2022-08-31 10:48:31 +0000
commit544f047f894046a68c373f55ddd072e91bcfbf38 (patch)
treee57c8e4c10b3fd50082d2a69909e6df6c2bfe97d
parent998b0a4ad84252180ab7b06b281f923ce1d0747b (diff)
downloadsrc-544f047f894046a68c373f55ddd072e91bcfbf38.tar.gz
src-544f047f894046a68c373f55ddd072e91bcfbf38.zip
Store mpidr as a 64-bit value on arm64
The mpidr register is 64 bit on arm64 and 32 bit on arm. Fix this by extending the arm64 definition to include the top 32 bits. To preserve KBI when MFCing split the value into two 32 bit values. This will be cleaned up later only on main. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36346
-rw-r--r--sys/arm/arm/pmu_acpi.c2
-rw-r--r--sys/arm/arm/pmu_fdt.c2
-rw-r--r--sys/arm/include/pcpu.h2
-rw-r--r--sys/arm64/arm64/machdep.c3
-rw-r--r--sys/arm64/arm64/mp_machdep.c17
-rw-r--r--sys/arm64/include/pcpu.h9
6 files changed, 24 insertions, 11 deletions
diff --git a/sys/arm/arm/pmu_acpi.c b/sys/arm/arm/pmu_acpi.c
index 2e031338f144..8812ac7b3af4 100644
--- a/sys/arm/arm/pmu_acpi.c
+++ b/sys/arm/arm/pmu_acpi.c
@@ -72,7 +72,7 @@ madt_handler(ACPI_SUBTABLE_HEADER *entry, void *arg)
for (i = 0; i < MAXCPU; i++) {
pcpu = pcpu_find(i);
- if (pcpu != NULL && pcpu->pc_mpidr == intr->ArmMpidr) {
+ if (pcpu != NULL && PCPU_GET_MPIDR(pcpu) == intr->ArmMpidr) {
cpuid = i;
break;
}
diff --git a/sys/arm/arm/pmu_fdt.c b/sys/arm/arm/pmu_fdt.c
index 0b435375aa22..fef15e106a33 100644
--- a/sys/arm/arm/pmu_fdt.c
+++ b/sys/arm/arm/pmu_fdt.c
@@ -105,7 +105,7 @@ pmu_parse_affinity(device_t dev, struct pmu_softc *sc, struct pmu_intr *irq,
for (i = 0; i < MAXCPU; i++) {
pcpu = pcpu_find(i);
- if (pcpu != NULL && pcpu->pc_mpidr == mpidr) {
+ if (pcpu != NULL && PCPU_GET_MPIDR(pcpu) == mpidr) {
irq->cpuid = i;
return (0);
}
diff --git a/sys/arm/include/pcpu.h b/sys/arm/include/pcpu.h
index 2353b1d06b17..ced701516c70 100644
--- a/sys/arm/include/pcpu.h
+++ b/sys/arm/include/pcpu.h
@@ -139,6 +139,8 @@ set_tls(void *tls)
#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member)
#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value))
+#define PCPU_GET_MPIDR(pc) ((pc)->pc_mpidr)
+
void pcpu0_init(void);
#endif /* _KERNEL */
diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 5ce5d279e8e0..c47e16e6b2b6 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -300,7 +300,8 @@ cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
{
pcpu->pc_acpi_id = 0xffffffff;
- pcpu->pc_mpidr = 0xffffffff;
+ pcpu->pc_mpidr_low = 0xffffffff;
+ pcpu->pc_mpidr_high = 0xffffffff;
}
void
diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c
index a6e2be300bae..d1fbb4c079d2 100644
--- a/sys/arm64/arm64/mp_machdep.c
+++ b/sys/arm64/arm64/mp_machdep.c
@@ -153,7 +153,7 @@ static bool
is_boot_cpu(uint64_t target_cpu)
{
- return (cpuid_to_pcpu[0]->pc_mpidr == (target_cpu & CPU_AFF_MASK));
+ return (PCPU_GET_MPIDR(cpuid_to_pcpu[0]) == (target_cpu & CPU_AFF_MASK));
}
static void
@@ -207,7 +207,7 @@ init_secondary(uint64_t cpu)
{
struct pcpu *pcpup;
pmap_t pmap0;
- u_int mpidr;
+ uint64_t mpidr;
ptrauth_mp_start(cpu);
@@ -218,10 +218,10 @@ init_secondary(uint64_t cpu)
*/
mpidr = READ_SPECIALREG(mpidr_el1) & CPU_AFF_MASK;
if (cpu >= MAXCPU || cpuid_to_pcpu[cpu] == NULL ||
- cpuid_to_pcpu[cpu]->pc_mpidr != mpidr) {
+ PCPU_GET_MPIDR(cpuid_to_pcpu[cpu]) != mpidr) {
for (cpu = 0; cpu < mp_maxid; cpu++)
if (cpuid_to_pcpu[cpu] != NULL &&
- cpuid_to_pcpu[cpu]->pc_mpidr == mpidr)
+ PCPU_GET_MPIDR(cpuid_to_pcpu[cpu]) == mpidr)
break;
if ( cpu >= MAXCPU)
panic("MPIDR for this CPU is not in pcpu table");
@@ -517,7 +517,8 @@ start_cpu(u_int cpuid, uint64_t target_cpu, int domain)
pcpup = (struct pcpu *)pcpu_mem;
pcpu_init(pcpup, cpuid, sizeof(struct pcpu));
- pcpup->pc_mpidr = target_cpu & CPU_AFF_MASK;
+ pcpup->pc_mpidr_low = target_cpu & CPU_AFF_MASK;
+ pcpup->pc_mpidr_high = (target_cpu & CPU_AFF_MASK) >> 32;
dpcpu[cpuid - 1] = (void *)(pcpup + 1);
dpcpu_init(dpcpu[cpuid - 1], cpuid);
@@ -688,11 +689,15 @@ cpu_init_fdt(void)
void
cpu_mp_start(void)
{
+ uint64_t mpidr;
+
mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
/* CPU 0 is always boot CPU. */
CPU_SET(0, &all_cpus);
- cpuid_to_pcpu[0]->pc_mpidr = READ_SPECIALREG(mpidr_el1) & CPU_AFF_MASK;
+ mpidr = READ_SPECIALREG(mpidr_el1) & CPU_AFF_MASK;
+ cpuid_to_pcpu[0]->pc_mpidr_low = mpidr;
+ cpuid_to_pcpu[0]->pc_mpidr_high = mpidr >> 32;
switch(arm64_bus_method) {
#ifdef DEV_ACPI
diff --git a/sys/arm64/include/pcpu.h b/sys/arm64/include/pcpu.h
index b93f3b2e4816..8d60b4ef6356 100644
--- a/sys/arm64/include/pcpu.h
+++ b/sys/arm64/include/pcpu.h
@@ -48,8 +48,10 @@ struct debug_monitor_state;
struct pmap *pc_curpmap; \
struct pmap *pc_curvmpmap; \
u_int pc_bcast_tlbi_workaround; \
- u_int pc_mpidr; /* stored MPIDR value */ \
- char __pad[201]
+ /* Store as two u_int values to preserve KBI */ \
+ u_int pc_mpidr_low; /* lower MPIDR 32 bits */ \
+ u_int pc_mpidr_high; /* upper MPIDR 32 bits */ \
+ char __pad[197]
#ifdef _KERNEL
@@ -83,6 +85,9 @@ get_curthread(void)
#define PCPU_PTR(member) (&pcpup->pc_ ## member)
#define PCPU_SET(member,value) (pcpup->pc_ ## member = (value))
+#define PCPU_GET_MPIDR(pc) \
+ ((((uint64_t)((pc)->pc_mpidr_high)) << 32) | ((pc)->pc_mpidr_low))
+
#endif /* _KERNEL */
#endif /* !_MACHINE_PCPU_H_ */