source: GPL/branches/uniaud32-2.1.x/drv32/init.c@ 519

Last change on this file since 519 was 519, checked in by David Azarewicz, 15 years ago

Changes to PCI bus scan, malloc, cleanup all warnings, misc other changes

File size: 9.0 KB
Line 
1/* $Id: init.c,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $ */
2/*
3 * Init strategy handler
4 *
5 * (C) 2000-2002 InnoTek Systemberatung GmbH
6 * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 *
23 */
24
25#define INCL_NOPMAPI
26#define INCL_DOSINFOSEG // Need Global info seg in rm.cpp algorithms
27#include <os2.h>
28#include <string.h>
29
30// Device support
31#include <devhelp.h>
32#include <devtype.h>
33#include <devrp.h>
34#include "devown.h"
35#include <version.h>
36#include <ossidc32.h>
37#include <dbgos2.h>
38#include <irqos2.h>
39//#include <bsedos16.h>
40#ifdef KEE
41#include <kee.h>
42#endif
43#include "parse.h"
44#include "malloc.h"
45
46const char ERR_ERROR[] = "ERROR: ";
47const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
48const char ERR_INIT[] = "Initialization failed\r\r\n";
49const char ERR_NAMES[] = "Query names failed\r\r\n";
50const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on ALSA "ALSA_VERSION"\r\n";
51
52//const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
53const char szCopyRight2[]= "Copyright 2000-2010 The ALSA Project\r\n\r\n";
54const char szCopyRight3[]= "Copyright 2005-2010 Netlabs http://www.netlabs.org\r\n";
55
56const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
57const char szMixerFound[]= "Detected Mixer: ";
58const char szEOL[] = "\r\n";
59
60typedef struct {
61 USHORT MsgLength;
62 WORD32 MsgPtr;
63} MSG_TABLE;
64
65extern "C" FARPTR16 MSG_TABLE32;
66extern "C" char szLastALSAError1[];
67extern "C" char szLastALSAError2[];
68extern "C" int sprintf (char *buffer, const char *format, ...);
69
70extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
71extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile);
72extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
73extern "C" void SaveBuffer(void);
74
75#define VMDHA_FIXED 0x0002
76
77extern "C" APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
78
79//Print messages with DosWrite when init is done or has failed (see startup.asm)
80void DevSaveMessage(char FAR48 *str, int length)
81{
82 MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
83 char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
84 int i;
85
86 for(i=0;i<length;i++) {
87 str16[msg->MsgLength + i] = str[i];
88 }
89 str16[msg->MsgLength + length] = 0;
90 msg->MsgLength += length;
91
92 return;
93}
94
95//SvL: Lock our 32 bits data & code segments
96int LockSegments(void)
97{
98#ifdef KEE
99 KEEVMLock lock;
100#else
101 char lock[12];
102 ULONG PgCount;
103#endif
104 ULONG segsize;
105
106 /*
107 * Locks DGROUP into physical memory
108 */
109 //NOTE: VMLock rounds base address down to nearest page
110 // So we MUST take this into account when calculating the
111 // size of our code/data
112 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
113 if(segsize & 0xFFF) {
114 segsize += PAGE_SIZE;
115 }
116 segsize &= ~0xFFF;
117#ifdef KEE
118 if(KernVMLock(VMDHL_LONG,
119 (PVOID)((OffsetBeginDS32) & ~0xFFF),
120 segsize,
121 &lock,
122 (KEEVMPageList*)-1,
123 0)) {
124#else
125 if(DevVMLock(VMDHL_LONG,
126 ((OffsetBeginDS32) & ~0xFFF),
127 segsize,
128 (LINEAR)-1,
129 (LINEAR)lock,
130 (LINEAR)&PgCount)) {
131#endif
132 return(1);
133 }
134 /*
135 * Locks CODE32 into physical memory
136 */
137 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
138 if(segsize & 0xFFF) {
139 segsize += PAGE_SIZE;
140 }
141 segsize &= ~0xFFF;
142#ifdef KEE
143 if(KernVMLock(VMDHL_LONG,
144 (PVOID)((OffsetBeginCS32) & ~0xFFF),
145 segsize,
146 &lock,
147 (KEEVMPageList*)-1,
148 0)) {
149#else
150 if(DevVMLock(VMDHL_LONG,
151 ((OffsetBeginCS32) & ~0xFFF),
152 segsize,
153 (LINEAR)-1,
154 (LINEAR)lock,
155 (LINEAR)&PgCount)) {
156#endif
157 return(1);
158 }
159 return 0;
160}
161
162// Write a string of specified length
163static VOID WriteString(const char __far* str, int length)
164{
165 // Write the string
166 DevSaveMessage((char __far *)str, length);
167 return;
168}
169
170#if 0
171void SaveBuffer(void)
172{
173 ULONG result;
174 HFILE hFile;
175 ULONG usAction;
176 // write log to file at end of INIT strategy
177 if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0,
178 FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW,
179 OPEN_ACCESS_READWRITE |
180 OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
181 NULL ) == 0)
182 {
183 if (szprintBuf)
184 DOS16WRITE(hFile, szprintBuf, wrOffset, &result);
185
186 DOS16CLOSE(hFile);
187 }
188
189 return;
190}
191#endif
192// Initialize device driver
193WORD32 DiscardableInit(RPInit __far* rp)
194{
195 char debugmsg[64];
196 char FAR48 *args;
197
198#ifdef KEE
199 GetTKSSBase();
200#endif
201
202 if(LockSegments()) {
203 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
204 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
205 return RPDONE | RPERR_COMMAND;
206 }
207
208 DebugLevel = 1;
209 rp->Out.FinalCS = 0;
210 rp->Out.FinalDS = 0;
211
212 if ( szprintBuf == 0 ) {
213 VMAlloc( DBG_MAX_BUF_SIZE, VMDHA_FIXED, &szprintBuf );
214 if (szprintBuf) {
215 memset( szprintBuf, 0, DBG_MAX_BUF_SIZE );
216 wrOffset= 0;
217 }
218 }
219 if (!HeapInit(HEAP_SIZE)) {
220 rprintf(("HeapInit failed!"));
221 }
222
223 args = MAKE_FARPTR32(rp->In.Args);
224 GetParms(args);
225
226 if(fVerbose) {
227 WriteString(szALSA, sizeof(szALSA)-1);
228 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
229 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
230 }
231
232 if(fDebug) {
233 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
234 WriteString(debugmsg, strlen(debugmsg));
235 }
236
237 //get the current time (to force retrieval of GIS pointer)
238 os2gettimemsec();
239
240 char szMixerName[64];
241 char szDeviceName[128];
242
243 if(OSS32_Initialize() != OSSERR_SUCCESS)
244 {
245 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
246 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
247 if(szLastALSAError1[0]) {
248 WriteString(szLastALSAError1, strlen(szLastALSAError1));
249 }
250 if(szLastALSAError2[0]) {
251 WriteString(szLastALSAError2, strlen(szLastALSAError2));
252 }
253 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
254 } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
255 sizeof(szDeviceName),szMixerName,
256 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
257 {
258 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
259 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
260 if(szLastALSAError1[0]) {
261 WriteString(szLastALSAError1, strlen(szLastALSAError1));
262 }
263 if(szLastALSAError2[0]) {
264 WriteString(szLastALSAError2, strlen(szLastALSAError2));
265 }
266
267 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
268 }
269 else
270 if(fVerbose) {
271 WriteString(szDeviceName, strlen(szDeviceName));
272 WriteString(szEOL, sizeof(szEOL)-1);
273 WriteString(szMixerFound, sizeof(szMixerFound)-1);
274 WriteString(szMixerName, strlen(szMixerName));
275 WriteString(szEOL, sizeof(szEOL)-1);
276
277#if 0
278 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++) {
279 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
280 {
281 WriteString(szDeviceName, strlen(szDeviceName));
282 WriteString(szEOL, sizeof(szEOL)-1);
283 WriteString(szMixerFound, sizeof(szMixerFound)-1);
284 WriteString(szMixerName, strlen(szMixerName));
285 WriteString(szEOL, sizeof(szEOL)-1);
286 }
287 else break;
288 }
289#endif
290 WriteString(szEOL, sizeof(szEOL)-1);
291 }
292 // Complete the installation
293 rp->Out.FinalCS = _OffsetFinalCS16;
294 rp->Out.FinalDS = _OffsetFinalDS16;
295
296 //SaveBuffer();
297
298 // Confirm a successful installation
299 return RPDONE;
300}
301
Note: See TracBrowser for help on using the repository browser.