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

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

Created swlibs dir

File size: 5.4 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
21#include <stdlib.h>
22#include <stdio.h>
23
24#include <conio.h>
25
26#include <3dfx.h>
27#define FX_DLL_DEFINITION
28#include <fxdll.h>
29#include "fxpci.h"
30#include "pcilib.h"
31
32#include <fxdpmi.h>
33#include <fxmemmap.h>
34
35/* Callback declarations */
36static FxBool pciInitializeDPMI(void);
37static FxBool pciShutdownDPMI(void);
38static const char* pciIdentifierDPMI(void);
39
40static FxU8 pciPortInByteDPMI(FxU16 port);
41static FxU16 pciPortInWordDPMI(FxU16 port);
42static FxU32 pciPortInLongDPMI(FxU16 port);
43
44static FxBool pciPortOutByteDPMI(FxU16 port, FxU8 data);
45static FxBool pciPortOutWordDPMI(FxU16 port, FxU16 data);
46static FxBool pciPortOutLongDPMI(FxU16 port, FxU32 data);
47
48static FxBool pciMapLinearDPMI(FxU32 busNumber, FxU32 physAddr,
49 FxU32* linearAddr, FxU32* length);
50static FxBool pciUnmapLinearDPMI(FxU32 linearAddr, FxU32 length);
51
52static FxBool pciSetPermissionDPMI(const FxU32 addrBase, const FxU32 addrLen,
53 const FxBool writePermP);
54
55static FxBool pciMsrGetDPMI(MSRInfo* in, MSRInfo* out);
56static FxBool pciMsrSetDPMI(MSRInfo* in, MSRInfo* out);
57
58static FxBool pciOutputStringDPMI(const char* msg);
59static FxBool pciSetPassThroughBaseDPMI(FxU32* baseAddr, FxU32 baseAddrLen);
60
61static char pciIdent[] = "@#% fxPCI for DOS";
62
63static const FxPlatformIOProcs __ioProcsDPMI = {
64 pciInitializeDPMI,
65 pciShutdownDPMI,
66 pciIdentifierDPMI,
67
68 pciPortInByteDPMI,
69 pciPortInWordDPMI,
70 pciPortInLongDPMI,
71
72 pciPortOutByteDPMI,
73 pciPortOutWordDPMI,
74 pciPortOutLongDPMI,
75
76 pciMapLinearDPMI,
77 pciUnmapLinearDPMI,
78 pciSetPermissionDPMI,
79
80 pciMsrGetDPMI,
81 pciMsrSetDPMI,
82
83 pciOutputStringDPMI,
84 pciSetPassThroughBaseDPMI
85};
86const FxPlatformIOProcs* ioProcsDPMI = &__ioProcsDPMI;
87
88FxBool
89pciPlatformInit(void)
90{
91 gCurPlatformIO = ioProcsDPMI;
92 return FXTRUE;
93}
94
95/* Basic platform init/shutdown stuff */
96static FxBool
97pciInitializeDPMI(void)
98{
99 return FXTRUE;
100}
101
102static FxBool
103pciShutdownDPMI(void)
104{
105 return FXTRUE;
106}
107
108static const char*
109pciIdentifierDPMI(void)
110{
111 return pciIdent;
112}
113
114/* Device address space management stuff */
115
116static FxBool
117pciMapLinearDPMI(FxU32 busNumber, FxU32 physical_addr,
118 FxU32 *linear_addr, FxU32 *length)
119{
120 FxBool onWindows;
121
122 /*
123 ** First, check to see if we're a DOS app under Windows, and if
124 ** so, then check to see if there's already an app connected to
125 ** the VXD.
126 *
127 * NB: To be compatible w/ the 'previous' pci libraries this is only
128 * done the first time that we're mapping a board otherwise it will
129 * fail on the vxd ref count because any previous mappings bump the
130 * reference count.
131 */
132 {
133 static FxBool didVxdCheck = FXFALSE;
134
135 if (!didVxdCheck) {
136 DpmiCheckVxd((FxBool *) &onWindows, &pciVxdVer);
137 didVxdCheck = FXTRUE;
138
139 if (onWindows) {
140 if (BYTE1(pciVxdVer) != FX_MAJOR_VER || BYTE0(pciVxdVer) < FX_MINOR_VER) {
141 pciErrorCode = PCI_ERR_WRONGVXD;
142 return FXFALSE;
143 }
144
145 if (VXDREFCOUNT(pciVxdVer) > 0) {
146 pciErrorCode = PCI_ERR_VXDINUSE;
147 return FXFALSE;
148 }
149 }
150 }
151 }
152
153 /* If we got here, it's OK to map the memory */
154 *linear_addr = DpmiMapPhysicalToLinear( physical_addr, *length );
155
156 return FXTRUE;
157}
158
159static FxBool
160pciUnmapLinearDPMI( FxU32 linear_addr, FxU32 length )
161{
162 DpmiUnmapMemory(linear_addr, length);
163}
164
165/* Platform port io stuff */
166static FxU8
167pciPortInByteDPMI(FxU16 port)
168{
169 return inp(port);
170}
171
172static FxU16
173pciPortInWordDPMI(FxU16 port)
174{
175 return inpw(port);
176}
177
178static FxU32
179pciPortInLongDPMI(FxU16 port)
180{
181 return inpd(port);
182}
183
184static FxBool
185pciPortOutByteDPMI(FxU16 port, FxU8 data)
186{
187 return outp(port, data);
188}
189
190static FxBool
191pciPortOutWordDPMI(FxU16 port, FxU16 data)
192{
193 return outpw(port, data);
194}
195
196static FxBool
197pciPortOutLongDPMI(FxU16 port, FxU32 data)
198{
199 return outpd(port, data);
200}
201
202static FxBool
203pciMsrGetDPMI(MSRInfo* in, MSRInfo* out)
204{
205 return DpmiGetMSR((FxU32)in, (FxU32)out);
206}
207
208static FxBool
209pciMsrSetDPMI(MSRInfo* in, MSRInfo* out)
210{
211 return DpmiSetMSR((FxU32)in, (FxU32)out);
212}
213
214/* Platform utilities. */
215static FxBool
216pciOutputStringDPMI(const char* msg)
217{
218 return DpmiOutputDebugString(msg);
219}
220
221static FxBool
222pciSetPermissionDPMI(const FxU32 addrBase, const FxU32 addrLen,
223 const FxBool writePermP)
224{
225 return DpmiLinearRangeSetPermission(addrBase, addrLen, writePermP);
226}
227
228static FxBool
229pciSetPassThroughBaseDPMI(FxU32* baseAddr, FxU32 baseAddrLen)
230{
231 return DpmiSetPassThroughBase(baseAddr, baseAddrLen);
232}
233
Note: See TracBrowser for help on using the repository browser.