aboutsummaryrefslogtreecommitdiff
path: root/pk/frontend.c
diff options
context:
space:
mode:
Diffstat (limited to 'pk/frontend.c')
-rw-r--r--pk/frontend.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/pk/frontend.c b/pk/frontend.c
index 3771bca..0929d54 100644
--- a/pk/frontend.c
+++ b/pk/frontend.c
@@ -3,14 +3,30 @@
#include "pk.h"
#include "atomic.h"
#include "frontend.h"
+#include "sbi.h"
+#include "mcall.h"
#include <stdint.h>
+uint64_t tohost_sync(unsigned dev, unsigned cmd, uint64_t payload)
+{
+ uint64_t fromhost;
+ __sync_synchronize();
+
+ sbi_device_message m = {dev, cmd, payload}, *p;
+ do_mcall(MCALL_SEND_DEVICE_REQUEST, &m);
+ while ((p = (void*)do_mcall(MCALL_RECEIVE_DEVICE_RESPONSE)) == 0);
+ kassert(p == &m);
+
+ __sync_synchronize();
+ return m.data;
+}
+
long frontend_syscall(long n, long a0, long a1, long a2, long a3, long a4, long a5, long a6)
{
static volatile uint64_t magic_mem[8];
static spinlock_t lock = SPINLOCK_INIT;
- long irq = spinlock_lock_irqsave(&lock);
+ spinlock_lock(&lock);
magic_mem[0] = n;
magic_mem[1] = a0;
@@ -21,15 +37,10 @@ long frontend_syscall(long n, long a0, long a1, long a2, long a3, long a4, long
magic_mem[6] = a5;
magic_mem[7] = a6;
- mb();
-
- write_csr(tohost, magic_mem);
- while (swap_csr(fromhost, 0) == 0);
-
- mb();
+ tohost_sync(0, 0, (uintptr_t)magic_mem);
long ret = magic_mem[0];
- spinlock_unlock_irqrestore(&lock, irq);
+ spinlock_unlock(&lock);
return ret;
}