1 // **************************************************************************** 2 // 3 // OsSupportBeOS.H 4 // 5 // Set editor tabs to 3 for your viewing pleasure. 6 // 7 // ---------------------------------------------------------------------------- 8 // 9 // This file is part of Echo Digital Audio's generic driver library. 10 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005 11 // All rights reserved 12 // www.echoaudio.com 13 // 14 // This library is free software; you can redistribute it and/or 15 // modify it under the terms of the GNU Lesser General Public 16 // License as published by the Free Software Foundation; either 17 // version 2.1 of the License, or (at your option) any later version. 18 // 19 // This library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 // Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public 25 // License along with this library; if not, write to the Free Software 26 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 // 28 // **************************************************************************** 29 30 // Prevent problems with multiple includes 31 #ifndef _ECHOOSSUPPORTBEOS_ 32 #define _ECHOOSSUPPORTBEOS_ 33 34 #include <KernelExport.h> 35 #include <SupportDefs.h> 36 #include <ByteOrder.h> 37 #include "queue.h" 38 #include "debug.h" 39 40 #include <stdio.h> 41 #include <string.h> 42 #include "util/kernel_cpp.h" 43 44 #if DEBUG > 0 45 // BeOS debug printf macro 46 #define ECHO_DEBUGPRINTF( strings ) TRACE(strings) 47 #define ECHO_DEBUGBREAK() kernel_debugger("echo driver debug break"); 48 #define ECHO_DEBUG 49 50 #else 51 52 #define ECHO_DEBUGPRINTF( strings ) 53 #define ECHO_DEBUGBREAK() 54 55 #endif 56 57 // 58 // Assert macro 59 // 60 //#define ECHO_ASSERT(exp) ASSERT(exp) 61 #define ECHO_ASSERT(exp) 62 63 // 64 // Specify OS specific types 65 // 66 typedef char *PCHAR ; 67 typedef uint8 BYTE; 68 typedef uint8 *PBYTE; 69 typedef uint16 WORD; 70 typedef uint16 *PWORD; 71 typedef uint32 DWORD; 72 typedef unsigned long ULONG; 73 typedef unsigned long NUINT; 74 typedef long NINT; 75 typedef void *PVOID; 76 typedef DWORD *PDWORD; 77 #define VOID void 78 typedef bool BOOL; 79 typedef bool BOOLEAN; 80 typedef char *PTCHAR; 81 typedef char TCHAR; 82 typedef char CHAR; 83 typedef char* LPSTR; 84 //typedef SInt32 INT; 85 typedef int32 INT32; 86 typedef int32 *PINT; 87 typedef int8 INT8; 88 typedef long HANDLE; 89 typedef long LONG; 90 typedef int64 LONGLONG; 91 typedef uint64 ULONGLONG ; 92 typedef uint64 *PULONGLONG ; 93 typedef long *PKEVENT ; 94 #undef NULL 95 #define NULL 0 96 #define CALLBACK 97 98 #define CONST const 99 typedef void ** PPVOID; 100 101 #define PAGE_SIZE B_PAGE_SIZE 102 103 #define WideToSInt64(x) (*((int64*)(&x))) 104 #define WideToUInt64(x) (*((uint64*)(&x))) 105 106 // 107 // Return Status Values 108 // 109 typedef unsigned long ECHOSTATUS; 110 111 112 // 113 // Define our platform specific things here. 114 // 115 typedef struct _echo_mem { 116 LIST_ENTRY(_echo_mem) next; 117 void *log_base; 118 void *phy_base; 119 area_id area; 120 size_t size; 121 } echo_mem; 122 123 // 124 // Define generic byte swapping functions 125 // 126 #define SWAP(x)B_HOST_TO_LENDIAN_INT32(x) 127 128 // 129 // Define what a physical address is on this OS 130 // 131 typedef unsigned long PHYS_ADDR; // Define physical addr type 132 typedef unsigned long* PPHYS_ADDR; // Define physical addr pointer type 133 134 typedef echo_mem* PPAGE_BLOCK; 135 136 137 // 138 // Version information. 139 // In NT, we want to get this from a resource 140 // 141 #define APPVERSION OsGetVersion() 142 #define APPREVISION OsGetRevision() 143 #define APPRELEASE OsGetRelease() 144 145 BYTE OsGetVersion(); 146 BYTE OsGetRevision(); 147 BYTE OsGetRelease(); 148 149 // 150 // Global Memory Management Functions 151 // 152 153 // 154 // This tag is used to mark all memory allocated by EchoGals. 155 // Due to the way PoolMon displays things, we spell Echo backwards 156 // so it displays correctly. 157 // 158 #define ECHO_POOL_TAG 'OHCE' 159 160 161 // 162 // OsAllocateInit - Set up memory tracking. Call this once - not 163 // once per PCI card, just one time. 164 // 165 void OsAllocateInit(); 166 167 // 168 // Allocate locked, non-pageable block of memory. Does not have to be 169 // physically contiguous. Primarily used to implement the overloaded 170 // new operator for classes that must remain memory resident. 171 // 172 ECHOSTATUS OsAllocateNonPaged 173 ( 174 DWORD dwByteCt, 175 PPVOID ppMemAddr 176 ); 177 178 179 // 180 // Unlock and free, non-pageable block of memory. 181 // 182 ECHOSTATUS OsFreeNonPaged 183 ( 184 PVOID pMemAddr 185 ); 186 187 188 // 189 // Copy memory 190 // 191 //!!! Anything faster we can use? 192 #define OsCopyMemory(pDest, pSrc, dwBytes) memcpy(pDest, pSrc, dwBytes) 193 194 // 195 // Set memory to zero 196 // 197 #define OsZeroMemory(pDest, dwBytes) memset(pDest, 0, dwBytes) 198 199 200 // 201 // This class is uniquely defined for each OS. It provides 202 // information that other components may require. 203 // For example, in Windows NT it contains a device object used by various 204 // memory management methods. 205 // Since static variables are used in place of globals, an instance must 206 // be constructed and initialized by the OS Interface object prior to 207 // constructing the CEchoGals derived object. The CEchoGals and 208 // CDspCommObject classes must have access to it during their respective 209 // construction times. 210 // 211 class COsSupport 212 { 213 public: 214 // 215 // Construction/destruction 216 // 217 COsSupport 218 ( 219 WORD wDeviceId, // PCI bus device id 220 WORD wCardRev // Hardware revision number 221 ); 222 223 ~COsSupport(); 224 225 // 226 // Timer Methods 227 // 228 229 // 230 // Return the system time in microseconds. 231 // Return error status if the OS doesn't support this function. 232 // 233 ECHOSTATUS OsGetSystemTime 234 ( 235 PULONGLONG pullTime 236 ); 237 238 239 // 240 // Stall execution for dwTime microseconds. 241 // Return error status if the OS doesn't support this function. 242 // 243 ECHOSTATUS OsSnooze 244 ( 245 DWORD dwTime // Duration in micro seconds 246 ); 247 248 249 // 250 // Memory Management Methods 251 // 252 253 // 254 // Allocate a block of physical memory pages 255 // 256 ECHOSTATUS AllocPhysPageBlock 257 ( 258 DWORD dwBytes, 259 PPAGE_BLOCK &pPageBlock 260 ); 261 262 // 263 // Free a block of physical memory 264 // 265 ECHOSTATUS FreePhysPageBlock 266 ( 267 DWORD dwBytes, 268 PPAGE_BLOCK pPageBlock 269 ); 270 271 // 272 // Get the virtual address for a page block 273 // 274 PVOID GetPageBlockVirtAddress 275 ( 276 PPAGE_BLOCK pPageBlock 277 ); 278 279 // 280 // Get the physical address for a segment of a page block 281 // 282 ECHOSTATUS GetPageBlockPhysSegment 283 ( 284 PPAGE_BLOCK pPageBlock, // pass in a previously allocated block 285 DWORD dwOffset, // pass in the offset into the block 286 PHYS_ADDR &PhysAddr, // returns the physical address 287 DWORD &dwSegmentSize // and the length of the segment 288 ); 289 290 291 // 292 // Add additional methods here 293 // 294 295 // 296 // Display and/or log an error message w/title 297 // 298 void EchoErrorMsg 299 ( 300 PCHAR pszMsg, 301 PCHAR pszTitle 302 ); 303 304 // 305 // Return PCI card device ID 306 // 307 WORD GetDeviceId() 308 { return( m_wDeviceId ); } 309 310 // 311 // Return the hardware revision number 312 // 313 WORD GetCardRev() 314 { 315 return m_wCardRev; 316 } 317 318 // 319 // Get the current timestamp for MIDI input data 320 // 321 LONGLONG GetMidiInTimestamp() 322 { 323 return system_time(); 324 } 325 326 // 327 // Overload new & delete so memory for this object is allocated 328 // from non-paged memory. 329 // 330 PVOID operator new( size_t Size ); 331 VOID operator delete( PVOID pVoid ); 332 333 protected: 334 335 private: 336 WORD m_wDeviceId; // PCI Device ID 337 WORD m_wCardRev; // Hardware revision 338 339 // 340 // Define data here. 341 // 342 #ifdef ECHO_DEBUG 343 DWORD m_dwPageBlockCount; 344 #endif 345 346 }; // class COsSupport 347 348 typedef COsSupport * PCOsSupport; 349 350 #endif // _ECHOOSSUPPORTBEOS_ 351