📄 system.c
字号:
//
// Copyright(C) Renesas Technology Corp. 2003-2004. All rights reserved.
//
// USB OHCI Host Controller Driver for ITS-DS7
//
// FILE : SYSTEM.C
// CREATED : 2002.06.07 (sample code in Platform Builder 4.1)
// MODIFIED : 2004.09.01
// AUTHOR : Renesas Technology Corp.
// HARDWARE : RENESAS ITS-DS7
// HISTORY :
// 2003.06.20
// - Created release code.
// (based on USB OHCI Host Controller Driver for
// ITS-DS4 Souce Kit Ver.1.2.0 for WCE 4.2)
// 2004.09.01
// - Created release code for WCE5.0.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
#include <windows.h>
#include <hcdddsi.h>
#include "its_ds7.h"
// Amount of memory to use for HCD buffer
DWORD g_dwTotalAvailablePhysicalMemory;
DWORD g_dwHighPriorityPhysicalMemory;
static HANDLE g_IsrHandle = NULL;
typedef struct _SOhcdPdd
{
PVOID pvMemoryObject;
PVOID pvOhcdMddObject;
PVOID pvVirtualAddress; // register base
PVOID pvMemBase; // Host controller RAM area
PUCHAR ioPortBase;
CRITICAL_SECTION csPdd; // serializes access to the PDD object
} SOhcdPdd;
#define UnusedParameter(x) x = x
#define ALLOC_PAGE_SIZE 4096
/* HcdPdd_DllMain
*
* DLL Entry point.
*
* Return Value:
*/
extern BOOL HcdPdd_DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
UnusedParameter(hinstDLL);
UnusedParameter(dwReason);
UnusedParameter(lpvReserved);
return TRUE;
}
/* GetRegistryConfig
*
* Note: Will need to be changed to support multiple instances.
*
* Return Value:
* TRUE for success, FALSE for error
*/
static BOOL
GetRegistryConfig(
LPCWSTR RegKeyPath, // IN - driver registry key path
DWORD * lpdwRegBase, // OUT - register base address
DWORD * lpdwMemBase, // OUT - shared memory base address
DWORD * lpdwHWMemBase, // OUT - shared memory address for hardware
DWORD * lpdwTotalMemSize, // OUT - total shared memory size
DWORD * lpdwHiPrioMemSize, // OUT - high priority memory size
DWORD * lpdwSysIntr // OUT - system interrupt number
)
{
HKEY hKey;
DWORD dwData;
DWORD dwSize;
DWORD dwType;
DWORD dwRet;
// Open key
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegKeyPath,0,0,&hKey);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(1,
(TEXT("!OHCD:GetRegistryConfig RegOpenKeyEx(%s) failed %d\r\n"),
RegKeyPath, dwRet));
return FALSE;
}
dwSize = sizeof(dwData);
// Read register base address
dwRet = RegQueryValueEx(hKey, TEXT("RegBase"), 0, &dwType,
(PUCHAR)&dwData, &dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwRegBase = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: RegBase = %08x.\r\n"), *lpdwRegBase));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: RegBase not found in registry.\r\n")));
return FALSE;
}
// Read OHCI shared memory base address
dwRet = RegQueryValueEx(hKey, TEXT("MemBase"), 0, &dwType,
(PUCHAR)&dwData, &dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwMemBase = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: MemBase = %08x.\r\n"), *lpdwMemBase));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: MemBase not found in registry.\r\n")));
return FALSE;
}
// Read shared memory base address for host controller hardware
dwRet = RegQueryValueEx(hKey, TEXT("HWMemBase"), 0, &dwType,
(PUCHAR)&dwData, &dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwHWMemBase = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: HWMemBase = %08x.\r\n"), *lpdwHWMemBase));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: HWMemBase not found in registry.\r\n")));
return FALSE;
}
// Read total shared memory size
dwRet = RegQueryValueEx(hKey, TEXT("TotalMemSize"), 0, &dwType,
(PUCHAR)&dwData, &dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwTotalMemSize = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: TotalMemSize = %08x.\r\n"), *lpdwTotalMemSize));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: TotalMemSize not found in registry.\r\n")));
return FALSE;
}
// Read high priority shared memory size
dwRet = RegQueryValueEx(hKey, TEXT("HiPrioMemSize"), 0, &dwType,
(PUCHAR)&dwData, &dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwHiPrioMemSize = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: HiPrioMemSize = %08x.\r\n"), *lpdwHiPrioMemSize));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: HiPrioMemSize is not found in registry.\r\n")));
return FALSE;
}
// Read SysIntr from registry
dwRet = RegQueryValueEx(hKey, TEXT("SysIntr"), 0 , &dwType,
(PUCHAR)&dwData,&dwSize);
if (dwRet == ERROR_SUCCESS) {
*lpdwSysIntr = dwData;
DEBUGMSG(ZONE_INIT,
(TEXT("OHCD: SysIntr = %d.\r\n"), *lpdwSysIntr));
}
else {
RETAILMSG(1,
(TEXT("!OHCD: SysIntr is not found in registry.\r\n")));
return FALSE;
}
return TRUE;
} // GetRegistryConfig
/* InitializeOHCI
*
* Configure and initialize OHCI card
*
* Return Value:
* Return TRUE if card could be located and configured, otherwise FALSE
*/
static BOOL
InitializeOHCI(
SOhcdPdd * pPddObject, // IN - Pointer to PDD structure
LPCWSTR szDriverRegKey) // IN - Pointer to active registry key string
{
LPVOID pobMem = NULL;
LPVOID pobOhcd = NULL;
LPVOID pvUsbRegister;
LPVOID pvUsbHcca;
DWORD dwRegAddr;
DWORD dwMemAddr;
DWORD dwHWMemBase;
DWORD dwBase;
DWORD dwOffset;
DWORD dwTotalMemSize;
DWORD dwHiPrioMemSize;
DWORD dwSysIntr;
DWORD address;
if (!GetRegistryConfig(
szDriverRegKey,
&dwRegAddr,
&dwMemAddr,
&dwHWMemBase,
&dwTotalMemSize,
&dwHiPrioMemSize,
&dwSysIntr)) {
RETAILMSG(1,
(TEXT("!OHCD: Error reading registry settings\r\n")));
return FALSE;
}
// Adjust 4kB page boundary for USB registers
dwBase = dwRegAddr & ~(ALLOC_PAGE_SIZE - 1);
dwOffset = dwRegAddr & (ALLOC_PAGE_SIZE - 1);
// Allocate and map vertual address for USB registers
pPddObject->pvVirtualAddress = VirtualAlloc(
0, ALLOC_PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
if (pPddObject->pvVirtualAddress == NULL) {
RETAILMSG(1,
(TEXT("InitializeOHCI: VirtualAlloc (register) failed!\r\n")));
goto error_return;
}
if (!VirtualCopy(pPddObject->pvVirtualAddress,
(LPVOID)dwBase, ALLOC_PAGE_SIZE, PAGE_READWRITE|PAGE_NOCACHE)) {
RETAILMSG(1,
(TEXT("InitializeOHCI: VirtualCopy (register) failed!\r\n")));
goto error_return;
}
pvUsbRegister = (PVOID)(
(DWORD)pPddObject->pvVirtualAddress + dwOffset);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -