📄 kitl.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// File: kitl.c
//
#include <windows.h>
#include <halether.h>
#include <oal.h>
//------------------------------------------------------------------------------
//
// Global: g_oalKitlBuffer
//
// This global variable is intended to be used by KITL protocol implementation.
//
UINT8 g_oalKitlBuffer[OAL_KITL_BUFFER_SIZE];
//------------------------------------------------------------------------------
//
// Global: g_kitlState
//
// This global static variable store common KITL state information.
//
static struct {
CHAR deviceId[OAL_KITL_ID_SIZE];
OAL_KITL_ARGS args;
OAL_KITL_DEVICE *pDevice;
} g_kitlState;
//------------------------------------------------------------------------------
// External functions
//
BOOL OALKitlSerialInit(
LPSTR deviceId, OAL_KITL_DEVICE *pDevice, OAL_KITL_ARGS *pArgs,
KITLTRANSPORT *pKitl
);
BOOL OALKitlEthInit(
LPSTR deviceId, OAL_KITL_DEVICE *pDevice, OAL_KITL_ARGS *pArgs,
KITLTRANSPORT *pKitl
);
//------------------------------------------------------------------------------
//
// Function: OALKitlGetDevLoc
//
// This function allows other module to obtain KITL device location.
//
BOOL OALKitlGetDevLoc(DEVICE_LOCATION *pDevLoc)
{
memcpy(pDevLoc, &g_kitlState.args.devLoc, sizeof(*pDevLoc));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: OEMKitlInit
//
// This function is called from KitlInit to initialize KITL device and
// KITLTRANSPORT structure. Implementation verify boot args structure validity
// and call KITL device class init function.
//
BOOL OEMKitlInit(PKITLTRANSPORT pKitl)
{
BOOL rc = FALSE;
OALMSG(OAL_KITL&&OAL_FUNC, (L"+OEMKitlInit(0x%08x)\r\n", pKitl));
switch (g_kitlState.pDevice->type) {
#ifdef KITL_ETHER
case OAL_KITL_TYPE_ETH:
rc = OALKitlEthInit(
g_kitlState.deviceId, g_kitlState.pDevice,
&g_kitlState.args, pKitl
);
break;
#endif
#ifdef KITL_SERIAL
case OAL_KITL_TYPE_SERIAL:
rc = OALKitlSerialInit(
g_kitlState.deviceId, g_kitlState.pDevice,
&g_kitlState.args, pKitl
);
break;
#endif
}
OALMSG(OAL_KITL&&OAL_FUNC, (L"-OEMKitlInit(rc = %d)\r\n", rc));
return rc;
}
//------------------------------------------------------------------------------
//
// Function: OALKitlInit
//
// This function is called from OEMInit to initialize KITL. It typically
// calls initialization routine for device KITL class and then KitlInit.
// The kernel/KITL then call back OEMKitlInit at moment when debug/KITL
// connection should be initialized.
//
BOOL OALKitlInit(
LPCSTR deviceId, OAL_KITL_ARGS *pArgs, OAL_KITL_DEVICE *pDevice
) {
BOOL rc = FALSE;
OALMSG(OAL_KITL&&OAL_FUNC, (
L"+OALKitlInit('%hs', 0x%08x - %d/%d/0x%08x, 0x%08x)\r\n", deviceId,
pArgs->flags, pArgs->devLoc.IfcType, pArgs->devLoc.BusNumber,
pArgs->devLoc.LogicalLoc, pDevice
));
// Display KITL parameters
OALMSG(OAL_INFO, (
L"DeviceId................. %hs\r\n", deviceId
));
OALMSG(OAL_INFO, (
L"pArgs->flags............. 0x%x\r\n", pArgs->flags
));
OALMSG(OAL_INFO, (
L"pArgs->devLoc.IfcType.... %d\r\n", pArgs->devLoc.IfcType
));
OALMSG(OAL_INFO, (
L"pArgs->devLoc.LogicalLoc. 0x%x\r\n", pArgs->devLoc.LogicalLoc
));
OALMSG(OAL_INFO, (
L"pArgs->devLoc.PhysicalLoc 0x%x\r\n", pArgs->devLoc.PhysicalLoc
));
OALMSG(OAL_INFO, (
L"pArgs->devLoc.Pin........ %d\r\n", pArgs->devLoc.Pin
));
OALMSG(OAL_INFO, (
L"pArgs->ip4address........ %s\r\n", OALKitlIPtoString(pArgs->ipAddress)
));
OALMSG(OAL_INFO, (
L"pDevice->Name............ %s\r\n", pDevice->name
));
OALMSG(OAL_INFO, (
L"pDevice->ifcType......... %d\r\n", pDevice->ifcType
));
OALMSG(OAL_INFO, (
L"pDevice->id.............. 0x%x\r\n", pDevice->id
));
OALMSG(OAL_INFO, (
L"pDevice->resource........ %d\r\n", pDevice->resource
));
OALMSG(OAL_INFO, (
L"pDevice->type............ %d\r\n", pDevice->type
));
OALMSG(OAL_INFO, (
L"pDevice->pDriver......... 0x%x\r\n", pDevice->pDriver
));
// If KITL is disabled simply return
if ((pArgs->flags & OAL_KITL_FLAGS_ENABLED) == 0) {
OALMSG(OAL_WARN, (L"WARN: OALKitlInit: KITL Disabled\r\n"));
rc = TRUE;
goto cleanUp;
}
// Find if we support device on given location
g_kitlState.pDevice = OALKitlFindDevice(&pArgs->devLoc, pDevice);
if (g_kitlState.pDevice == NULL) {
OALMSG(OAL_ERROR, (
L"ERROR: OALKitlInit: No supported KITL device at interface %d "
L"bus %d location 0x%08x\r\n", pArgs->devLoc.IfcType,
pArgs->devLoc.BusNumber, pArgs->devLoc.LogicalLoc
));
goto cleanUp;
}
// Save KITL configuration
memcpy(g_kitlState.deviceId, deviceId, sizeof(g_kitlState.deviceId));
memcpy(&g_kitlState.args, pArgs, sizeof(g_kitlState.args));
// Start KITL in desired mode
if (!KitlInit((pArgs->flags & OAL_KITL_FLAGS_PASSIVE) == 0)) {
OALMSG(OAL_ERROR, (L"ERROR: OALKitlInit: KitlInit failed\r\n"));
goto cleanUp;
}
rc = TRUE;
cleanUp:
OALMSG(OAL_KITL&&OAL_FUNC, (L"-OALKitlInit(rc = %d)\r\n", rc));
return rc;
}
//------------------------------------------------------------------------------
//
// Function: OALKitlPowerOff
//
// This function is called as part of OEMPowerOff implementation. It should
// save all information about KITL device and put it to power off mode.
//
VOID OALKitlPowerOff()
{
OALMSG(OAL_KITL&&OAL_FUNC, (L"+OALKitlPowerOff\r\n"));
switch (g_kitlState.pDevice->type) {
#ifdef KITL_ETHER
case OAL_KITL_TYPE_ETH:
{
OAL_KITL_ETH_DRIVER *pDriver;
pDriver = (OAL_KITL_ETH_DRIVER*)g_kitlState.pDevice->pDriver;
if (pDriver->pfnPowerOff != NULL) pDriver->pfnPowerOff();
}
break;
#endif
#ifdef KITL_SERIAL
case OAL_KITL_TYPE_SERIAL:
{
OAL_KITL_SERIAL_DRIVER *pDriver;
pDriver = (OAL_KITL_SERIAL_DRIVER*)g_kitlState.pDevice->pDriver;
if (pDriver->pfnPowerOff != NULL) pDriver->pfnPowerOff();
}
break;
#endif
}
OALMSG(OAL_KITL&&OAL_FUNC, (L"-OALKitlPowerOff\r\n"));
}
//------------------------------------------------------------------------------
//
// Function: OALKitlPowerOn
//
// This function is called as part of OEMPowerOff implementation. It should
// restore KITL device back to working state.
//
VOID OALKitlPowerOn()
{
OALMSG(OAL_KITL&&OAL_FUNC, (L"+OALKitlPowerOn\r\n"));
switch (g_kitlState.pDevice->type) {
#ifdef KITL_ETHER
case OAL_KITL_TYPE_ETH:
{
OAL_KITL_ETH_DRIVER *pDriver;
pDriver = (OAL_KITL_ETH_DRIVER*)g_kitlState.pDevice->pDriver;
if (pDriver->pfnPowerOn != NULL) pDriver->pfnPowerOn();
}
break;
#endif
#ifdef KITL_SERIAL
case OAL_KITL_TYPE_SERIAL:
{
OAL_KITL_SERIAL_DRIVER *pDriver;
pDriver = (OAL_KITL_SERIAL_DRIVER*)g_kitlState.pDevice->pDriver;
if (pDriver->pfnPowerOn != NULL) pDriver->pfnPowerOn();
}
break;
#endif
}
OALMSG(OAL_KITL&&OAL_FUNC, (L"-OALKitlPowerOn\r\n"));
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -