CSDHCBase::~CSDHCBase( ) { // We call PreDeinit just in case we are not being destroyed by // a call to SHC_PreDeinit. PreDeinit(); if (m_fHardwareInitialized) { DeinitializeHardware(); } if (m_pHCDContext) { // Cleanup the host context SDHCDDeleteContext(m_pHCDContext); } if (m_pSlots) delete [] m_pSlots; if (m_pSlotInfos) LocalFree(m_pSlotInfos); if (m_hBusAccess) CloseBusAccessHandle(m_hBusAccess); }
/////////////////////////////////////////////////////////////////////////////// // SDH_Deinit - the deinit entry point // Input: hDeviceContext - the context returned from SDH_Init // Output: // Return: always returns TRUE // Notes: /////////////////////////////////////////////////////////////////////////////// BOOL SDH_Deinit(DWORD hDeviceContext) { PSDCARD_HC_CONTEXT pHostContext; DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: +SDH_Deinit\n"))); pHostContext = (PSDCARD_HC_CONTEXT)hDeviceContext; // deregister the host controller SDHCDDeregisterHostController(pHostContext); if( pHostContext && pHostContext->pHCSpecificContext ) { free( pHostContext->pHCSpecificContext ); } // cleanup the context SDHCDDeleteContext((PSDCARD_HC_CONTEXT)hDeviceContext); return TRUE; }
/////////////////////////////////////////////////////////////////////////////// // 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; }