]> mj.ucw.cz Git - pciutils.git/blob - lib/i386-io-windows.h
libpci: i386-io-windows.h: Skip I/O setup on 16/32-bit non-NT systems
[pciutils.git] / lib / i386-io-windows.h
1 /*
2  *      The PCI Library -- Access to i386 I/O ports on Windows
3  *
4  *      Copyright (c) 2004 Alexander Stock <stock.alexander@gmx.de>
5  *      Copyright (c) 2006 Martin Mares <mj@ucw.cz>
6  *
7  *      Can be freely distributed and used under the terms of the GNU GPL.
8  */
9
10 #include <io.h>
11 #include <windows.h>
12
13 #ifndef __GNUC__
14 #include <conio.h>
15 #else
16 int _outp(unsigned short port, int databyte);
17 unsigned short _outpw(unsigned short port, unsigned short dataword);
18 unsigned long _outpd(unsigned short port, unsigned long dataword);
19 int _inp(unsigned short port);
20 unsigned short _inpw(unsigned short port);
21 unsigned long _inpd(unsigned short port);
22 #endif
23
24 #define outb(x,y) _outp(y,x)
25 #define outw(x,y) _outpw(y,x)
26 #define outl(x,y) _outpd(y,x)
27
28 #define inb(x) _inp(x)
29 #define inw(x) _inpw(x)
30 #define inl(x) _inpd(x)
31
32 static int
33 intel_setup_io(struct pci_access *a)
34 {
35   typedef int (*MYPROC)(void);
36   MYPROC InitializeWinIo;
37   HMODULE lib;
38
39 #ifndef _WIN64
40   /* 16/32-bit non-NT systems allow applications to access PCI I/O ports without any special setup. */
41   OSVERSIONINFOA version;
42   version.dwOSVersionInfoSize = sizeof(version);
43   if (GetVersionExA(&version) && version.dwPlatformId < VER_PLATFORM_WIN32_NT)
44     {
45       a->debug("Detected 16/32-bit non-NT system, skipping NT setup...");
46       return 1;
47     }
48 #endif
49
50   lib = LoadLibrary("WinIo.dll");
51   if (!lib)
52     {
53       a->warning("i386-io-windows: Couldn't load WinIo.dll.");
54       return 0;
55     }
56   /* XXX: Is this really needed? --mj */
57   GetProcAddress(lib, "InitializeWinIo");
58
59   InitializeWinIo = (MYPROC) GetProcAddress(lib, "InitializeWinIo");
60   if (!InitializeWinIo)
61     {
62       a->warning("i386-io-windows: Couldn't find InitializeWinIo function.");
63       return 0;
64     }
65
66   if (!InitializeWinIo())
67     {
68       a->warning("i386-io-windows: InitializeWinIo() failed.");
69       return 0;
70     }
71
72   return 1;
73 }
74
75 static inline int
76 intel_cleanup_io(struct pci_access *a UNUSED)
77 {
78   //TODO: DeInitializeWinIo!
79   return 1;
80 }
81
82 static inline void intel_io_lock(void)
83 {
84 }
85
86 static inline void intel_io_unlock(void)
87 {
88 }