| 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 | #include <devrp.h> | 
|---|
| 34 | #include "devown.h" | 
|---|
| 35 | #include <version.h> | 
|---|
| 36 | #include <ossidc32.h> | 
|---|
| 37 | #include <dbgos2.h> | 
|---|
| 38 | #include <printfos2.h> | 
|---|
| 39 | #include <irqos2.h> | 
|---|
| 40 | //#include <bsedos16.h> | 
|---|
| 41 | #ifdef KEE | 
|---|
| 42 | #include <kee.h> | 
|---|
| 43 | #endif | 
|---|
| 44 | #include "parse.h" | 
|---|
| 45 |  | 
|---|
| 46 | const char ERR_ERROR[]   = "ERROR: "; | 
|---|
| 47 | const char ERR_LOCK[]    = "Unable to lock 32 bit data & code segments, exiting...\r\r\n"; | 
|---|
| 48 | const char ERR_INIT[]    = "Initialization failed\r\r\n"; | 
|---|
| 49 | const char ERR_NAMES[]    = "Query names failed\r\r\n"; | 
|---|
| 50 | const char szALSA[]      = "\r\n\r\nOS/2 Universal Audio Core Driver v"ALSA_VERSION"\r\n"; | 
|---|
| 51 |  | 
|---|
| 52 | const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n"; | 
|---|
| 53 | const char szCopyRight2[]= "Copyright 2000-2002 The ALSA Project\r\n\r\n"; | 
|---|
| 54 | const char szCopyRight3[]= "Copyright 2005-2006 Netlabs http://www.netlabs.org\r\n"; | 
|---|
| 55 | //const char szCopyRight3[]= "Maintained by http://os2.kiev.ua/en/uniaud.php\r\n\r\n"; | 
|---|
| 56 |  | 
|---|
| 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 |  | 
|---|
| 66 | extern "C" FARPTR16 MSG_TABLE32; | 
|---|
| 67 | extern "C" char szLastALSAError1[]; | 
|---|
| 68 | extern "C" char szLastALSAError2[]; | 
|---|
| 69 | extern "C" int sprintf (char *buffer, const char *format, ...); | 
|---|
| 70 |  | 
|---|
| 71 | extern "C" int wrOffset; | 
|---|
| 72 | extern "C" char *szprintBuf; | 
|---|
| 73 | extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 ); | 
|---|
| 74 | extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile); | 
|---|
| 75 | extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual); | 
|---|
| 76 | extern "C" void SaveBuffer(void); | 
|---|
| 77 |  | 
|---|
| 78 | //Print messages with DosWrite when init is done or has failed (see startup.asm) | 
|---|
| 79 | void DevSaveMessage(char FAR48 *str, int length) | 
|---|
| 80 | { | 
|---|
| 81 | MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32); | 
|---|
| 82 | char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr); | 
|---|
| 83 | int i; | 
|---|
| 84 |  | 
|---|
| 85 | for(i=0;i<length;i++) { | 
|---|
| 86 | str16[msg->MsgLength + i] = str[i]; | 
|---|
| 87 | } | 
|---|
| 88 | str16[msg->MsgLength + length] = 0; | 
|---|
| 89 | msg->MsgLength += length; | 
|---|
| 90 |  | 
|---|
| 91 | return; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | void _cdecl printfos2(char *string) | 
|---|
| 95 | { | 
|---|
| 96 | DevSaveMessage(string, strlen(string)); | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | //SvL: Lock our 32 bits data & code segments | 
|---|
| 100 | int LockSegments(void) | 
|---|
| 101 | { | 
|---|
| 102 | #ifdef KEE | 
|---|
| 103 | KEEVMLock lock; | 
|---|
| 104 | #else | 
|---|
| 105 | char   lock[12]; | 
|---|
| 106 | ULONG  PgCount; | 
|---|
| 107 | #endif | 
|---|
| 108 | ULONG  segsize; | 
|---|
| 109 |  | 
|---|
| 110 | /* | 
|---|
| 111 | * Locks DGROUP into physical memory | 
|---|
| 112 | */ | 
|---|
| 113 | //NOTE: VMLock rounds base address down to nearest page | 
|---|
| 114 | //      So we MUST take this into account when calculating the | 
|---|
| 115 | //      size of our code/data | 
|---|
| 116 | segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF); | 
|---|
| 117 | if(segsize & 0xFFF) { | 
|---|
| 118 | segsize += PAGE_SIZE; | 
|---|
| 119 | } | 
|---|
| 120 | segsize &= ~0xFFF; | 
|---|
| 121 | #ifdef KEE | 
|---|
| 122 | if(KernVMLock(VMDHL_LONG, | 
|---|
| 123 | (PVOID)((OffsetBeginDS32) & ~0xFFF), | 
|---|
| 124 | segsize, | 
|---|
| 125 | &lock, | 
|---|
| 126 | (KEEVMPageList*)-1, | 
|---|
| 127 | 0)) { | 
|---|
| 128 | #else | 
|---|
| 129 | if(DevVMLock(VMDHL_LONG, | 
|---|
| 130 | ((OffsetBeginDS32) & ~0xFFF), | 
|---|
| 131 | segsize, | 
|---|
| 132 | (LINEAR)-1, | 
|---|
| 133 | (LINEAR)lock, | 
|---|
| 134 | (LINEAR)&PgCount)) { | 
|---|
| 135 | #endif | 
|---|
| 136 | return(1); | 
|---|
| 137 | } | 
|---|
| 138 | /* | 
|---|
| 139 | * Locks CODE32 into physical memory | 
|---|
| 140 | */ | 
|---|
| 141 | segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF); | 
|---|
| 142 | if(segsize & 0xFFF) { | 
|---|
| 143 | segsize += PAGE_SIZE; | 
|---|
| 144 | } | 
|---|
| 145 | segsize &= ~0xFFF; | 
|---|
| 146 | #ifdef KEE | 
|---|
| 147 | if(KernVMLock(VMDHL_LONG, | 
|---|
| 148 | (PVOID)((OffsetBeginCS32) & ~0xFFF), | 
|---|
| 149 | segsize, | 
|---|
| 150 | &lock, | 
|---|
| 151 | (KEEVMPageList*)-1, | 
|---|
| 152 | 0)) { | 
|---|
| 153 | #else | 
|---|
| 154 | if(DevVMLock(VMDHL_LONG, | 
|---|
| 155 | ((OffsetBeginCS32) & ~0xFFF), | 
|---|
| 156 | segsize, | 
|---|
| 157 | (LINEAR)-1, | 
|---|
| 158 | (LINEAR)lock, | 
|---|
| 159 | (LINEAR)&PgCount)) { | 
|---|
| 160 | #endif | 
|---|
| 161 | return(1); | 
|---|
| 162 | } | 
|---|
| 163 | return 0; | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | // Write a string of specified length | 
|---|
| 167 | static VOID WriteString(const char __far* str, int length) | 
|---|
| 168 | { | 
|---|
| 169 | // Write the string | 
|---|
| 170 | DevSaveMessage((char __far *)str, length); | 
|---|
| 171 | return; | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | #if 0 | 
|---|
| 175 | void SaveBuffer(void) | 
|---|
| 176 | { | 
|---|
| 177 | ULONG result; | 
|---|
| 178 | HFILE hFile; | 
|---|
| 179 | ULONG usAction; | 
|---|
| 180 | // write log to file at end of INIT strategy | 
|---|
| 181 | if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0, | 
|---|
| 182 | FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW, | 
|---|
| 183 | OPEN_ACCESS_READWRITE | | 
|---|
| 184 | OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH, | 
|---|
| 185 | NULL ) == 0) | 
|---|
| 186 | { | 
|---|
| 187 | if (szprintBuf) | 
|---|
| 188 | DOS16WRITE(hFile, szprintBuf, wrOffset, &result); | 
|---|
| 189 |  | 
|---|
| 190 | DOS16CLOSE(hFile); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | return; | 
|---|
| 194 | } | 
|---|
| 195 | #endif | 
|---|
| 196 | // Initialize device driver | 
|---|
| 197 | WORD32 DiscardableInit(RPInit __far* rp) | 
|---|
| 198 | { | 
|---|
| 199 | char        debugmsg[64]; | 
|---|
| 200 | char FAR48 *args; | 
|---|
| 201 |  | 
|---|
| 202 | #ifdef KEE | 
|---|
| 203 | GetTKSSBase(); | 
|---|
| 204 | #endif | 
|---|
| 205 |  | 
|---|
| 206 | if(LockSegments()) { | 
|---|
| 207 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1); | 
|---|
| 208 | WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1); | 
|---|
| 209 | return RPDONE | RPERR_COMMAND; | 
|---|
| 210 | } | 
|---|
| 211 |  | 
|---|
| 212 | rp->Out.FinalCS = 0; | 
|---|
| 213 | rp->Out.FinalDS = 0; | 
|---|
| 214 |  | 
|---|
| 215 | args = MAKE_FARPTR32(rp->In.Args); | 
|---|
| 216 | GetParms(args); | 
|---|
| 217 |  | 
|---|
| 218 | if(fVerbose) { | 
|---|
| 219 | WriteString(szALSA, sizeof(szALSA)-1); | 
|---|
| 220 | WriteString(szCopyRight1, sizeof(szCopyRight1)-1); | 
|---|
| 221 | WriteString(szCopyRight3, sizeof(szCopyRight3)-1); | 
|---|
| 222 | WriteString(szCopyRight2, sizeof(szCopyRight2)-1); | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | if(fDebug) { | 
|---|
| 226 | sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32); | 
|---|
| 227 | WriteString(debugmsg, strlen(debugmsg)); | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | //get the current time (to force retrieval of GIS pointer) | 
|---|
| 231 | os2gettimemsec(); | 
|---|
| 232 |  | 
|---|
| 233 | char szMixerName[64]; | 
|---|
| 234 | char szDeviceName[128]; | 
|---|
| 235 |  | 
|---|
| 236 | if(OSS32_Initialize() != OSSERR_SUCCESS) | 
|---|
| 237 | { | 
|---|
| 238 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1); | 
|---|
| 239 | WriteString(ERR_INIT, sizeof(ERR_INIT)-1); | 
|---|
| 240 | if(szLastALSAError1[0]) { | 
|---|
| 241 | WriteString(szLastALSAError1, strlen(szLastALSAError1)); | 
|---|
| 242 | } | 
|---|
| 243 | if(szLastALSAError2[0]) { | 
|---|
| 244 | WriteString(szLastALSAError2, strlen(szLastALSAError2)); | 
|---|
| 245 | } | 
|---|
| 246 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND; | 
|---|
| 247 | } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName, | 
|---|
| 248 | sizeof(szDeviceName),szMixerName, | 
|---|
| 249 | sizeof(szMixerName), TRUE) != OSSERR_SUCCESS) | 
|---|
| 250 | { | 
|---|
| 251 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1); | 
|---|
| 252 | WriteString(ERR_NAMES, sizeof(ERR_INIT)-1); | 
|---|
| 253 | if(szLastALSAError1[0]) { | 
|---|
| 254 | WriteString(szLastALSAError1, strlen(szLastALSAError1)); | 
|---|
| 255 | } | 
|---|
| 256 | if(szLastALSAError2[0]) { | 
|---|
| 257 | WriteString(szLastALSAError2, strlen(szLastALSAError2)); | 
|---|
| 258 | } | 
|---|
| 259 |  | 
|---|
| 260 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND; | 
|---|
| 261 | } | 
|---|
| 262 | else | 
|---|
| 263 | if(fVerbose) { | 
|---|
| 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 | if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS) | 
|---|
| 273 | { | 
|---|
| 274 | WriteString(szDeviceName, strlen(szDeviceName)); | 
|---|
| 275 | WriteString(szEOL, sizeof(szEOL)-1); | 
|---|
| 276 | WriteString(szMixerFound, sizeof(szMixerFound)-1); | 
|---|
| 277 | WriteString(szMixerName, strlen(szMixerName)); | 
|---|
| 278 | WriteString(szEOL, sizeof(szEOL)-1); | 
|---|
| 279 | } | 
|---|
| 280 | else break; | 
|---|
| 281 | } | 
|---|
| 282 | #endif | 
|---|
| 283 | WriteString(szEOL, sizeof(szEOL)-1); | 
|---|
| 284 | } | 
|---|
| 285 | #ifdef DEBUG | 
|---|
| 286 | dprintf(("DiscardableInit. cp1")); | 
|---|
| 287 | #endif | 
|---|
| 288 | // Complete the installation | 
|---|
| 289 | rp->Out.FinalCS = _OffsetFinalCS16; | 
|---|
| 290 | rp->Out.FinalDS = _OffsetFinalDS16; | 
|---|
| 291 | #ifdef DEBUG | 
|---|
| 292 | dprintf(("DiscardableInit. cp2")); | 
|---|
| 293 | #endif | 
|---|
| 294 |  | 
|---|
| 295 | //    SaveBuffer(); | 
|---|
| 296 |  | 
|---|
| 297 | // Confirm a successful installation | 
|---|
| 298 | return RPDONE; | 
|---|
| 299 | } | 
|---|
| 300 |  | 
|---|