From: Martin Mares Date: Sun, 30 Jul 2006 11:14:28 +0000 (+0200) Subject: lib/i386-ports.c, lib/i386-io-*: Moved the logic which keeps track of X-Git-Tag: v3.0.0~47 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9007a292f24685d7c1ab51506fae8df22ced007f;p=pciutils.git lib/i386-ports.c, lib/i386-io-*: Moved the logic which keeps track of the port access state to generic code. --- diff --git a/ChangeLog b/ChangeLog index 03f7589..3cc1575 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-07-30 Martin Mares + * lib/i386-ports.c, lib/i386-io-*: Moved the logic which keeps track of + the port access state to generic code. + * lib/i386-io-hurd.h: Ask the kernel for I/O port access appropriately. Contributed by Thomas Schwinge and Samuel Thibault. diff --git a/lib/i386-io-hurd.h b/lib/i386-io-hurd.h index 6433886..2866b35 100644 --- a/lib/i386-io-hurd.h +++ b/lib/i386-io-hurd.h @@ -38,11 +38,13 @@ intel_setup_io(void) return errno ? 0 : 1; } -static inline void +static inline int 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); + + return -1; } diff --git a/lib/i386-io-linux.h b/lib/i386-io-linux.h index ee119d2..e697471 100644 --- a/lib/i386-io-linux.h +++ b/lib/i386-io-linux.h @@ -1,7 +1,7 @@ /* * The PCI Library -- Access to i386 I/O ports on Linux * - * Copyright (c) 1997--2003 Martin Mares + * Copyright (c) 1997--2006 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -12,20 +12,15 @@ #include #endif -static int intel_iopl_set = -1; - static int intel_setup_io(void) { - if (intel_iopl_set < 0) - intel_iopl_set = (iopl(3) < 0) ? 0 : 1; - return intel_iopl_set; + return (iopl(3) < 0) ? 0 : 1; } -static inline void +static inline int intel_cleanup_io(void) { - if (intel_iopl_set > 0) - iopl(3); - intel_iopl_set = -1; + iopl(3); + return -1; } diff --git a/lib/i386-io-sunos.h b/lib/i386-io-sunos.h index 0d64faf..753e2ea 100644 --- a/lib/i386-io-sunos.h +++ b/lib/i386-io-sunos.h @@ -2,7 +2,7 @@ * The PCI Library -- Access to i386 I/O ports on Solaris * * Copyright (c) 2003 Bill Moore - * Copyright (c) 2003 Martin Mares + * Copyright (c) 2003--2006 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -10,29 +10,17 @@ #include #include -static int intel_iopl_set = -1; - static int intel_setup_io(void) { - if (intel_iopl_set < 0) - { - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) - intel_iopl_set = 0; - else - intel_iopl_set = 1; - } - return intel_iopl_set; + return (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) ? 0 : 1; } -static inline void +static inline int intel_cleanup_io(void) { - if (intel_iopl_set > 0) - { - /* FIXME: How to switch off I/O port access? */ - } - intel_iopl_set = -1; + /* FIXME: How to switch off I/O port access? */ + return 1; } static inline u8 diff --git a/lib/i386-io-windows.h b/lib/i386-io-windows.h index c875a7d..f8b896d 100644 --- a/lib/i386-io-windows.h +++ b/lib/i386-io-windows.h @@ -18,49 +18,43 @@ #define inw(x) _inpw(x) #define inl(x) _inpd(x) -static int intel_iopl_set = -1; - static int intel_setup_io(void) { - if (intel_iopl_set < 0) - { - typedef int (*MYPROC)(void); - MYPROC InitializeWinIo; - HMODULE lib; - - intel_iopl_set = 0; + typedef int (*MYPROC)(void); + MYPROC InitializeWinIo; + HMODULE lib; - lib = LoadLibrary("WinIo.dll"); - if (!lib) - { - fprintf(stderr, "libpci: Couldn't load WinIo.dll.\n"); - return 0; - } - /* XXX: Is this really needed? --mj */ - GetProcAddress(lib, "InitializeWinIo"); + intel_iopl_set = 0; - InitializeWinIo = (MYPROC) GetProcAddress(lib, "InitializeWinIo"); - if (!InitializeWinIo) - { - fprintf(stderr, "libpci: Couldn't find InitializeWinIo function.\n"); - return 0; - } + lib = LoadLibrary("WinIo.dll"); + if (!lib) + { + fprintf(stderr, "libpci: Couldn't load WinIo.dll.\n"); + return 0; + } + /* XXX: Is this really needed? --mj */ + GetProcAddress(lib, "InitializeWinIo"); - if (!InitializeWinIo()) - { - fprintf(stderr, "libpci: InitializeWinIo() failed.\n"); - return 0; - } + InitializeWinIo = (MYPROC) GetProcAddress(lib, "InitializeWinIo"); + if (!InitializeWinIo) + { + fprintf(stderr, "libpci: Couldn't find InitializeWinIo function.\n"); + return 0; + } - intel_iopl_set = 1; + if (!InitializeWinIo()) + { + fprintf(stderr, "libpci: InitializeWinIo() failed.\n"); + return 0; } - return intel_iopl_set; + + return 1; } -static inline void +static inline int intel_cleanup_io(void) { //TODO: DeInitializeWinIo! - //intel_iopl_set = -1; + return 1; } diff --git a/lib/i386-ports.c b/lib/i386-ports.c index 23feaf3..d491ad6 100644 --- a/lib/i386-ports.c +++ b/lib/i386-ports.c @@ -24,17 +24,28 @@ #error Do not know how to access I/O ports on this OS. #endif +static int conf12_io_enabled = -1; /* -1=haven't tried, 0=failed, 1=succeeded */ + +static int +conf12_setup_io(void) +{ + if (conf12_io_enabled < 0) + conf12_io_enabled = intel_setup_io(); + return conf12_io_enabled; +} + static void conf12_init(struct pci_access *a) { - if (!intel_setup_io()) - a->error("You need to be root to have access to I/O ports."); + if (!conf12_setup_io()) + a->error("No permission to access I/O ports (you probably have to be root)."); } static void conf12_cleanup(struct pci_access *a UNUSED) { - intel_cleanup_io(); + if (conf12_io_enabled > 0) + conf12_io_enabled = intel_cleanup_io(); } /* @@ -84,7 +95,7 @@ conf1_detect(struct pci_access *a) unsigned int tmp; int res = 0; - if (!intel_setup_io()) + if (!conf12_setup_io()) { a->debug("...no I/O permission"); return 0; @@ -161,7 +172,7 @@ conf1_write(struct pci_dev *d, int pos, byte *buf, int len) static int conf2_detect(struct pci_access *a) { - if (!intel_setup_io()) + if (!conf12_setup_io()) { a->debug("...no I/O permission"); return 0;