the port access state to generic code.
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.
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;
}
/*
* 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;
}
* 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
#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;
}
#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();
}
/*
unsigned int tmp;
int res = 0;
- if (!intel_setup_io())
+ if (!conf12_setup_io())
{
a->debug("...no I/O permission");
return 0;
static int
conf2_detect(struct pci_access *a)
{
- if (!intel_setup_io())
+ if (!conf12_setup_io())
{
a->debug("...no I/O permission");
return 0;