]> mj.ucw.cz Git - pciutils.git/blob - lib/i386-io-hurd.h
lib/i386-io-hurd.h: Ask the kernel for I/O port access appropriately.
[pciutils.git] / lib / i386-io-hurd.h
1 /*
2  *      The PCI Library -- Access to i386 I/O ports on GNU Hurd
3  *
4  *      Copyright (c) 2003 Marco Gerards <metgerards@student.han.nl>
5  *      Copyright (c) 2003 Martin Mares <mj@ucw.cz>
6  *      Copyright (c) 2006 Samuel Thibault <samuel.thibault@ens-lyon.org> and
7  *                         Thomas Schwinge <tschwinge@gnu.org>
8  *
9  *      Can be freely distributed and used under the terms of the GNU GPL.
10  */
11
12 #include <sys/io.h>
13
14 #include <mach/machine/mach_i386.h>
15 #include <device/device.h>
16 #include <hurd.h>
17
18 #include <stdio.h>
19
20 static mach_port_t io_port;
21
22 static inline int
23 intel_setup_io(void)
24 {
25   mach_port_t device;
26
27   if ((errno = get_privileged_ports(NULL, &device)))
28     perror("intel_setup_io() can't get_privileged_ports()");
29
30   if (!errno && (errno = device_open(device, D_READ | D_WRITE, "io", &io_port)))
31     perror("intel_setup_io() can't device_open()");
32
33   mach_port_deallocate(mach_task_self(), device);
34
35   if (!errno && (errno = i386_io_port_add(mach_thread_self(), io_port)))
36     perror("intel_setup_io() can't i386_io_port_add()");
37
38   return errno ? 0 : 1;
39 }
40
41 static inline void
42 intel_cleanup_io(void)
43 {
44   if ((errno = i386_io_port_remove(mach_thread_self(), io_port)))
45     perror("intel_cleanup_io() can't i386_io_port_remove()");
46
47   mach_port_deallocate(mach_task_self(), io_port);
48 }