From 846f7bffcaa69f72bcbee43f95c4ba144a27c166 Mon Sep 17 00:00:00 2001 From: emilia Date: Sun, 27 Aug 2023 22:10:32 +0000 Subject: kernel: mmio: Check for physical addresses This commit adds extra documentation to mmio_write() as well as adding checks for physical addresses and handling them properly. git-svn-id: https://svn.vegaa.systems/svn/vega-Vega/trunk@38 a8a8aea2-181d-ee11-89e8-15fd0e089fc4 --- sys/include/sys/mmio.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'sys') diff --git a/sys/include/sys/mmio.h b/sys/include/sys/mmio.h index ea0439f..65e423c 100644 --- a/sys/include/sys/mmio.h +++ b/sys/include/sys/mmio.h @@ -33,11 +33,28 @@ #define _SYS_MMIO_H_ #include +#include +/* + * mmio_write - Writes to MMIO address with specific size + * + * @addr: Address to write to. + * @val: Value to write. + * + * These functions will add the higher half + * offset (VM_HIGHER_HALF) if the MMIO address + * is less than VM_HIGHER_HALF as it'll be safe + * to assume it's a physical address. Page faults + * from writes could be due to the resulting virtual + * address not being mapped. + */ #define _MMIO_WRITE_TYPE(TYPE, SUFFIX) \ static inline void \ mmio_write##SUFFIX(uintptr_t addr, TYPE val) \ { \ + if (addr < VM_HIGHER_HALF) { \ + addr += VM_HIGHER_HALF; \ + } \ *(volatile TYPE *)addr = val; \ } -- cgit v1.2.3