1 // **************************************************************************** 2 // 3 // OsSupportBeOS.H 4 // 5 // Include file for BeOS Support Services to the CEchoGals 6 // generic driver class 7 // 8 // Set editor tabs to 3 for your viewing pleasure. 9 // 10 // ---------------------------------------------------------------------------- 11 // 12 // Copyright Echo Digital Audio Corporation (c) 1998 - 2002 13 // All rights reserved 14 // www.echoaudio.com 15 // 16 // Permission is hereby granted, free of charge, to any person obtaining a 17 // copy of this software and associated documentation files (the 18 // "Software"), to deal with the Software without restriction, including 19 // without limitation the rights to use, copy, modify, merge, publish, 20 // distribute, sublicense, and/or sell copies of the Software, and to 21 // permit persons to whom the Software is furnished to do so, subject to 22 // the following conditions: 23 // 24 // - Redistributions of source code must retain the above copyright 25 // notice, this list of conditions and the following disclaimers. 26 // 27 // - Redistributions in binary form must reproduce the above copyright 28 // notice, this list of conditions and the following disclaimers in the 29 // documentation and/or other materials provided with the distribution. 30 // 31 // - Neither the name of Echo Digital Audio, nor the names of its 32 // contributors may be used to endorse or promote products derived from 33 // this Software without specific prior written permission. 34 // 35 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 36 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 37 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 38 // IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR 39 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 40 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 41 // SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. 42 // 43 // **************************************************************************** 44 45 #ifdef _DEBUG 46 #pragma optimize("",off) 47 #endif 48 49 // Prevent problems with multiple includes 50 #ifndef _ECHOOSSUPPORTBEOS_ 51 #define _ECHOOSSUPPORTBEOS_ 52 53 extern "C" 54 { 55 #include <stdio.h> 56 #include <endian.h> 57 58 #ifdef _DEBUG 59 60 #include <KernelExport.h> 61 62 extern "C" 63 { 64 65 // BeOS debug printf macro 66 //#define ECHO_DEBUGPRINTF( strings ) DbgPrint##strings 67 #define ECHO_DEBUGPRINTF( strings ) dprintf##strings 68 //#define ECHO_DEBUGBREAK() 69 #define ECHO_DEBUGBREAK() kernel_debugger("echo driver debug break"); 70 #define ECHO_DEBUG 71 72 } 73 74 #else 75 76 #define ECHO_DEBUGPRINTF( strings ) 77 #define ECHO_DEBUGBREAK() 78 79 #endif 80 81 // 82 // Specify OS specific types 83 // 84 typedef void ** PPVOID; 85 typedef signed char INT8; 86 typedef int32 INT32; 87 typedef int32 WORD; 88 typedef int64 DWORD; 89 typedef void * PVOID; 90 typedef unsigned long long ULONGLONG; 91 typedef unsigned long long * PULONGLONG; 92 typedef char * PCHAR; 93 94 // 95 // Return Status Values 96 // 97 typedef unsigned long ECHOSTATUS; 98 99 100 // 101 // Define generic byte swapping functions 102 // 103 #ifdef BIG_ENDIAN 104 #include <ByteOrder.h> 105 WORD B_HOST_TO_LENDIAN( WORD in ) { return B_HOST_TO_LENDIAN_INT32(in); } 106 DWORD B_HOST_TO_LENDIAN( DWORD in ) { return B_HOST_TO_LENDIAN_INT64(in); } 107 #define SWAP(x) B_HOST_TO_LENDIAN( x ) 108 #else 109 #define SWAP(x) x 110 #endif 111 // 112 // Define what a physical address is on this OS 113 // 114 typedef unsigned long PHYS_ADDR; // Define physical addr type 115 typedef unsigned long * PPHYS_ADDR; // Define physical addr pointer type 116 117 // 118 // Global Memory Management Functions 119 // 120 121 // 122 // This tag is used to mark all memory allocated by EchoGals. 123 // Due to the way PoolMon displays things, we spell Echo backwards 124 // so it displays correctly. 125 // 126 #define ECHO_POOL_TAG 'OHCE' 127 128 129 // 130 // OsAllocateInit - Set up memory tracking. Call this once - not 131 // once per PCI card, just one time. 132 // 133 void OsAllocateInit(); 134 135 // 136 // Allocate locked, non-pageable block of memory. Does not have to be 137 // physically contiguous. Primarily used to implement the overloaded 138 // new operator for classes that must remain memory resident. 139 // 140 ECHOSTATUS OsAllocateNonPaged 141 ( 142 DWORD dwByteCt, 143 PPVOID ppMemAddr 144 ); 145 146 147 // 148 // Unlock and free, non-pageable block of memory. 149 // 150 ECHOSTATUS OsFreeNonPaged 151 ( 152 PVOID pMemAddr 153 ); 154 155 156 // 157 // Copy memory 158 // 159 #define OsCopyMemory(pDest,pSrc,dwBytes) memcpy(pDest,pSrc,dwBytes) 160 161 // 162 // Set memory to zero 163 // 164 #define OsZeroMemory(pDest,dwBytes) memset(pDest,0,dwBytes) 165 166 167 // 168 // This class is uniquely defined for each OS. It provides 169 // information that other components may require. 170 // For example, in Windows NT it contains a device object used by various 171 // memory management methods. 172 // Since static variables are used in place of globals, an instance must 173 // be constructed and initialized by the OS Interface object prior to 174 // constructing the CEchoGals derived object. The CEchoGals and 175 // CDspCommObject classes must have access to it during their respective 176 // construction times. 177 // 178 class COsSupport 179 { 180 public: 181 // 182 // Construction/destruction 183 // 184 COsSupport 185 ( 186 DWORD dwDeviceId // PCI bus device id 187 ); 188 189 ~COsSupport(); 190 191 // 192 // Timer Methods 193 // 194 195 // 196 // Return the system time in microseconds. 197 // Return error status if the OS doesn't support this function. 198 // 199 ECHOSTATUS OsGetSystemTime 200 ( 201 PULONGLONG pullTime 202 ); 203 204 205 // 206 // Stall execution for dwTime microseconds. 207 // Return error status if the OS doesn't support this function. 208 // 209 ECHOSTATUS OsSnooze 210 ( 211 DWORD dwTime 212 ); 213 214 215 // 216 // Memory Management Methods 217 // 218 219 // 220 // Allocate locked, non-pageable, physically contiguous memory pages 221 // in the drivers address space. Used to allocate memory for the DSP 222 // communications area and Ducks. 223 // 224 ECHOSTATUS OsPageAllocate 225 ( 226 DWORD dwPageCt, // How many pages to allocate 227 PPVOID ppPageAddr, // Where to return the memory ptr 228 PPHYS_ADDR pPhysicalPageAddr // Where to return the physical PCI addr 229 ); 230 231 // 232 // Unlock and free non-pageable, physically contiguous memory pages 233 // in the drivers address space. 234 // Used to free memory for the DSP communications area and Ducks. 235 // 236 ECHOSTATUS OsPageFree 237 ( 238 DWORD dwPageCt, // How many pages to free 239 PVOID pPageAddr, // Virtual memory ptr 240 PHYS_ADDR PhysicalPageAddr // Physical PCI addr 241 ); 242 243 // 244 // Add additional methods here 245 // 246 247 // 248 // Display and/or log an error message w/title 249 // 250 void EchoErrorMsg 251 ( 252 PCHAR pszMsg, 253 PCHAR pszTitle 254 ); 255 256 // 257 // Return PCI card device ID 258 // 259 DWORD GetDeviceId() 260 { return( m_dwDeviceId ); } 261 262 // 263 // Overload new & delete so memory for this object is allocated 264 // from non-paged memory. 265 // 266 PVOID operator new( size_t Size ); 267 VOID operator delete( PVOID pVoid ); 268 269 protected: 270 271 private: 272 DWORD m_dwDeviceId; // PCI Device ID 273 274 // 275 // Define data here. 276 // 277 278 KIRQL m_IrqlCurrent; // Old IRQ level 279 bigtime_t m_ullStartTime; // All system time relative to this time 280 class CPtrQueue * m_pPtrQue; // Store read only ptrs so they 281 // can be unmapped 282 283 }; // class COsSupport 284 285 typedef COsSupport * PCOsSupport; 286 287 #endif // _ECHOOSSUPPORTBEOS_ 288