diff options
Diffstat (limited to 'arch/arm64/lib/system.c')
| -rw-r--r-- | arch/arm64/lib/system.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/arch/arm64/lib/system.c b/arch/arm64/lib/system.c index 4e227f6..25af2bf 100644 --- a/arch/arm64/lib/system.c +++ b/arch/arm64/lib/system.c @@ -28,18 +28,42 @@ void tb_system_off(void) void tb_system_reset(void) { uint64_t rmr; + uint64_t el; + register uint64_t r0 asm("x0") = 0x84000008; + register uint64_t r1 asm("x1") = 0; + register uint64_t r2 asm("x2") = 0; + register uint64_t r3 asm("x3") = 0; dprintf(ALWAYS, "system reset\n"); - asm volatile("mrs %0, rmr_el2" : "=r" (rmr)); - rmr |= (1 << 1); /* RR, request reset */ - asm volatile( - "msr rmr_el2, %0\n" - "dsb sy\n" - "isb\n" - :: "r" (rmr)); + /* + * the firmware conduit first, PSCI SYSTEM_RESET through + * the machine's own monitor. this is the only legal way + * up from EL1: RMR_EL1 is undefined on hardware that + * implements a higher exception level, the access traps + * and the machine never resets. + */ + asm volatile("smc #0" + : "+r"(r0), "+r"(r1), "+r"(r2), "+r"(r3)); - /* if the reset domain ignores us, park */ + /* + * no monitor answered, or it refused. ask the reset + * domain directly from a level that may write it. + */ + asm volatile("mrs %0, CurrentEL" : "=r" (el)); + el >>= 2; + + if (el >= 2) { + asm volatile("mrs %0, rmr_el2" : "=r" (rmr)); + rmr |= (1 << 1); /* RR, request reset */ + asm volatile( + "msr rmr_el2, %0\n" + "dsb sy\n" + "isb\n" + :: "r" (rmr)); + } + + /* nothing worked, park */ for (;;) { asm volatile("wfi"); } |
