]> mj.ucw.cz Git - pciutils.git/commitdiff
lib/i386-io-hurd.h: Ask the kernel for I/O port access appropriately.
authorMartin Mares <mj@ucw.cz>
Sun, 30 Jul 2006 11:06:09 +0000 (13:06 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 30 Jul 2006 11:06:09 +0000 (13:06 +0200)
ChangeLog
lib/i386-io-hurd.h

index 4cf2916f6f49a0b0082ee1cf9ef6bfb8f1826f39..03f7589031b08bac7c1a4b48936b92e90b59f4c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-07-30  Martin Mares  <mj@ucw.cz>
 
+       * lib/i386-io-hurd.h: Ask the kernel for I/O port access appropriately.
+       Contributed by Thomas Schwinge and Samuel Thibault.
+
        * lib/i386-ports.c: Define _GNU_SOURCE, it's needed by the Hurd module.
 
        * lib/header.h: Whitespace cleanups.
index 82ef775ae5f103489318997562acbd99be8a2d69..6433886664e7b152b91084804686780049d31367 100644 (file)
@@ -3,19 +3,46 @@
  *
  *     Copyright (c) 2003 Marco Gerards <metgerards@student.han.nl>
  *     Copyright (c) 2003 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 2006 Samuel Thibault <samuel.thibault@ens-lyon.org> and
+ *                        Thomas Schwinge <tschwinge@gnu.org>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 
 #include <sys/io.h>
 
+#include <mach/machine/mach_i386.h>
+#include <device/device.h>
+#include <hurd.h>
+
+#include <stdio.h>
+
+static mach_port_t io_port;
+
 static inline int
 intel_setup_io(void)
 {
-  return 1;
+  mach_port_t device;
+
+  if ((errno = get_privileged_ports(NULL, &device)))
+    perror("intel_setup_io() can't get_privileged_ports()");
+
+  if (!errno && (errno = device_open(device, D_READ | D_WRITE, "io", &io_port)))
+    perror("intel_setup_io() can't device_open()");
+
+  mach_port_deallocate(mach_task_self(), device);
+
+  if (!errno && (errno = i386_io_port_add(mach_thread_self(), io_port)))
+    perror("intel_setup_io() can't i386_io_port_add()");
+
+  return errno ? 0 : 1;
 }
 
-static inline int
+static inline void
 intel_cleanup_io(void)
 {
+  if ((errno = i386_io_port_remove(mach_thread_self(), io_port)))
+    perror("intel_cleanup_io() can't i386_io_port_remove()");
+
+  mach_port_deallocate(mach_task_self(), io_port);
 }