[PATCH 4/4] {net,open}bsd: Implement I/O port API

Adam Jackson ajax at redhat.com
Wed Sep 22 13:10:52 PDT 2010


Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 src/Makefile.am   |    4 +-
 src/bsd_io.c      |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bsd_io.h      |   59 ++++++++++++++++++++++++++
 src/netbsd_pci.c  |   14 ++++++-
 src/openbsd_pci.c |   14 ++++++-
 5 files changed, 205 insertions(+), 4 deletions(-)
 create mode 100644 src/bsd_io.c
 create mode 100644 src/bsd_io.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 0ee8449..373d27a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,11 +34,11 @@ OS_SUPPORT = freebsd_pci.c
 endif
 
 if NETBSD
-OS_SUPPORT = netbsd_pci.c
+OS_SUPPORT = netbsd_pci.c bsd_io.c bsd_io.h
 endif
 
 if OPENBSD
-OS_SUPPORT = openbsd_pci.c
+OS_SUPPORT = openbsd_pci.c bsd_io.c bsd_io.h
 endif
 
 if SOLARIS
diff --git a/src/bsd_io.c b/src/bsd_io.c
new file mode 100644
index 0000000..3f69e71
--- /dev/null
+++ b/src/bsd_io.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "pciaccess.h"
+#include "pciaccess_private.h"
+#include <sys/types.h>
+#include <machine/sysarch>
+
+#if defined(__amd64__) || defined(__i386__)
+
+#if defined(__amd64__)
+
+#if defined(__OpenBSD__)
+#define i386_iopl(x) amd64_iopl(x)
+#endif
+
+#if defined(__NetBSD__)
+#define i386_iopl(x) x64_64_iopl(x)
+#endif
+
+#endif
+
+static int iopl_refcnt;
+
+_pci_hidden struct pci_io_handle *
+pci_device_bsd_open_legacy_io(struct pci_io_handle *ret,
+                              struct pci_device *dev, pciaddr_t base,
+                              pciaddr_t size)
+{
+    if (!iopl_refcnt) {
+        if (i386_iopl(1) < 0)
+            return FALSE;
+    }
+    iopl_refcnt++;
+
+    ret->base = base;
+    ret->size = size;
+
+    return ret;
+}
+
+_pci_hidden struct pci_io_handle *
+pci_device_bsd_open_device_io(struct pci_io_handle *ret,
+                              struct pci_device *dev, int bar,
+                              pciaddr_t base, pciaddr_t size)
+{
+    return pci_device_bsd_open_legacy_io(ret, dev,
+                                         dev->regions[bar].base + base, size);
+
+}
+
+_pci_hidden void
+pci_device_bsd_close_io(struct pci_device *dev,
+                        struct pci_io_handle *handle)
+{
+    if (--iopl_refcnt == 0)
+        i386_iopl(0);
+}
+
+_pci_hidden uint32_t
+pci_device_bsd_read32(struct pci_io_handle *handle, uint32_t port)
+{
+    return inl(port + handle->base);
+}
+
+_pci_hidden uint16_t
+pci_device_bsd_read16(struct pci_io_handle *handle, uint32_t port)
+{
+    return inw(port + handle->base);
+}
+
+_pci_hidden uint8_t
+pci_device_bsd_read8(struct pci_io_handle *handle, uint32_t port)
+{
+    return inb(port + handle->base);
+}
+
+_pci_hidden void
+pci_device_bsd_write32(struct pci_io_handle *handle, uint32_t port,
+                       uint32_t data)
+{
+    outl(data, port + handle->base);
+}
+
+_pci_hidden void
+pci_device_bsd_write16(struct pci_io_handle *handle, uint32_t port,
+                       uint16_t data)
+{
+    outw(data, port + handle->base);
+}
+
+_pci_hidden void
+pci_device_bsd_write8(struct pci_io_handle *handle, uint32_t port,
+                      uint8_t data)
+{
+    outb(data, port + handle->base);
+}
+
+#endif
diff --git a/src/bsd_io.h b/src/bsd_io.h
new file mode 100644
index 0000000..21a9f1a
--- /dev/null
+++ b/src/bsd_io.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "pciaccess.h"
+#include "pciaccess_private.h"
+
+_pci_hidden struct pci_io_handle *
+pci_device_bsd_open_legacy_io(struct pci_io_handle *ret,
+                              struct pci_device *dev, pciaddr_t base,
+                              pciaddr_t size);
+
+_pci_hidden struct pci_io_handle *
+pci_device_bsd_open_device_io(struct pci_io_handle *ret,
+                              struct pci_device *dev, int bar,
+                              pciaddr_t base, pciaddr_t size);
+
+_pci_hidden void
+pci_device_bsd_close_io(struct pci_device *dev,
+                        struct pci_io_handle *handle);
+
+_pci_hidden uint32_t
+pci_device_bsd_read32(struct pci_io_handle *handle, uint32_t port);
+
+_pci_hidden uint16_t
+pci_device_bsd_read16(struct pci_io_handle *handle, uint32_t port);
+
+_pci_hidden uint8_t
+pci_device_bsd_read8(struct pci_io_handle *handle, uint32_t port);
+
+_pci_hidden void
+pci_device_bsd_write32(struct pci_io_handle *handle, uint32_t port,
+                       uint32_t data);
+
+_pci_hidden void
+pci_device_bsd_write16(struct pci_io_handle *handle, uint32_t port,
+                       uint16_t data);
+
+_pci_hidden void
+pci_device_bsd_write8(struct pci_io_handle *handle, uint32_t port,
+                      uint8_t data);
diff --git a/src/netbsd_pci.c b/src/netbsd_pci.c
index f33b3eb..7431826 100644
--- a/src/netbsd_pci.c
+++ b/src/netbsd_pci.c
@@ -37,6 +37,7 @@
 
 #include "pciaccess.h"
 #include "pciaccess_private.h"
