diff --git a/sys/compat/linuxkpi/common/include/linux/io.h b/sys/compat/linuxkpi/common/include/linux/io.h index b6247f0cd707..aad6b73724ea 100644 --- a/sys/compat/linuxkpi/common/include/linux/io.h +++ b/sys/compat/linuxkpi/common/include/linux/io.h @@ -35,6 +35,8 @@ #include #include +#include + static inline uint32_t __raw_readl(const volatile void *addr) { @@ -62,7 +64,7 @@ __raw_writeq(uint64_t b, volatile void *addr) /* * XXX This is all x86 specific. It should be bus space access. */ -#define mmiowb() +#define mmiowb() barrier() #undef writel static inline void @@ -92,6 +94,27 @@ writew(uint16_t b, void *addr) *(volatile uint16_t *)addr = b; } +#undef ioread8 +static inline uint8_t +ioread8(const volatile void *addr) +{ + return *(const volatile uint8_t *)addr; +} + +#undef ioread16 +static inline uint16_t +ioread16(const volatile void *addr) +{ + return *(const volatile uint16_t *)addr; +} + +#undef ioread32 +static inline uint32_t +ioread32(const volatile void *addr) +{ + return *(const volatile uint32_t *)addr; +} + #undef ioread32be static inline uint32_t ioread32be(const volatile void *addr) @@ -99,6 +122,27 @@ ioread32be(const volatile void *addr) return be32toh(*(const volatile uint32_t *)addr); } +#undef iowrite8 +static inline void +iowrite8(uint8_t v, volatile void *addr) +{ + *(volatile uint8_t *)addr = v; +} + +#undef iowrite16 +static inline void +iowrite16(uint16_t v, volatile void *addr) +{ + *(volatile uint16_t *)addr = v; +} + +#undef iowrite32 +static inline void +iowrite32(uint32_t v, volatile void *addr) +{ + *(volatile uint32_t *)addr = v; +} + #undef iowrite32be static inline void iowrite32be(uint32_t v, volatile void *addr) @@ -137,6 +181,8 @@ void *_ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr); _ioremap_attr((addr), (size), VM_MEMATTR_UNCACHEABLE) #define ioremap_wc(addr, size) \ _ioremap_attr((addr), (size), VM_MEMATTR_WRITE_COMBINING) +#define ioremap_wb(addr, size) \ + _ioremap_attr((addr), (size), VM_MEMATTR_WRITE_BACK) #define ioremap(addr, size) \ _ioremap_attr((addr), (size), VM_MEMATTR_UNCACHEABLE) void iounmap(void *addr); @@ -166,5 +212,35 @@ __iowrite64_copy(void *to, void *from, size_t count) #endif } +enum { + MEMREMAP_WB = 1 << 0, + MEMREMAP_WT = 1 << 1, + MEMREMAP_WC = 1 << 2, +}; + +static inline void * +memremap(resource_size_t offset, size_t size, unsigned long flags) +{ + void *addr = NULL; + + if ((flags & MEMREMAP_WB) && + (addr = ioremap_wb(offset, size)) != NULL) + goto done; + if ((flags & MEMREMAP_WT) && + (addr = ioremap_nocache(offset, size)) != NULL) + goto done; + if ((flags & MEMREMAP_WC) && + (addr = ioremap_wc(offset, size)) != NULL) + goto done; +done: + return (addr); +} + +static inline void +memunmap(void *addr) +{ + /* XXX May need to check if this is RAM */ + iounmap(addr); +} #endif /* _LINUX_IO_H_ */