source: trunk/src/opengl/glide/swlibs/pcilib/fxvxd.c

Last change on this file was 2887, checked in by sandervl, 26 years ago

Created swlibs dir

File size: 7.7 KB
Line 
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 */
36static FxBool pciInitialize9x(void);
37static FxBool pciShutdown9x(void);
38static const char* pciIdentifier9x(void);
39
40static FxU8 pciPortInByte9x(FxU16 port);
41static FxU16 pciPortInWord9x(FxU16 port);
42static FxU32 pciPortInLong9x(FxU16 port);
43
44static FxBool pciPortOutByte9x(FxU16 port, FxU8 data);
45static FxBool pciPortOutWord9x(FxU16 port, FxU16 data);
46static FxBool pciPortOutLong9x(FxU16 port, FxU32 data);
47
48static FxBool pciMapLinear9x(FxU32 busNumber, FxU32 physAddr,
49 FxU32* linearAddr, FxU32* length);
50static FxBool pciUnmapLinear9x(FxU32 linearAddr, FxU32 length);
51
52static FxBool pciSetPermission9x(const FxU32 addrBase, const FxU32 addrLen,
53 const FxBool writePermP);
54
55static FxBool pciMsrGet9x(MSRInfo* in, MSRInfo* out);
56static FxBool pciMsrSet9x(MSRInfo* in, MSRInfo* out);
57
58static FxBool pciOutputString9x(const char* msg);
59static FxBool pciSetPassThroughBase9x(FxU32* baseAddr, FxU32 baseAddrLen);
60
61static char pciIdent[] = "@#% fxPCI for Windows 9x";
62
63static 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};
86const FxPlatformIOProcs* ioProcs9x = &__ioProcs9x;
87
88/* Basic platform init/shutdown stuff */
89static FxBool
90pciInitialize9x(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
102static FxBool
103pciShutdown9x(void)
104{
105 FxBool
106 retVal = (hMemmapFile != INVALID_HANDLE_VALUE);
107
108 if (retVal) CloseHandle( hMemmapFile );
109 return retVal;
110}
111
112static const char*
113pciIdentifier9x(void)
114{
115 return pciIdent;
116}
117
118/* Device address space management stuff */
119
120static FxBool
121pciMapLinear9x(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
193static FxBool
194pciUnmapLinear9x( 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 */
205static FxU8
206pciPortInByte9x(FxU16 port)
207{
208 return _inp(port);
209}
210
211static FxU16
212pciPortInWord9x(FxU16 port)
213{
214 return _inpw(port);
215}
216
217static FxU32
218pciPortInLong9x(FxU16 port)
219{
220 return _inpd(port);
221}
222
223static FxBool
224pciPortOutByte9x(FxU16 port, FxU8 data)
225{
226 return _outp(port, data);
227}
228
229static FxBool
230pciPortOutWord9x(FxU16 port, FxU16 data)
231{
232 return _outpw(port, data);
233}
234
235static FxBool
236pciPortOutLong9x(FxU16 port, FxU32 data)
237{
238 return _outpd(port, data);
239}
240
241static 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
251static 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. */
262static FxBool
263pciOutputString9x(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
280static FxBool
281pciSetPermission9x(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
302static FxBool
303pciSetPassThroughBase9x(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
Note: See TracBrowser for help on using the repository browser.