?? osal.c
字號:
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1997 by Philips Semiconductors
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor.
PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/
/*
HISTORY
960510 Tilakraj Roy Created
961019 Tilakraj Roy Moved the CTC 1.1 bug fix in IRQGen from IRQAck.
970521 Tilakraj Roy Rewrote for Generic Target TMMan
980604 Volker Schildwach Ported to Windows CE
981021 Tilakraj Roy Changes for integrating into common source base
*/
/*----------------------------------------------------------------------------
SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
#include <windows.h>
#include "ceddk.h"
#include "stdlib.h"
/*----------------------------------------------------------------------------
DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmmanapi.h"
#include "tmmanlib.h"
#include "platform.h"
/* Synchronization Object Abstraction Functions */
typedef struct tagSynchronizationObject
{
UInt32 UserModeHandle;
UInt32 KernelModeHandle;
UInt32 SynchronizationFlags;
} SynchronizationObject;
Bool syncobjCreate (
UInt32 SynchronizationFlags,
UInt32 OSSynchronizationHandle,
UInt32 *SynchronizationHandlePointer,
Int8* Name )
{
ULONG Idx;
HANDLE hEvent;
WCHAR UnicodeString[constTMManNameSpaceNameLength + 1];
// we have to find all the '\' in the string and ignore those.
// so we doa reverse scan for back slashes.
for( Idx = ( strlen ( Name ) + 1 ); Idx > 0 ; Idx -- )
{
if ( Name [Idx-1] =='\\' )
break;
}
//BUGBUG: we have to alllocate one character more than necessary and zero it out
// WINCE UNICODE bug!
MultiByteToWideChar( CP_ACP, // code page
MB_PRECOMPOSED, // character-type options
( Name + Idx ) , // address of string to map
-1, // number of bytes in string
UnicodeString, // address of wide-character buffer
(constTMManNameSpaceNameLength + 1) * 2 );// size of buffer);
if ( ( hEvent = CreateEvent( NULL, FALSE, FALSE, UnicodeString ) ) == NULL )
{
DPF (0,("Osal:syncobjCreate:CreateEvent:FAIL[%x]\n",GetLastError() ));
return False;
}
*SynchronizationHandlePointer = (UInt32)hEvent;
return True;
}
Bool syncobjSignal (
UInt32 SynchronizationHandle )
{
return SetEvent((HANDLE)SynchronizationHandle );
}
Bool syncobjDestroy (
UInt32 SynchronizationHandle )
{
return CloseHandle((HANDLE)SynchronizationHandle);
}
Bool critsectCreate (
UInt32* CriticalSectionObjectPointer )
{
CRITICAL_SECTION * pCriticalSection;
pCriticalSection = (CRITICAL_SECTION *)memAllocate(sizeof(CRITICAL_SECTION) );
if ( ! pCriticalSection )
return False;
InitializeCriticalSection(pCriticalSection);
*CriticalSectionObjectPointer = (UInt32)pCriticalSection;
return True;
}
Bool critsectDestroy (
UInt32 CriticalSectionObject )
{
memFree ( (Pointer) CriticalSectionObject );
return True;
}
/* Note that the caller has to allocate storage
sizeof (UInt32) for nested context and pass the address
of that parameter to this function.
*/
Bool critsectEnter (
UInt32 CriticalSectionObject, Pointer NestedContext )
{
EnterCriticalSection(( CRITICAL_SECTION *)CriticalSectionObject);
return True;
}
Bool critsectLeave (
UInt32 CriticalSectionObject, Pointer NestedContext )
{
LeaveCriticalSection(( CRITICAL_SECTION *)CriticalSectionObject);
return True;
}
Pointer clientGetObjectFromProcess ( UInt32 Process )
{
UInt32 ClientIdx;
for ( ClientIdx = 0 ; ClientIdx < TMManGlobal->MaximumClients ; ClientIdx ++ )
{
if ( !TMManGlobal->ClientList[ClientIdx] )
continue;
if ( ((ClientObject*)TMManGlobal->ClientList[ClientIdx])->Process != Process )
continue;
break;
}
if ( ClientIdx == TMManGlobal->MaximumClients )
{
return Null;
}
return (Pointer)TMManGlobal->ClientList[ClientIdx];
}
Pointer clientGetDeviceObjectFromClient ( Pointer Client, UInt32 DSPNumber )
{
return NULL;
}
typedef struct tagPageTableObject
{
PVOID BufferAddress;
UInt32 BufferSize;
} PageTableObject;
UInt32 pagetableGetTempBufferSize (
UInt32 BufferAddress, UInt32 BufferSize )
{
return ADDRESS_AND_SIZE_TO_SPAN_PAGES ( BufferAddress, BufferSize ) * sizeof(PageTableEntry);
}
Bool pagetableCreate (
UInt32 BufferAddress,
UInt32 BufferSize,
Pointer TempBuffer,
UInt32 HalHandle,
PageTableEntry **PageTablePointer,
UInt32 *PageTableEntryCountPointer,
UInt32 *PageTableHandlePointer )
{
// I think we need some documentation here:
// Parameter description:
// BufferAddress : virtual address tp pre-allocated non-cached memory
// BufferSize : size of buffer in bytes
// TempBuffer : pre-allocated temporary buffer for page table entries
// HalHandle : hal handle
// PageTablePointer : returns ptr to array of the page table struct
// PageTableEntryCountPointer : returns number of contiguous regions (length of array)
// PageTableHandlePointer : returns identifier for this page table (used for deletion)
DWORD dwActualOut = 0;
DWORD* pPageBuffer = NULL;
DWORD dwPageBufferSize = 0;
DWORD dwPageTableEntries = 0;
DWORD i = 0;
DWORD dwContCount = 0;
PageTableObject* pPageTableObj ;
// get required size for page buffer
if (KernelIoControl(
( TMManGlobal->OEMIOCTLBase + TMM_IOCTL_SYSMEM_PAGE_LOCK_OFFSET ),
NULL,
BufferSize,
NULL,
0,
&dwPageBufferSize) == FALSE)
{
DPF (0,("Osal:pagetableCreate:KernelIoControl FAILED\n"));
goto pagetableCreateExit1;
}
pPageBuffer = (DWORD*)memAllocate (dwPageBufferSize);
// lock pages and get list of physical adresses
if (KernelIoControl(
( TMManGlobal->OEMIOCTLBase + TMM_IOCTL_SYSMEM_PAGE_LOCK_OFFSET ),
(void*)BufferAddress,
BufferSize,
pPageBuffer,
dwPageBufferSize,
&dwActualOut) == FALSE)
{
DPF (0,("Osal:pagetableCreate:KernelIoControl FAILED\n"));
goto pagetableCreateExit2;
}
// fill structures:
dwPageTableEntries = dwActualOut / sizeof(DWORD);
// thereby combine physical contigous regions
((PageTableEntry*)TempBuffer)[0].PhysicalAddress = pPageBuffer[0];
((PageTableEntry*)TempBuffer)[0].RunLength = PAGE_SIZE;
DPF(8,("Osal:pagetableCreate: Entri[0]= %x\n",pPageBuffer[0]));
for (i=1; i < dwPageTableEntries; i++)
{
DPF(8,("Osal:pagetableCreate: Entri[%d]= %x\n",i,pPageBuffer[i]));
if (pPageBuffer[i] == (pPageBuffer[i-1] + PAGE_SIZE))
{
// increase size of contiguous region
((PageTableEntry*)TempBuffer)[dwContCount].RunLength += PAGE_SIZE;
}
else
{
// start next contiguous region:
dwContCount++;
((PageTableEntry*)TempBuffer)[dwContCount].RunLength = PAGE_SIZE;
((PageTableEntry*)TempBuffer)[dwContCount].PhysicalAddress = pPageBuffer[i];
}
}
DPF(8,("Osal:pagetableCreate: dwContCount = %d\n",dwContCount));
DPF(8,("Osal:pagetableCreate: dwPageTableEntries = %d\n",dwPageTableEntries));
// allocate page table object handle
pPageTableObj = (PageTableObject*)memAllocate(sizeof(PageTableObject));
pPageTableObj->BufferAddress = (PVOID)BufferAddress;
pPageTableObj->BufferSize = BufferSize;
// set return values:
*PageTablePointer = TempBuffer,
*PageTableEntryCountPointer = dwContCount+1,
*PageTableHandlePointer = (UInt32)pPageTableObj;
memFree(pPageBuffer);
return TRUE;
pagetableCreateExit2:
memFree(pPageBuffer);
pagetableCreateExit1:
return FALSE;
}
Bool pagetableDestroy (
UInt32 PageTableHandle )
{
DWORD dwActualOut = 0;
PageTableObject *PageTableObj = (PageTableObject*)PageTableHandle;
BOOL bRet = FALSE;
bRet= KernelIoControl(
( TMManGlobal->OEMIOCTLBase + TMM_IOCTL_SYSMEM_PAGE_UNLOCK_OFFSET ),
PageTableObj->BufferAddress,
PageTableObj->BufferSize,
NULL,
0,
&dwActualOut);
memFree(PageTableObj);
return bRet;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -