]> mj.ucw.cz Git - pciutils.git/commitdiff
lib/i386-ports.c, lib/i386-io-*: Moved the logic which keeps track of
authorMartin Mares <mj@ucw.cz>
Sun, 30 Jul 2006 11:14:28 +0000 (13:14 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 30 Jul 2006 11:14:28 +0000 (13:14 +0200)
the port access state to generic code.

ChangeLog
lib/i386-io-hurd.h
lib/i386-io-linux.h
lib/i386-io-sunos.h
lib/i386-io-windows.h
lib/i386-ports.c

index 03f7589031b08bac7c1a4b48936b92e90b59f4c5..3cc15755fb324918d5da7677658db9c619a3660c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-07-30  Martin Mares  <mj@ucw.cz>
 
+       * 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.
 
index 6433886664e7b152b91084804686780049d31367..2866b3586825509fd6e5d7810eade5d170970f12 100644 (file)
@@ -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;
 }
index ee119d25094608eb1ecc43be4f4c37951671e2f7..e6974712bd5ed3bf46076d216b5f2d2b82710cf1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     The PCI Library -- Access to i386 I/O ports on Linux
  *
- *     Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2006 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 #include <asm/io.h>
 #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;
 }
index 0d64faf3c84e987cb9f48414c8cb0438b46a951f..753e2ea6076f72d216eee4503ee2adc4d7ac3006 100644 (file)
@@ -2,7 +2,7 @@
  *     The PCI Library -- Access to i386 I/O ports on Solaris
  *
  *     Copyright (c) 2003 Bill Moore <billm@eng.sun.com>
- *     Copyright (c) 2003 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 2003--2006 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 #include <sys/sysi86.h>
 #include <sys/psw.h>
 
-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
index c875a7d1dcb8e29c6d94a6cedcce08f37d3b6c93..f8b896db8c0de8452bd5c56603d6b49c81a3c71c 100644 (file)
 #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;
 }
index 23feaf355b84f64831e517377d5fceb270616953..d491ad68320677c99f48dd42c1e73caafe072e4e 100644 (file)
 #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;