// Get the creation proc address and call it PCSDHCBase CSDHCBase::CreateSDHCControllerObject( LPCTSTR pszActiveKey ) { PCSDHCBase pSDHC = NULL; HKEY hkDevice = OpenDeviceKey(pszActiveKey); if (hkDevice) { CReg regDevice(hkDevice, _T("")); DEBUGCHK(regDevice.IsOK()); TCHAR szDll[MAX_PATH]; if (regDevice.ValueSZ(DEVLOAD_DLLNAME_VALNAME, szDll, dim(szDll))) { szDll[dim(szDll) - 1] = 0; // Null-terminate TCHAR szProc[MAX_PATH]; if (regDevice.ValueSZ(SDHC_CREATION_PROC_KEY, szProc, dim(szProc))) { szProc[dim(szProc) - 1] = 0; // Null-terminate HMODULE hMod = LoadLibrary(szDll); if (hMod) { LPSDHC_CREATION_PROC pfnCreate = (LPSDHC_CREATION_PROC) GetProcAddress(hMod, szProc); if (pfnCreate) { pSDHC = (*pfnCreate)(); } FreeLibrary(hMod); } } } RegCloseKey(hkDevice); } return pSDHC; }
DWORD GetDeviceRegistryParams( LPCWSTR context, VOID *pBase, DWORD count, const DEVICE_REGISTRY_PARAM params[] ) { DWORD status = ERROR_SUCCESS; HKEY hKey; DWORD i; // Open registry context to read parameters if ((hKey = OpenDeviceKey(context)) == NULL) { // It looks like we didn't get active registry key, // try open key directly if ((status = RegOpenKeyEx( HKEY_LOCAL_MACHINE, context, 0, 0, &hKey )) != ERROR_SUCCESS) { goto cleanUp; } } // For all members of array for (i = 0; i < count && status == ERROR_SUCCESS; i++) { switch (params[i].type) { case PARAM_DWORD: status = GetDWordParam(hKey, pBase, ¶ms[i]); break; case PARAM_STRING: status = GetStringParam(hKey, pBase, ¶ms[i]); break; case PARAM_MULTIDWORD: status = GetMultiDWordParam(hKey, pBase, ¶ms[i]); break; case PARAM_BIN: status = GetBinParam(hKey, pBase, ¶ms[i]); break; default: status = STATUS_FAIL_CHECK; break; } } // Close key RegCloseKey(hKey); // Release allocated memory in case of failure if (status != ERROR_SUCCESS) { UCHAR *pBuffer, *pValue; while (i-- > 0) { pValue = (UCHAR*)pBase + params[i].offset; switch (params[i].type) { case PARAM_STRING: case PARAM_BIN: if (params[i].size == 0) { pBuffer = (UCHAR*)(*(VOID**)pValue); *(VOID**)pValue = NULL; LocalFree(pBuffer); } break; } } } cleanUp: return status; }
BOOL CSDHCBase::Init( LPCTSTR pszActiveKey ) { BOOL fRet = FALSE; SD_API_STATUS status; HKEY hkDevice = NULL; hkDevice = OpenDeviceKey(pszActiveKey); if (!hkDevice || !m_regDevice.Open(hkDevice, _T(""))) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC: Failed to open device key\n"))); goto EXIT; } // Get a handle to our parent bus. m_hBusAccess = CreateBusAccessHandle(pszActiveKey); if (m_hBusAccess == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC: Could not get handle to parent\n"))); goto EXIT; } m_cSlots = DetermineSlotCount(); if (m_cSlots == 0) { goto EXIT; } ValidateSlotCount(); RETAILMSG(0,(TEXT("CSDHCBase::Init m_cSlots=%d\n"),m_cSlots)); // jylee m_pSlotInfos = (PSDHC_SLOT_INFO) LocalAlloc(LPTR, sizeof(SDHC_SLOT_INFO) * m_cSlots); if (m_pSlotInfos == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate slot info objects\n"))); goto EXIT; } status = SDHCDAllocateContext(m_cSlots, &m_pHCDContext); if (!SD_API_SUCCESS(status)) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate context : 0x%08X \n"), status)); goto EXIT; } // Set our extension m_pHCDContext->pHCSpecificContext = this; if (!InitializeHardware()) { goto EXIT; } RETAILMSG(0,(TEXT("AllocateSlotObjects\n"))); // Allocate slot objects m_pSlots = AllocateSlotObjects(m_cSlots); if (m_pSlots == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate slot objects\n"))); goto EXIT; } // Initialize the slots for (DWORD dwSlot = 0; dwSlot < m_cSlots; ++dwSlot) { PSDHC_SLOT_INFO pSlotInfo = &m_pSlotInfos[dwSlot]; PCSDHCSlotBase pSlot = GetSlot(dwSlot); RETAILMSG(0,(TEXT("pSlot->Init\n"))); RETAILMSG(0,(TEXT("pSlotInfo->pucRegisters : 0x%x\r\n"),pSlotInfo->pucRegisters)); if (!pSlot->Init(dwSlot, pSlotInfo->pucRegisters, m_pHCDContext, m_dwSysIntr, m_hBusAccess, m_interfaceType, m_dwBusNumber, &m_regDevice)) { goto EXIT; } } // set the host controller name SDHCDSetHCName(m_pHCDContext, TEXT("HSMMC")); // set init handler SDHCDSetControllerInitHandler(m_pHCDContext, CSDHCBase::SDHCInitialize); // set deinit handler SDHCDSetControllerDeinitHandler(m_pHCDContext, CSDHCBase::SDHCDeinitialize); // set the Send packet handler SDHCDSetBusRequestHandler(m_pHCDContext, CSDHCBase::SDHCBusRequestHandler); // set the cancel I/O handler SDHCDSetCancelIOHandler(m_pHCDContext, CSDHCBase::SDHCCancelIoHandler); // set the slot option handler SDHCDSetSlotOptionHandler(m_pHCDContext, CSDHCBase::SDHCSlotOptionHandler); // These values must be set before calling SDHCDRegisterHostController() // because they are used during that call. m_dwPriority = m_regDevice.ValueDW(SDHC_PRIORITY_KEY, SDHC_CARD_CONTROLLER_PRIORITY); RETAILMSG(0,(TEXT("SDHCDRegisterHostController\n"))); // jylee // now register the host controller status = SDHCDRegisterHostController(m_pHCDContext); if (!SD_API_SUCCESS(status)) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to register host controller: %0x08X \n"), status)); goto EXIT; } m_fRegisteredWithBusDriver = TRUE; fRet = TRUE; RETAILMSG(0,(TEXT("CSDHCBase::Init Finished.\n"))); // jylee EXIT: if (hkDevice) RegCloseKey(hkDevice); return fRet; }
static BOOLEAN SupportChildDrivers( VOID ) { BOOLEAN Success; HKEY XenbusKey; HRESULT Error; DWORD SubKeys; DWORD MaxSubKeyLength; DWORD SubKeyLength; PTCHAR SubKeyName; HKEY DeviceKey; PTCHAR DriverKeyName; HKEY DriverKey; PTCHAR MatchingDeviceID; DWORD Index; Log("====>"); Success = OpenBusKey("XENHID", &XenbusKey); if (!Success) { // If there is no key then this must be a fresh installation if (GetLastError() == ERROR_FILE_NOT_FOUND) goto done; goto fail1; } Error = RegQueryInfoKey(XenbusKey, NULL, NULL, NULL, &SubKeys, &MaxSubKeyLength, NULL, NULL, NULL, NULL, NULL, NULL); if (Error != ERROR_SUCCESS) { SetLastError(Error); goto fail2; } SubKeyLength = MaxSubKeyLength + sizeof (TCHAR); SubKeyName = malloc(SubKeyLength); if (SubKeyName == NULL) goto fail3; for (Index = 0; Index < SubKeys; Index++) { SubKeyLength = MaxSubKeyLength + sizeof (TCHAR); memset(SubKeyName, 0, SubKeyLength); Error = RegEnumKeyEx(XenbusKey, Index, (LPTSTR)SubKeyName, &SubKeyLength, NULL, NULL, NULL, NULL); if (Error != ERROR_SUCCESS) { SetLastError(Error); goto fail4; } Success = OpenDeviceKey("XENHID", SubKeyName, &DeviceKey); if (!Success) goto fail5; Success = GetDriverKeyName(DeviceKey, &DriverKeyName); if (!Success) goto fail6; if (DriverKeyName == NULL) goto loop; Success = OpenDriverKey(DriverKeyName, &DriverKey); if (!Success) goto loop; Success = GetMatchingDeviceID(DriverKey, &MatchingDeviceID); if (!Success) goto fail7; Success = SupportDeviceID(MatchingDeviceID); if (!Success) goto fail8; free(MatchingDeviceID); RegCloseKey(DriverKey); loop: if (DriverKeyName != NULL) free(DriverKeyName); RegCloseKey(DeviceKey); } free(SubKeyName); RegCloseKey(XenbusKey); done: Log("<===="); return TRUE; fail8: Log("fail8"); free(MatchingDeviceID); fail7: Log("fail7"); RegCloseKey(DriverKey); free(DriverKeyName); fail6: Log("fail6"); RegCloseKey(DeviceKey); fail5: Log("fail5"); fail4: Log("fail4"); free(SubKeyName); fail3: Log("fail3"); fail2: Log("fail2"); RegCloseKey(XenbusKey); fail1: Error = GetLastError(); { PTCHAR Message; Message = GetErrorMessage(Error); Log("fail1 (%s)", Message); LocalFree(Message); } return FALSE; }
/////////////////////////////////////////////////////////////////////////////// // SDH_Init - the init entry point // Input: dwContext - the context for this init // Output: // Return: returns instance context // Notes: /////////////////////////////////////////////////////////////////////////////// DWORD SDH_Init(DWORD dwContext) { PSDCARD_HC_CONTEXT pHostContext; // new HC context SD_API_STATUS status; // SD status PSDH_HARDWARE_CONTEXT pController; // new instance HKEY hKeyDevice; LPCTSTR pszActiveKey; DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: +SDH_Init\n"))); DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: Active RegPath: %s \n"), (PTSTR)dwContext)); pController = NULL; // allocate the context status = SDHCDAllocateContext(SDH_SLOTS, &pHostContext); if (!SD_API_SUCCESS(status)) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to allocate context : 0x%08X \n"), status)); return 0; } // create our extension pController = (PSDH_HARDWARE_CONTEXT)malloc( sizeof(SDH_HARDWARE_CONTEXT) ); if( pController == NULL ) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to allocate extension\n"))); return 0; } memset( pController, 0, sizeof(SDH_HARDWARE_CONTEXT) ); // Set our extension pHostContext->pHCSpecificContext = pController; pController = GetExtensionFromHCDContext(PSDH_HARDWARE_CONTEXT, pHostContext); pszActiveKey = (LPCTSTR) dwContext; pController->pszActiveKey = pszActiveKey; pController->hBusAccessHandle = CreateBusAccessHandle( pszActiveKey ); hKeyDevice = OpenDeviceKey(pszActiveKey); if (!hKeyDevice || !LoadRegistrySettings(hKeyDevice, pController) ) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed load the registry settings\n"))); return 0; } RegCloseKey( hKeyDevice ); DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: Real RegPath: %s \n"),pController->RegPath)); // save off the host context pController->pHCContext = pHostContext; // set the name SDHCDSetHCName(pHostContext, TEXT("Lubbock")); // set init handler SDHCDSetControllerInitHandler(pHostContext,SDInitialize); // set deinit handler SDHCDSetControllerDeinitHandler(pHostContext, SDDeinitialize); // set the bus request handler SDHCDSetBusRequestHandler(pHostContext,SDHBusRequestHandler); // set the cancel I/O handler SDHCDSetCancelIOHandler(pHostContext, SDHCancelIoHandler); // set the slot option handler SDHCDSetSlotOptionHandler(pHostContext, SDHSlotOptionHandler); // now register the host controller status = SDHCDRegisterHostController(pHostContext); if (!SD_API_SUCCESS(status)) { if( pController ) { free( pController ); } SDHCDDeleteContext(pHostContext); DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to register host controller: %0x08X \n"),status)); return 0; } DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: -SDH_Init\n"))); // return the Host Controller context return (DWORD)pHostContext; }
/*++ ******************************************************************************* Routine: Ser_GetRegistryData Description: Take the registry path provided to COM_Init and use it to find this requested comm port's DeviceArrayIndex, teh IOPort Base Address, and the Interrupt number. Arguments: LPCTSTR regKeyPath the registry path passed in to COM_Init. Return Value: -1 if there is an error. ******************************************************************************* --*/ BOOL Ser_GetRegistryData(PSER_INFO pHWHead, LPCTSTR regKeyPath) { #define GCI_BUFFER_SIZE 256 LONG regError; HKEY hKey; DWORD dwDataSize = GCI_BUFFER_SIZE; DDKISRINFO dii; DDKWINDOWINFO dwi; DEBUGMSG(ZONE_INIT, (TEXT("Try to open %s\r\n"), regKeyPath)); // We've been handed the name of a key in the registry that was generated // on the fly by device.exe. We're going to open that key and pull from it // a value that is the name of this serial port's real key. That key // will have the DeviceArrayIndex that we're trying to find. hKey = OpenDeviceKey(regKeyPath); if ( hKey == NULL ) { DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("Failed to open device key\r\n"))); return ( FALSE ); } // read interrupt configuration parameters dii.cbSize = sizeof(dii); regError = DDKReg_GetIsrInfo(hKey, &dii); if(regError == ERROR_SUCCESS) { if(dii.dwSysintr != SYSINTR_NOP) { pHWHead->dwSysIntr = dii.dwSysintr; } else { regError = ERROR_FILE_NOT_FOUND; } pHWHead->ser16550.dwSysIntr = pHWHead->dwSysIntr; pHWHead->ser16550.dwIrq = dii.dwIrq; if(dii.szIsrDll[0] == 0) { pHWHead->ser16550.RegIsrDll[0]=0; DEBUGMSG(ZONE_INIT | ZONE_ERROR, (_T("COM16550:GetRegistryConfig: no ISR DLL specified\r\n"))); } else { _tcscpy(pHWHead->ser16550.RegIsrDll, dii.szIsrDll); } if(dii.szIsrHandler[0] == 0) { pHWHead->ser16550.RegIsrHandler[0]=0; DEBUGMSG(ZONE_INIT | ZONE_ERROR, (_T("COM16550:GetRegistryConfig: no ISR handler specified\r\n"))); } else { _tcscpy(pHWHead->ser16550.RegIsrHandler, dii.szIsrHandler); } } if ( regError == ERROR_SUCCESS ) { dwi.cbSize = sizeof(dwi); regError = DDKReg_GetWindowInfo(hKey, &dwi); if(regError == ERROR_SUCCESS) { if(dwi.dwNumMemWindows == 1) { pHWHead->dwMemBase = dwi.memWindows[0].dwBase; pHWHead->dwMemLen = dwi.memWindows[0].dwLen; } else { regError = ERROR_FILE_NOT_FOUND; } } } RegCloseKey (hKey); if ( regError != ERROR_SUCCESS ) { DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("Failed to get serial registry values, Error 0x%X\r\n"), regError)); return ( FALSE ); } DEBUGMSG ( ZONE_INIT, (TEXT("SerInit - SysIntr %d, HD64465 UART base addr %X \r\n"), pHWHead->dwSysIntr, pHWHead->dwMemBase)); return ( TRUE ); }
static BOOLEAN AllowInstall( VOID ) { BOOLEAN Success; PTCHAR DeviceKeyName = NULL; HKEY DeviceKey = NULL; PTCHAR DriverKeyName = NULL; HKEY DriverKey = NULL; HRESULT Error; DWORD MaxValueLength; DWORD DriverDescLength; PTCHAR DriverDesc = NULL; DWORD Type; // Look for a legacy platform device Success = GetDeviceKeyName(PLATFORM_DEVICE_0001_NAME, &DeviceKeyName); if (!Success) goto fail1; if (DeviceKeyName != NULL) goto found; Success = GetDeviceKeyName(PLATFORM_DEVICE_0002_NAME, &DeviceKeyName); if (!Success) goto fail2; if (DeviceKeyName != NULL) goto found; // No legacy platform device goto done; found: Success = OpenDeviceKey(DeviceKeyName, &DeviceKey); if (!Success) goto fail3; // Check for a bound driver Success = GetDriverKeyName(DeviceKey, &DriverKeyName); if (!Success) goto fail4; if (DriverKeyName == NULL) goto done; Success = OpenDriverKey(DriverKeyName, &DriverKey); if (!Success) goto fail5; Error = RegQueryInfoKey(DriverKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &MaxValueLength, NULL, NULL); if (Error != ERROR_SUCCESS) { SetLastError(Error); goto fail6; } DriverDescLength = MaxValueLength + sizeof (TCHAR); DriverDesc = malloc(DriverDescLength); if (DriverDesc == NULL) goto fail7; memset(DriverDesc, 0, DriverDescLength); Error = RegQueryValueEx(DriverKey, "DriverDesc", NULL, &Type, (LPBYTE)DriverDesc, &DriverDescLength); if (Error != ERROR_SUCCESS) { if (Error == ERROR_FILE_NOT_FOUND) goto done; SetLastError(Error); goto fail8; } if (Type != REG_SZ) { SetLastError(ERROR_BAD_FORMAT); goto fail9; } if (strcmp(DriverDesc, "Xen Platform") != 0) { SetLastError(ERROR_INSTALL_FAILURE); goto fail10; } done: if (DriverDesc != NULL) { free(DriverDesc); RegCloseKey(DriverKey); } if (DriverKeyName != NULL) { free(DriverKeyName); RegCloseKey(DeviceKey); } if (DeviceKeyName != NULL) free(DeviceKeyName); return TRUE; fail10: Log("fail10"); fail9: Log("fail9"); fail8: Log("fail8"); free(DriverDesc); fail7: Log("fail7"); fail6: Log("fail6"); RegCloseKey(DriverKey); fail5: Log("fail5"); free(DriverKeyName); fail4: Log("fail4"); RegCloseKey(DeviceKey); fail3: Log("fail3"); free(DeviceKeyName); fail2: Log("fail2"); fail1: Error = GetLastError(); { PTCHAR Message; Message = GetErrorMessage(Error); Log("fail1 (%s)", Message); LocalFree(Message); } return FALSE; }