Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 May 2016 12:04:57 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299364 - head/sys/compat/linuxkpi/common/include/linux
Message-ID:  <201605101204.u4AC4vhR007264@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue May 10 12:04:57 2016
New Revision: 299364
URL: https://svnweb.freebsd.org/changeset/base/299364

Log:
  Add more LinuxKPI I/O functions.
  
  Obtained from:	kmacy @
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/linux/io.h

Modified: head/sys/compat/linuxkpi/common/include/linux/io.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/io.h	Tue May 10 11:39:36 2016	(r299363)
+++ head/sys/compat/linuxkpi/common/include/linux/io.h	Tue May 10 12:04:57 2016	(r299364)
@@ -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 *
 /*
  * 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
     _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, s
 #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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605101204.u4AC4vhR007264>