aboutsummaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authoremilia <emilia@vegaa.systems>2023-08-27 22:29:25 +0000
committeremilia <emilia@vegaa.systems>2023-08-27 22:29:25 +0000
commitadad27da61ca0b875d48f4e06bd36c36bb01d415 (patch)
treec7e5b277fc321e4ce6c2a003ed231a4d399d9aba /sys/include
parent15d4bef9c8b47bde58b822fc9a3b41b77dd7348c (diff)
kernel: mmio: Add MMIO read helpers
git-svn-id: https://svn.vegaa.systems/svn/vega-Vega/trunk@42 a8a8aea2-181d-ee11-89e8-15fd0e089fc4
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/sys/mmio.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h
index 8e3db52..334b31c 100644
--- a/sys/include/sys/mmio.h
+++ b/sys/include/sys/mmio.h
@@ -62,6 +62,24 @@
}
/*
+ * mmio_read<n> - Does the same as mmio_write<n> but for reading
+ *
+ * @addr: Address to read from.
+ */
+#define _MMIO_READ_TYPE(TYPE, SUFFIX) \
+ static inline TYPE \
+ mmio_read##SUFFIX(void *addr, TYPE val) \
+ { \
+ uintptr_t tmp; \
+ \
+ tmp = (uintptr_t)addr; \
+ if (tmp < VM_HIGHER_HALF) { \
+ tmp += VM_HIGHER_HALF; \
+ } \
+ return *(volatile TYPE *)tmp; \
+ }
+
+/*
* To write to an MMIO address of, for example,
* 8 bits, use mmio_write8(addr, val)
*/
@@ -73,4 +91,16 @@ _MMIO_WRITE_TYPE(uint64_t, 64)
#endif
__extension__
+/*
+ * To read from an MMIO address of, for example,
+ * 8 bits, use mmio_read8(addr)
+ */
+_MMIO_READ_TYPE(uint8_t, 8)
+_MMIO_READ_TYPE(uint16_t, 16)
+_MMIO_READ_TYPE(uint32_t, 32)
+#if __SIZEOF_SIZE_T__ == 8
+_MMIO_READ_TYPE(uint64_t, 64)
+#endif
+__extension__
+
#endif /* !_SYS_MMIO_H_ */