📄 kitl.c
字号:
//**********************************************************************
//
// Filename: kitl.c
//
// Description:
//
// 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.
//
// Use of this source code is subject to the terms of the Cirrus 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
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
#include <windows.h>
#include <nkintr.h>
#include <kitl.h>
#include <halether.h>
#include <kitlprot.h>
//#include <platform.h>
#include <memorymap.h>
#include <mdppfs.h>
#include <drv_glob.h>
#include "ethdbg.h"
#include <devload.h>
#include <oal_kitl.h>
#include <cs8950sw.h>
#include <hwdefs.h>
#include <ceddk.h>
#include <oal_args.h>
#include <oal_ethdrv.h>
#include <oalintr.h>
#define pDriverGlobals ((PDRIVER_GLOBALS) DRIVER_GLOBALS_VIRTUAL_MEMORY)
static CHAR gDeviceId[OAL_KITL_ID_SIZE]="";
//Use the first word of CS8950_VIRTUAL_MEMORY to store if KITL is enabled.
static ULONG *pulCS8950KitlUsed = (ULONG *)CS8950_VIRTUAL_MEMORY;
OAL_KITL_ETH_DRIVER g_kitlEthCS8900A = {
(OAL_KITLETH_INIT) CS8950Init, //Type cast to avoid compile warning.
NULL,
NULL,
(OAL_KITLETH_SEND_FRAME) CS8950SendFrame, //Type cast to avoid compile warning.
CS8950GetFrame,
CS8950EnableInts,
CS8950DisableInts,
NULL,
NULL,
(OAL_KITLETH_CURRENT_PACKET_FILTER) CS8950EthCurrentPacketFilter,
(OAL_KITLETH_MULTICAST_LIST) CS8950EthMulticastList
};
OAL_KITL_ETH_DRIVER g_kitlEthNE2000 = OAL_ETHDRV_NE2000;
OAL_KITL_DEVICE g_kitlDeviceEp93xx[] = {
{
NULL, InterfaceTypeUndefined,
ETHERNET_BASE,
// PHYSICAL_SYSTEM_ASIC_REG_BASE + 0x00010000,
0, OAL_KITL_TYPE_ETH,
NULL
},
{
NULL, 0, 0, 0, 0, NULL
}
};
#ifdef IMGSHAREETH
BOOL bNewFilter = FALSE; // User mode --> Kernel mode to set new filter.
DWORD dwFilter; // The filter..
BOOL bNewMulticast = FALSE; // User mode --> Kernel mode for new list
DWORD dwNoOfEntry;
UCHAR ucMultiAddr[32][6]; // The new list..
// VMINI assumes 32 multicast list entry..
//
#endif
/* OEMKitlStartup
*
* Initialization routine - called from KitlInit() to perform platform specific
* HW init.
*
* Return Value:
* Return TRUE if init is successful, FALSE if error.
*/
BOOL OEMKitlStartup (void)
{
BOOL rc = FALSE;
OAL_KITL_ARGS KITLArgs;
BOOL bTemp;
NKDbgPrintfW(L"+OEMKitlStartup MAC \r\n");
memcpy(gDeviceId,
(DRIVER_GLOBALS_POINTER)->eth.strEdbgName,
EDBG_MAX_DEV_NAMELEN);
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);
KITLArgs.devLoc.IfcType = InterfaceTypeUndefined;
KITLArgs.devLoc.BusNumber = 0;
switch(pDriverGlobals->eth.EdbgHardwareType)
{
#ifdef EP93XX_PCCARD
case EDBG_ADAPTER_NE2000:
g_kitlDeviceEp93xx->pDriver=&g_kitlEthNE2000;
g_kitlDeviceEp93xx->name=L"NE2000";
KITLArgs.devLoc.PhysicalLoc = (PVOID)(PCMCIACARD_IO_PHYSICAL + 0x320);
KITLArgs.devLoc.LogicalLoc = (PVOID)KITLArgs.devLoc.PhysicalLoc;
/*
pulEthernetBase = (ULONG *)(PCMCIACARD_IO + 0x320);
*/
EdbgOutputDebugString("INFO: EDBG using NE2000 controller.\r\n");
break;
#endif
//
case EDBG_ADAPTER_CS8950:
g_kitlDeviceEp93xx->pDriver=&g_kitlEthCS8900A;
g_kitlDeviceEp93xx->name=L"CS8950";
KITLArgs.devLoc.PhysicalLoc = (PVOID) ETHERNET_BASE;
//(PVOID)(PHYSICAL_SYSTEM_ASIC_REG_BASE + 0x00010000);
KITLArgs.devLoc.LogicalLoc = (DWORD)KITLArgs.devLoc.PhysicalLoc;
KITLArgs.devLoc.Pin=SYSINTR_ETHER;
//
// CS8950 DMA's to SDRAM. Need to give the library a physical and virtual
// address to uncached memory.
//
// Reserved the first 16 bytes for pulCS8950KitlUsed.
bTemp = CS8950DMAInit
(
CS8950_PHYSICAL_MEMORY+16,
CS8950_VIRTUAL_MEMORY+16,
CS8950_MEMORY_SIZE-16
);
//CS8950 now is used for KITL so Ethernet NDIS can check
// the address CS8950_VIRTUAL_MEMORY to abort NDIS.
//Write the pattern 0x5a5a5a5a to indicate CS8950 KITL is active.
*pulCS8950KitlUsed = 0x5a5a5a5a;
if(!bTemp)
{
EdbgOutputDebugString("ERROR: Failed to Initialize CS8950 DMA buffer.\r\n");
return FALSE;
}
//
// We need to do this since the board does not have a MAC address.
// Lets use the same mac address as eboot.
//
CS8950WriteEEPROM(0, pDriverGlobals->eth.EdbgAddr.wMAC[0]);
CS8950WriteEEPROM(1, pDriverGlobals->eth.EdbgAddr.wMAC[1]);
CS8950WriteEEPROM(2, pDriverGlobals->eth.EdbgAddr.wMAC[2]);
EdbgOutputDebugString("INFO: EDBG using Internal EP931x controller.\r\n");
break;
default:
EdbgOutputDebugString
(
"Unsupported debug Ethernet parameters - adapter: %u\n",
pDriverGlobals->eth.EdbgHardwareType
);
return (FALSE);
}
if (gDeviceId[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(gDeviceId, "EP93xx", sizeof("EP93xx") -1 );
KITLArgs.flags |= OAL_KITL_FLAGS_EXTNAME;
}
rc = OALKitlInit(gDeviceId, &KITLArgs, g_kitlDeviceEp93xx);
EdbgOutputDebugString("-OEMKitlStartup(rc = %d)\r\n", rc);
return(rc);
}
DWORD OALGetTickCount(void)
{
extern DWORD OEMGetTickCount(void);
return OEMGetTickCount( );
}
UINT16 READ_PORT_USHORT(UINT16 *pAddr)
{
return(*(volatile unsigned short *)pAddr);
}
void WRITE_PORT_USHORT(UINT16 *pAddr, UINT16 Data)
{
*(volatile UINT16 *)pAddr = Data;
}
UINT16 READ_PORT_USHORT16(UINT16 *pAddr)
{
return(*(volatile unsigned short *)pAddr);
}
void WRITE_PORT_USHORT16(UINT16 *pAddr, UINT16 Data)
{
*(volatile UINT16 *)pAddr = Data;
}
UCHAR
READ_PORT_UCHAR(
PUCHAR Port
)
{
return *(volatile UCHAR * const)Port;
}
VOID
WRITE_PORT_UCHAR(
PUCHAR Port,
UCHAR Value
)
{
*(volatile UCHAR * const)Port = Value;
}
VOID
WRITE_REGISTER_USHORT(
PUSHORT Register,
USHORT Value
)
{
*(volatile USHORT * const)Register = Value;
}
VOID
WRITE_REGISTER_ULONG(
PULONG Register,
ULONG Value
)
{
*(volatile ULONG * const)Register = Value;
}
USHORT
READ_REGISTER_USHORT(
PUSHORT Register
)
{
return (*(volatile USHORT * const)Register);
}
ULONG
READ_REGISTER_ULONG(
PULONG Register
)
{
return (*(volatile ULONG * const)Register);
}
//
DWORD GetSystemTimeInMsec(void)
{
DWORD dwValue;
dwValue = *TIM_DEBUGVALUELOW;
dwValue >>= 10;
// div by 1024 to get msec from usec (should really use
// 1000 instead of 1024, but it is close enough
dwValue|= (*TIM_DEBUGVALUEHIGH & DEBUGVALUEHIGH_MASK)<<22;
return dwValue;
}
//****************************************************************************
// GetSystemTimeInUSec
//****************************************************************************
//
ULONGLONG GetSystemTimeInUSec(void)
{
volatile LARGE_INTEGER liValue;
//
// Must read the low value first.
//
liValue.LowPart = (ULONG)*TIM_DEBUGVALUELOW;
liValue.HighPart = (ULONG)(*TIM_DEBUGVALUEHIGH & DEBUGVALUEHIGH_MASK);
return liValue.QuadPart;
}
//****************************************************************************
// DelayInMsec
//****************************************************************************
// Delay a certain number of milliseconds.
//
//
//
void DelayInMsec(DWORD msec)
{
DWORD passed, startTime;
startTime=GetSystemTimeInMsec();
passed=0;
//
// Get stuck in this loop until
//
while ( passed < msec)
{
passed = GetSystemTimeInMsec()-startTime;
}
}
//****************************************************************************
// DelayInuSec
//****************************************************************************
// Delay a certain number of microseconds.
//
//
//
void DelayInuSec(DWORD uS)
{
DWORD passed, startTime;
startTime= *TIM_DEBUGVALUELOW;
passed=0;
//
// Get stuck in this loop until
//
while ( passed < uS)
{
passed = (*TIM_DEBUGVALUELOW - startTime);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -