From bd20d5b5a916e050d280bb4a67e77252d2034445 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 30 Jul 2006 13:06:09 +0200 Subject: [PATCH] lib/i386-io-hurd.h: Ask the kernel for I/O port access appropriately. --- ChangeLog | 3 +++ lib/i386-io-hurd.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4cf2916..03f7589 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-07-30 Martin Mares + * 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. diff --git a/lib/i386-io-hurd.h b/lib/i386-io-hurd.h index 82ef775..6433886 100644 --- a/lib/i386-io-hurd.h +++ b/lib/i386-io-hurd.h @@ -3,19 +3,46 @@ * * Copyright (c) 2003 Marco Gerards * Copyright (c) 2003 Martin Mares + * Copyright (c) 2006 Samuel Thibault and + * Thomas Schwinge * * Can be freely distributed and used under the terms of the GNU GPL. */ #include +#include +#include +#include + +#include + +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); } -- 2.39.2