📄 ohcd.c
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2001. Samsung Electronics, co. ltd All rights reserved.
Module Name:
ohcd.c
Abstract:
Platform dependant part of the USB Open Host Controller Driver (OHCD).
rev:
2001.12.26 : OHC base pointer is changed(with VirtaulAlloc&VirtualCopy) (kwangyoon LEE, kwangyoon@samsung.com)
Because Windows CE may not run in Full-Kernel thread mode (when ROMFLAGS bit 1 is cleared)
CHECK IMGNOTALLKMODE environment variable!!!
2001.12.26 : code clean-up (kwangyoon LEE, kwangyoon@samsung.com)
Notes:
--*/
#include <windows.h>
#include <nkintr.h>
#include <oalintr.h>
#include <ceddk.h>
#include <ohcdddsi.h>
// Registry key and value names
#define OHCI_DRIVER_KEY TEXT("Drivers\\BuiltIn\\OHCI")
#define USE_EXISTING_VALUE_NAME TEXT("UseExistingSettings")
#define IRQ_VALUE_NAME TEXT("Irq")
#define IOBASE_VALUE_NAME TEXT("MemBase")
// Amount of memory to use for HCD buffer
static const DWORD gcTotalAvailablePhysicalMemory = 65536; // 64K
static const DWORD gcHighPriorityPhysicalMemory = 0x4000; // 16K
typedef struct _SOhcdPdd
{
LPVOID lpvMemoryObject;
LPVOID lpvOhcdMddObject;
} SOhcdPdd;
#define UnusedParameter(x) x = x
#define USB_INTR 11
#define USB_BASE 0xB0900000
#define USB_PHYSICAL_BASE 0x49000000
#define USB_OPERATIONAL_REGISTER_SIZE 0x4096
#define ZONE_ERROR 1
volatile ULONG *v_USBreg;
/* OhcdPdd_DllMain
*
* DLL Entry point.
*
* Return Value:
*/
extern BOOL HcdPdd_DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
UnusedParameter(hinstDLL);
UnusedParameter(dwReason);
UnusedParameter(lpvReserved);
RETAILMSG(1,(TEXT("HcdPdd_DllMain ohcd Entry point \r\n")));
return TRUE;
}
/* GetRegistryConfig
*
* Function to get the IRQ and I/O port range from the registry.
* Note: Will need to be changed to support multiple instances.
*
* Return Value:
* TRUE for success, FALSE for error
*/
static BOOL
GetRegistryConfig(
DWORD * lpdwUseExistingSettings, // OUT- Receives value that indicates whether to
// just use the resources assigned by the BIOS.
DWORD * lpdwIrq, // OUT- Receives IRQ value
DWORD * lpdwIoBase) // OUT- Receives I/O base
{
HKEY hKey;
DWORD dwData;
DWORD dwSize;
DWORD dwType;
BOOL fRet=FALSE;
DWORD dwRet;
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,OHCI_DRIVER_KEY,0,0,&hKey);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR,(TEXT("!OHCD:GetRegistryConfig RegOpenKeyEx(%s) failed %d\r\n"),
OHCI_DRIVER_KEY, dwRet));
return FALSE;
}
dwSize = sizeof(dwData);
dwRet = RegQueryValueEx(hKey,USE_EXISTING_VALUE_NAME,0,&dwType,(PUCHAR)&dwData,&dwSize);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR, (TEXT("!OHCD:GetRegistryConfig RegQueryValueEx(%s) failed %d\r\n"),
USE_EXISTING_VALUE_NAME, dwRet));
goto GetRegistryConfig_exit;
}
*lpdwUseExistingSettings = dwData;
dwSize = sizeof(dwData);
dwRet = RegQueryValueEx(hKey,IRQ_VALUE_NAME,0,&dwType,(PUCHAR)&dwData,&dwSize);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR, (TEXT("!OHCD:GetRegistryConfig RegQueryValueEx(%s) failed %d\r\n"),
IRQ_VALUE_NAME, dwRet));
goto GetRegistryConfig_exit;
}
*lpdwIrq = dwData;
dwSize = sizeof(dwData);
dwRet = RegQueryValueEx(hKey,IOBASE_VALUE_NAME,0,&dwType,(PUCHAR)&dwData,&dwSize);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR,(TEXT("!OHCD:GetRegistryConfig RegQueryValueEx(%s) failed %d\r\n"),
IOBASE_VALUE_NAME, dwRet));
goto GetRegistryConfig_exit;
}
*lpdwIoBase = dwData;
fRet = TRUE;
GetRegistryConfig_exit:
RegCloseKey(hKey);
return fRet;
} // GetRegistryConfig
/* SetRegistryConfig
*
* Function to set the IRQ and I/O port range in the registry.
* Note: Will need to be changed to support multiple instances.
*
* Return Value:
* TRUE for success, FALSE for error
*/
static BOOL
SetRegistryConfig(
DWORD dwIrq, // IN - IRQ value
DWORD dwIoBase) // IN - I/O base
{
HKEY hKey;
BOOL fRet=FALSE;
DWORD dwRet;
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,OHCI_DRIVER_KEY,0,0,&hKey);
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR,(TEXT("!OHCD:SetRegistryConfig RegOpenKeyEx(%s) failed %d\r\n"),
OHCI_DRIVER_KEY, dwRet));
return FALSE;
}
dwRet = RegSetValueEx(hKey,IRQ_VALUE_NAME,0,REG_DWORD,(PUCHAR)&dwIrq,sizeof(DWORD));
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR, (TEXT("!OHCD:SetRegistryConfig RegQueryValueEx(%s) failed %d\r\n"),
IRQ_VALUE_NAME, dwRet));
goto SetRegistryConfig_exit;
}
dwRet = RegSetValueEx(hKey,IOBASE_VALUE_NAME,0,REG_DWORD,(PUCHAR)&dwIoBase,sizeof(DWORD));
if (dwRet != ERROR_SUCCESS) {
RETAILMSG(ZONE_ERROR,(TEXT("!OHCD:SetRegistryConfig RegQueryValueEx(%s) failed %d\r\n"),
IOBASE_VALUE_NAME, dwRet));
goto SetRegistryConfig_exit;
}
fRet = TRUE;
SetRegistryConfig_exit:
RegCloseKey(hKey);
return fRet;
} // SetRegistryConfig
/* ConfigureOHCICard
*
* Configure OHCI controller I/O base and IRQ based on settings read from registry.
* This should really call routines which access the IRQ routing and memory base through
* the PCI BIOS and reconfigure the card. Since we currently don't have the routines
* to do this, use the following algorithm:
* -- If fUseExisting flag is set, read the values from the PCI config registers on the
* card, and update pioPortBase and pIrq.
* -- If fUseExisting is not set, verify that the passed in values of pioPortBase and
* pIrq match, and return FALSE if they do not. (change - don't fail if mem base
* doesn't match, since this is determined by the PCI config mechanism, it will not
* conflict with other cards.)
*
* Return Value
* Return TRUE if successful, FALSE if card could not be detected, or if configuration
* does not match what was specified in the registry, and fUseExistingSettings is not set.
*/
BOOL
ConfigureOHCICard(
BOOL fUseExistingSettings,
PUCHAR *pioPortBase, // IN - contains physical address of register base
// OUT- contains virtual address of register base
ULONG *pIrq) // IN - contains IRQ value
// OUT- (if fUseExistingSettings) contains actual IRQ value
{
const USHORT cDefaultOhcdPortRange = 0x70;
const ULONG cHTBAMemorySpace = 0;
const ULONG cHTBAIOSpace = 1;
ULONG portRange = cDefaultOhcdPortRange;
ULONG inIoSpace = cHTBAMemorySpace;
ULONG portBase;
int bus, device, function;
*pIrq = USB_INTR;
(DWORD)*pioPortBase = USB_BASE; // This address must be changed to the virtual address.
// In this time, I don't konw the virtual address map.
// The physical IO address on the 2400 board.
// This value must be defined in the config.bib.
// by hjcho 04/16
// Virtual address allocation.
// In the MDD, the USB operational registers are accessed.
// I think that I have to do virtual allocation and virtual copy to use all registers
// for the USB operations.
// Currently, I am not sure these codes are needed.
// by hjcho 04/16
v_USBreg = (ULONG*)VirtualAlloc(0, USB_OPERATIONAL_REGISTER_SIZE,
MEM_RESERVE, PAGE_NOACCESS);
if (v_USBreg == NULL)
{
ERRORMSG(1,
(TEXT("USB Operational Register Addresses: VirtualAlloc failed!\r\n")));
goto error_return;
}
if (!VirtualCopy((PVOID)v_USBreg,
(PVOID)USB_BASE,
USB_OPERATIONAL_REGISTER_SIZE,
PAGE_READWRITE|PAGE_NOCACHE) )
{
ERRORMSG(1,
(TEXT("USB Operational Register Addresses: VirtualCopy failed!\r\n")));
goto error_return;
}
SetRegistryConfig(*pIrq, (DWORD)*pioPortBase);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -