summaryrefslogtreecommitdiff
path: root/sys/src/9/imx8/main.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2022-07-10 11:35:58 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2022-07-10 11:35:58 +0000
commit32183b1abf7a670e11c59595fda4cd64dad1008b (patch)
treedf981740dcf697e8c3f4f13b553364a95b1aaec3 /sys/src/9/imx8/main.c
parent414cefcb0b40082d73942ea619de59b371bd685d (diff)
imx8: implement /dev/reboot support
Diffstat (limited to 'sys/src/9/imx8/main.c')
-rw-r--r--sys/src/9/imx8/main.c56
1 files changed, 52 insertions, 4 deletions
diff --git a/sys/src/9/imx8/main.c b/sys/src/9/imx8/main.c
index 1b7ee9969..d83dca421 100644
--- a/sys/src/9/imx8/main.c
+++ b/sys/src/9/imx8/main.c
@@ -10,6 +10,8 @@
#include "sysreg.h"
#include "ureg.h"
+#include "rebootcode.i"
+
Conf conf;
/*
@@ -124,7 +126,7 @@ mpinit(void)
MACHP(i)->machno = i;
cachedwbinvse(MACHP(i), MACHSIZE);
- u.r0 = 0x84000003;
+ u.r0 = 0x84000003; /* CPU_ON */
u.r1 = (sysrd(MPIDR_EL1) & ~0xFF) | i;
u.r2 = PADDR(_start);
u.r3 = i;
@@ -188,12 +190,13 @@ main(void)
void
exit(int)
{
- Ureg u = { .r0 = 0x84000009 };
+ Ureg u = { .r0 = 0x84000002 }; /* CPU_OFF */
cpushutdown();
splfhi();
- /* system reset */
+ if(m->machno == 0)
+ u.r0 = 0x84000009; /* SYSTEM RESET */
smccall(&u);
}
@@ -214,9 +217,54 @@ writeconf(void)
{
}
+static void
+rebootjump(void *entry, void *code, ulong size)
+{
+ void (*f)(void*, void*, ulong);
+
+ intrcpushutdown();
+
+ /* redo identity map */
+ mmuidmap((uintptr*)L1);
+
+ /* setup reboot trampoline function */
+ f = (void*)REBOOTADDR;
+ memmove(f, rebootcode, sizeof(rebootcode));
+
+ cachedwbinvse(f, sizeof(rebootcode));
+ cacheiinvse(f, sizeof(rebootcode));
+
+ (*f)(entry, code, size);
+
+ for(;;);
+}
+
void
-reboot(void *, void *, ulong)
+reboot(void*, void *code, ulong size)
{
+ writeconf();
+ while(m->machno != 0){
+ procwired(up, 0);
+ sched();
+ }
+
+ cpushutdown();
+ delay(2000);
+
+ splfhi();
+
+ /* turn off buffered serial console */
+ serialoq = nil;
+
+ /* shutdown devices */
+ chandevshutdown();
+
+ /* stop the clock */
+ clockshutdown();
+ intrsoff();
+
+ /* off we go - never to return */
+ rebootjump((void*)(KTZERO-KZERO), code, size);
}
void