diff options
author | emilia <emilia@vegaa.systems> | 2023-08-27 22:29:25 +0000 |
---|---|---|
committer | emilia <emilia@vegaa.systems> | 2023-08-27 22:29:25 +0000 |
commit | adad27da61ca0b875d48f4e06bd36c36bb01d415 (patch) | |
tree | c7e5b277fc321e4ce6c2a003ed231a4d399d9aba | |
parent | 15d4bef9c8b47bde58b822fc9a3b41b77dd7348c (diff) |
kernel: mmio: Add MMIO read helpers
git-svn-id: https://svn.vegaa.systems/svn/vega-Vega/trunk@42 a8a8aea2-181d-ee11-89e8-15fd0e089fc4
-rw-r--r-- | sys/include/sys/mmio.h | 30 |
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_ */ |