📄 ohcd.c
字号:
DEBUGMSG(ZONE_ERROR,
(TEXT("OHCD: Error, can't find USB Controller\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_PCI,
(TEXT("OHCD: Revision Stepping value = 0x%02X\r\n"),
pciConfig.RevisionID));
// The bottom bit is 1 for the "Resource Type Indicator (RTE)" but we don't
// want that set.
portBase = pciConfig.u.type0.BaseAddresses[0] & ~0x1;
ioPhysicalBase.LowPart = portBase;
if (HalTranslateBusAddress(PCIBus, bus, ioPhysicalBase, &inIoSpace,
&ioPhysicalBase)) {
if (!inIoSpace) {
if ((*pioPortBase = (PUCHAR)MmMapIoSpace(ioPhysicalBase,
portRange, FALSE)) == NULL) {
// We may as well not continue
DEBUGMSG(ZONE_INIT | ZONE_ERROR,
(TEXT("OHCD: Error mapping I/O Ports.\r\n")));
return FALSE;
}
} else {
*pioPortBase = (PUCHAR)ioPhysicalBase.LowPart;
}
} else {
DEBUGMSG(ZONE_INIT | ZONE_ERROR,
(TEXT("OHCD: Error translating I/O Ports.\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_PCI,
(TEXT("OHCD: ioPhysicalBase 0x%X, IoSpace 0x%X\r\n"),
ioPhysicalBase.LowPart, inIoSpace));
DEBUGMSG(ZONE_PCI,
(TEXT("OHCD: ioPortBase 0x%X, portBase 0x%X\r\n"),
*pioPortBase, portBase));
return TRUE;
}
/* 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;
DWORD t;
if (!GetRegistryConfig(&dwUseExistingSettings, &dwIRQ, (DWORD *)&ioPortBase)) {
RETAILMSG(1,(TEXT("!OHCD: Error reading registry settings\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_INIT,(TEXT("OHCD: Read config from registry: Use existing: %u, IRQ: %u, I/O base: %X\r\n"),
dwUseExistingSettings,dwIRQ,ioPortBase));
fResult = ConfigureOHCICard(!!dwUseExistingSettings,&ioPortBase, &dwIRQ);
if(fResult)
{
// HcRhDescriptorA configuration
t = *(volatile unsigned long *)(ioPortBase+0x48);
t &= 0x00FFFFFF;
t |= 1 << 24;
*(volatile unsigned long *)(ioPortBase+0x48) = t;
dwSysIntr = dwIRQ;
// 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 = OhcdMdd_CreateMemoryObject(gcTotalAvailablePhysicalMemory,
gcHighPriorityPhysicalMemory, NULL,NULL);
if(pobMem)
{
pobOhcd = OhcdMdd_CreateOhcdObject(pPddObject, pobMem,
szDriverRegKey, ioPortBase, dwSysIntr);
fResult = pobOhcd ? TRUE : FALSE;
}
else
fResult = FALSE;
if(!fResult)
{
if(pobOhcd)
OhcdMdd_DestroyOhcdObject(pobOhcd);
if(pobMem)
OhcdMdd_DestroyMemoryObject(pobMem);
pobOhcd = NULL;
pobMem = NULL;
}
}
pPddObject->lpvMemoryObject = pobMem;
pPddObject->lpvOhcdMddObject = pobOhcd;
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
OhcdPdd_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;
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 OhcdPdd_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 OhcdPdd_PowerUp(DWORD hDeviceContext)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
OhcdMdd_PowerUp(pPddObject->lpvOhcdMddObject);
return;
}
extern void OhcdPdd_PowerDown(DWORD hDeviceContext)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
OhcdMdd_PowerDown(pPddObject->lpvOhcdMddObject);
return;
}
extern BOOL OhcdPdd_Deinit(DWORD hDeviceContext)
{
SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
if(pPddObject->lpvOhcdMddObject)
OhcdMdd_DestroyOhcdObject(pPddObject->lpvOhcdMddObject);
if(pPddObject->lpvMemoryObject)
OhcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);
return TRUE;
}
extern DWORD OhcdPdd_Open(DWORD hDeviceContext, DWORD AccessCode,
DWORD ShareMode)
{
UnusedParameter(hDeviceContext);
UnusedParameter(AccessCode);
UnusedParameter(ShareMode);
return 1; // we can be opened, but only once!
}
extern BOOL OhcdPdd_Close(DWORD hOpenContext)
{
UnusedParameter(hOpenContext);
return TRUE;
}
extern DWORD OhcdPdd_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
UnusedParameter(hOpenContext);
UnusedParameter(pBuffer);
UnusedParameter(Count);
return (DWORD)-1; // an error occured
}
extern DWORD OhcdPdd_Write(DWORD hOpenContext, LPCVOID pSourceBytes,
DWORD NumberOfBytes)
{
UnusedParameter(hOpenContext);
UnusedParameter(pSourceBytes);
UnusedParameter(NumberOfBytes);
return (DWORD)-1;
}
extern DWORD OhcdPdd_Seek(DWORD hOpenContext, LONG Amount, DWORD Type)
{
UnusedParameter(hOpenContext);
UnusedParameter(Amount);
UnusedParameter(Type);
return (DWORD)-1;
}
extern BOOL OhcdPdd_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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -