📄 ohcd.c
字号:
*pioPortBase = v_USBreg;
RETAILMSG(1,(TEXT("USB:*pIrq=%d, *pioPortBase=0x%X\r\n"),*pIrq, *pioPortBase));
return TRUE;
error_return:
if (v_USBreg)
VirtualFree((PVOID)v_USBreg, 0, MEM_RELEASE);
v_USBreg = 0;
return FALSE;
}
/* InitializeOHCI
*
* Configure and initialize OHCI card
*
* Return Value:
* Return TRUE if card could be located and configured, otherwise FALSE
*/
static BOOL
InitializeOHCI(
SOhcdPdd * pPddObject, // IN - Pointer to PDD structure
LPCWSTR szDriverRegKey) // IN - Pointer to active registry key string
{
DWORD dwUseExistingSettings;
PUCHAR ioPortBase = NULL;
DWORD dwSysIntr, dwIRQ;
BOOL fResult = FALSE;
LPVOID pobMem = NULL;
LPVOID pobOhcd = NULL;
RETAILMSG(1, (TEXT("++InitializeOHCI\r\n")));
#if 0 // LKY 2001.12, currently We don't use registry!
if (!GetRegistryConfig(&dwUseExistingSettings, &dwIRQ, (DWORD *)&ioPortBase)) {
RETAILMSG(1,(TEXT("!OHCD: Error reading registry settings\r\n")));
return FALSE;
}
RETAILMSG(1, (TEXT("OHCD: Read config from registry: Use existing: %u, IRQ: %u, I/O base: %X\r\n"),
dwUseExistingSettings,dwIRQ,ioPortBase));
#endif
fResult = ConfigureOHCICard(!!dwUseExistingSettings, &ioPortBase, &dwIRQ);
if (fResult)
{
// The "MapIrq2SysIntr()" makes the system IRQ value be mapped to the physical interrupt.
// This function is defined in the 'oalintr.h' in the directory 'INC'.
// The dwIRQ may be used a higher value than 10. The value 0 to 10 is alreay used.
// by hjcho. 04/16
// dwSysIntr = SYSINTR_USB = SYSINTR_FIRMWARE + dwIRQ
// dwIRQ = 11. I decided its value temporary.
// by hjcho 04/17
dwSysIntr = MapIrq2SysIntr(dwIRQ);
RETAILMSG(1,(TEXT("OHCD: MapIrq2SysIntr(%u): %u\r\n"),dwIRQ,dwSysIntr));
// The PDD can supply a buffer of contiguous physical memory here, or can let the
// MDD try to allocate the memory from system RAM. In our case, let the MDD do it.
pobMem = HcdMdd_CreateMemoryObject(gcTotalAvailablePhysicalMemory,
gcHighPriorityPhysicalMemory, NULL,NULL);
if(pobMem)
{
RETAILMSG(1,(TEXT("OHCD: Memory Object\r\n")));
pobOhcd = HcdMdd_CreateHcdObject(pPddObject, pobMem,
szDriverRegKey, ioPortBase, dwSysIntr);
fResult = pobOhcd ? TRUE : FALSE;
}
else
fResult = FALSE;
if (!fResult)
{
if (pobOhcd)
HcdMdd_DestroyHcdObject(pobOhcd);
if (pobMem)
HcdMdd_DestroyMemoryObject(pobMem);
pobOhcd = NULL;
pobMem = NULL;
RETAILMSG(1, (TEXT("--InitializeOHCI FAILED!!!\r\n")));
return fResult;
}
}
else
{
RETAILMSG(1, (TEXT("ConfigureOHCICard() FAILED!!!\r\n")));
return fResult;
}
pPddObject->lpvMemoryObject = pobMem;
pPddObject->lpvOhcdMddObject = pobOhcd;
RETAILMSG(1, (TEXT("--InitializeOHCI\r\n")));
return fResult;
}
/* OhcdPdd_Init
*
* PDD Entry point - called at system init to detect and configure OHCI 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.
{
SOhcdPdd * pPddObject = malloc(sizeof(SOhcdPdd));
BOOL fRet = FALSE;
RETAILMSG(1, (TEXT("USB:OhcdPdd_Init\r\n")));
fRet = InitializeOHCI(pPddObject, (LPCWSTR)dwContext);
if(!fRet)
{
free(pPddObject);
pPddObject = NULL;
}
return (DWORD)pPddObject;
}
/* OhcdPdd_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)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
HcdMdd_PowerUp(pPddObject->lpvOhcdMddObject);
return;
}
extern void HcdPdd_PowerDown(DWORD hDeviceContext)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
HcdMdd_PowerDown(pPddObject->lpvOhcdMddObject);
return;
}
extern BOOL HcdPdd_Deinit(DWORD hDeviceContext)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
if(pPddObject->lpvOhcdMddObject)
HcdMdd_DestroyHcdObject(pPddObject->lpvOhcdMddObject);
if(pPddObject->lpvMemoryObject)
HcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);
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;
}
extern void HcdPdd_InitiatePowerUp(void)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -