source: GPL/branches/uniaud32-next/drv32/rmhelp.c@ 675

Last change on this file since 675 was 675, checked in by Paul Smedley, 4 years ago

More code cleanups from AlexT from #os2russian

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