+#include "bsd_io.h"
 
 static int pcifd;
 
@@ -318,7 +319,18 @@ static const struct pci_system_methods netbsd_pci_methods = {
 	pci_device_netbsd_unmap_range,
 	pci_device_netbsd_read,
 	pci_device_netbsd_write,
-	pci_fill_capabilities_generic
+	pci_fill_capabilities_generic,
+#if defined(__i386__) || defined(__amd64__)
+        pci_device_x86_open_device_io,
+        pci_device_x86_open_legacy_io,
+        pci_device_x86_close_io,
+        pci_device_x86_read32,
+        pci_device_x86_read16,
+        pci_device_x86_read8,
+        pci_device_x86_write32,
+        pci_device_x86_write16,
+        pci_device_x86_write8,
+#endif
 };
 
 int
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index e954144..4529329 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -32,6 +32,7 @@
 
 #include "pciaccess.h"
 #include "pciaccess_private.h"
+#include "bsd_io.h"
 
 /*
  * This should allow for 16 domains, which should cover everything
@@ -403,7 +404,18 @@ static const struct pci_system_methods openbsd_pci_methods = {
 	pci_device_openbsd_unmap_range,
 	pci_device_openbsd_read,
 	pci_device_openbsd_write,
-	pci_fill_capabilities_generic
+	pci_fill_capabilities_generic,
+#if defined(__i386__) || defined(__amd64__)
+        pci_device_x86_open_device_io,
+        pci_device_x86_open_legacy_io,
+        pci_device_x86_close_io,
+        pci_device_x86_read32,
+        pci_device_x86_read16,
+        pci_device_x86_read8,
+        pci_device_x86_write32,
+        pci_device_x86_write16,
+        pci_device_x86_write8,
+#endif
 };
 
 int
-- 
1.7.2.2



More information about the xorg-devel mailing list