📄 kitl.c
字号:
// Copyright (c) David Vescovi. All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// File: kitl.c
//
//------------------------------------------------------------------------------
#include <bsp.h>
#include <kitl_cfg.h>
#include <devload.h>
static BOOL SetDeviceDriverFlags(LPCWSTR szKeyPath, DWORD flags)
{
BOOL rc = FALSE;
HKEY hKey;
UINT32 value;
// Open/create key
if (NKRegCreateKeyEx(
HKEY_LOCAL_MACHINE, szKeyPath, 0, NULL, 0, 0, NULL,
&hKey, &value
) != ERROR_SUCCESS) goto cleanUp;
// Set value
rc = NKRegSetValueEx(
hKey, L"Flags", 0, REG_DWORD, (UCHAR*)&flags, sizeof(DWORD)
) == ERROR_SUCCESS;
// Close key
NKRegCloseKey(hKey);
cleanUp:
return rc;
}
//------------------------------------------------------------------------------
//
// Platform entry point for KITL. Called when KITLIoctl (IOCTL_KITL_STARTUP, ...) is called.
//
BOOL OEMKitlStartup()
{
BOOL rc = FALSE;
OAL_KITL_ARGS *pKITLArgs, KITLArgs;
CHAR *pszDeviceId;
OAL_KITL_DEVICE *pDevice;
KITL_RETAILMSG(ZONE_KITL_OAL, ("+OEMKitlStartup\r\n"));
// Look for bootargs left by the bootloader or left over from an earlier boot.
//
pKITLArgs = (OAL_KITL_ARGS*) OALArgsQuery(OAL_ARGS_QUERY_KITL);
pszDeviceId = (CHAR*) OALArgsQuery(OAL_ARGS_QUERY_DEVID);
// If no KITL arguments were found (typically provided by the bootloader), then select
// some default settings.
//
if (pKITLArgs == NULL)
{
KITL_RETAILMSG(ZONE_WARNING, (
"WARN: Boot arguments not found, use defaults\r\n"
));
memset(&KITLArgs, 0, sizeof(OAL_KITL_ARGS));
// By default, enable: KITL, DHCP, and VMINI...
KITLArgs.flags = (OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_DHCP | OAL_KITL_FLAGS_VMINI);
// Use LAN91C111 controller on ETH1 for KITL.
KITLArgs.devLoc.IfcType = Internal;
KITLArgs.devLoc.BusNumber = 0;
KITLArgs.devLoc.PhysicalLoc = (PVOID)(SMSC_ETH1_PA_BASE_REG + 0x300);
KITLArgs.devLoc.LogicalLoc = (DWORD)KITLArgs.devLoc.PhysicalLoc;
pKITLArgs = &KITLArgs;
}
if (pszDeviceId == NULL)
{
KITL_RETAILMSG(ZONE_ERROR, ("ERROR: Unable to locate Device ID buffer\r\n"));
goto cleanUp;
}
else if (pszDeviceId[0] == '\0')
{
// We don't yet have the Ethernet controller's MAC address (this is obtained
// in the initialization function. Store a base name for the device, and
// signal that it should be extended with the MAC address later.
//
strncpy(pszDeviceId, BSP_DEVICE_PREFIX, OAL_KITL_ID_SIZE);
pKITLArgs->flags |= OAL_KITL_FLAGS_EXTNAME;
}
pDevice = OALKitlFindDevice(&pKITLArgs->devLoc, g_kitlDevices);
if (pDevice == NULL)
{
KITL_RETAILMSG(ZONE_ERROR, ("ERROR: Kitl Device not found in kitl_cfg table.\r\n"));
goto cleanUp;
}
// Finally call KITL library.
//
rc = OALKitlInit(pszDeviceId, pKITLArgs, pDevice);
cleanUp:
KITL_RETAILMSG(ZONE_KITL_OAL, ("-OEMKitlStartup(rc = %d)\r\n", rc));
return(rc);
}
//------------------------------------------------------------------------------
//
// Function: OALKitlInitRegistry
//
// This function is called during the initialization process to allow the
// OAL to denote devices which are being used by the KITL connection
// and thus shouldn't be touched during the OS initialization process. The
// OAL provides this information via the registry.
//
VOID OALKitlInitRegistry()
{
DEVICE_LOCATION devLoc;
DWORD dwHardwareConfiguration;
// If we're using one of the devices for the KITL connection, then we
// should disable the driver (via the "no load" option in the registry)
// in order to avoid a conflict.
//
KITL_RETAILMSG(ZONE_KITL_OAL, ("+OALKitlInitRegistry\r\n"));
dwHardwareConfiguration = *(UINT32 *) OALArgsQuery(BSP_ARGS_QUERY_HARDWARE);
if (((dwHardwareConfiguration & GUMCFG_CF) && !(dwHardwareConfiguration & GUMCFG_WIFI)) ||
(!(dwHardwareConfiguration & GUMCFG_CF) && (dwHardwareConfiguration & GUMCFG_WIFI)))
{
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\PCC_GUM1", DEVFLAGS_NOLOAD);
}
// Get KITL device location
if (!OALKitlGetDevLoc(&devLoc)) goto cleanUp;
switch (devLoc.LogicalLoc)
{
case PXA255_BASE_REG_PA_PCMCIA_S0_IO + 0x300:
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\PCC_GUM0", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: PCCARD Slot 0 being used for KITL - disabling driver instance...\r\n"));
break;
case PXA255_BASE_REG_PA_PCMCIA_S1_IO + 0x300:
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\PCC_GUM1", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: PCCARD Slot 1 being used for KITL - disabling driver instance...\r\n"));
break;
case SMSC_ETH1_PA_BASE_REG + 0x300:
SetDeviceDriverFlags(L"Comm\\ETH1", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: ETH1 being used for KITL - disabling driver instance...\r\n"));
break;
case SMSC_ETH2_PA_BASE_REG + 0x300:
SetDeviceDriverFlags(L"Comm\\ETH2", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: ETH2 being used for KITL - disabling driver instance...\r\n"));
break;
case PXA255_BASE_REG_PA_STUART:
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\Serial1", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: STUART being used for KITL - disabling driver instance...\r\n"));
break;
case PXA255_BASE_REG_PA_BTUART:
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\Serial3", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: BTUART being used for KITL - disabling driver instance...\r\n"));
break;
case PXA255_BASE_REG_PA_HWUART:
SetDeviceDriverFlags(L"Drivers\\BuiltIn\\Serial4", DEVFLAGS_NOLOAD);
KITL_RETAILMSG(TRUE, ("INFO: HWUART being used for KITL - disabling driver instance...\r\n"));
break;
}
cleanUp:
KITL_RETAILMSG(ZONE_KITL_OAL, ("-OALKitlInitRegistry\r\n"));
return;
}
//------------------------------------------------------------------------------
//
// Function: OEMKitlIoctl
//
// This function handles KITL IOCTL codes.
//
//
BOOL OEMKitlIoctl (DWORD code, VOID * pInBuffer, DWORD inSize, VOID * pOutBuffer, DWORD outSize, DWORD * pOutSize)
{
BOOL fRet = FALSE;
switch (code) {
case IOCTL_HAL_INITREGISTRY:
OALKitlInitRegistry();
break;
default:
fRet = OALIoCtlVBridge (code, pInBuffer, inSize, pOutBuffer, outSize, pOutSize);
}
return fRet;
}
DWORD OEMKitlGetSecs (void)
{
SYSTEMTIME st;
DWORD dwRet;
static DWORD dwBias;
static DWORD dwLastTime;
OEMGetRealTime( &st );
dwRet = ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
dwBias = dwRet;
if (dwRet < dwLastTime) {
KITL_RETAILMSG(ZONE_WARNING, ("WARN: Time went backwards (or wrapped): cur: %u, last %u\n",dwRet,dwLastTime));
}
dwLastTime = dwRet;
return (dwRet);
}
//------------------------------------------------------------------------------
//
// Function: OALGetTickCount
//
// This function is called by some KITL libraries to obtain relative time
// since device boot. It is mostly used to implement timeout in network
// protocol.
//
UINT32 OALGetTickCount()
{
return OEMKitlGetSecs () * 1000;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -