📄 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 "bvd1.h"
#include "bvd1bd.h"
#include <drv_glob.h>
#include <oalintr.h>
#include "Oemioctl.h"
#include "sdmmc_load.h"
#include "cken.h"
#include "Ind.h"
#define CLK_MMC 0x00001000 //for the time being
// extern functions used by the loader.
static BOOL SDMMC_DETECT = 0;
extern PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
extern BOOL StartClock(unsigned int ,BOOL );
// extern BOOL StopClock(unsigned int ,BOOL );
BOOL IsCardOnSite();
extern unsigned int GetClock(BOOL );
// Global variables.
HANDLE gSDMMCDetectThread;
HANDLE gSDMMCIntrEvent;
// Pointer to driver globals area
// Pointer to System Registers
volatile CLKMAN_REGS *v_pClockRegs = NULL;
volatile IND_CTRL *v_pIndCtrlReg = NULL;
volatile PDRIVER_GLOBALS v_pDrvGlob = (volatile PDRIVER_GLOBALS)DRIVER_GLOBALS_U_VIRTUAL;
#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
BOOL IsCardOnSite()
{
if(v_pIndCtrlReg->status & 0x0080) //SD_CD signal
return TRUE;
else
return FALSE;
}
/*
; The volume will mount as \SDCard
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\sdmmc]
"Dll"="sdmmc.dll"
"Prefix"="DSK"
"Order"=dword:1
"Ioctl"=dword:4
"FSD"="fatfs.dll"
"Folder"="SDCard"
*/
//WCHAR *szRegKey = L"Drivers\\BuiltIn\\sdmmc";
WCHAR *szRegKey = L"Drivers\\Built\\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", 3);
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(1, (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_pIndCtrlReg)
{
VirtualFree((void *)v_pIndCtrlReg,sizeof(IND_CTRL),MEM_RELEASE);
v_pIndCtrlReg = NULL;
}
if(v_pClockRegs)
{
VirtualFree((void *)v_pClockRegs,0x400,MEM_RELEASE);
v_pClockRegs = 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)
{
if(v_pIndCtrlReg == NULL)
{
v_pIndCtrlReg = (volatile IND_CTRL *)
VirtualAllocCopy(sizeof(IND_CTRL), (char *)TEXT("SDMMC Loader -- LOGIC control reg"), (PVOID)INDICATOR_LIGHT_BASE_U_VIRTUAL);
}
if(v_pClockRegs == NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -