📄 ether.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
// File: ether.c
//
// Core Ethernet routines for the Intel Mainstone II bootloader.
//
//------------------------------------------------------------------------------
/*
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#include <windows.h>
#include <bulverde.h>
#include <mainstoneii.h>
#include <ethdbg.h>
#include <ndis.h>
#include <rndismini.h>
#include <halether.h>
#include <oal_memory.h>
#include <ethdrv.h>
#include <ceddk.h>
#include "loader.h"
// Miscellaneous definitions.
//
#define CARD_DETECT 0x20
#define PCMCIA_POWER 0x0F
#define PCMCIA_RESET 0x10
#define VS1 0x40
#define VS2 0x80
#define PCMCIA_VCC3V_VPP0V 0x08
#define PCMCIA_VCC5V_VPP0V 0x04
#define CIS_R0 0x3F8
#define OSCR_OFFSET 0x10 // OSCR0
#define SDBG_USB_SERIAL 101
// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
PFN_EDBG_INIT pfnEDbgInit;
PFN_EDBG_GET_FRAME pfnEDbgGetFrame;
PFN_EDBG_SEND_FRAME pfnEDbgSendFrame;
PFN_EDBG_ENABLE_INTS pfnEDbgEnableInts;
PFN_EDBG_DISABLE_INTS pfnEDbgDisableInts;
PFN_EDBG_GET_PENDING_INTS pfnEDbgGetPendingInts;
PFN_EDBG_READ_EEPROM pfnEDbgReadEEPROM;
PFN_EDBG_WRITE_EEPROM pfnEDbgWriteEEPROM;
PFN_EDBG_SET_OPTIONS pfnEDbgSetOptions;
#ifdef IMGSHAREETH
PFN_EDBG_CURRENT_PACKET_FILTER pfnCurrentPacketFilter;
PFN_EDBG_MULTICAST_LIST pfnMulticastList;
#endif
extern BOOL RndisInit( BYTE *pbBaseAddress, DWORD dwMultiplier, USHORT MacAddr[3]);
extern EBOOT_CFG g_EbootCFG;
static void Wait(UINT32 microSeconds)
{
volatile UINT32 *TimerOSCRAddress= (volatile UINT32 *) OALPAtoVA((BULVERDE_BASE_REG_PA_OST + OSCR_OFFSET), FALSE);
UINT32 Value, Time;
Time = *TimerOSCRAddress;
Value = Time + (microSeconds * 4);
if (Value < Time)
{ // test for wrap.
while (Time < *TimerOSCRAddress);
}
while (*TimerOSCRAddress <= Value);
}
void msWait(UINT32 msVal)
{
Wait(msVal*1000);
}
VOID OALStall(UINT32 microSeconds)
{
Wait(microSeconds);
}
BOOL LocatePCMCIACard(BOOT_DEVICE_TYPE EthDevice, UINT32 SlotAddress)
{
UINT32 SlotVoltage = PCMCIA_VCC3V_VPP0V;
volatile UINT32 *pSRCR = NULL;
// volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *) OALPAtoVA(MAINSTONEII_BASE_REG_PA_FPGA, FALSE);
volatile BULVERDE_MEMCTRL_REG *pMEMCTRLRegs = (volatile BULVERDE_MEMCTRL_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_MEMC, FALSE);
switch (EthDevice)
{
/* case ETH_DEVICE_PCMCIA0:
pSRCR = (volatile UINT32 *)&(pBLRegs->pcmcia0_srcr);
break;
case ETH_DEVICE_PCMCIA1:
pSRCR = (volatile UINT32 *)&(pBLRegs->pcmcia1_srcr);
break;*/
default:
break;
}
if (!pSRCR)
{
return(FALSE);
}
// Initialize the PCMCIA interface if a card is detected.
//
if (!((*pSRCR & CARD_DETECT) == CARD_DETECT))
{
KITLOutputDebugString("INFO: Performing PCMCIA NIC initialization. Please wait...\r\n");
// Configure the MAX1602EE power supply based on the voltage requirement of the card.
//
if (((*pSRCR & VS1) == VS1) && ((*pSRCR & VS2) == VS2))
{
// 5 volt card detected.
//
SlotVoltage = PCMCIA_VCC5V_VPP0V;
}
else
{
// 3.3 volt card detected.
//
SlotVoltage = PCMCIA_VCC3V_VPP0V;
}
*pSRCR &= ~(PCMCIA_POWER | PCMCIA_RESET);
msWait(50);
*pSRCR |= SlotVoltage;
msWait(50);
*pSRCR |= PCMCIA_RESET;
msWait(50);
*pSRCR &= ~PCMCIA_RESET;
msWait(50);
pMEMCTRLRegs->mecr = 0x3;
msWait(50);
return (TRUE);
}
return (FALSE);
}
static BOOL VerifyEthernetPCMCIACard(UINT32 SlotAddress)
{
UINT8 Attribute;
UINT8 *pAttribute = (UINT8 *) SlotAddress;
UINT8 *pLastAttribute;
// End of the PCMCIA attribute list.
//
pLastAttribute = pAttribute + 0x200;
//
Attribute = *pAttribute;
if (Attribute != (UINT8) 0x01)
{
KITLOutputDebugString("ERROR: Invalid PCMCIA configuration data 0x%x.\r\n", Attribute);
return (FALSE);
}
// Look for tuple.
//
while ((Attribute != (UINT8) 0x21) && (pAttribute < pLastAttribute))
{
pAttribute += sizeof(UINT16); // Step to tuple length.
Attribute = *pAttribute;
pAttribute += sizeof(UINT16) + (sizeof(UINT16) * Attribute); // Step over tuple.
Attribute = *pAttribute;
}
// Find a valid tuple?
//
if (pAttribute < pLastAttribute)
{
pAttribute += sizeof(UINT16); // Defined tuple length.
if ((Attribute = *pAttribute) == 2)
{
pAttribute += sizeof(UINT16);
Attribute = *pAttribute;
// Found an Ethernet card...
//
if (Attribute == 0x06)
{
return (TRUE);
}
}
}
return (FALSE);
}
// EthDevice == 0 --> Try to initialize PCMCIA Slot 0.
// EthDevice == 1 --> Try to initialize PCMCIA Slot 1.
// EthDevice == 2 --> Try to initialize DM9000.
// EthDevice == 3 --> Try to initialize RNDIS
UINT32 InitSpecifiedEthDevice(OAL_KITL_ARGS *pKITLArgs, UINT32 BootDevice)
{
UINT32 EbootDeviceAddress = 0;
UINT32 Offset;
UINT8 *pAttribute = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -