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