📄 system.c
字号:
WCHAR IsrDll[DEVDLL_LEN];
WCHAR IsrHandler[DEVENTRY_LEN];
DWORD Irq = -1;
BOOL fResult = FALSE;
LPVOID pobMem = NULL;
LPVOID pobUhcd = NULL;
DWORD PhysAddr;
if (!GetRegistryConfig(szDriverRegKey, &PhysAddr, &dwAddrLen, &dwIOSpace, &dwSysIntr, &IfcType, &dwBusNumber, &InstallIsr, IsrDll, IsrHandler, &Irq)) {
RETAILMSG(1,(TEXT("!UHCD: Error reading registry settings\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_INIT,(TEXT("UHCD: Read config from registry: Base Address: 0x%X, Length: 0x%X, I/O Port: %s, SysIntr: 0x%X, Interface Type: %u, Bus Number: %u\r\n"),
PhysAddr, dwAddrLen, dwIOSpace ? L"YES" : L"NO", dwSysIntr, IfcType, dwBusNumber));
ioPortBase = (PUCHAR)PhysAddr;
if (!(fResult = ConfigureUHCICard(&ioPortBase, dwAddrLen, dwIOSpace, IfcType, dwBusNumber))) {
goto InitializeUHCI_Error;
}
if (InstallIsr) {
// Install ISR handler
g_IsrHandle = LoadIntChainHandler(IsrDll, IsrHandler, (BYTE)Irq);
if (!g_IsrHandle) {
DEBUGMSG(ZONE_ERROR, (L"UHCD: Couldn't install ISR handler\r\n"));
} else {
GIISR_INFO Info;
PHYSICAL_ADDRESS PortAddress = {PhysAddr, 0};
DEBUGMSG(ZONE_INIT, (L"UHCD: Installed ISR handler, Dll = '%s', Handler = '%s', Irq = %d\r\n",
IsrDll, IsrHandler, Irq));
if (!TransBusAddrToStatic(IfcType, dwBusNumber, PortAddress, dwAddrLen, &dwIOSpace, &(PVOID)PhysAddr)) {
DEBUGMSG(ZONE_ERROR, (L"UHCD: Failed TransBusAddrToStatic\r\n"));
return FALSE;
}
// Set up ISR handler
Info.SysIntr = dwSysIntr;
Info.CheckPort = TRUE;
Info.PortIsIO = (dwIOSpace) ? TRUE : FALSE;
Info.UseMaskReg = TRUE;;
Info.PortAddr = PhysAddr + 0x2;
Info.PortSize = sizeof(WORD);
Info.MaskAddr = PhysAddr + 0x4;
if (!KernelLibIoControl(g_IsrHandle, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL)) {
DEBUGMSG(ZONE_ERROR, (L"UHCD: KernelLibIoControl call failed.\r\n"));
}
}
}
// The PDD can supply a buffer of contiguous physical memory here, or can let the
// MDD try to allocate the memory from system RAM. We will use the HalAllocateCommonBuffer()
// API to allocate the memory and bus controller physical addresses and pass this information
// into the MDD.
pPddObject->AdapterObject.ObjectSize = sizeof(DMA_ADAPTER_OBJECT);
pPddObject->AdapterObject.InterfaceType = IfcType;
pPddObject->AdapterObject.BusNumber = dwBusNumber;
if ((pPddObject->pvVirtualAddress = HalAllocateCommonBuffer(&pPddObject->AdapterObject, gcTotalAvailablePhysicalMemory, &pPddObject->LogicalAddress, FALSE)) == NULL) {
goto InitializeUHCI_Error;
}
if (!(pobMem = HcdMdd_CreateMemoryObject(gcTotalAvailablePhysicalMemory, gcHighPriorityPhysicalMemory, (PUCHAR) pPddObject->pvVirtualAddress, (PUCHAR) pPddObject->LogicalAddress.LowPart))) {
goto InitializeUHCI_Error;
}
if (!(pobUhcd = HcdMdd_CreateHcdObject(pPddObject, pobMem, szDriverRegKey, ioPortBase, dwSysIntr))) {
goto InitializeUHCI_Error;
}
pPddObject->lpvMemoryObject = pobMem;
pPddObject->lpvUhcdMddObject = pobUhcd;
_tcsncpy(pPddObject->szDriverRegKey, szDriverRegKey, MAX_PATH);
pPddObject->ioPortBase = ioPortBase;
pPddObject->dwSysIntr = dwSysIntr;
// PCI OHCI support suspend and resume
HcdMdd_SetCapability (pobUhcd, HCD_SUSPEND_RESUME );
return TRUE;
InitializeUHCI_Error:
if (g_IsrHandle) {
FreeIntChainHandler(g_IsrHandle);
g_IsrHandle = NULL;
}
if (pobUhcd)
HcdMdd_DestroyHcdObject(pobUhcd);
if (pobMem)
HcdMdd_DestroyMemoryObject(pobMem);
if(pPddObject->pvVirtualAddress)
HalFreeCommonBuffer(&pPddObject->AdapterObject, gcTotalAvailablePhysicalMemory, pPddObject->LogicalAddress, pPddObject->pvVirtualAddress, FALSE);
pPddObject->lpvMemoryObject = NULL;
pPddObject->lpvUhcdMddObject = NULL;
pPddObject->pvVirtualAddress = NULL;
return FALSE;
}
/* HcdPdd_Init
*
* PDD Entry point - called at system init to detect and configure UHCI card.
*
* Return Value:
* Return pointer to PDD specific data structure, or NULL if error.
*/
extern DWORD
HcdPdd_Init(
DWORD dwContext) // IN - Pointer to context value. For device.exe, this is a string
// indicating our active registry key.
{
SUhcdPdd * pPddObject = malloc(sizeof(SUhcdPdd));
BOOL fRet = FALSE;
if (pPddObject) {
pPddObject->pvVirtualAddress = NULL;
InitializeCriticalSection(&pPddObject->csPdd);
fRet = InitializeUHCI(pPddObject, (LPCWSTR)dwContext);
if(!fRet)
{
free(pPddObject);
pPddObject = NULL;
}
}
return (DWORD)pPddObject;
}
/* HcdPdd_CheckConfigPower
*
* Check power required by specific device configuration and return whether it
* can be supported on this platform. For CEPC, this is trivial, just limit to
* the 500mA requirement of USB. For battery powered devices, this could be
* more sophisticated, taking into account current battery status or other info.
*
* Return Value:
* Return TRUE if configuration can be supported, FALSE if not.
*/
extern BOOL HcdPdd_CheckConfigPower(
UCHAR bPort, // IN - Port number
DWORD dwCfgPower, // IN - Power required by configuration
DWORD dwTotalPower) // IN - Total power currently in use on port
{
return ((dwCfgPower + dwTotalPower) > 500) ? FALSE : TRUE;
}
extern void HcdPdd_PowerUp(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
HcdMdd_PowerUp(pPddObject->lpvUhcdMddObject);
return;
}
extern void HcdPdd_PowerDown(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
HcdMdd_PowerDown(pPddObject->lpvUhcdMddObject);
return;
}
extern BOOL HcdPdd_Deinit(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
if(pPddObject->lpvUhcdMddObject)
HcdMdd_DestroyHcdObject(pPddObject->lpvUhcdMddObject);
if(pPddObject->lpvMemoryObject)
HcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);
if(pPddObject->pvVirtualAddress)
HalFreeCommonBuffer(&pPddObject->AdapterObject, gcTotalAvailablePhysicalMemory, pPddObject->LogicalAddress, pPddObject->pvVirtualAddress, FALSE);
if (g_IsrHandle) {
FreeIntChainHandler(g_IsrHandle);
g_IsrHandle = NULL;
}
return TRUE;
}
extern DWORD HcdPdd_Open(DWORD hDeviceContext, DWORD AccessCode,
DWORD ShareMode)
{
UnusedParameter(hDeviceContext);
UnusedParameter(AccessCode);
UnusedParameter(ShareMode);
return 1; // we can be opened, but only once!
}
extern BOOL HcdPdd_Close(DWORD hOpenContext)
{
UnusedParameter(hOpenContext);
return TRUE;
}
extern DWORD HcdPdd_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
UnusedParameter(hOpenContext);
UnusedParameter(pBuffer);
UnusedParameter(Count);
return (DWORD)-1; // an error occured
}
extern DWORD HcdPdd_Write(DWORD hOpenContext, LPCVOID pSourceBytes,
DWORD NumberOfBytes)
{
UnusedParameter(hOpenContext);
UnusedParameter(pSourceBytes);
UnusedParameter(NumberOfBytes);
return (DWORD)-1;
}
extern DWORD HcdPdd_Seek(DWORD hOpenContext, LONG Amount, DWORD Type)
{
UnusedParameter(hOpenContext);
UnusedParameter(Amount);
UnusedParameter(Type);
return (DWORD)-1;
}
extern BOOL HcdPdd_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
UnusedParameter(hOpenContext);
UnusedParameter(dwCode);
UnusedParameter(pBufIn);
UnusedParameter(dwLenIn);
UnusedParameter(pBufOut);
UnusedParameter(dwLenOut);
UnusedParameter(pdwActualOut);
return FALSE;
}
// Manage WinCE suspend/resume events
// This gets called by the MDD's IST when it detects a power resume.
// By default it has nothing to do.
extern void HcdPdd_InitiatePowerUp (DWORD hDeviceContext)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -