diff options
Diffstat (limited to 'core/include/drivers/serial.h')
-rw-r--r-- | core/include/drivers/serial.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/include/drivers/serial.h b/core/include/drivers/serial.h index b8f00df..c1e9ebe 100644 --- a/core/include/drivers/serial.h +++ b/core/include/drivers/serial.h @@ -27,6 +27,12 @@ #ifndef __DRIVERS_SERIAL_H #define __DRIVERS_SERIAL_H +#include <assert.h> +#include <stdbool.h> +#include <types_ext.h> +#include <mm/core_memprot.h> +#include <mm/core_mmu.h> + struct serial_chip { const struct serial_ops *ops; }; @@ -38,4 +44,25 @@ struct serial_ops { int (*getchar)(struct serial_chip *chip); }; +struct io_pa_va { + paddr_t pa; + vaddr_t va; +}; + +/* + * Helper function to return a physical or virtual address for a device, + * depending on whether the MMU is enabled or not + */ +static inline vaddr_t io_pa_or_va(struct io_pa_va *p) +{ + assert(p->pa); + if (cpu_mmu_enabled()) { + if (!p->va) + p->va = (vaddr_t)phys_to_virt_io(p->pa); + assert(p->va); + return p->va; + } + return p->pa; +} + #endif /*__DRIVERS_SERIASERIAL_H*/ |