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

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

Code cleanups from AlexT

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#ifndef KEE
206 GetTKSSBase();
207#endif
208
209 DebugLevel = 1;
210 rp->init_out.usCodeEnd = 0;
211 rp->init_out.usDataEnd = 0;
212
213 if(LockSegments())
214 {
215 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
216 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
217 return RPDONE | RPERR_BADCOMMAND;
218 }
219
220 RMCreateDriverU32(); // register driver in Resource Manager
221
222 if ( szprintBuf == 0 )
223 {
224 VMAlloc( DBG_MAX_BUF_SIZE, VMDHA_FIXED, &szprintBuf );
225 if (szprintBuf)
226 {
227 memset( szprintBuf, 0, DBG_MAX_BUF_SIZE );
228 wrOffset= 0;
229 }
230 }
231 if (!HeapInit(HEAP_SIZE))
232 {
233 rprintf(("HeapInit failed!"));
234 }
235
236 args = MAKE_FARPTR32(rp->init_in.szArgs);
237 GetParms(args);
238
239 #ifdef DEBUG
240 rprintf(("Uniaud32 version %s-DEBUG",UNIAUD_VERSION));
241 #else
242 rprintf(("Uniaud32 version %s",UNIAUD_VERSION));
243 #endif
244 rprintf(("Based on linux %s",CONFIG_SND_VERSION));
245
246 if(fVerbose)
247 {
248 WriteString(szALSA, sizeof(szALSA)-1);
249 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
250 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
251 }
252
253 if(fDebug)
254 {
255 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
256 WriteString(debugmsg, strlen(debugmsg));
257 }
258
259 //get the current time (to force retrieval of GIS pointer)
260 os2gettimemsec();
261
262 char szMixerName[64];
263 char szDeviceName[128];
264
265 if(OSS32_Initialize() != OSSERR_SUCCESS)
266 {
267 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
268 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
269 if(szLastALSAError1[0])
270 {
271 WriteString(szLastALSAError1, strlen(szLastALSAError1));
272 }
273 if(szLastALSAError2[0])
274 {
275 WriteString(szLastALSAError2, strlen(szLastALSAError2));
276 }
277 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
278 }
279 else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
280 sizeof(szDeviceName),szMixerName,
281 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
282 {
283 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
284 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
285 if(szLastALSAError1[0])
286 {
287 WriteString(szLastALSAError1, strlen(szLastALSAError1));
288 }
289 if(szLastALSAError2[0])
290 {
291 WriteString(szLastALSAError2, strlen(szLastALSAError2));
292 }
293
294 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
295 }
296 else
297 if(fVerbose)
298 {
299 WriteString(szDeviceName, strlen(szDeviceName));
300 WriteString(szEOL, sizeof(szEOL)-1);
301 WriteString(szMixerFound, sizeof(szMixerFound)-1);
302 WriteString(szMixerName, strlen(szMixerName));
303 WriteString(szEOL, sizeof(szEOL)-1);
304
305 #if 0
306 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++)
307 {
308 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
309 {
310 WriteString(szDeviceName, strlen(szDeviceName));
311 WriteString(szEOL, sizeof(szEOL)-1);
312 WriteString(szMixerFound, sizeof(szMixerFound)-1);
313 WriteString(szMixerName, strlen(szMixerName));
314 WriteString(szEOL, sizeof(szEOL)-1);
315 }
316 else break;
317 }
318 #endif
319 WriteString(szEOL, sizeof(szEOL)-1);
320 }
321 // Complete the installation
322 rp->init_out.usCodeEnd = _OffsetFinalCS16;
323 rp->init_out.usDataEnd = _OffsetFinalDS16;
324
325 //SaveBuffer();
326
327 // Confirm a successful installation
328 return RPDONE;
329}
Note: See TracBrowser for help on using the repository browser.