]> mj.ucw.cz Git - pciutils.git/blob - lib/i386-io-windows.h
Polishing the Windows port.
[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  *
6  *      Can be freely distributed and used under the terms of the GNU GPL.
7  */
8
9 #include <io.h>
10 #include <conio.h>
11 #include <windows.h>
12
13 #define outb(x,y) _outp(y,x)
14 #define outw(x,y) _outpw(y,x)
15 #define outl(x,y) _outpd(y,x)
16
17 #define inb(x) _inp(x)
18 #define inw(x) _inpw(x)
19 #define inl(x) _inpd(x)
20
21 static int intel_iopl_set = -1;
22
23 static int
24 intel_setup_io(void)
25 {
26   if (intel_iopl_set < 0)
27     {
28       typedef int (*MYPROC)(void);
29       MYPROC InitializeWinIo;
30       HMODULE lib;
31
32       intel_iopl_set = 0;
33
34       lib = LoadLibrary("WinIo.dll");
35       if (!lib)
36         {
37           fprintf(stderr, "libpci: Couldn't load WinIo.dll.\n");
38           return 0;
39         }
40       /* XXX: Is this really needed? --mj */
41       GetProcAddress(lib, "InitializeWinIo");
42
43       InitializeWinIo = (MYPROC) GetProcAddress(lib, "InitializeWinIo");
44       if (!InitializeWinIo)
45         {
46           fprintf(stderr, "libpci: Couldn't find InitializeWinIo function.\n");
47           return 0;
48         }
49
50       if (!InitializeWinIo())
51         {
52           fprintf(stderr, "libpci: InitializeWinIo() failed.\n");
53           return 0;
54         }
55
56       intel_iopl_set = 1;
57     }
58   return intel_iopl_set;
59 }
60
61 static inline void
62 intel_cleanup_io(void)
63 {
64   //TODO: DeInitializeWinIo!
65   //intel_iopl_set = -1;
66 }