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

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

Remove remaining support for non-KEE builds

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