Back to index

glibc  2.9
ioperm.c
Go to the documentation of this file.
00001 /* Access to hardware i/o ports.  Hurd/x86 version.
00002    Copyright (C) 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sys/io.h>
00021 #include <hurd.h>
00022 #include <mach/i386/mach_i386.h>
00023 
00024 int
00025 ioperm (unsigned long int from, unsigned long int num, int turn_on)
00026 {
00027 #if ! HAVE_I386_IO_PERM_MODIFY
00028   return __hurd_fail (ENOSYS);
00029 #else
00030   error_t err;
00031   device_t devmaster;
00032 
00033   /* With the device master port we get a capability that represents
00034      this range of io ports.  */
00035   err = __get_privileged_ports (NULL, &devmaster);
00036   if (! err)
00037     {
00038       io_perm_t perm;
00039       err = __i386_io_perm_create (devmaster, from, from + num - 1, &perm);
00040       __mach_port_deallocate (__mach_task_self (), devmaster);
00041       if (! err)
00042        {
00043          /* Now we add or remove that set from our task's bitmap.  */
00044          err = __i386_io_perm_modify (__mach_task_self (), perm, turn_on);
00045          __mach_port_deallocate (__mach_task_self (), perm);
00046        }
00047 
00048       if (err == MIG_BAD_ID)       /* Old kernels don't have these RPCs.  */
00049        err = ENOSYS;
00050     }
00051 
00052   return err ? __hurd_fail (err) : 0;
00053 #endif
00054 }