Skip to content

Commit 735dad9

Browse files
author
James Morse
committed
arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs
The MPAM system registers will be lost if the CPU is reset during PSCI's CPU_SUSPEND. Add a PM notifier to restore them. mpam_thread_switch(current) can't be used as this won't make any changes if the in-memory copy says the register already has the correct value. In reality the system register is UNKNOWN out of reset. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Co-developed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 831a7f1 commit 735dad9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

arch/arm64/kernel/mpam.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <asm/mpam.h>
55

66
#include <linux/arm_mpam.h>
7+
#include <linux/cpu_pm.h>
78
#include <linux/jump_label.h>
89
#include <linux/percpu.h>
910

@@ -13,12 +14,44 @@ DEFINE_PER_CPU(u64, arm64_mpam_current);
1314

1415
u64 arm64_mpam_global_default;
1516

17+
static int mpam_pm_notifier(struct notifier_block *self,
18+
unsigned long cmd, void *v)
19+
{
20+
u64 regval;
21+
int cpu = smp_processor_id();
22+
23+
switch (cmd) {
24+
case CPU_PM_EXIT:
25+
/*
26+
* Don't use mpam_thread_switch() as the system register
27+
* value has changed under our feet.
28+
*/
29+
regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
30+
write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
31+
isb();
32+
33+
write_sysreg_s(regval, SYS_MPAM0_EL1);
34+
35+
return NOTIFY_OK;
36+
default:
37+
return NOTIFY_DONE;
38+
}
39+
}
40+
41+
static struct notifier_block mpam_pm_nb = {
42+
.notifier_call = mpam_pm_notifier,
43+
};
44+
1645
static int __init arm64_mpam_register_cpus(void)
1746
{
1847
u64 mpamidr = read_sanitised_ftr_reg(SYS_MPAMIDR_EL1);
1948
u16 partid_max = FIELD_GET(MPAMIDR_EL1_PARTID_MAX, mpamidr);
2049
u8 pmg_max = FIELD_GET(MPAMIDR_EL1_PMG_MAX, mpamidr);
2150

51+
if (!system_supports_mpam())
52+
return 0;
53+
54+
cpu_pm_register_notifier(&mpam_pm_nb);
2255
return mpam_register_requestor(partid_max, pmg_max);
2356
}
2457
/* Must occur before mpam_msc_driver_init() from subsys_initcall() */

0 commit comments

Comments
 (0)