1 | /*
|
---|
2 | * Resource manager helper functions
|
---|
3 | *
|
---|
4 | * This program is free software; you can redistribute it and/or
|
---|
5 | * modify it under the terms of the GNU General Public License as
|
---|
6 | * published by the Free Software Foundation; either version 2 of
|
---|
7 | * the License, or (at your option) any later version.
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | #define INCL_NOPMAPI
|
---|
12 | #define INCL_DOSINFOSEG
|
---|
13 | #include <os2.h>
|
---|
14 |
|
---|
15 | #include <devhelp.h>
|
---|
16 | #include <devinfo.h>
|
---|
17 |
|
---|
18 | #include <rmbase.h> // Resource manager definitions.
|
---|
19 | #include "rmcalls.h"
|
---|
20 | #include <rmioctl.h>
|
---|
21 |
|
---|
22 | #include <version.h>
|
---|
23 | #include <dbgos2.h>
|
---|
24 | #include <unicard.h>
|
---|
25 | #include <osspci.h>
|
---|
26 | #include <ossidc32.h>
|
---|
27 | #include "pciids.h"
|
---|
28 |
|
---|
29 | #include <string.h>
|
---|
30 |
|
---|
31 | #define MAX_RESHANDLES 16
|
---|
32 |
|
---|
33 | static HDRIVER DriverHandle = (HDRIVER)-1;
|
---|
34 | static HADAPTER AdapterHandle = 0;
|
---|
35 |
|
---|
36 | typedef struct
|
---|
37 | {
|
---|
38 | ULONG NumResource;
|
---|
39 | HRESOURCE hResource[MAX_RESHANDLES];
|
---|
40 | } RESOURCES;
|
---|
41 |
|
---|
42 | static RESOURCES Resource_stt = {0};
|
---|
43 |
|
---|
44 | //******************************************************************************
|
---|
45 | //******************************************************************************
|
---|
46 | VOID RMCreateDriverU32(VOID)
|
---|
47 | {
|
---|
48 | HDRIVER hDriver;
|
---|
49 | DRIVERSTRUCT DriverStruct;
|
---|
50 | char DriverName[sizeof(RM_DRIVER_NAME)];
|
---|
51 | char VendorName[sizeof(RM_DRIVER_VENDORNAME)];
|
---|
52 | char DriverDesc[sizeof(RM_DRIVER_DESCRIPTION)];
|
---|
53 |
|
---|
54 | //copy strings to stack, because we need to give RM 16:16 pointers
|
---|
55 | //(which can only be (easily) generated from 32 bits stack addresses)
|
---|
56 | strcpy(DriverName, RM_DRIVER_NAME);
|
---|
57 | strcpy(VendorName, RM_DRIVER_VENDORNAME);
|
---|
58 | strcpy(DriverDesc, RM_DRIVER_DESCRIPTION);
|
---|
59 |
|
---|
60 | DriverStruct.DrvrName = FlatToSel((ULONG)DriverName);
|
---|
61 | DriverStruct.DrvrDescript = FlatToSel((ULONG)DriverDesc);
|
---|
62 | DriverStruct.VendorName = FlatToSel((ULONG)VendorName);
|
---|
63 | DriverStruct.MajorVer = RM_VMAJOR;
|
---|
64 | DriverStruct.MinorVer = RM_VMINOR;
|
---|
65 | DriverStruct.Date.Year = RM_DRIVER_BUILDYEAR;
|
---|
66 | DriverStruct.Date.Month = RM_DRIVER_BUILDMONTH;
|
---|
67 | DriverStruct.Date.Day = RM_DRIVER_BUILDDAY;
|
---|
68 | DriverStruct.DrvrFlags = 0;
|
---|
69 | DriverStruct.DrvrType = DRT_AUDIO;
|
---|
70 | DriverStruct.DrvrSubType = 0;
|
---|
71 | DriverStruct.DrvrCallback = 0;
|
---|
72 |
|
---|
73 | APIRET rc = RMCreateDriver( FlatToSel((ULONG)&DriverStruct),
|
---|
74 | FlatToSel((ULONG)&hDriver) );
|
---|
75 |
|
---|
76 | if( rc == RMRC_SUCCESS )
|
---|
77 | {
|
---|
78 | DriverHandle = hDriver;
|
---|
79 | }
|
---|
80 | dprintf(("RMCreateDriver rc=%d DriverHandle=%x", rc, DriverHandle));
|
---|
81 | }
|
---|
82 |
|
---|
83 | //******************************************************************************
|
---|
84 | //******************************************************************************
|
---|
85 | VOID RMCreateAdapterU32(ULONG DevID, ULONG *phAdapter, USHORT BusDevFunc, ULONG CardNum)
|
---|
86 | {
|
---|
87 | APIRET rc;
|
---|
88 | char szAdapterName[128];
|
---|
89 | char szMixerName[64];
|
---|
90 |
|
---|
91 | szAdapterName[0] = szMixerName[0] = '\0';
|
---|
92 |
|
---|
93 | if(OSS32_QueryNames(CardNum, szAdapterName, sizeof(szAdapterName),
|
---|
94 | szMixerName, sizeof(szMixerName), FALSE) != OSSERR_SUCCESS )
|
---|
95 | {
|
---|
96 | return; // error
|
---|
97 | }
|
---|
98 |
|
---|
99 | switch(DevID)
|
---|
100 | {
|
---|
101 | case PCIID_VIA_686A:
|
---|
102 | case PCIID_VIA_8233:
|
---|
103 | case PCIID_SI_7012:
|
---|
104 | case PCIID_INTEL_82801:
|
---|
105 | case PCIID_INTEL_82901:
|
---|
106 | case PCIID_INTEL_92801BA:
|
---|
107 | case PCIID_INTEL_440MX:
|
---|
108 | case PCIID_INTEL_ICH3:
|
---|
109 | case PCIID_INTEL_ICH4:
|
---|
110 | case PCIID_INTEL_ICH5:
|
---|
111 | case PCIID_INTEL_ICH6:
|
---|
112 | case PCIID_INTEL_ICH7:
|
---|
113 | case PCIID_NVIDIA_MCP_AUDIO:
|
---|
114 | case PCIID_NVIDIA_MCP2_AUDIO:
|
---|
115 | case PCIID_NVIDIA_MCP3_AUDIO:
|
---|
116 | case PCIID_NVIDIA_CK8S_AUDIO:
|
---|
117 | case PCIID_NVIDIA_CK8_AUDIO:
|
---|
118 | strcat(szAdapterName, " with ");
|
---|
119 | strcat(szAdapterName, szMixerName);
|
---|
120 | break;
|
---|
121 | /*
|
---|
122 | case PCIID_CREATIVELABS_SBLIVE:
|
---|
123 | case PCIID_ALS4000:
|
---|
124 | case PCIID_CMEDIA_CM8338A:
|
---|
125 | case PCIID_CMEDIA_CM8338B:
|
---|
126 | case PCIID_CMEDIA_CM8738:
|
---|
127 | case PCIID_CMEDIA_CM8738B:
|
---|
128 | case PCIID_CIRRUS_4281:
|
---|
129 | case PCIID_CIRRUS_4280:
|
---|
130 | case PCIID_CIRRUS_4612:
|
---|
131 | case PCIID_CIRRUS_4615:
|
---|
132 | case PCIID_ESS_ALLEGRO_1:
|
---|
133 | case PCIID_ESS_ALLEGRO:
|
---|
134 | case PCIID_ESS_MAESTRO3:
|
---|
135 | case PCIID_ESS_MAESTRO3_1:
|
---|
136 | case PCIID_ESS_MAESTRO3_HW:
|
---|
137 | case PCIID_ESS_MAESTRO3_2:
|
---|
138 | case PCIID_ESS_CANYON3D_2LE:
|
---|
139 | case PCIID_ESS_CANYON3D_2:
|
---|
140 | case PCIID_ESS_ES1938:
|
---|
141 | case PCIID_AUREAL_VORTEX:
|
---|
142 | case PCIID_AUREAL_VORTEX2:
|
---|
143 | case PCIID_AUREAL_ADVANTAGE:
|
---|
144 | case PCIID_ENSONIQ_CT5880:
|
---|
145 | case PCIID_ENSONIQ_ES1371:
|
---|
146 | case PCIID_YAMAHA_YMF724:
|
---|
147 | case PCIID_YAMAHA_YMF724F:
|
---|
148 | case PCIID_YAMAHA_YMF740:
|
---|
149 | case PCIID_YAMAHA_YMF740C:
|
---|
150 | case PCIID_YAMAHA_YMF744:
|
---|
151 | case PCIID_YAMAHA_YMF754:
|
---|
152 | case PCIID_ESS_M2E:
|
---|
153 | case PCIID_ESS_M2:
|
---|
154 | case PCIID_ESS_M1:
|
---|
155 | case PCIID_ALI_5451:
|
---|
156 | case PCIID_TRIDENT_4DWAVE_DX:
|
---|
157 | case PCIID_TRIDENT_4DWAVE_NX:
|
---|
158 | case PCIID_SI_7018:
|
---|
159 | case PCIID_FM801:
|
---|
160 | case PCIID_ATIIXP_SB200:
|
---|
161 | case PCIID_ATIIXP_SB300:
|
---|
162 | case PCIID_ATIIXP_SB400:
|
---|
163 | case PCIID_AUDIGYLS:
|
---|
164 | case PCIID_AUDIGYLS1:
|
---|
165 | case PCIID_AUDIGYLS2:
|
---|
166 | break;
|
---|
167 | */
|
---|
168 | }
|
---|
169 |
|
---|
170 | if( !szAdapterName[0] )
|
---|
171 | {
|
---|
172 | strcpy(szAdapterName, "Unknown");
|
---|
173 | }
|
---|
174 |
|
---|
175 | //copy to stack, because we need to give RM 16:16 pointers
|
---|
176 | //(which can only be (easily) generated from 32 bits stack addresses)
|
---|
177 | RESOURCES Resource_loc;
|
---|
178 | // is any resoures detected and registered in RM ?
|
---|
179 | if( Resource_stt.NumResource )
|
---|
180 | {
|
---|
181 | memcpy( &Resource_loc, &Resource_stt, sizeof(Resource_loc) );
|
---|
182 | }
|
---|
183 | else
|
---|
184 | {
|
---|
185 | dprintf(("No resources allocated !!!"));
|
---|
186 | Resource_loc.NumResource = 0;
|
---|
187 | }
|
---|
188 |
|
---|
189 | ADJUNCT adjBusDevFunc;
|
---|
190 | adjBusDevFunc.pNextAdj = NULL;
|
---|
191 | adjBusDevFunc.AdjLength = sizeof(adjBusDevFunc);
|
---|
192 | adjBusDevFunc.AdjType = ADJ_PCI_DEVFUNC;
|
---|
193 | adjBusDevFunc.PCI_DevFunc = BusDevFunc;
|
---|
194 |
|
---|
195 | ADAPTERSTRUCT AdapterStruct;
|
---|
196 | AdapterStruct.AdaptDescriptName = FlatToSel((ULONG)szAdapterName); /* ### IHV */
|
---|
197 | AdapterStruct.AdaptFlags = AS_16MB_ADDRESS_LIMIT; // AdaptFlags /* ### IHV */
|
---|
198 | AdapterStruct.BaseType = AS_BASE_MMEDIA; // BaseType
|
---|
199 | AdapterStruct.SubType = AS_SUB_MM_AUDIO; // SubType
|
---|
200 | AdapterStruct.InterfaceType = AS_INTF_GENERIC; // InterfaceType
|
---|
201 | AdapterStruct.HostBusType = AS_HOSTBUS_PCI; // HostBusType /* ### IHV */
|
---|
202 | AdapterStruct.HostBusWidth = AS_BUSWIDTH_32BIT; // HostBusWidth /* ### IHV */
|
---|
203 | AdapterStruct.pAdjunctList = FlatToSel((ULONG)&adjBusDevFunc);// pAdjunctList /* ### IHV */
|
---|
204 | AdapterStruct.Reserved = 0;
|
---|
205 |
|
---|
206 | //--- Register adapter. We'll record any error code, but won't fail
|
---|
207 | // the driver initialization and won't return resources.
|
---|
208 | //NOTE: hAdapter must be used as FlatToSel only works for stack variables
|
---|
209 | HADAPTER hAdapter;
|
---|
210 | rc = RMCreateAdapter(DriverHandle, // Handle to driver
|
---|
211 | FlatToSel((ULONG)&hAdapter), // (OUT) Handle to adapter
|
---|
212 | FlatToSel((ULONG)&AdapterStruct), // Adapter structure
|
---|
213 | 0, // Parent device (defaults OK)
|
---|
214 | Resource_loc.NumResource ? (FlatToSel((ULONG)&Resource_loc)) : 0); // Allocated resources.
|
---|
215 |
|
---|
216 | dprintf(("RMCreateAdapter rc=%d", rc));
|
---|
217 |
|
---|
218 | if( rc == 0 )
|
---|
219 | {
|
---|
220 | AdapterHandle = hAdapter;
|
---|
221 | *phAdapter = hAdapter;
|
---|
222 | Resource_stt.NumResource = 0; // no resource handles to be freed
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | RMDeallocRes();
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | //******************************************************************************
|
---|
231 | //******************************************************************************
|
---|
232 | BOOL RMRequestIO(ULONG ulIOBase, ULONG ulIOLength)
|
---|
233 | {
|
---|
234 | RESOURCESTRUCT Resource;
|
---|
235 | HRESOURCE hres;
|
---|
236 | APIRET rc;
|
---|
237 |
|
---|
238 | Resource.ResourceType = RS_TYPE_IO;
|
---|
239 | Resource.IOResource.BaseIOPort = (USHORT)ulIOBase;
|
---|
240 | Resource.IOResource.NumIOPorts = (USHORT)ulIOLength;
|
---|
241 | Resource.IOResource.IOFlags = RS_IO_EXCLUSIVE;
|
---|
242 | Resource.IOResource.IOAddressLines = ( ulIOBase > 0x3ff ) ? 16 : 10;
|
---|
243 |
|
---|
244 | rc = RMAllocResource(DriverHandle, // Handle to driver.
|
---|
245 | FlatToSel((ULONG)&hres), // OUT: "allocated" resource node handle
|
---|
246 | FlatToSel((ULONG)&Resource)); // Resource to allocate.
|
---|
247 |
|
---|
248 | if( rc == 0 && Resource_stt.NumResource < MAX_RESHANDLES )
|
---|
249 | {
|
---|
250 | Resource_stt.hResource[Resource_stt.NumResource++] = hres; return TRUE;
|
---|
251 | }
|
---|
252 |
|
---|
253 | dprintf(("RMAllocResource[%d] IO rc = %d", Resource_stt.NumResource, rc));
|
---|
254 |
|
---|
255 | return FALSE;
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 | //******************************************************************************
|
---|
260 | //******************************************************************************
|
---|
261 | BOOL RMRequestMem(ULONG ulMemBase, ULONG ulMemLength)
|
---|
262 | {
|
---|
263 | RESOURCESTRUCT Resource;
|
---|
264 | HRESOURCE hres;
|
---|
265 | APIRET rc;
|
---|
266 |
|
---|
267 | Resource.ResourceType = RS_TYPE_MEM;
|
---|
268 | Resource.MEMResource.MemBase = ulMemBase;
|
---|
269 | Resource.MEMResource.MemSize = ulMemLength;
|
---|
270 | Resource.MEMResource.MemFlags = RS_MEM_EXCLUSIVE;
|
---|
271 |
|
---|
272 | rc = RMAllocResource(DriverHandle, // Handle to driver.
|
---|
273 | FlatToSel((ULONG)&hres), // OUT: "allocated" resource node handle
|
---|
274 | FlatToSel((ULONG)&Resource)); // Resource to allocate.
|
---|
275 |
|
---|
276 | if( rc == 0 && Resource_stt.NumResource < MAX_RESHANDLES )
|
---|
277 | {
|
---|
278 | Resource_stt.hResource[Resource_stt.NumResource++] = hres; return TRUE;
|
---|
279 | }
|
---|
280 |
|
---|
281 | dprintf(("RMAllocResource[%d] MEM rc = %d", Resource_stt.NumResource, rc));
|
---|
282 |
|
---|
283 | return rc == 0;
|
---|
284 | }
|
---|
285 |
|
---|
286 |
|
---|
287 | //******************************************************************************
|
---|
288 | //******************************************************************************
|
---|
289 | BOOL RMRequestIRQ(ULONG ulIrq, BOOL fShared, PHRESOURCE phRes)
|
---|
290 | {
|
---|
291 | RESOURCESTRUCT Resource;
|
---|
292 | HRESOURCE hRes;
|
---|
293 | APIRET rc;
|
---|
294 |
|
---|
295 | memset( &Resource, 0, sizeof(Resource) );
|
---|
296 | Resource.ResourceType = RS_TYPE_IRQ;
|
---|
297 | Resource.IRQResource.IRQLevel = (USHORT)ulIrq & 0xff;
|
---|
298 | Resource.IRQResource.PCIIrqPin = 0;
|
---|
299 | Resource.IRQResource.IRQFlags = ( fShared ) ? RS_IRQ_SHARED : RS_IRQ_EXCLUSIVE;
|
---|
300 |
|
---|
301 | rc = RMAllocResource(DriverHandle, // Handle to driver.
|
---|
302 | FlatToSel((ULONG)&hRes), // OUT: "allocated" resource node handle
|
---|
303 | FlatToSel((ULONG)&Resource)); // Resource to allocate.
|
---|
304 |
|
---|
305 | if (rc == 0)
|
---|
306 | {
|
---|
307 | *phRes = hRes;
|
---|
308 | if (AdapterHandle)
|
---|
309 | {
|
---|
310 | dprintf(("RMRequestIRQ: DriverHandle=%x AdapterHandle=%x hRes=%x", DriverHandle, AdapterHandle, hRes));
|
---|
311 | rc = RMModifyResources(DriverHandle, AdapterHandle, RM_MODIFY_ADD, hRes);
|
---|
312 | }
|
---|
313 | else
|
---|
314 | {
|
---|
315 | if (Resource_stt.NumResource < MAX_RESHANDLES )
|
---|
316 | {
|
---|
317 | Resource_stt.hResource[Resource_stt.NumResource++] = hRes;
|
---|
318 | }
|
---|
319 | }
|
---|
320 | }
|
---|
321 | dprintf(("RMAllocResource[%d] IRQ=%d rc=%d", Resource_stt.NumResource, ulIrq, rc));
|
---|
322 | return rc == 0;
|
---|
323 | }
|
---|
324 |
|
---|
325 | //******************************************************************************
|
---|
326 | //******************************************************************************
|
---|
327 | BOOL RMDeallocateIRQ(HRESOURCE hRes)
|
---|
328 | {
|
---|
329 | APIRET rc;
|
---|
330 |
|
---|
331 | dprintf(("RMDeallocateIRQ: DriverHandle=%x AdapterHandle=%x hRes=%x", DriverHandle, AdapterHandle, hRes));
|
---|
332 | rc = RMModifyResources(DriverHandle, AdapterHandle, RM_MODIFY_DELETE, hRes);
|
---|
333 |
|
---|
334 | return rc == 0;
|
---|
335 | }
|
---|
336 |
|
---|
337 | //******************************************************************************
|
---|
338 | //******************************************************************************
|
---|
339 | VOID RMDeallocRes(VOID)
|
---|
340 | {
|
---|
341 | // free resource handles
|
---|
342 | while( Resource_stt.NumResource )
|
---|
343 | {
|
---|
344 | RMDeallocResource(DriverHandle, Resource_stt.hResource[--Resource_stt.NumResource]);
|
---|
345 | }
|
---|
346 | }
|
---|
347 |
|
---|
348 | /* DAZ - dirty hack so that resource manager is updated correctly
|
---|
349 | * when using APIC and multiple adapters */
|
---|
350 | VOID RMSetHandles(HADAPTER hAdapter)
|
---|
351 | {
|
---|
352 | AdapterHandle = hAdapter;
|
---|
353 | }
|
---|