1 | /* $Id: init.cpp 178 2001-04-30 21:08:00Z sandervl $ */
|
---|
2 |
|
---|
3 | /* SCCSID = %W% %E% */
|
---|
4 | /****************************************************************************
|
---|
5 | * *
|
---|
6 | * Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
7 | * *
|
---|
8 | * The following IBM OS/2 source code is provided to you solely for the *
|
---|
9 | * the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
10 | * You may use this code in accordance with the IBM License Agreement *
|
---|
11 | * provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
12 | * *
|
---|
13 | ****************************************************************************/
|
---|
14 | /**@internal %W%
|
---|
15 | * Top level device driver initialization.
|
---|
16 | * @version %I%
|
---|
17 | * @context
|
---|
18 | * Physical DD initialization context: Ring3 with I/O privledge.
|
---|
19 | * Discarded after use.
|
---|
20 | * @notes
|
---|
21 | * Creates resource manager object and uses that RM object to figure out
|
---|
22 | * whether audio hardware is present. If present, RM provides IO resources
|
---|
23 | * to operate hardware. This modules uses that information to create
|
---|
24 | * Audio HW objects and other global data structures.
|
---|
25 | * @history
|
---|
26 | */
|
---|
27 |
|
---|
28 | #pragma code_seg ("_inittext");
|
---|
29 | ////#pragma data_seg ("_initdata","endds");
|
---|
30 |
|
---|
31 | extern "C" { // 16-bit header files are not C++ aware
|
---|
32 | #define INCL_NOPMAPI
|
---|
33 | #define INCL_DOSMISC
|
---|
34 | #include <os2.h>
|
---|
35 | #include <audio.h>
|
---|
36 | #include <os2mixer.h>
|
---|
37 | }
|
---|
38 |
|
---|
39 | #include <ctype.h>
|
---|
40 | #include <string.h>
|
---|
41 | #include <devhelp.h>
|
---|
42 | #include "strategy.h" // OS/2 DD strategy interface
|
---|
43 | #include "header.h" // Device driver header
|
---|
44 | #include "parse.h" // Parses DEVICE= command line
|
---|
45 | #include "malloc.h" // Heap memory used by this driver
|
---|
46 | #include "mpu401.hpp" // Object definition
|
---|
47 | #include "wavehw.hpp" // Object definition
|
---|
48 | #include "irq.hpp" // Object definition
|
---|
49 | #include "timer.hpp" // Object definition
|
---|
50 | #include "stream.hpp" // pStreamList
|
---|
51 | #include "rm.hpp" // Object definition
|
---|
52 | #include "end.h" // end_of_data, end_of_text()
|
---|
53 | #include "sizedefs.h" // HEAP_SIZE
|
---|
54 | #include "idc_vdd.h" // VDD interface and Data Structs
|
---|
55 | #include <include.h> // Pragmas and more.
|
---|
56 | #include <sbversion.h>
|
---|
57 | #include "commdbg.h"
|
---|
58 | #include <dbgos2.h>
|
---|
59 |
|
---|
60 | #ifndef PCI_VENDOR_ID_CREATIVE
|
---|
61 | #define PCI_VENDOR_ID_CREATIVE 0x1102UL
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
|
---|
65 | #define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002UL
|
---|
66 | #endif
|
---|
67 | #define PCI_ID ((PCI_DEVICE_ID_CREATIVE_EMU10K1<<16UL)|PCI_VENDOR_ID_CREATIVE)
|
---|
68 |
|
---|
69 | // Default MIDI timer interval, milliseconds.
|
---|
70 | static USHORT MIDI_TimerInterval = 10;
|
---|
71 |
|
---|
72 | static char szSBLive[] = "SoundBlaster Live! MMPM/2 Audio Driver v"SBLIVE_VERSION;
|
---|
73 | static char szCopyRight[] = "Copyright 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)";
|
---|
74 | static char NEWLINE[] = "\r\n";
|
---|
75 | static char szSBLiveNotFound[] = "SB Live! hardware not detected!";
|
---|
76 | static char szSBLiveAllocResFailed1[] = "Another device driver was granted exclusive access to IRQ ";
|
---|
77 | static char szSBLiveAllocResFailed2[] = "Unable to allocate hardware resources! Aborting...";
|
---|
78 | static char szSBLiveConfig1[] = "SB Live! configuration: IRQ ";
|
---|
79 | static char szSBLiveConfig2[] = ", IO Port 0x";
|
---|
80 |
|
---|
81 |
|
---|
82 | //
|
---|
83 | // ASCII Z-String used to register for PDD-VDD IDC must
|
---|
84 | // Name is copied from header at runtime.
|
---|
85 | //
|
---|
86 | char szPddName[9] = {0};
|
---|
87 | char digit[16] = {0};
|
---|
88 |
|
---|
89 | ResourceManager* pRM = 0; // Resource manager object.
|
---|
90 |
|
---|
91 | //
|
---|
92 | // Strategy Init
|
---|
93 | //
|
---|
94 | void StrategyInit(PREQPACKET prp)
|
---|
95 | {
|
---|
96 | Device_Help = (PFN) prp->s.init_in.ulDevHlp;
|
---|
97 | prp->s.init_out.usCodeEnd = 0;
|
---|
98 | prp->s.init_out.usDataEnd = 0;
|
---|
99 | prp->usStatus = RPDONE | RPERR | RPGENFAIL;
|
---|
100 |
|
---|
101 | /* Initialize Heap. */
|
---|
102 | unsigned uInitSize; // Actual size of Heap following initialization.
|
---|
103 | uInitSize = HeapInit( HEAP_SIZE );
|
---|
104 | if ((HEAP_SIZE-uInitSize) > 64) { // Should get size of request, less some overhead.
|
---|
105 | // ### pError->vLog( HeapInitFailure ); //### Error log 'pError' not yet created.
|
---|
106 | return;
|
---|
107 | }
|
---|
108 | /* Heap initialized. */
|
---|
109 |
|
---|
110 | // Initialize global lists.
|
---|
111 | pAudioHWList = new QUEUEHEAD;
|
---|
112 | pStreamList = new QUEUEHEAD;
|
---|
113 | pTimerList = new QUEUEHEAD;
|
---|
114 |
|
---|
115 | // Fetch command line parameters.
|
---|
116 | if (!GetParms(prp->s.init_in.szArgs)) {
|
---|
117 | return;
|
---|
118 | }
|
---|
119 |
|
---|
120 | // Now that we've grabbed our cmd line options,
|
---|
121 | // we can start processing stuff that depends on those switches.
|
---|
122 |
|
---|
123 | if (fInt3BeforeInit) int3();
|
---|
124 |
|
---|
125 | // If we got a /V (verbose) flag on the DEVICE= command, route messages
|
---|
126 | // to the display.
|
---|
127 | if (fVerbose) {
|
---|
128 | USHORT result;
|
---|
129 |
|
---|
130 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
131 | DosWrite(1, (VOID FAR*)szSBLive, sizeof(szSBLive)-1, &result);
|
---|
132 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
133 |
|
---|
134 | DosWrite(1, (VOID FAR*)szCopyRight, sizeof(szCopyRight), &result);
|
---|
135 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
136 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
137 | }
|
---|
138 |
|
---|
139 | if (szCL_DevName[0] != ' ') // Was a valid device name specified?
|
---|
140 | memcpy(phdr->abName,szCL_DevName,8); // yes, copy it to the dev header
|
---|
141 |
|
---|
142 | pRM = new ResourceManager(PCI_ID); // Create the RM object.
|
---|
143 | if (! pRM) {
|
---|
144 | return;
|
---|
145 | }
|
---|
146 |
|
---|
147 | //SvL: Check if SB Live hardware has been detected by the resource manager
|
---|
148 | if(pRM->getState() != rmDriverCreated || !pRM->bIsDevDetected(PCI_ID, SEARCH_ID_DEVICEID, TRUE))
|
---|
149 | {
|
---|
150 | hardware_notfound:
|
---|
151 | USHORT result;
|
---|
152 |
|
---|
153 | DosWrite(1, (VOID FAR*)szSBLiveNotFound, sizeof(szSBLiveNotFound)-1, &result);
|
---|
154 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
155 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
156 | return;
|
---|
157 | }
|
---|
158 | LDev_Resources *pResources = pRM->pGetDevResources(PCI_ID, SEARCH_ID_DEVICEID, TRUE);
|
---|
159 | if ((!pResources) || pResources->isEmpty()) {
|
---|
160 | goto hardware_notfound;
|
---|
161 | }
|
---|
162 | if (pRM->getState() == rmAllocFailed) {
|
---|
163 | USHORT result;
|
---|
164 |
|
---|
165 | DosWrite(1, (VOID FAR*)szSBLiveAllocResFailed1, sizeof(szSBLiveAllocResFailed1)-1, &result);
|
---|
166 | DecWordToASCII(digit, (USHORT)pResources->uIRQLevel[0], 0);
|
---|
167 | DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
|
---|
168 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
169 | DosWrite(1, (VOID FAR*)szSBLiveAllocResFailed2, sizeof(szSBLiveAllocResFailed2)-1, &result);
|
---|
170 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
171 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
172 | return;
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (fVerbose) {
|
---|
176 | USHORT result;
|
---|
177 |
|
---|
178 | DecWordToASCII(digit, (USHORT)pResources->uIRQLevel[0], 0);
|
---|
179 | DosWrite(1, (VOID FAR*)szSBLiveConfig1, sizeof(szSBLiveConfig1)-1, &result);
|
---|
180 | DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
|
---|
181 |
|
---|
182 | DosWrite(1, (VOID FAR*)szSBLiveConfig2, sizeof(szSBLiveConfig2)-1, &result);
|
---|
183 | HexWordToASCII(digit, pResources->uIOBase[0], 0);
|
---|
184 | DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
|
---|
185 |
|
---|
186 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
187 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
188 | }
|
---|
189 | delete pResources;
|
---|
190 |
|
---|
191 | // Build the MPU401 object only if we got a good 2115 init.
|
---|
192 | // First create a timer, then the HW object.
|
---|
193 | TIMER* pMPUTimer =
|
---|
194 | new TIMER(NULL, MIDI_TimerInterval, STREAM_MPU401_PLAY );
|
---|
195 | if (pMPUTimer->eState() != TIMER_Disabled)
|
---|
196 | new MPU_401(pMPUTimer);
|
---|
197 |
|
---|
198 | SetHardwareType(AUDIOHW_MPU401_PLAY, MIDI, OPERATION_PLAY, 0);
|
---|
199 | SetHardwareType(AUDIOHW_MPU401_PLAY, DATATYPE_MIDI, OPERATION_PLAY, 0);
|
---|
200 | SetHardwareType(AUDIOHW_MPU401_PLAY, 0, OPERATION_PLAY, 0); //### Must be fixed.
|
---|
201 |
|
---|
202 | // Build the Wave Playback Hardware object
|
---|
203 | new WAVEPLAY();
|
---|
204 | new WAVEREC();
|
---|
205 |
|
---|
206 | #if 0
|
---|
207 | // fill in the ADAPTERINFO
|
---|
208 | codec_info.ulNumPorts = NUMIORANGES;
|
---|
209 | codec_info.Range[0].ulPort = pResourcesWSS->uIOBase[0];
|
---|
210 | codec_info.Range[0].ulRange = pResourcesWSS->uIOLength[0];
|
---|
211 | codec_info.Range[1].ulPort = pResourcesWSS->uIOBase[1];
|
---|
212 | codec_info.Range[1].ulRange = pResourcesWSS->uIOLength[1];
|
---|
213 | codec_info.Range[2].ulPort = pResourcesWSS->uIOBase[2];
|
---|
214 | codec_info.Range[2].ulRange = pResourcesWSS->uIOLength[2];
|
---|
215 | codec_info.Range[3].ulPort = pResourcesICS->uIOBase[0];
|
---|
216 | codec_info.Range[3].ulRange = pResourcesICS->uIOLength[0];
|
---|
217 |
|
---|
218 | // set up the addressing to the codec data for the vdd
|
---|
219 | pfcodec_info = (ADAPTERINFO __far *)&codec_info;
|
---|
220 | DevHelp_VirtToLin (SELECTOROF(pfcodec_info), (ULONG)(OFFSETOF(pfcodec_info)),
|
---|
221 | (PLIN)&pLincodec);
|
---|
222 |
|
---|
223 | // copy the pdd name out of the header.
|
---|
224 | for (int i = 0; i < sizeof(szPddName)-1 ; i++) {
|
---|
225 | if (phdr->abName[i] <= ' ')
|
---|
226 | break;
|
---|
227 | szPddName[i] = phdr->abName[i];
|
---|
228 | }
|
---|
229 | // register the VDD IDC entry point..
|
---|
230 | DevHelp_RegisterPDD ((NPSZ)szPddName, (PFN)IDCEntry_VDD);
|
---|
231 | #endif
|
---|
232 |
|
---|
233 | prp->usStatus = RPDONE;
|
---|
234 | prp->s.init_out.usCodeEnd = (USHORT) &end_of_text;
|
---|
235 | prp->s.init_out.usDataEnd = (USHORT) &end_of_heap;
|
---|
236 | }
|
---|