extern DWORD WINAPI DRG_Init(DWORD dwContext) { PWCHAR* pRegPath = NULL; SDCARD_CLIENT_REGISTRATION_INFO ClientInfo; // client into SD_API_STATUS Status; // intermediate status HANDLE hThread; NDIS_DEBUG_PRINTF(DBG_TRACE, "AR6K_SDIO: +DRG_Init by DiskImage !!! \r\n"); // get the device handle from the bus driver hClientHandle = SDGetDeviceHandle(dwContext, pRegPath); if (NULL == hClientHandle) { NDIS_DEBUG_PRINTF(DBG_ERR, "-DRG_Init: Failed to get client handle \r\n"); return 0; } memset(&ClientInfo, 0, sizeof(ClientInfo)); // set client options and register as a client device _tcscpy(ClientInfo.ClientName, TEXT("Atheros AR6K SDIO Wifi Card")); // set the callback ClientInfo.pSlotEventCallBack = SlotEventCallBack; Status = SDRegisterClient(hClientHandle, NULL, &ClientInfo); if (!SD_API_SUCCESS(Status)) { NDIS_DEBUG_PRINTF(DBG_ERR, "-DRG_Init: Failed to register client : 0x%08X \r\n", Status); return 0; } drvInit(); if (!createRegKeyValues()) { NDIS_DEBUG_PRINTF(DBG_ERR, "-DRG_Init: Failed to create ndis registryentries \r\n"); return 0; } // Perform NDIS register adapter on a separate thread to avoid // blocking the SDIO bus driver hThread = CreateThread(NULL, 0, NdisRegisterAdapterThread, NULL, 0, NULL); CeSetThreadPriority(hThread, 200); CloseHandle(hThread); NDIS_DEBUG_PRINTF(DBG_TRACE, "DRG_Init : Exit\r\n"); return 1; }
/////////////////////////////////////////////////////////////////////////////// // SMC_Init - the init entry point for the memory driver // Input: dwContext - the context for this init // Output: // Return: non-zero context // Notes: /////////////////////////////////////////////////////////////////////////////// extern "C" DWORD WINAPI SMC_Init(DWORD dwContext) { SD_DEVICE_HANDLE hClientHandle; // client handle PSD_MEMCARD_INFO pDevice; // this instance of the device SDCARD_CLIENT_REGISTRATION_INFO ClientInfo; // client into ULONG BufferSize; // size of buffer HKEY hSubKey; // registry key SD_API_STATUS Status; // intermediate status DWORD data; // registry data DWORD dataLength; // registry data length DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: +SMC_Init\r\n"))); pDevice = (PSD_MEMCARD_INFO)SDAllocateMemoryWithTag( sizeof(SD_MEMCARD_INFO), SD_MEMORY_TAG); if (pDevice == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemory: Failed to allocate device info\r\n"))); DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_Init\r\n"))); return 0; } // initialize sterile I/O request to NULL pDevice->pSterileIoRequest = NULL; InitializeCriticalSection(&pDevice->CriticalSection); InitializeCriticalSection(&pDevice->RemovalLock); // get the device handle from the bus driver hClientHandle = SDGetDeviceHandle(dwContext, &pDevice->pRegPath); // store device handle in local context pDevice->hDevice = hClientHandle; if (NULL == hClientHandle) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemory: Failed to get client handle\r\n"))); CleanUpDevice(pDevice); DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_Init\r\n"))); return 0; } // allocate sterile I/O request pDevice->pSterileIoRequest = (PSG_REQ)LocalAlloc( LPTR, (sizeof(SG_REQ) + ((MAX_SG_BUF - 1) * sizeof(SG_BUF))) ); if (NULL == pDevice->pSterileIoRequest) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemory: Failed to allocate sterile I/O request\r\n"))); CleanUpDevice(pDevice); DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_Init\r\n"))); return 0; } // register our debug zones SDRegisterDebugZones(hClientHandle, pDevice->pRegPath); memset(&ClientInfo, 0, sizeof(ClientInfo)); // set client options and register as a client device _tcscpy(ClientInfo.ClientName, TEXT("Memory Card")); // set the callback ClientInfo.pSlotEventCallBack = SlotEventCallBack; Status = SDRegisterClient(hClientHandle, pDevice, &ClientInfo); if (!SD_API_SUCCESS(Status)) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemory: Failed to register client : 0x%08X\r\n"), Status)); CleanUpDevice(pDevice); DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_Init\r\n"))); return 0; } #ifdef _FOR_MOVI_NAND_ /** * Description : There is no way to distinguish between HSMMC and moviNAND. * So, We assume A HSMMC card is a moviNAND. Default value is false; */ pDevice->IsHSMMC = FALSE; #endif // configure card and retrieve disk size/format information if( SDMemCardConfig( pDevice ) != ERROR_SUCCESS ) { CleanUpDevice(pDevice); DEBUGMSG( SDCARD_ZONE_ERROR, (TEXT("SDMemory: Error initializing MemCard structure and card\r\n"))); return 0; } // aet a default block transfer size pDevice->BlockTransferSize = DEFAULT_BLOCK_TRANSFER_SIZE; // read configuration from registry // open the reg path if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, pDevice->pRegPath, 0, KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS ) { // read "BlockTransferSize" dataLength = sizeof(pDevice->BlockTransferSize); RegQueryValueEx( hSubKey, BLOCK_TRANSFER_SIZE_KEY, NULL, NULL, (PUCHAR)&(pDevice->BlockTransferSize), &dataLength); if (pDevice->BlockTransferSize != DEFAULT_BLOCK_TRANSFER_SIZE) { DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: Initialize: Using block transfer size of %d blocks\r\n"), pDevice->BlockTransferSize)); } // read "SingleBlockWrites" // default to using mulitple block writes pDevice->SingleBlockWrites = FALSE; dataLength = sizeof(DWORD); data = 0; if (RegQueryValueEx( hSubKey, SINGLE_BLOCK_WRITES_KEY, NULL, NULL, (PUCHAR)&data, &dataLength) == ERROR_SUCCESS ) { // key is present pDevice->SingleBlockWrites = TRUE; DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: Initialize: Using single block write commands only\r\n"))); } // read "DisablePowerManagement" // on by default unless key is present pDevice->EnablePowerManagement = TRUE; dataLength = sizeof(DWORD); data = 0; if (RegQueryValueEx( hSubKey, DISABLE_POWER_MANAGEMENT, NULL, NULL, (PUCHAR)&data, &dataLength) == ERROR_SUCCESS ) { // key is present DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: Initialize: Disabled power management\r\n"))); pDevice->EnablePowerManagement = FALSE; } // read "IdleTimeout" pDevice->IdleTimeout = DEFAULT_IDLE_TIMEOUT; dataLength = sizeof(pDevice->IdleTimeout); if (RegQueryValueEx( hSubKey, IDLE_TIMEOUT, NULL, NULL, (PUCHAR)&pDevice->IdleTimeout, &dataLength) == ERROR_SUCCESS ) { // key is present DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: Initialize: Using idle timeout of %u milliseconds\r\n"), pDevice->IdleTimeout)); } // read "IdlePowerState" // default power state for idle // if the power state is greater than D2, we do idle checking pDevice->PowerStateForIdle = D2; dataLength = sizeof(DWORD); data = 0; if (RegQueryValueEx( hSubKey, IDLE_POWER_STATE, NULL, NULL, (PUCHAR)&data, &dataLength) == ERROR_SUCCESS ) { if (data <= (ULONG)D4) { pDevice->PowerStateForIdle = (CEDEVICE_POWER_STATE)data; } } DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: Idle Timeout: %d Idle Power State: %d\r\n"), pDevice->IdleTimeout, pDevice->PowerStateForIdle)); RegCloseKey(hSubKey); } // allocate our buffer list; we need 2 buffers: 1 for read and 1 for write data BufferSize = (ULONG)(pDevice->BlockTransferSize * SD_BLOCK_SIZE); // create the data buffer memory list pDevice->hBufferList = SDCreateMemoryList(SD_MEMORY_TAG, 2, BufferSize); if (pDevice->hBufferList == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemory: Initialize: Failed to allocate buffer list\r\n"))); CleanUpDevice(pDevice); return 0; } pDevice->fPreDeinitCalled = FALSE; InitializePowerManagement(pDevice); DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_Init\r\n"))); return (DWORD)pDevice; }