summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu.herrb@laas.fr>2011-12-30 16:54:54 +0100
committerMatthieu Herrb <matthieu.herrb@laas.fr>2011-12-30 16:54:54 +0100
commitb3ebe6957684dc8f5a1f54b2cd2f71afb9f803cc (patch)
treec1de5586effb261e8b916de60709514047e6ee36
parentaff5e83f4eae7e008267fb53d10448e1e8c9b1f2 (diff)
open_legacy_io: version compatible with privsep.kettenis
enables io early in pci_system_openbsd_create() which is called with full privileges before revocation.
-rw-r--r--src/openbsd_pci.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index 5656fff..9babcd2 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -23,6 +23,11 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
+#if defined(__i386__) || defined(__amd64__)
+#include <machine/sysarch.h>
+#include <machine/pio.h>
+#endif
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -296,6 +301,20 @@ pci_system_openbsd_destroy(void)
for (domain = 0; domain < ndomains; domain++)
close(pcifd[domain]);
ndomains = 0;
+
+#ifdef __i386__
+ struct i386_iopl_args ia;
+
+ ia.iopl = 0;
+ sysarch(I386_IOPL, &ia);
+#endif
+#ifdef __amd64__
+ struct amd64_iopl_args ia;
+
+ ia.iopl = 0;
+ sysarch(AMD64_IOPL, &ia);
+#endif
+
}
static int
@@ -394,49 +413,20 @@ pci_device_openbsd_probe(struct pci_device *device)
return 0;
}
-#if defined(__i386__) || defined(__amd64__)
-#include <machine/sysarch.h>
-#include <machine/pio.h>
-#endif
-
static struct pci_io_handle *
pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
struct pci_device *dev, pciaddr_t base, pciaddr_t size)
{
-#ifdef __i386__
- struct i386_iopl_args ia;
-
- ia.iopl = 1;
- if (sysarch(I386_IOPL, &ia))
- return NULL;
-
- ret->base = base;
- ret->size = size;
- return ret;
-#endif
-#ifdef __amd64__
- struct amd64_iopl_args ia;
-
- ia.iopl = 1;
- if (sysarch(AMD64_IOPL, &ia))
- return NULL;
-
- ret->base = base;
- ret->size = size;
- return ret;
-#endif
#ifdef PCI_MAGIC_IO_RANGE
ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
aperturefd, PCI_MAGIC_IO_RANGE + base);
if (ret->memory == MAP_FAILED)
return NULL;
+#endif
ret->base = base;
ret->size = size;
return ret;
-#endif
-
- return NULL;
}
static uint32_t
@@ -665,6 +655,21 @@ pci_system_openbsd_create(void)
}
}
}
+#ifdef __i386__
+ struct i386_iopl_args ia;
+
+ ia.iopl = 1;
+ if (sysarch(I386_IOPL, &ia))
+ return NULL;
+#endif
+#ifdef __amd64__
+ struct amd64_iopl_args ia;
+
+ ia.iopl = 1;
+ if (sysarch(AMD64_IOPL, &ia))
+ return NULL;
+
+#endif
return 0;
}