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

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

More code cleanups from AlexT from #os2russian

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