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

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

Add source for uniaud32 based on code from linux kernel 5.4.86

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