vmm: Add mmio helper functions
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 12 Dec 2017 18:22:00 +0000 (13:22 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 12 Dec 2017 18:23:05 +0000 (13:23 -0500)
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/vmm/include/vmm/mmio.h [new file with mode: 0644]

diff --git a/user/vmm/include/vmm/mmio.h b/user/vmm/include/vmm/mmio.h
new file mode 100644 (file)
index 0000000..677f34a
--- /dev/null
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+static inline uint8_t read_mmreg8(uintptr_t reg)
+{
+       return *((volatile uint8_t*)reg);
+}
+
+static inline uint8_t read_mmreg16(uintptr_t reg)
+{
+       return *((volatile uint16_t*)reg);
+}
+
+static inline uint32_t read_mmreg32(uintptr_t reg)
+{
+       return *((volatile uint32_t*)reg);
+}
+
+static inline uint64_t read_mmreg64(uintptr_t reg)
+{
+       return *((volatile uint64_t*)reg);
+}
+
+static inline void write_mmreg8(uintptr_t reg, uint8_t val)
+{
+       *((volatile uint8_t*)reg) = val;
+}
+
+static inline void write_mmreg16(uintptr_t reg, uint16_t val)
+{
+       *((volatile uint16_t*)reg) = val;
+}
+
+static inline void write_mmreg32(uintptr_t reg, uint32_t val)
+{
+       *((volatile uint32_t*)reg) = val;
+}
+
+static inline void write_mmreg64(uintptr_t reg, uint64_t val)
+{
+       *((volatile uint64_t*)reg) = val;
+}
+
+__END_DECLS