1 | /*
|
---|
2 | ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
|
---|
3 | ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
|
---|
4 | ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
|
---|
5 | ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
|
---|
6 | ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
|
---|
7 | ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
---|
8 | ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
|
---|
9 | ** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
|
---|
10 | **
|
---|
11 | ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
|
---|
12 | ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
|
---|
13 | ** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
|
---|
14 | ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
|
---|
15 | ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
|
---|
16 | ** THE UNITED STATES.
|
---|
17 | **
|
---|
18 | ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
|
---|
19 | */
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <stdio.h>
|
---|
22 |
|
---|
23 | #define WIN32_LEANER_AND_MEANER
|
---|
24 | #include <windows.h>
|
---|
25 | #include <conio.h>
|
---|
26 |
|
---|
27 | #include <3dfx.h>
|
---|
28 | #define FX_DLL_DEFINITION
|
---|
29 | #include <fxdll.h>
|
---|
30 | #include <fxmemmap.h>
|
---|
31 | #include "fxpci.h"
|
---|
32 | #include "pcilib.h"
|
---|
33 | #include "fxw32.h"
|
---|
34 |
|
---|
35 | /* Callback declarations */
|
---|
36 | static FxBool pciInitialize9x(void);
|
---|
37 | static FxBool pciShutdown9x(void);
|
---|
38 | static const char* pciIdentifier9x(void);
|
---|
39 |
|
---|
40 | static FxU8 pciPortInByte9x(FxU16 port);
|
---|
41 | static FxU16 pciPortInWord9x(FxU16 port);
|
---|
42 | static FxU32 pciPortInLong9x(FxU16 port);
|
---|
43 |
|
---|
44 | static FxBool pciPortOutByte9x(FxU16 port, FxU8 data);
|
---|
45 | static FxBool pciPortOutWord9x(FxU16 port, FxU16 data);
|
---|
46 | static FxBool pciPortOutLong9x(FxU16 port, FxU32 data);
|
---|
47 |
|
---|
48 | static FxBool pciMapLinear9x(FxU32 busNumber, FxU32 physAddr,
|
---|
49 | FxU32* linearAddr, FxU32* length);
|
---|
50 | static FxBool pciUnmapLinear9x(FxU32 linearAddr, FxU32 length);
|
---|
51 |
|
---|
52 | static FxBool pciSetPermission9x(const FxU32 addrBase, const FxU32 addrLen,
|
---|
53 | const FxBool writePermP);
|
---|
54 |
|
---|
55 | static FxBool pciMsrGet9x(MSRInfo* in, MSRInfo* out);
|
---|
56 | static FxBool pciMsrSet9x(MSRInfo* in, MSRInfo* out);
|
---|
57 |
|
---|
58 | static FxBool pciOutputString9x(const char* msg);
|
---|
59 | static FxBool pciSetPassThroughBase9x(FxU32* baseAddr, FxU32 baseAddrLen);
|
---|
60 |
|
---|
61 | static char pciIdent[] = "@#% fxPCI for Windows 9x";
|
---|
62 |
|
---|
63 | static const FxPlatformIOProcs __ioProcs9x = {
|
---|
64 | pciInitialize9x,
|
---|
65 | pciShutdown9x,
|
---|
66 | pciIdentifier9x,
|
---|
67 |
|
---|
68 | pciPortInByte9x,
|
---|
69 | pciPortInWord9x,
|
---|
70 | pciPortInLong9x,
|
---|
71 |
|
---|
72 | pciPortOutByte9x,
|
---|
73 | pciPortOutWord9x,
|
---|
74 | pciPortOutLong9x,
|
---|
75 |
|
---|
76 | pciMapLinear9x,
|
---|
77 | pciUnmapLinear9x,
|
---|
78 | pciSetPermission9x,
|
---|
79 |
|
---|
80 | pciMsrGet9x,
|
---|
81 | pciMsrSet9x,
|
---|
82 |
|
---|
83 | pciOutputString9x,
|
---|
84 | pciSetPassThroughBase9x
|
---|
85 | };
|
---|
86 | const FxPlatformIOProcs* ioProcs9x = &__ioProcs9x;
|
---|
87 |
|
---|
88 | /* Basic platform init/shutdown stuff */
|
---|
89 | static FxBool
|
---|
90 | pciInitialize9x(void)
|
---|
91 | {
|
---|
92 | hMemmapFile = CreateFile("\\\\.\\FXMEMMAP.VXD", 0, 0, NULL, 0,
|
---|
93 | FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
---|
94 | if ( hMemmapFile == INVALID_HANDLE_VALUE ) {
|
---|
95 | pciErrorCode = PCI_ERR_MEMMAPVXD;
|
---|
96 | return FXFALSE;
|
---|
97 | }
|
---|
98 |
|
---|
99 | return FXTRUE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | static FxBool
|
---|
103 | pciShutdown9x(void)
|
---|
104 | {
|
---|
105 | FxBool
|
---|
106 | retVal = (hMemmapFile != INVALID_HANDLE_VALUE);
|
---|
107 |
|
---|
108 | if (retVal) CloseHandle( hMemmapFile );
|
---|
109 | return retVal;
|
---|
110 | }
|
---|
111 |
|
---|
112 | static const char*
|
---|
113 | pciIdentifier9x(void)
|
---|
114 | {
|
---|
115 | return pciIdent;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /* Device address space management stuff */
|
---|
119 |
|
---|
120 | static FxBool
|
---|
121 | pciMapLinear9x(FxU32 busNumber, FxU32 physical_addr,
|
---|
122 | FxU32 *linear_addr, FxU32 *length)
|
---|
123 | {
|
---|
124 | FxU32 nret;
|
---|
125 | FxU32 Physical [2]; /* Physical address[0] & size[1] */
|
---|
126 | FxU32 Linear [2]; /* Linear address[0] & size[1] */
|
---|
127 | LPDWORD pPhysical = Physical;
|
---|
128 | LPDWORD pLinear = Linear;
|
---|
129 |
|
---|
130 | Physical[0] = physical_addr;
|
---|
131 | Physical[1] = *length;
|
---|
132 |
|
---|
133 | if ( !pciLibraryInitialized ) {
|
---|
134 | pciErrorCode = PCI_ERR_NOTOPEN;
|
---|
135 | return FXFALSE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | #ifndef DIRECTX
|
---|
139 | /*
|
---|
140 | * Check version:
|
---|
141 | * The policy is that major and minor versions must match, and
|
---|
142 | * further that the reference count is less than or equal to one.
|
---|
143 | */
|
---|
144 | DeviceIoControl(hMemmapFile, GETAPPVERSIONDWORD, NULL, 0, &pciVxdVer,
|
---|
145 | sizeof(pciVxdVer), &nret, NULL);
|
---|
146 | if (HIBYTE(pciVxdVer) != FX_MAJOR_VER || LOBYTE(pciVxdVer) < FX_MINOR_VER) {
|
---|
147 | pciErrorCode = PCI_ERR_WRONGVXD;
|
---|
148 | return FXFALSE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | #if 0
|
---|
152 | /* Check for mutual exclusion. Turned off everywhere for now because
|
---|
153 | * the DirectDraw driver does not bother to do anything w/ the mutex
|
---|
154 | * so no one else knows whether or not the hw is taken. Mmmm.... whacked.
|
---|
155 | */
|
---|
156 | if (VXDREFCOUNT(pciVxdVer) > 1) {
|
---|
157 | pciErrorCode = PCI_ERR_VXDINUSE;
|
---|
158 | return FXFALSE;
|
---|
159 | }
|
---|
160 | #endif
|
---|
161 | #endif /* !DIRECTX */
|
---|
162 |
|
---|
163 | /* Map physical to linear */
|
---|
164 | /* xxx - returns 0 in Linear if fails, but really should
|
---|
165 | check return value, 0 is suceess, -1 is failure. */
|
---|
166 |
|
---|
167 | #ifndef DIRECTX
|
---|
168 | /* Stuff added to auto-switch passthru using fxmemmap */
|
---|
169 | if (getenv("SST_DUALHEAD") == NULL) {
|
---|
170 | DeviceIoControl(hMemmapFile, GETLINEARADDR_AUTO,
|
---|
171 | &pPhysical, sizeof(pPhysical),
|
---|
172 | &pLinear, sizeof(pLinear),
|
---|
173 | &nret, NULL);
|
---|
174 | } else
|
---|
175 | #endif /* !DIRECTX */
|
---|
176 | {
|
---|
177 | DeviceIoControl(hMemmapFile, GETLINEARADDR,
|
---|
178 | &pPhysical, sizeof(pPhysical),
|
---|
179 | &pLinear, sizeof(pLinear),
|
---|
180 | &nret, NULL);
|
---|
181 | }
|
---|
182 |
|
---|
183 | *linear_addr = Linear[0];
|
---|
184 |
|
---|
185 | if ( nret == 0 ) {
|
---|
186 | pciErrorCode = PCI_ERR_MEMMAP;
|
---|
187 | return FXFALSE;
|
---|
188 | }
|
---|
189 |
|
---|
190 | return FXTRUE;
|
---|
191 | }
|
---|
192 |
|
---|
193 | static FxBool
|
---|
194 | pciUnmapLinear9x( FxU32 linear_addr, FxU32 length )
|
---|
195 | {
|
---|
196 | FxU32 nret;
|
---|
197 |
|
---|
198 | return DeviceIoControl(hMemmapFile, DECREMENTMUTEX,
|
---|
199 | NULL, 0,
|
---|
200 | NULL, 0,
|
---|
201 | &nret, NULL);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /* Platform port io stuff */
|
---|
205 | static FxU8
|
---|
206 | pciPortInByte9x(FxU16 port)
|
---|
207 | {
|
---|
208 | return _inp(port);
|
---|
209 | }
|
---|
210 |
|
---|
211 | static FxU16
|
---|
212 | pciPortInWord9x(FxU16 port)
|
---|
213 | {
|
---|
214 | return _inpw(port);
|
---|
215 | }
|
---|
216 |
|
---|
217 | static FxU32
|
---|
218 | pciPortInLong9x(FxU16 port)
|
---|
219 | {
|
---|
220 | return _inpd(port);
|
---|
221 | }
|
---|
222 |
|
---|
223 | static FxBool
|
---|
224 | pciPortOutByte9x(FxU16 port, FxU8 data)
|
---|
225 | {
|
---|
226 | return _outp(port, data);
|
---|
227 | }
|
---|
228 |
|
---|
229 | static FxBool
|
---|
230 | pciPortOutWord9x(FxU16 port, FxU16 data)
|
---|
231 | {
|
---|
232 | return _outpw(port, data);
|
---|
233 | }
|
---|
234 |
|
---|
235 | static FxBool
|
---|
236 | pciPortOutLong9x(FxU16 port, FxU32 data)
|
---|
237 | {
|
---|
238 | return _outpd(port, data);
|
---|
239 | }
|
---|
240 |
|
---|
241 | static FxBool pciMsrGet9x(MSRInfo* in, MSRInfo* out)
|
---|
242 | {
|
---|
243 | FxU32 nret;
|
---|
244 |
|
---|
245 | return DeviceIoControl( hMemmapFile, GETMSR,
|
---|
246 | in, sizeof(*in),
|
---|
247 | out, sizeof(*out),
|
---|
248 | &nret, NULL);
|
---|
249 | }
|
---|
250 |
|
---|
251 | static FxBool pciMsrSet9x(MSRInfo* in, MSRInfo* out)
|
---|
252 | {
|
---|
253 | FxU32 nret;
|
---|
254 |
|
---|
255 | return DeviceIoControl( hMemmapFile, SETMSR,
|
---|
256 | in, sizeof(*in),
|
---|
257 | out, sizeof(*out),
|
---|
258 | &nret, NULL);
|
---|
259 | }
|
---|
260 |
|
---|
261 | /* Platform utilities. */
|
---|
262 | static FxBool
|
---|
263 | pciOutputString9x(const char* msg)
|
---|
264 | {
|
---|
265 | FxBool retVal = FXTRUE;
|
---|
266 |
|
---|
267 | if (pciLibraryInitialized) {
|
---|
268 | OutputDebugString(msg);
|
---|
269 | } else {
|
---|
270 | pciErrorCode = PCI_ERR_NOTOPEN;
|
---|
271 | retVal = FXFALSE;
|
---|
272 | }
|
---|
273 |
|
---|
274 | return retVal;
|
---|
275 | }
|
---|
276 |
|
---|
277 | /* Ganked from vmm.h */
|
---|
278 | #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
|
---|
279 |
|
---|
280 | static FxBool
|
---|
281 | pciSetPermission9x(const FxU32 addrBase, const FxU32 addrLen,
|
---|
282 | const FxBool writePermP)
|
---|
283 | {
|
---|
284 | FxU32 vxdParamArray[] = {
|
---|
285 | addrBase,
|
---|
286 | addrLen,
|
---|
287 | 0
|
---|
288 | };
|
---|
289 | FxU32 nRet = 0;
|
---|
290 |
|
---|
291 | /* Set the user accessable bit. We don't dork w/ the
|
---|
292 | * rest of the bits.
|
---|
293 | */
|
---|
294 | vxdParamArray[2] = (writePermP ? PC_USER : 0);
|
---|
295 |
|
---|
296 | return DeviceIoControl(hMemmapFile, SETADDRPERM,
|
---|
297 | vxdParamArray, sizeof(vxdParamArray),
|
---|
298 | NULL, 0,
|
---|
299 | &nRet, NULL);
|
---|
300 | }
|
---|
301 |
|
---|
302 | static FxBool
|
---|
303 | pciSetPassThroughBase9x(FxU32* baseAddr, FxU32 baseAddrLen)
|
---|
304 | {
|
---|
305 | FxU32 vxdParams[] = { (FxU32)baseAddr, baseAddrLen };
|
---|
306 | FxU32 nRet = 0;
|
---|
307 |
|
---|
308 | return DeviceIoControl(hMemmapFile, SETPASSTHROUGHBASE,
|
---|
309 | vxdParams, sizeof(vxdParams),
|
---|
310 | NULL, 0,
|
---|
311 | &nRet, NULL);
|
---|
312 | }
|
---|
313 |
|
---|