aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
authorWesley W. Terpstra <wesley@sifive.com>2018-03-05 14:59:44 -0800
committerGitHub <noreply@github.com>2018-03-05 14:59:44 -0800
commit2bbd8e1a1bccae13ec87882baf423abfc6ef76fd (patch)
tree95453fbde3440dc2dbc67ba55fc0a9da7fd2555b /machine
parente5846a2bc707eaa58dc8ab6a8d20a090c6ee8570 (diff)
downloadpk-2bbd8e1a1bccae13ec87882baf423abfc6ef76fd.zip
pk-2bbd8e1a1bccae13ec87882baf423abfc6ef76fd.tar.gz
pk-2bbd8e1a1bccae13ec87882baf423abfc6ef76fd.tar.bz2
mtrap: add a halt IPI used for poweroff (#86)
Otherwise, linux complains the moment an interrupt arrives and wakes up one of the not-looping cores.
Diffstat (limited to 'machine')
-rw-r--r--machine/mentry.S5
-rw-r--r--machine/mtrap.c23
-rw-r--r--machine/mtrap.h1
3 files changed, 18 insertions, 11 deletions
diff --git a/machine/mentry.S b/machine/mentry.S
index 41d7017..3dcf2b6 100644
--- a/machine/mentry.S
+++ b/machine/mentry.S
@@ -91,6 +91,11 @@ trap_vector:
beqz a1, 1f
sfence.vma
1:
+ andi a1, a0, IPI_HALT
+ beqz a1, 1f
+ wfi
+ j 1b
+1:
j .Lmret
diff --git a/machine/mtrap.c b/machine/mtrap.c
index 778990f..b8dcc68 100644
--- a/machine/mtrap.c
+++ b/machine/mtrap.c
@@ -31,17 +31,6 @@ static uintptr_t mcall_console_putchar(uint8_t ch)
return 0;
}
-void poweroff(uint16_t code)
-{
- printm("Power off\n");
- finisher_exit(code);
- if (htif) {
- htif_poweroff();
- } else {
- while (1) { asm volatile ("#noop\n"); }
- }
-}
-
void putstring(const char* s)
{
while (*s)
@@ -229,3 +218,15 @@ void trap_from_machine_mode(uintptr_t* regs, uintptr_t dummy, uintptr_t mepc)
bad_trap(regs, dummy, mepc);
}
}
+
+void poweroff(uint16_t code)
+{
+ printm("Power off\r\n");
+ finisher_exit(code);
+ if (htif) {
+ htif_poweroff();
+ } else {
+ send_ipi_many(0, IPI_HALT);
+ while (1) { asm volatile ("wfi\n"); }
+ }
+}
diff --git a/machine/mtrap.h b/machine/mtrap.h
index eafdb14..c4d43d0 100644
--- a/machine/mtrap.h
+++ b/machine/mtrap.h
@@ -78,6 +78,7 @@ static inline void wfi()
#define IPI_SOFT 0x1
#define IPI_FENCE_I 0x2
#define IPI_SFENCE_VMA 0x4
+#define IPI_HALT 0x8
#define MACHINE_STACK_SIZE RISCV_PGSIZE
#define MENTRY_HLS_OFFSET (INTEGER_CONTEXT_SIZE + SOFT_FLOAT_CONTEXT_SIZE)