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

Last change on this file was 677, checked in by Paul Smedley, 4 years ago

More code cleanups from AlexT from #os2russian

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