Hi,

Please consider this patch. It implements PCI I/O space on Linux by using iopl()
to enable blanket I/O permissions.

It does also fix a small typo while at it ;-)

Regards

-- 
Robert Millan
diff --git a/lib/librumpuser/rumpuser.c b/lib/librumpuser/rumpuser.c
index b78cec3..7c3b2e5 100644
--- a/lib/librumpuser/rumpuser.c
+++ b/lib/librumpuser/rumpuser.c
@@ -48,6 +48,10 @@ __RCSID("$NetBSD: rumpuser.c,v 1.62 2014/07/22 22:41:58 justin Exp $");
 #include <time.h>
 #include <unistd.h>
 
+#ifdef __linux__
+#include <sys/io.h>
+#endif
+
 #include <rump/rumpuser.h>
 
 #include "rumpuser_int.h"
@@ -75,6 +79,24 @@ rumpuser_init(int version, const struct rumpuser_hyperup *hyp)
 }
 
 int
+rumpuser_io_init(void)
+{
+	static int rump_io_inited = 0;
+	if (rump_io_inited)
+		return 0;
+
+#if defined(__linux__)
+	if (iopl(3) == 0) {
+		rump_io_inited = 1;
+		return 0;
+	}
+	return errno;
+#else
+	return ENOSYS;
+#endif
+}
+
+int
 rumpuser_clock_gettime(int enum_rumpclock, int64_t *sec, long *nsec)
 {
 	enum rumpclock rclk = enum_rumpclock;
diff --git a/sys/rump/dev/lib/libpci/pci_at_mainbus.c b/sys/rump/dev/lib/libpci/pci_at_mainbus.c
index 934dfa8..14b2688 100644
--- a/sys/rump/dev/lib/libpci/pci_at_mainbus.c
+++ b/sys/rump/dev/lib/libpci/pci_at_mainbus.c
@@ -61,13 +61,14 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV)
 
 	if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/pci", '0',
 	    cmaj, 0, 4)) != 0)
-		printf("pci: failed to create /dev/pci nodes: %d", error);
+		printf("pci: failed to create /dev/pci nodes: %d\n", error);
 }
 
 RUMP_COMPONENT(RUMP_COMPONENT_DEV_AFTERMAINBUS)
 {
 	struct pcibus_attach_args pba;
 	device_t mainbus;
+	int error;
 
 	/* XXX: attach args should come from elsewhere */
 	memset(&pba, 0, sizeof(pba));
@@ -80,9 +81,12 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV_AFTERMAINBUS)
 #endif
 	pba.pba_flags = PCI_FLAGS_MEM_OKAY |
 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;;
-#if 0
-	pba.pba_flags |= PCI_FLAGS_IO_OKAY;
-#endif
+
+	error = rumpuser_io_init();
+	if (error == 0)
+		pba.pba_flags |= PCI_FLAGS_IO_OKAY;
+	else
+		printf("pci: unable to raise I/O privilege level (error %d)\n", error);
 
 	mainbus = device_find_by_driver_unit("mainbus", 0);
 	if (!mainbus)
diff --git a/sys/rump/dev/lib/libpci/rumpdev_bus_space.c b/sys/rump/dev/lib/libpci/rumpdev_bus_space.c
index 9f61bcb..19635df 100644
--- a/sys/rump/dev/lib/libpci/rumpdev_bus_space.c
+++ b/sys/rump/dev/lib/libpci/rumpdev_bus_space.c
@@ -65,7 +65,8 @@ bus_space_read_1(bus_space_tag_t bst, bus_space_handle_t bsh,
 	uint8_t rv;
 
 	if (bst == 0) {
-		panic("8bit IO space not supported");
+		unsigned short addr = bsh + offset;
+		__asm__ __volatile__("inb %1, %0" : "=a"(rv) : "d"(addr));
 	} else {
 		rv = *(volatile uint8_t *)(bsh + offset);
 	}
@@ -80,7 +81,8 @@ bus_space_read_2(bus_space_tag_t bst, bus_space_handle_t bsh,
 	uint16_t rv;
 
 	if (bst == 0) {
-		panic("16bit IO space not supported");
+		unsigned short addr = bsh + offset;
+		__asm__ __volatile__("inw %1, %0" : "=a"(rv) : "d"(addr));
 	} else {
 		rv = *(volatile uint16_t *)(bsh + offset);
 	}
@@ -95,12 +97,8 @@ bus_space_read_4(bus_space_tag_t bst, bus_space_handle_t bsh,
 	uint32_t rv;
 
 	if (bst == 0) {
-#if 1
-		panic("IO space not supported in this build");
-#else
 		unsigned short addr = bsh + offset;
 		__asm__ __volatile__("inl %1, %0" : "=a"(rv) : "d"(addr)); 
-#endif
 	} else {
 		rv = *(volatile uint32_t *)(bsh + offset);
 	}
@@ -114,9 +112,8 @@ bus_space_write_1(bus_space_tag_t bst, bus_space_handle_t bsh,
 {
 
 	if (bst == 0) {
-#if 1
-		panic("IO space not supported in this build");
-#endif
+		unsigned short addr = bsh + offset;
+		__asm__ __volatile__("outb %0, %1" :: "a"(v), "d"(addr));
 	} else {
 		*(volatile uint8_t *)(bsh + offset) = v;
 	}
@@ -128,9 +125,8 @@ bus_space_write_2(bus_space_tag_t bst, bus_space_handle_t bsh,
 {
 
 	if (bst == 0) {
-#if 1
-		panic("IO space not supported in this build");
-#endif
+		unsigned short addr = bsh + offset;
+		__asm__ __volatile__("outw %0, %1" :: "a"(v), "d"(addr));
 	} else {
 		*(volatile uint16_t *)(bsh + offset) = v;
 	}
@@ -142,12 +138,8 @@ bus_space_write_4(bus_space_tag_t bst, bus_space_handle_t bsh,
 {
 
 	if (bst == 0) {
-#if 1
-		panic("IO space not supported in this build");
-#else
 		unsigned short addr = bsh + offset;
 		__asm__ __volatile__("outl %0, %1" :: "a"(v), "d"(addr));
-#endif
 	} else {
 		*(volatile uint32_t *)(bsh + offset) = v;
 	}
diff --git a/sys/rump/include/rump/rumpuser.h b/sys/rump/include/rump/rumpuser.h
index 6937066..cc67e22 100644
--- a/sys/rump/include/rump/rumpuser.h
+++ b/sys/rump/include/rump/rumpuser.h
@@ -249,4 +249,10 @@ int	rumpuser_sp_anonmmap(void *, size_t, void **);
 int	rumpuser_sp_raise(void *, int);
 void	rumpuser_sp_fini(void *);
 
+/*
+ * enable userspace I/O
+ */
+
+int rumpuser_io_init(void);
+
 #endif /* _RUMP_RUMPUSER_H_ */
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
rumpkernel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rumpkernel-users

Reply via email to