📄 sdmmc_load.c
字号:
/* Copyright ?1999 Intel Corp. */
/*
Module Name:
sdmmc_load.c
Abstract:
Implementation of the WinCE SD-MMC Loader Device Driver.
Functions:
Notes:
*/
#include <windows.h>
#include <memory.h>
#include <nkintr.h>
#include "XSC1.h"
#include "XSC1bd.h"
#include <drv_glob.h>
#include <oalintr.h>
#include "bcr.h"
#include "sdmmc_load.h"
#include "cken.h"
#include "oalintr.h"
// extern functions used by the loader.
extern PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
extern BOOL StartClock(unsigned int ,BOOL );
extern BOOL StopClock(unsigned int ,BOOL );
extern unsigned int GetClock(BOOL );
// Global variables.
HANDLE hSDEvent;
void InitializeHardware(void);
HANDLE hDevice = NULL;
HANDLE gSDMMCDetectThread;
HANDLE gSDMMCIntrEvent;
static BOOL SDMMC_DETECT = 0;
static BOOL IsSDStable = 1;
// Pointer to driver globals area
PDRIVER_GLOBALS v_pDriverGlobals = NULL;
// Pointer to System Registers
PGPIO_REGS v_pGPIOReg = NULL;
#ifdef DEBUG
DBGPARAM dpCurSettings =
{
TEXT("PwrButton"), {
TEXT("Data"),TEXT("IntrThread"),TEXT("2"),TEXT("3"),
TEXT("4"),TEXT("5"),TEXT("6"),TEXT("7"),
TEXT("8"),TEXT("9"),TEXT("10"),TEXT("Values"),
TEXT("Init"),TEXT("Function"),TEXT("Warning"),TEXT("Error")},
0xB518 // Errors & Init only, by default
};
#define ZONE_DATA DEBUGZONE(0)
#define ZONE_INTRTHREAD DEBUGZONE(1)
#define ZONE_VALUE DEBUGZONE(11)
#define ZONE_FUNCTION DEBUGZONE(13)
#define ZONE_WARN DEBUGZONE(14)
#define ZONE_ERROR DEBUGZONE(15)
#endif
WCHAR *szRegKey = L"Drivers\\sdmmc";
WCHAR *szPrefix = L"DSK";
WCHAR *szDLL = L"sdmmc.dll";
WCHAR *szFriendlyName = L"SDCard/MMC Block Driver";
WCHAR *szFSD=L"fatfs.dll";
WCHAR *szFolder= L"SDMMC Disk";
WCHAR *szProfile= L"SDMMC";
WCHAR *szSDMMCGuid =L"{A32942B7-920C-486b-B0E6-92A702A99B35}\0{A4E7EDDA-E575-4252-9D6B-4195D48BB865}\0\0";
#define WRITE_REG_SZ(Name, Value) RegSetValueEx( hKey, Name, 0, REG_SZ, (LPBYTE)Value, (wcslen(Value)+1)*sizeof(WCHAR))
#define WRITE_REG_DWORD(Name, Value) { DWORD dwValue = Value; RegSetValueEx( hKey, Name, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD)); }
/************************************************************************************************************
* Function: GetRegistryValue
*
* Purpose: Given a Handle and a name, reads the Win CE registry and obtains the value for it.
*
* Returns: SUCCESS on reading the registry correctly or FAILURE otherwise.
*
************************************************************************************************************/
BOOL GetRegistryValue(HKEY hKey, PTSTR szValueName, PDWORD pdwValue)
{
DWORD dwValType, dwValLen;
LONG lStatus;
dwValLen = sizeof(DWORD);
lStatus = RegQueryValueEx( hKey, szValueName, NULL, &dwValType, (PBYTE)pdwValue, &dwValLen);
if ((lStatus != ERROR_SUCCESS) || (dwValType != REG_DWORD))
{
NKDbgPrintfW(L"RelFSD_Load::RegQueryValueEx(%s) failed -returned %d Error=%08X\r\n", szValueName, lStatus, GetLastError());
*pdwValue = -1;
return FALSE;
}
NKDbgPrintfW(L"RelFSD_Load::GetRegistryValue(%s) Value(%x) hKey: %x\r\n", szValueName,*pdwValue,hKey);
return TRUE;
}
/************************************************************************************************************
* Function: DoRegSetup
*
* Purpose: Given a pointer to a key, will fill it up correctly with the values needed to load the SD-MMC driver.
*
* Returns: void
*
************************************************************************************************************/
void DoRegSetup(WCHAR *szRegKey)
{
HKEY hKey = NULL;
DWORD dwDisp = 0;
#ifdef USE_TALISKER
DWORD Status;
#endif
LONG nErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szRegKey, 0, 0, &hKey);
if (nErr == ERROR_SUCCESS)
{
// NKDbgPrintfW( L"Successfully opened key %s\r\n", szRegKey);
}
else
{
nErr = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szRegKey, 0, L"", 0, 0, NULL, &hKey, &dwDisp);
if (nErr == ERROR_SUCCESS)
{
// NKDbgPrintfW( L"Successfully created key %s\r\n", szRegKey);
}
else
{
// NKDbgPrintfW( L"!!! Failed to create key %s\r\n", szRegKey);
}
}
if (hKey)
{
WRITE_REG_SZ( L"Prefix", szPrefix);
WRITE_REG_SZ( L"Dll", szDLL);
WRITE_REG_SZ( L"FriendlyName", szFriendlyName);
WRITE_REG_DWORD( L"Order", 0);
WRITE_REG_DWORD( L"Ioctl", 4);
WRITE_REG_SZ( L"FSD", szFSD);
WRITE_REG_SZ( L"Folder", szFolder);
#ifdef USE_TALISKER
WRITE_REG_SZ( L"Profile", TEXT("SDMMC"));
Status = RegSetValueEx( hKey,L"IClass", 0, REG_MULTI_SZ, (LPBYTE)szSDMMCGuid, 500);
if(Status == ERROR_SUCCESS)
//RETAILMSG(0, (TEXT("DoRegSetUp is done successfully\r\n")));
#endif
RegCloseKey( hKey);
}
}
void DoGetHandleValue(WCHAR *szRegKey, PHANDLE phDevice)
{
LONG nErr;
HKEY hKey = NULL;
*phDevice = NULL;
nErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szRegKey, 0, 0, &hKey);
if (nErr == ERROR_SUCCESS)
{
if (!GetRegistryValue(hKey, L"HDEVICE", (PDWORD)phDevice))
{
*phDevice = NULL;
}
}
RegCloseKey( hKey);
}
void DoSetHandleValue(WCHAR *szRegKey, HANDLE hDevice)
{
HKEY hKey = NULL;
LONG nErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szRegKey, 0, 0, &hKey);
if (nErr == ERROR_SUCCESS)
{
WRITE_REG_DWORD(L"HDEVICE", (DWORD)hDevice)
}
RegCloseKey( hKey);
}
void DoDeleteHandleValue(WCHAR *szRegKey)
{
HKEY hKey = NULL;
LONG nErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, szRegKey, 0, 0, &hKey);
if (nErr == ERROR_SUCCESS)
{
RegDeleteValue( hKey, L"HDEVICE");
}
RegCloseKey( hKey);
}
/************************************************************************************************************
* Function: SDMMC_FreeAddresses
*
* Purpose: required for some clean up activity. Typically this function will free up all memory held by the
* loader. Ofcourse this will not happen because the way the loader is structured right now is that
* for as long as the system is alive the loader thread will always be active.
*
* Returns: void
*
************************************************************************************************************/
void SDMMC_FreeAddresses(void)
{
if (v_pDriverGlobals)
{
VirtualFree(v_pDriverGlobals,DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,MEM_RELEASE);
v_pDriverGlobals = NULL;
}
if (v_pGPIOReg)
{
VirtualFree((void *)v_pGPIOReg,0x400,MEM_RELEASE);
v_pGPIOReg = NULL;
}
}
/************************************************************************************************************
* Function: SDMMC_InitializeAddresses
*
* Purpose: required for some initial resource allocation. Typically this function will allocate all memory
* needed by the loader.
*
* Returns: void
*
************************************************************************************************************/
BOOL SDMMC_InitializeAddresses(void)
{
//RETAILMSG(0, (TEXT("v_pGPIOReg=0x%x, v_pDriverGlobals=0x%x\r\n"), v_pGPIOReg, v_pDriverGlobals));
if (v_pDriverGlobals == NULL)
{
v_pDriverGlobals = (PDRIVER_GLOBALS)
VirtualAllocCopy(DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,(char *)TEXT("SDMMC_Initialise addresses: DRIVER_GLOBALS"),
(PVOID)DRIVER_GLOBALS_PHYSICAL_MEMORY_START);
}
if (v_pGPIOReg == NULL)
{
v_pGPIOReg = (PGPIO_REGS)
VirtualAllocCopy(0x400,(char *)TEXT("SDMMC Loader GPIO Regs"),
(PVOID)GPIO_BASE_U_VIRTUAL);
}
if ((v_pDriverGlobals==NULL)||(v_pGPIOReg==NULL))
{
SDMMC_FreeAddresses();
//RETAILMSG(0, (TEXT("GPIO and Drv_Global virtual allocate failed!!\r\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -