📄 uhcd.c
字号:
// will end in 01. Page 348 shows that for memory mapping,
// the register ends in 0.
#if 1
// so far, the only UHCI controller I've tested is the PIIX4, which
// is I/O mapped.
DEBUGCHK( pciConfig.VendorID == UHCD_VENDOR_ID_INTEL &&
pciConfig.DeviceID == UHCD_DEVICE_ID_PIIX4 );
// check for I/O mapping (see comment above)
DEBUGCHK( (((DWORD)*pioPortBase) & ~PCI_ADDRESS_IO_ADDRESS_MASK) == PCI_ADDRESS_IO_SPACE );
*pioPortBase = (PUCHAR)( ((DWORD)*pioPortBase) & PCI_ADDRESS_IO_ADDRESS_MASK );
DEBUGMSG(ZONE_INIT, (TEXT("UHCD: Using I/O Mapping. ioPortBase = 0x%X\n"), *pioPortBase));
#else
if ( ((DWORD)*pioPortBase) & 0x1 ) {
DEBUGCHK( (((DWORD)*pioPortBase) & (1 << 1) ) == 0 );
*pioPortBase = (PUCHAR)(((DWORD)*pioPortBase) ^ 0x1);
DEBUGMSG(ZONE_INIT, (TEXT("UHCD: Using I/O Mapping. ioPortBase = 0x%X\n"), *pioPortBase));
} else {
// Memory mapped
ULONG portBase;
PHYSICAL_ADDRESS ioPhysicalBase;
ULONG inIoSpace = 0;
ULONG portRange = 0x70; // cDefaultUhcdPortRange;
// So far, we haven't seen any memory mapped UHCI controllers
DEBUGCHK( FALSE );
// The bottom bit is 0 for memory-mapped
DEBUGCHK( !(pciConfig.u.type0.BaseAddresses[ UHCD_PIIX4_ADDRESS_REG ] & 0x1) );
portBase = pciConfig.u.type0.BaseAddresses[ UHCD_PIIX4_ADDRESS_REG ];
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_ERROR, (TEXT("UHCD: Error mapping I/O Ports.\r\n")));
return FALSE;
}
} else {
*pioPortBase = (PUCHAR)ioPhysicalBase.LowPart;
}
} else {
DEBUGMSG(ZONE_ERROR, (TEXT("UHCD: Error translating I/O Ports.\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_INIT,
(TEXT("UHCD: ioPhysicalBase 0x%X, IoSpace 0x%X\r\n"),
ioPhysicalBase.LowPart, inIoSpace));
DEBUGMSG(ZONE_INIT,
(TEXT("UHCD: ioPortBase 0x%X, portBase 0x%X\r\n"),
*pioPortBase, portBase));
}
#endif
return TRUE;
}
/* InitializeUHCI
*
* Configure and initialize UHCI card
*
* Return Value:
* Return TRUE if card could be located and configured, otherwise FALSE
*/
static BOOL
InitializeUHCI(
SUhcdPdd * 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 pobUhcd = NULL;
if (!GetRegistryConfig(&dwUseExistingSettings, &dwIRQ, (DWORD *)&ioPortBase)) {
RETAILMSG(1,(TEXT("!UHCD: Error reading registry settings\r\n")));
return FALSE;
}
DEBUGMSG(ZONE_INIT,(TEXT("UHCD: Read config from registry: Use existing: %u, IRQ: %u, I/O base: %X\r\n"),
dwUseExistingSettings,dwIRQ,ioPortBase));
fResult = ConfigureUHCICard(!!dwUseExistingSettings,&ioPortBase, &dwIRQ);
if(fResult)
{
dwSysIntr = MapIrq2SysIntr(dwIRQ);
DEBUGMSG(ZONE_INIT,(TEXT("UHCD: 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 = UhcdMdd_CreateMemoryObject(gcTotalAvailablePhysicalMemory,
gcHighPriorityPhysicalMemory, NULL,NULL);
if(pobMem)
{
pobUhcd = UhcdMdd_CreateUhcdObject(pPddObject, pobMem,
szDriverRegKey, ioPortBase, dwSysIntr);
fResult = pobUhcd ? TRUE : FALSE;
}
else
fResult = FALSE;
if(!fResult)
{
if(pobUhcd)
UhcdMdd_DestroyUhcdObject(pobUhcd);
if(pobMem)
UhcdMdd_DestroyMemoryObject(pobMem);
pobUhcd = NULL;
pobMem = NULL;
}
}
pPddObject->lpvMemoryObject = pobMem;
pPddObject->lpvUhcdMddObject = pobUhcd;
return fResult;
}
/* UhcdPdd_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
UhcdPdd_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;
fRet = InitializeUHCI(pPddObject, (LPCWSTR)dwContext);
if(!fRet)
{
free(pPddObject);
pPddObject = NULL;
}
return (DWORD)pPddObject;
}
/* UhcdPdd_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 UhcdPdd_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 UhcdPdd_PowerUp(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
UhcdMdd_PowerUp(pPddObject->lpvUhcdMddObject);
return;
}
extern void UhcdPdd_PowerDown(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
UhcdMdd_PowerDown(pPddObject->lpvUhcdMddObject);
return;
}
extern BOOL UhcdPdd_Deinit(DWORD hDeviceContext)
{
SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
if(pPddObject->lpvUhcdMddObject)
UhcdMdd_DestroyUhcdObject(pPddObject->lpvUhcdMddObject);
if(pPddObject->lpvMemoryObject)
UhcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);
return TRUE;
}
extern DWORD UhcdPdd_Open(DWORD hDeviceContext, DWORD AccessCode,
DWORD ShareMode)
{
UnusedParameter(hDeviceContext);
UnusedParameter(AccessCode);
UnusedParameter(ShareMode);
return 1; // we can be opened, but only once!
}
extern BOOL UhcdPdd_Close(DWORD hOpenContext)
{
UnusedParameter(hOpenContext);
return TRUE;
}
extern DWORD UhcdPdd_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
UnusedParameter(hOpenContext);
UnusedParameter(pBuffer);
UnusedParameter(Count);
return (DWORD)-1; // an error occured
}
extern DWORD UhcdPdd_Write(DWORD hOpenContext, LPCVOID pSourceBytes,
DWORD NumberOfBytes)
{
UnusedParameter(hOpenContext);
UnusedParameter(pSourceBytes);
UnusedParameter(NumberOfBytes);
return (DWORD)-1;
}
extern DWORD UhcdPdd_Seek(DWORD hOpenContext, LONG Amount, DWORD Type)
{
UnusedParameter(hOpenContext);
UnusedParameter(Amount);
UnusedParameter(Type);
return (DWORD)-1;
}
extern BOOL UhcdPdd_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.
// The CEPC does not have power suspend/resume functionality so
// there's nothing we need to do beyond merely providing the entry point.
extern void UhcdPdd_InitiatePowerUp (void)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -