source: GPL/branches/uniaud32-next/drv32/init.c@ 649

Last change on this file since 649 was 649, checked in by Paul Smedley, 5 years ago

Patch from AlexT to improve Resource Manager information

File size: 9.3 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//DAZ #include <devrp.h>
34#include <strategy.h>
35#include "devown.h"
36#include <version.h>
37#include <ossidc32.h>
38#include <dbgos2.h>
39#include <irqos2.h>
40#include <osspci.h>
41//#include <bsedos16.h>
42#ifdef KEE
43#include <kee.h>
44#endif
45#include "parse.h"
46#include "malloc.h"
47#include "sound/version.h"
48
49const char ERR_ERROR[] = "ERROR: ";
50const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
51const char ERR_INIT[] = "Initialization failed\r\r\n";
52const char ERR_NAMES[] = "Query names failed\r\r\n";
53#ifdef DEBUG
54const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"-DEBUG\r\nBased on Linux "ALSA_VERSION"\r\n";
55#else
56const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on Linux "ALSA_VERSION"\r\n";
57#endif
58
59//const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
60const char szCopyRight2[]= "Copyright 2000-2021 The ALSA Project\r\n\r\n";
61const char szCopyRight3[]= "Copyright 2005-2021 Netlabs http://www.netlabs.org\r\n";
62
63const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
64const char szMixerFound[]= "Detected Mixer: ";
65const char szEOL[] = "\r\n";
66
67typedef struct {
68 USHORT MsgLength;
69 WORD32 MsgPtr;
70} MSG_TABLE;
71
72extern FARPTR16 MSG_TABLE32;
73extern char szLastALSAError1[];
74extern char szLastALSAError2[];
75extern int sprintf (char *buffer, const char *format, ...);
76
77extern APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
78extern APIRET APIENTRY DOS16CLOSE(HFILE hFile);
79extern APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
80extern void SaveBuffer(void);
81
82#define VMDHA_FIXED 0x0002
83
84extern APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
85
86//Print messages with DosWrite when init is done or has failed (see startup.asm)
87void DevSaveMessage(char FAR48 *str, int length)
88{
89 MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
90 char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
91 int i;
92
93 for(i=0;i<length;i++) {
94 str16[msg->MsgLength + i] = str[i];
95 }
96 str16[msg->MsgLength + length] = 0;
97 msg->MsgLength += length;
98
99 return;
100}
101
102//SvL: Lock our 32 bits data & code segments
103int LockSegments(void)
104{
105#ifdef KEE
106 KEEVMLock lock;
107#else
108 char lock[12];
109 ULONG PgCount;
110#endif
111 ULONG segsize;
112
113 /*
114 * Locks DGROUP into physical memory
115 */
116 //NOTE: VMLock rounds base address down to nearest page
117 // So we MUST take this into account when calculating the
118 // size of our code/data
119 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
120 if(segsize & 0xFFF) {
121 segsize += PAGE_SIZE;
122 }
123 segsize &= ~0xFFF;
124#ifdef KEE
125 if(KernVMLock(VMDHL_LONG,
126 (PVOID)((OffsetBeginDS32) & ~0xFFF),
127 segsize,
128 &lock,
129 (KEEVMPageList*)-1,
130 0)) {
131#else
132 if(DevVMLock(VMDHL_LONG,
133 ((OffsetBeginDS32) & ~0xFFF),
134 segsize,
135 (LINEAR)-1,
136 (LINEAR)lock,
137 (LINEAR)&PgCount)) {
138#endif
139 return(1);
140 }
141 /*
142 * Locks CODE32 into physical memory
143 */
144 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
145 if(segsize & 0xFFF) {
146 segsize += PAGE_SIZE;
147 }
148 segsize &= ~0xFFF;
149#ifdef KEE
150 if(KernVMLock(VMDHL_LONG,
151 (PVOID)((OffsetBeginCS32) & ~0xFFF),
152 segsize,
153 &lock,
154 (KEEVMPageList*)-1,
155 0)) {
156#else
157 if(DevVMLock(VMDHL_LONG,
158 ((OffsetBeginCS32) & ~0xFFF),
159 segsize,
160 (LINEAR)-1,
161 (LINEAR)lock,
162 (LINEAR)&PgCount)) {
163#endif
164 return(1);
165 }
166 return 0;
167}
168
169// Write a string of specified length
170static VOID WriteString(const char __far* str, int length)
171{
172 // Write the string
173 DevSaveMessage((char __far *)str, length);
174 return;
175}
176
177#if 0
178void SaveBuffer(void)
179{
180 ULONG result;
181 HFILE hFile;
182 ULONG usAction;
183 // write log to file at end of INIT strategy
184 if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0,
185 FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW,
186 OPEN_ACCESS_READWRITE |
187 OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
188 NULL ) == 0)
189 {
190 if (szprintBuf)
191 DOS16WRITE(hFile, szprintBuf, wrOffset, &result);
192
193 DOS16CLOSE(hFile);
194 }
195
196 return;
197}
198#endif
199// Initialize device driver
200WORD32 DiscardableInit(REQPACKET __far* rp)
201{
202 char debugmsg[64];
203 char FAR48 *args;
204
205#ifdef KEE
206 GetTKSSBase();
207#endif
208//_asm int 3;
209
210 DebugLevel = 1;
211 rp->init_out.usCodeEnd = 0;
212 rp->init_out.usDataEnd = 0;
213
214 if(LockSegments())
215 {
216 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
217 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
218 return RPDONE | RPERR_BADCOMMAND;
219 }
220
221 RMCreateDriverU32(); // register driver in Resource Manager
222
223 if ( szprintBuf == 0 )
224 {
225 VMAlloc( DBG_MAX_BUF_SIZE, VMDHA_FIXED, &szprintBuf );
226 if (szprintBuf)
227 {
228 memset( szprintBuf, 0, DBG_MAX_BUF_SIZE );
229 wrOffset= 0;
230 }
231 }
232 if (!HeapInit(HEAP_SIZE))
233 {
234 rprintf(("HeapInit failed!"));
235 }
236
237 args = MAKE_FARPTR32(rp->init_in.szArgs);
238 GetParms(args);
239
240 #ifdef DEBUG
241 rprintf(("Uniaud32 version %s-DEBUG",UNIAUD_VERSION));
242 #else
243 rprintf(("Uniaud32 version %s",UNIAUD_VERSION));
244 #endif
245 rprintf(("Based on linux %s",CONFIG_SND_VERSION));
246
247 if(fVerbose)
248 {
249 WriteString(szALSA, sizeof(szALSA)-1);
250 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
251 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
252 }
253
254 if(fDebug)
255 {
256 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
257 WriteString(debugmsg, strlen(debugmsg));
258 }
259
260 //get the current time (to force retrieval of GIS pointer)
261 os2gettimemsec();
262
263 char szMixerName[64];
264 char szDeviceName[128];
265
266 if(OSS32_Initialize() != OSSERR_SUCCESS)
267 {
268 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
269 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
270 if(szLastALSAError1[0])
271 {
272 WriteString(szLastALSAError1, strlen(szLastALSAError1));
273 }
274 if(szLastALSAError2[0])
275 {
276 WriteString(szLastALSAError2, strlen(szLastALSAError2));
277 }
278 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
279 }
280 else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
281 sizeof(szDeviceName),szMixerName,
282 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
283 {
284 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
285 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
286 if(szLastALSAError1[0])
287 {
288 WriteString(szLastALSAError1, strlen(szLastALSAError1));
289 }
290 if(szLastALSAError2[0])
291 {
292 WriteString(szLastALSAError2, strlen(szLastALSAError2));
293 }
294
295 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
296 }
297 else
298 if(fVerbose)
299 {
300 WriteString(szDeviceName, strlen(szDeviceName));
301 WriteString(szEOL, sizeof(szEOL)-1);
302 WriteString(szMixerFound, sizeof(szMixerFound)-1);
303 WriteString(szMixerName, strlen(szMixerName));
304 WriteString(szEOL, sizeof(szEOL)-1);
305
306 #if 0
307 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++)
308 {
309 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
310 {
311 WriteString(szDeviceName, strlen(szDeviceName));
312 WriteString(szEOL, sizeof(szEOL)-1);
313 WriteString(szMixerFound, sizeof(szMixerFound)-1);
314 WriteString(szMixerName, strlen(szMixerName));
315 WriteString(szEOL, sizeof(szEOL)-1);
316 }
317 else break;
318 }
319 #endif
320 WriteString(szEOL, sizeof(szEOL)-1);
321 }
322 // Complete the installation
323 rp->init_out.usCodeEnd = _OffsetFinalCS16;
324 rp->init_out.usDataEnd = _OffsetFinalDS16;
325
326 //SaveBuffer();
327
328 // Confirm a successful installation
329 return RPDONE;
330}
Note: See TracBrowser for help on using the repository browser.