[305] | 1 | /* $Id: init.c,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $ */
|
---|
[32] | 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
|
---|
[677] | 31 | #include <devtype.h>
|
---|
| 32 | #include <stacktoflat.h>
|
---|
[32] | 33 | #include <version.h>
|
---|
| 34 | #include <ossidc32.h>
|
---|
| 35 | #include <dbgos2.h>
|
---|
[649] | 36 | #include <osspci.h>
|
---|
[32] | 37 | #include <kee.h>
|
---|
[675] | 38 | #include <malloc.h>
|
---|
[32] | 39 | #include "parse.h"
|
---|
[615] | 40 | #include "sound/version.h"
|
---|
[675] | 41 | #include "strategy.h"
|
---|
[32] | 42 |
|
---|
| 43 | const char ERR_ERROR[] = "ERROR: ";
|
---|
| 44 | const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
|
---|
| 45 | const char ERR_INIT[] = "Initialization failed\r\r\n";
|
---|
| 46 | const char ERR_NAMES[] = "Query names failed\r\r\n";
|
---|
[535] | 47 | #ifdef DEBUG
|
---|
[615] | 48 | const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"-DEBUG\r\nBased on Linux "ALSA_VERSION"\r\n";
|
---|
[535] | 49 | #else
|
---|
[615] | 50 | const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on Linux "ALSA_VERSION"\r\n";
|
---|
[535] | 51 | #endif
|
---|
[63] | 52 |
|
---|
[318] | 53 | //const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
|
---|
[615] | 54 | const char szCopyRight2[]= "Copyright 2000-2021 The ALSA Project\r\n\r\n";
|
---|
| 55 | const char szCopyRight3[]= "Copyright 2005-2021 Netlabs http://www.netlabs.org\r\n";
|
---|
[63] | 56 |
|
---|
[32] | 57 | const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
|
---|
| 58 | const char szMixerFound[]= "Detected Mixer: ";
|
---|
| 59 | const char szEOL[] = "\r\n";
|
---|
| 60 |
|
---|
| 61 | typedef struct {
|
---|
| 62 | USHORT MsgLength;
|
---|
| 63 | WORD32 MsgPtr;
|
---|
| 64 | } MSG_TABLE;
|
---|
| 65 |
|
---|
[587] | 66 | extern FARPTR16 MSG_TABLE32;
|
---|
| 67 | extern char szLastALSAError1[];
|
---|
| 68 | extern char szLastALSAError2[];
|
---|
| 69 | extern int sprintf (char *buffer, const char *format, ...);
|
---|
[32] | 70 |
|
---|
[587] | 71 | extern APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
|
---|
| 72 | extern APIRET APIENTRY DOS16CLOSE(HFILE hFile);
|
---|
| 73 | extern APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
|
---|
| 74 | extern void SaveBuffer(void);
|
---|
[32] | 75 |
|
---|
[502] | 76 | #define VMDHA_FIXED 0x0002
|
---|
| 77 |
|
---|
[587] | 78 | extern APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
|
---|
[502] | 79 |
|
---|
[32] | 80 | //Print messages with DosWrite when init is done or has failed (see startup.asm)
|
---|
| 81 | void 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++) {
|
---|
[587] | 88 | str16[msg->MsgLength + i] = str[i];
|
---|
[32] | 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
|
---|
[502] | 97 | int LockSegments(void)
|
---|
[32] | 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) {
|
---|
[587] | 110 | segsize += PAGE_SIZE;
|
---|
[32] | 111 | }
|
---|
| 112 | segsize &= ~0xFFF;
|
---|
[667] | 113 |
|
---|
[677] | 114 | if(KernVMLock(KEE_VML_LONGLOCK,
|
---|
[32] | 115 | (PVOID)((OffsetBeginDS32) & ~0xFFF),
|
---|
| 116 | segsize,
|
---|
| 117 | &lock,
|
---|
| 118 | (KEEVMPageList*)-1,
|
---|
| 119 | 0)) {
|
---|
[587] | 120 | return(1);
|
---|
[32] | 121 | }
|
---|
| 122 | /*
|
---|
| 123 | * Locks CODE32 into physical memory
|
---|
| 124 | */
|
---|
| 125 | segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
|
---|
| 126 | if(segsize & 0xFFF) {
|
---|
[587] | 127 | segsize += PAGE_SIZE;
|
---|
[32] | 128 | }
|
---|
| 129 | segsize &= ~0xFFF;
|
---|
[667] | 130 |
|
---|
[677] | 131 | if(KernVMLock(KEE_VML_LONGLOCK,
|
---|
[32] | 132 | (PVOID)((OffsetBeginCS32) & ~0xFFF),
|
---|
| 133 | segsize,
|
---|
| 134 | &lock,
|
---|
| 135 | (KEEVMPageList*)-1,
|
---|
| 136 | 0)) {
|
---|
[587] | 137 | return(1);
|
---|
[32] | 138 | }
|
---|
| 139 | return 0;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // Write a string of specified length
|
---|
| 143 | static 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
|
---|
| 151 | void 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
|
---|
[587] | 173 | WORD32 DiscardableInit(REQPACKET __far* rp)
|
---|
[32] | 174 | {
|
---|
[587] | 175 | char debugmsg[64];
|
---|
| 176 | char FAR48 *args;
|
---|
[32] | 177 |
|
---|
[649] | 178 | DebugLevel = 1;
|
---|
| 179 | rp->init_out.usCodeEnd = 0;
|
---|
| 180 | rp->init_out.usDataEnd = 0;
|
---|
| 181 |
|
---|
[587] | 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 |
|
---|
[649] | 189 | RMCreateDriverU32(); // register driver in Resource Manager
|
---|
[587] | 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;
|
---|
[32] | 198 | }
|
---|
[587] | 199 | }
|
---|
| 200 | if (!HeapInit(HEAP_SIZE))
|
---|
| 201 | {
|
---|
| 202 | rprintf(("HeapInit failed!"));
|
---|
| 203 | }
|
---|
[32] | 204 |
|
---|
[587] | 205 | args = MAKE_FARPTR32(rp->init_in.szArgs);
|
---|
| 206 | GetParms(args);
|
---|
[32] | 207 |
|
---|
[587] | 208 | #ifdef DEBUG
|
---|
| 209 | rprintf(("Uniaud32 version %s-DEBUG",UNIAUD_VERSION));
|
---|
| 210 | #else
|
---|
| 211 | rprintf(("Uniaud32 version %s",UNIAUD_VERSION));
|
---|
| 212 | #endif
|
---|
[615] | 213 | rprintf(("Based on linux %s",CONFIG_SND_VERSION));
|
---|
[502] | 214 |
|
---|
[587] | 215 | if(fVerbose)
|
---|
| 216 | {
|
---|
| 217 | WriteString(szALSA, sizeof(szALSA)-1);
|
---|
| 218 | WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
|
---|
| 219 | WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
|
---|
| 220 | }
|
---|
[32] | 221 |
|
---|
[587] | 222 | if(fDebug)
|
---|
| 223 | {
|
---|
| 224 | sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
|
---|
| 225 | WriteString(debugmsg, strlen(debugmsg));
|
---|
| 226 | }
|
---|
[535] | 227 |
|
---|
[587] | 228 | char szMixerName[64];
|
---|
| 229 | char szDeviceName[128];
|
---|
[535] | 230 |
|
---|
[587] | 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));
|
---|
[32] | 254 | }
|
---|
[587] | 255 | if(szLastALSAError2[0])
|
---|
| 256 | {
|
---|
| 257 | WriteString(szLastALSAError2, strlen(szLastALSAError2));
|
---|
| 258 | }
|
---|
[32] | 259 |
|
---|
[587] | 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);
|
---|
[32] | 270 |
|
---|
[587] | 271 | #if 0
|
---|
| 272 | for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++)
|
---|
[32] | 273 | {
|
---|
[587] | 274 | if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
|
---|
| 275 | {
|
---|
[32] | 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);
|
---|
[587] | 281 | }
|
---|
| 282 | else break;
|
---|
[32] | 283 | }
|
---|
[587] | 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;
|
---|
[32] | 290 |
|
---|
[587] | 291 | //SaveBuffer();
|
---|
[32] | 292 |
|
---|
[587] | 293 | // Confirm a successful installation
|
---|
| 294 | return RPDONE;
|
---|
[32] | 295 | }
|
---|