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 //#define NULL 0 95 #define CALLBACK 96 97 #define CONST const 98 typedef void ** PPVOID; 99 100 #define PAGE_SIZE B_PAGE_SIZE 101 102 #define WideToSInt64(x) (*((int64*)(&x))) 103 #define WideToUInt64(x) (*((uint64*)(&x))) 104 105 // 106 // Return Status Values 107 // 108 typedef unsigned long ECHOSTATUS; 109 110 111 // 112 // Define our platform specific things here. 113 // 114 typedef struct _echo_mem { 115 LIST_ENTRY(_echo_mem) next; 116 void *log_base; 117 void *phy_base; 118 area_id area; 119 size_t size; 120 } echo_mem; 121 122 // 123 // Define generic byte swapping functions 124 // 125 #define SWAP(x)B_HOST_TO_LENDIAN_INT32(x) 126 127 // 128 // Define what a physical address is on this OS 129 // 130 typedef unsigned long PHYS_ADDR; // Define physical addr type 131 typedef unsigned long* PPHYS_ADDR; // Define physical addr pointer type 132 133 typedef echo_mem* PPAGE_BLOCK; 134 135 136 // 137 // Version information. 138 // In NT, we want to get this from a resource 139 // 140 #define APPVERSION OsGetVersion() 141 #define APPREVISION OsGetRevision() 142 #define APPRELEASE OsGetRelease() 143 144 BYTE OsGetVersion(); 145 BYTE OsGetRevision(); 146 BYTE OsGetRelease(); 147 148 // 149 // Global Memory Management Functions 150 // 151 152 // 153 // This tag is used to mark all memory allocated by EchoGals. 154 // Due to the way PoolMon displays things, we spell Echo backwards 155 // so it displays correctly. 156 // 157 #define ECHO_POOL_TAG 'OHCE' 158 159 160 // 161 // OsAllocateInit - Set up memory tracking. Call this once - not 162 // once per PCI card, just one time. 163 // 164 void OsAllocateInit(); 165 166 // 167 // Allocate locked, non-pageable block of memory. Does not have to be 168 // physically contiguous. Primarily used to implement the overloaded 169 // new operator for classes that must remain memory resident. 170 // 171 ECHOSTATUS OsAllocateNonPaged 172 ( 173 DWORD dwByteCt, 174 PPVOID ppMemAddr 175 ); 176 177 178 // 179 // Unlock and free, non-pageable block of memory. 180 // 181 ECHOSTATUS OsFreeNonPaged 182 ( 183 PVOID pMemAddr 184 ); 185 186 187 // 188 // Copy memory 189 // 190 //!!! Anything faster we can use? 191 #define OsCopyMemory(pDest, pSrc, dwBytes) memcpy(pDest, pSrc, dwBytes) 192 193 // 194 // Set memory to zero 195 // 196 #define OsZeroMemory(pDest, dwBytes) memset(pDest, 0, dwBytes) 197 198 199 // 200 // This class is uniquely defined for each OS. It provides 201 // information that other components may require. 202 // For example, in Windows NT it contains a device object used by various 203 // memory management methods. 204 // Since static variables are used in place of globals, an instance must 205 // be constructed and initialized by the OS Interface object prior to 206 // constructing the CEchoGals derived object. The CEchoGals and 207 // CDspCommObject classes must have access to it during their respective 208 // construction times. 209 // 210 class COsSupport 211 { 212 public: 213 // 214 // Construction/destruction 215 // 216 COsSupport 217 ( 218 WORD wDeviceId, // PCI bus device id 219 WORD wCardRev // Hardware revision number 220 ); 221 222 ~COsSupport(); 223 224 // 225 // Timer Methods 226 // 227 228 // 229 // Return the system time in microseconds. 230 // Return error status if the OS doesn't support this function. 231 // 232 ECHOSTATUS OsGetSystemTime 233 ( 234 PULONGLONG pullTime 235 ); 236 237 238 // 239 // Stall execution for dwTime microseconds. 240 // Return error status if the OS doesn't support this function. 241 // 242 ECHOSTATUS OsSnooze 243 ( 244 DWORD dwTime // Duration in micro seconds 245 ); 246 247 248 // 249 // Memory Management Methods 250 // 251 252 // 253 // Allocate a block of physical memory pages 254 // 255 ECHOSTATUS AllocPhysPageBlock 256 ( 257 DWORD dwBytes, 258 PPAGE_BLOCK &pPageBlock 259 ); 260 261 // 262 // Free a block of physical memory 263 // 264 ECHOSTATUS FreePhysPageBlock 265 ( 266 DWORD dwBytes, 267 PPAGE_BLOCK pPageBlock 268 ); 269 270 // 271 // Get the virtual address for a page block 272 // 273 PVOID GetPageBlockVirtAddress 274 ( 275 PPAGE_BLOCK pPageBlock 276 ); 277 278 // 279 // Get the physical address for a segment of a page block 280 // 281 ECHOSTATUS GetPageBlockPhysSegment 282 ( 283 PPAGE_BLOCK pPageBlock, // pass in a previously allocated block 284 DWORD dwOffset, // pass in the offset into the block 285 PHYS_ADDR &PhysAddr, // returns the physical address 286 DWORD &dwSegmentSize // and the length of the segment 287 ); 288 289 290 // 291 // Add additional methods here 292 // 293 294 // 295 // Display and/or log an error message w/title 296 // 297 void EchoErrorMsg 298 ( 299 PCHAR pszMsg, 300 PCHAR pszTitle 301 ); 302 303 // 304 // Return PCI card device ID 305 // 306 WORD GetDeviceId() 307 { return( m_wDeviceId ); } 308 309 // 310 // Return the hardware revision number 311 // 312 WORD GetCardRev() 313 { 314 return m_wCardRev; 315 } 316 317 // 318 // Get the current timestamp for MIDI input data 319 // 320 LONGLONG GetMidiInTimestamp() 321 { 322 return system_time(); 323 } 324 325 // 326 // Overload new & delete so memory for this object is allocated 327 // from non-paged memory. 328 // 329 PVOID operator new( size_t Size ); 330 VOID operator delete( PVOID pVoid ); 331 332 protected: 333 334 private: 335 WORD m_wDeviceId; // PCI Device ID 336 WORD m_wCardRev; // Hardware revision 337 338 // 339 // Define data here. 340 // 341 #ifdef ECHO_DEBUG 342 DWORD m_dwPageBlockCount; 343 #endif 344 345 }; // class COsSupport 346 347 typedef COsSupport * PCOsSupport; 348 349 #endif // _ECHOOSSUPPORTBEOS_ 350