aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include/linux/io.h
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2016-05-10 12:04:57 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2016-05-10 12:04:57 +0000
commit684a5fef013149f5d8c58ac80d3b601d591dc7cf (patch)
tree7878c914e0016993b3ef3d186a984476531dc587 /sys/compat/linuxkpi/common/include/linux/io.h
parent7652bc32f7cb884604865d6d5a3730ef2dcf0dc3 (diff)
downloadsrc-684a5fef013149f5d8c58ac80d3b601d591dc7cf.tar.gz
src-684a5fef013149f5d8c58ac80d3b601d591dc7cf.zip
Add more LinuxKPI I/O functions.
Obtained from: kmacy @ MFC after: 1 week Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=299364
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/io.h')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/io.h78
1 files changed, 77 insertions, 1 deletions
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 <sys/endian.h>
#include <sys/types.h>
+#include <linux/compiler.h>
+
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_ */