1 // ****************************************************************************
5 // Implementation file for BeOS support services to the CEchoGals
6 // generic driver class
7 // Set editor tabs to 3 for your viewing pleasure.
9 // ----------------------------------------------------------------------------
11 // This file is part of Echo Digital Audio's generic driver library.
12 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
13 // All rights reserved
16 // This library is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU Lesser General Public
18 // License as published by the Free Software Foundation; either
19 // version 2.1 of the License, or (at your option) any later version.
21 // This library is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 // Lesser General Public License for more details.
26 // You should have received a copy of the GNU Lesser General Public
27 // License along with this library; if not, write to the Free Software
28 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 // ****************************************************************************
32 #include "OsSupportBeOS.h"
34 #include "EchoGalsXface.h"
36 #include <KernelExport.h>
40 // Version information.
41 // In NT, we want to get this from a resource
45 // Use EngFindResource, for now hard code
47 } // BYTE OsGetVersion()
51 // Use EngFindResource, for now hard code
53 } // BYTE OsGetRevision()
57 // Use EngFindResource, for now hard code
59 } // BYTE OsGetRelease()
62 // Global Memory Management Functions
64 DWORD gAllocNonPagedCount
= 0;
66 LIST_HEAD(mems
, _echo_mem
) mems
;
70 echo_mem_new(size_t size
)
74 if ((mem
= (echo_mem
*)malloc(sizeof(*mem
))) == NULL
)
77 mem
->area
= alloc_mem(&mem
->phy_base
, &mem
->log_base
, size
, "echo buffer");
79 if (mem
->area
< B_OK
) {
87 echo_mem_delete(echo_mem
*mem
)
90 delete_area(mem
->area
);
95 echo_mem_alloc(size_t size
)
99 mem
= echo_mem_new(size
);
103 LIST_INSERT_HEAD(&mems
, mem
, next
);
109 echo_mem_free(void *ptr
)
111 echo_mem
*mem
= NULL
;
113 LIST_FOREACH(mem
, &mems
, next
) {
114 if (mem
->log_base
!= ptr
)
116 LIST_REMOVE(mem
, next
);
118 echo_mem_delete(mem
);
123 void OsAllocateInit()
125 gAllocNonPagedCount
= 0;
131 // ***********************************************************************
133 // Allocate locked, non-pageable block of memory. Does not have to be
134 // physically contiguous. Primarily used to implement the overloaded
137 // ***********************************************************************
139 ECHOSTATUS OsAllocateNonPaged
141 DWORD dwByteCt
, // Block size in bytes
142 PPVOID ppMemAddr
// Where to return memory ptr
147 echo_mem
* mem
= echo_mem_alloc( dwByteCt
);
149 *ppMemAddr
= mem
->log_base
;
151 if ( NULL
== *ppMemAddr
)
153 ECHO_DEBUGPRINTF( ("OsAllocateNonPaged : Failed on %ld bytes\n",
156 return ECHOSTATUS_NO_MEM
;
159 OsZeroMemory( *ppMemAddr
, dwByteCt
);
161 gAllocNonPagedCount
++;
162 ECHO_DEBUGPRINTF(("gAllocNonPagedCount %ld\n",gAllocNonPagedCount
));
164 return ECHOSTATUS_OK
;
166 } // ECHOSTATUS OsAllocateNonPaged
169 // ***********************************************************************
171 // Unlock and free, non-pageable block of memory.
173 // ***********************************************************************
174 ECHOSTATUS OsFreeNonPaged
179 echo_mem_free( pMemAddr
);
181 gAllocNonPagedCount
--;
182 ECHO_DEBUGPRINTF(("gAllocNonPagedCount %ld\n",gAllocNonPagedCount
));
184 return ECHOSTATUS_OK
;
186 } // ECHOSTATUS OsFreeNonPaged
190 // ***********************************************************************
192 // This class is optional and uniquely defined for each OS. It provides
193 // information that other components may require.
194 // For example, in Windows NT it contains a device object used by various
195 // memory management methods.
196 // Since static variables are used in place of globals, an instance must
197 // be constructed and initialized by the OS Interface object prior to
198 // constructing the CEchoGals derived object. The CEchoGals and
199 // CDspCommObject classes must have access to it during their respective
200 // construction times.
202 // ***********************************************************************
204 COsSupport::COsSupport
206 WORD wDeviceId
, // PCI bus device ID
207 WORD wCardRev
// Card revision number
210 ECHO_DEBUGPRINTF(("COsSupport::COsSupport born, device id = 0x%x.\n", wDeviceId
));
212 m_wDeviceId
= wDeviceId
;
213 m_wCardRev
= wCardRev
;
216 COsSupport::~COsSupport()
218 ECHO_DEBUGPRINTF(("COsSupport is all gone - m_dwPageBlockCount %ld\n",m_dwPageBlockCount
));
225 ECHOSTATUS
COsSupport::OsGetSystemTime
227 PULONGLONG pullTime
// Where to return system time
230 *pullTime
= ULONGLONG(system_time());
232 return ECHOSTATUS_OK
;
234 } // ECHOSTATUS COsSupport::OsGetSystemTime
237 ECHOSTATUS
COsSupport::OsSnooze
239 DWORD dwTime
// Duration in micro seconds
243 status
= snooze(bigtime_t(dwTime
));
246 return ECHOSTATUS_OK
;
249 return ECHOSTATUS_OPERATION_CANCELED
; // maybe not appropriate, but anyway
252 return ECHOSTATUS_NOT_SUPPORTED
; // no generic error?
259 // Memory Management Methods
262 //---------------------------------------------------------------------------
264 // Allocate a physical page block that can be used for DSP bus mastering.
266 //---------------------------------------------------------------------------
268 ECHOSTATUS
COsSupport::AllocPhysPageBlock
271 PPAGE_BLOCK
&pPageBlock
274 DWORD dwRoundedBytes
;
279 dwRoundedBytes
= (dwBytes
+ (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
280 ECHO_DEBUGPRINTF(("COsSupport::AllocPhysPageBlock - dwBytes %ld dwRoundedBytes %ld\n",
281 dwBytes
,dwRoundedBytes
));
283 pPageBlock
= echo_mem_alloc ( dwRoundedBytes
);
285 if (NULL
== pPageBlock
)
287 ECHO_DEBUGPRINTF(("AllocPhysPageBlock failed for %ld bytes\n",dwBytes
));
290 return ECHOSTATUS_NO_MEM
;
293 ECHO_DEBUGPRINTF(("\tIOBufferMemoryDescriptor is OK\n"));
295 OsZeroMemory( pPageBlock
->log_base
, dwRoundedBytes
);
298 m_dwPageBlockCount
++;
299 ECHO_DEBUGPRINTF(("\tm_dwPageBlockCount %ld\n",m_dwPageBlockCount
));
302 return ECHOSTATUS_OK
;
307 //---------------------------------------------------------------------------
309 // Free a physical page block
311 //---------------------------------------------------------------------------
313 ECHOSTATUS
COsSupport::FreePhysPageBlock
316 PPAGE_BLOCK pPageBlock
319 echo_mem_free(pPageBlock
->log_base
);
322 m_dwPageBlockCount
--;
323 ECHO_DEBUGPRINTF(("\tm_dwPageBlockCount %ld\n",m_dwPageBlockCount
));
326 return ECHOSTATUS_OK
;
331 //---------------------------------------------------------------------------
333 // Get the virtual address for the buffer corresponding to the MDL
335 //---------------------------------------------------------------------------
337 PVOID
COsSupport::GetPageBlockVirtAddress
339 PPAGE_BLOCK pPageBlock
343 return pPageBlock
->log_base
;
345 } // GetPageBlockVirtAddress
348 //---------------------------------------------------------------------------
350 // Get the physical address for part of the buffer corresponding to the MDL
352 //---------------------------------------------------------------------------
354 ECHOSTATUS
COsSupport::GetPageBlockPhysSegment
356 PPAGE_BLOCK pPageBlock
, // pass in a previously allocated block
357 DWORD dwOffset
, // pass in the offset into the block
358 PHYS_ADDR
&PhysAddr
, // returns the physical address
359 DWORD
&dwSegmentSize
// and the length of the segment
363 PhysAddr
= ((PHYS_ADDR
)pPageBlock
->phy_base
+ dwOffset
);
365 return ECHOSTATUS_OK
;
367 } // GetPageBlockPhysSegment
371 // Add additional methods here
375 // Display an error message w/title
377 void COsSupport::EchoErrorMsg(PCHAR pszMsg
, PCHAR pszTitle
)
381 PVOID
COsSupport::operator new(size_t size
)
385 pMemory
= malloc(size
);
387 if ( NULL
== pMemory
)
389 ECHO_DEBUGPRINTF(("COsSupport::operator new - memory allocation failed\n"));
395 memset( pMemory
, 0, size
);
401 VOID
COsSupport::operator delete(PVOID memory
)