xref: /haiku/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h (revision 81f5654c124bf46fba0fd251f208e2d88d81e1ce)
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 #include <KernelExport.h>
54 #include <SupportDefs.h>
55 #include <ByteOrder.h>
56 #include "debug.h"
57 
58 #include <stdio.h>
59 #include <string.h>
60 #include "util/kernel_cpp.h"
61 
62 #if DEBUG > 0
63 // BeOS debug printf macro
64 #define ECHO_DEBUGPRINTF( strings ) TRACE(strings)
65 #define ECHO_DEBUGBREAK()			kernel_debugger("echo driver debug break");
66 #define ECHO_DEBUG
67 
68 #else
69 
70 #define ECHO_DEBUGPRINTF( strings )
71 #define ECHO_DEBUGBREAK()
72 
73 #endif
74 
75 //
76 //	Specify OS specific types
77 //
78 typedef void **			PPVOID;
79 typedef int8			INT8;
80 typedef int32			INT32;
81 typedef uint16			WORD;
82 typedef uint16 *		PWORD;
83 typedef uint32			DWORD;
84 typedef uint32 *		PDWORD;
85 typedef void *			PVOID;
86 #define VOID			void
87 typedef int8			BYTE;
88 typedef int8 *			PBYTE;
89 typedef unsigned long	ULONG;
90 typedef signed long long		LONGLONG;
91 typedef unsigned long long		ULONGLONG;
92 typedef unsigned long long *	PULONGLONG;
93 typedef char			CHAR;
94 typedef char *			PCHAR;
95 typedef	bool			BOOL;
96 typedef bool			BOOLEAN;
97 #define CONST			const
98 
99 #define PAGE_SIZE		B_PAGE_SIZE
100 
101 //
102 // Return Status Values
103 //
104 typedef unsigned long	ECHOSTATUS;
105 
106 
107 //
108 //	Define generic byte swapping functions
109 //
110 #define SWAP(x)	B_HOST_TO_LENDIAN_INT32(x)
111 
112 //
113 //	Define what a physical address is on this OS
114 //
115 typedef	uint32		PHYS_ADDR;			// Define physical addr type
116 typedef	uint32 *	PPHYS_ADDR;		// Define physical addr pointer type
117 
118 //
119 //	Global Memory Management Functions
120 //
121 
122 //
123 // This tag is used to mark all memory allocated by EchoGals.
124 //	Due to the way PoolMon displays things, we spell Echo backwards
125 //	so it displays correctly.
126 //
127 #define ECHO_POOL_TAG      'OHCE'
128 
129 
130 //
131 // OsAllocateInit - Set up memory tracking.  Call this once - not
132 // once per PCI card, just one time.
133 //
134 void OsAllocateInit();
135 
136 //
137 // Allocate locked, non-pageable block of memory.  Does not have to be
138 //	physically contiguous.  Primarily used to implement the overloaded
139 //	new operator for classes that must remain memory resident.
140 //
141 ECHOSTATUS OsAllocateNonPaged
142 (
143     DWORD	dwByteCt,
144     PPVOID	ppMemAddr
145 );
146 
147 
148 //
149 // Unlock and free, non-pageable block of memory.
150 //
151 ECHOSTATUS OsFreeNonPaged
152 (
153     PVOID	pMemAddr
154 );
155 
156 
157 //
158 // Copy memory
159 //
160 #define OsCopyMemory(pDest,pSrc,dwBytes) 	memcpy(pDest,pSrc,dwBytes)
161 
162 //
163 // Set memory to zero
164 //
165 #define OsZeroMemory(pDest,dwBytes)			memset(pDest,0,dwBytes)
166 
167 
168 //
169 // This class is uniquely defined for each OS.  It provides
170 //	information that other components may require.
171 // For example, in Windows NT it contains a device object used by various
172 //	memory management methods.
173 // Since static variables are used in place of globals, an instance must
174 //	be constructed and initialized by the OS Interface object prior to
175 //	constructing the CEchoGals derived object.  The CEchoGals and
176 //	CDspCommObject classes must have access to it during their respective
177 // construction times.
178 //
179 class COsSupport
180 {
181 public:
182 	//
183 	//	Construction/destruction
184 	//
185 	COsSupport
186 	(
187 		DWORD				dwDeviceId		// PCI bus device id
188 	);
189 
190 	~COsSupport();
191 
192 	//
193 	//	Timer Methods
194 	//
195 
196 	//
197 	// Return the system time in microseconds.
198 	// Return error status if the OS doesn't support this function.
199 	//
200 	ECHOSTATUS OsGetSystemTime
201 	(
202 		PULONGLONG	pullTime
203 	);
204 
205 
206 	//
207 	//	Stall execution for dwTime microseconds.
208 	// Return error status if the OS doesn't support this function.
209 	//
210 	ECHOSTATUS OsSnooze
211 	(
212 		DWORD	dwTime
213 	);
214 
215 
216 	//
217 	//	Memory Management Methods
218 	//
219 
220 	//
221 	// Allocate locked, non-pageable, physically contiguous memory pages
222 	//	in the drivers address space.  Used to allocate memory for the DSP
223 	//	communications area and Ducks.
224 	//
225 	ECHOSTATUS OsPageAllocate
226 	(
227 		DWORD			dwPageCt,				// How many pages to allocate
228 		PPVOID		ppPageAddr,				// Where to return the memory ptr
229 		PPHYS_ADDR	pPhysicalPageAddr		// Where to return the physical PCI addr
230 	);
231 
232 	//
233 	// Unlock and free non-pageable, physically contiguous memory pages
234 	//	in the drivers address space.
235 	// Used to free memory for the DSP communications area and Ducks.
236 	//
237 	ECHOSTATUS OsPageFree
238 	(
239 		DWORD			dwPageCt,				// How many pages to free
240 		PVOID			pPageAddr,				// Virtual memory ptr
241 		PHYS_ADDR	PhysicalPageAddr		// Physical PCI addr
242 	);
243 
244 	//
245 	// Add additional methods here
246 	//
247 
248 	//
249 	//	Display and/or log an error message w/title
250 	//
251 	void EchoErrorMsg
252 	(
253 		PCHAR pszMsg,
254 		PCHAR pszTitle
255 	);
256 
257 	//
258 	//	Return PCI card device ID
259 	//
260 	DWORD GetDeviceId()
261 		{ return( m_dwDeviceId ); }
262 
263 	//
264 	//	Overload new & delete so memory for this object is allocated
265 	//	from non-paged memory.
266 	//
267 	PVOID	operator new( size_t Size );
268 	VOID	operator delete( PVOID pVoid );
269 
270 protected:
271 
272 private:
273 	DWORD					m_dwDeviceId;		// PCI Device ID
274 
275 	//
276 	// Define data here.
277 	//
278 
279 	//KIRQL					m_IrqlCurrent;		// Old IRQ level
280 	bigtime_t			m_ullStartTime;	// All system time relative to this time
281 	class CPtrQueue *	m_pPtrQue;			// Store read only ptrs so they
282 													// can be unmapped
283 
284 };		// class COsSupport
285 
286 typedef COsSupport * PCOsSupport;
287 
288 #endif // _ECHOOSSUPPORTBEOS_
289