⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edeviceinit.c

📁 Xcale270Bsp包,wince平台
💻 C
字号:
/* 
** INTEL CONFIDENTIAL
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors.  Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.

** No 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. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
*/

#include <windows.h>
#include <ethdbg.h>
#include <halether.h>
#include "bvd1.h"
#include "bvd1bd.h"
#include "drv_glob.h"
#include "xllp_ethernet.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 SLOT1_ATT_SPACE		(PCMCIA_S1_ATTR_U_VIRTUAL)
#define SLOT1_IO_WINDOW		(PCMCIA_S1_IO_U_VIRTUAL+0x300)
#define SLOT0_ATT_SPACE	    (PCMCIA_S0_ATTR_U_VIRTUAL)
#define SLOT0_IO_WINDOW		(PCMCIA_S0_IO_U_VIRTUAL+0x300)

#define UNKNOWN_DEVICE  0
#define NONE            -1

DWORD   bootDevice = NONE;

#define OSCR_OFFSET 0x10

int LocateCard(UINT SlotAddress);

void Wait(unsigned);
usWait(unsigned);
msWait(unsigned); 
static UINT DetermineCardType(UINT SlotAddress);

extern XLLP_UINT32_T XllpEthernetTransmitPacket(P_XLLP_UINT16_T buffer, XLLP_UINT32_T length);
extern XLLP_UINT32_T XllpEthernetReceivePacket(P_XLLP_UINT32_T buffer, P_XLLP_INT32_T rxCount);
extern XLLP_UINT32_T XllpEthernetHWSetup(P_XLLP_UINT16_T macAddressP, XLLP_BOOL_T autoRelease, XLLP_BOOL_T autoNegotiate, XllpEthernetLoopbackEnableT enable);
extern void XllpEthernetSWInit(void* ioRegsP);
extern void XllpEthernetSetMulticastList (P_XLLP_UINT8_T multicastAddrP, XLLP_UINT32_T addrCntr);

//
// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
PFN_EDBG_INIT             pfnEDbgInit;
PFN_EDBG_ENABLE_INTS      pfnEDbgEnableInts;
PFN_EDBG_DISABLE_INTS     pfnEDbgDisableInts;
PFN_EDBG_GET_PENDING_INTS pfnEDbgGetPendingInts;
PFN_EDBG_GET_FRAME        pfnEDbgGetFrame;
PFN_EDBG_SEND_FRAME       pfnEDbgSendFrame;
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

int LocateCard(UINT SlotAddress)
{
	volatile BLR_REGS *BLR = (BLR_REGS *)FPGA_REGS_BASE_U_VIRTUAL;
	volatile XLLP_GPIO_T *v_pGPIOReg = (XLLP_GPIO_T *)GPIO_BASE_U_VIRTUAL;	//hzh
	volatile MEMC_STRUCT *v_pMEMCTRLReg = (volatile MEMC_STRUCT *)MEMC_BASE_U_VIRTUAL;
	volatile DWORD *v_pSRCR;
	int slotVoltage = PCMCIA_VCC3V_VPP0V;

	switch(SlotAddress)
	{
		case SLOT0_ATT_SPACE:
			v_pSRCR = (volatile DWORD *)&(BLR->pcmcia0_srcr);
			break;
		case SLOT1_ATT_SPACE:		
			v_pSRCR = (volatile DWORD *)&(BLR->pcmcia1_srcr);
			break;
		default:
			break;
	}

	// Initialize the PCMCIA interface if a card is detected
	//if (!((*v_pSRCR & CARD_DETECT) == CARD_DETECT))
	if (!(v_pGPIOReg->GPLR2 & (1<<19)))	//hzh
	{
		EdbgOutputDebugString("Performing card initialization.  Please wait ...\r\n");

		// Configure the MAX1602EE power supply based on the voltage requirement of the card
		//if (((*v_pSRCR & VS1) == VS1) && ((*v_pSRCR & VS2) == VS2))
		if (v_pGPIOReg->GPLR2 & (1<<18))	//hzh
		{
			// 5 volt card detected
			slotVoltage = PCMCIA_VCC5V_VPP0V;
		}
		else 
		{					
			// 3.3 volt card detected
			slotVoltage = PCMCIA_VCC3V_VPP0V;
		}
#if 0	//hzh
		*v_pSRCR &= ~(PCMCIA_POWER | PCMCIA_RESET);
		msWait(50);
		
		*v_pSRCR |= slotVoltage;
		msWait(50);

		*v_pSRCR |= PCMCIA_RESET;
		msWait(50);

		*v_pSRCR &= ~PCMCIA_RESET;
		msWait(50);

		v_pMEMCTRLReg->mecr = 0x3;		    
		msWait(50);			
#else
		v_pGPIOReg->GPSR1 |= 1<<20;
		msWait(50);
		v_pGPIOReg->GPCR1 |= 1<<20;
		msWait(50);
		v_pMEMCTRLReg->mecr = 0x2;
		msWait(50);
#endif
		return TRUE;
	} 
	return FALSE;
}


void Wait(unsigned Microscont)
{
    volatile unsigned *lTimerOSCRAddress= (unsigned *)(OST_BASE_U_VIRTUAL+OSCR_OFFSET);
  
    unsigned lValue,Time;

    Time=*lTimerOSCRAddress;

    lValue = Time + (Microscont*4);
    if (lValue < Time) 
    {  // test for wrap
        while (Time < *lTimerOSCRAddress);
    }
    while(*lTimerOSCRAddress <= lValue);
}

msWait(unsigned msVal) 
{
    Wait(msVal*1000);
}

static UINT
DetermineCardType(
	UINT SlotAddress		// Address of ATT space.
)
{
	PUCHAR pAttr = (PUCHAR) SlotAddress;
	PUCHAR pLastAttr;
	UINT CardType = 0;
	UCHAR Attr;
  

	EdbgOutputDebugString("Determining card type\r\n");

	for (pLastAttr = pAttr + 0x200; pAttr < pLastAttr; pAttr += 16) {
		EdbgOutputDebugString("0x%x:  %x %x %x %x ", pAttr,*pAttr,*(pAttr+2),*(pAttr+4),*(pAttr+6));
		EdbgOutputDebugString("%x %x %x %x\r\n",
			*(pAttr+8), *(pAttr+10), *(pAttr+12), *(pAttr+14));
	}

	pAttr = (PUCHAR) SlotAddress;
	for (pLastAttr = pAttr + 0x200; pAttr < pLastAttr; pAttr += 16) {
		EdbgOutputDebugString("0x%x:  %c%c%c%c ", pAttr,*pAttr,*(pAttr+2),*(pAttr+4),*(pAttr+6));
		EdbgOutputDebugString("%c%c%c%c\r\n",
			*(pAttr+8), *(pAttr+10), *(pAttr+12), *(pAttr+14));
	}


	pAttr = (PUCHAR) SlotAddress;
	pLastAttr = pAttr + 0x200;

	Attr = *pAttr;
	if (Attr != (UCHAR) 0x01 && Attr != (UCHAR)0x1c) //hzh, add 0x1c
	{
		EdbgOutputDebugString("Invalid configuration data 0x%X\r\n", *pAttr);
	}

	while ((Attr != (UCHAR) 0x21) && (pAttr < pLastAttr)) {
		pAttr += 2;						// step to tuple length
		Attr = *pAttr;
		pAttr += 2 + (2 * Attr);		// step over tuple
		Attr = *pAttr;
	}

	if (pAttr < pLastAttr) 
	{
		pAttr += 2;						// defined tuple length
		if ((Attr = *pAttr) == 2) 
		{
			pAttr += 2;
			Attr = *pAttr;

			if (Attr == 0x06)
			switch (Attr) {
			  case ((UCHAR) 6):  
				  //EdbgOutputDebugString("Type ETHERNET\r\n");
				  CardType = 1;
				  break;
			}
		}
	}
	return CardType;
}

// EthDevice == 0 --> Try to initialize PCMCIA Slot 0
// EthDevice == 1 --> Try to initialize PCMCIA Slot 1
// EthDevice == 2 --> Try to initialize SMSC
int InitSpecifiedEthDevice(EDBG_ADDR *MyAddr, DWORD EthDevice)
{
	UINT EbootDeviceAddress = UNKNOWN_DEVICE;
    int Offset;      
    PUCHAR pAttr;
	UCHAR uByte;
    UINT SlotAddress = 0;
	PDRIVER_GLOBALS pDriverGlobals = (PDRIVER_GLOBALS)DRIVER_GLOBALS_PHYSICAL_MEMORY_START;
    UINT   multiplier=0;
    volatile BLR_REGS *BLR = (BLR_REGS *)FPGA_REGS_BASE_U_VIRTUAL;
    volatile XLLP_GPIO_T *v_pGPIOReg = (XLLP_GPIO_T *)GPIO_BASE_U_VIRTUAL;	//hzh

	// If EBOOT is calling this function, then uninit_misc.EbootDevice will equal BOOT_DEVICE_NONE.  
	// In this case, we'll initialize the boot device given by EthDevice.
	// Once EBOOT determines the boot device, it will set uninit_misc.EbootDevice to the appropriate value.
	// When Ethernet Debugging is enabled, the ethernet device is initialized again by the Kernel.
	// When the Kernel calls into this function, we'll grab the value of the uninit_misc.EbootDevice and 
	// then specifically initialize that same device rather than seek the debug device.
	switch (pDriverGlobals->uninit_misc.EbootDevice)
	{
		case BOOT_DEVICE_NONE:
			switch (EthDevice)
			{
				case 0: 
					SlotAddress = SLOT0_ATT_SPACE;
					break;
				case 1:
					SlotAddress = SLOT1_ATT_SPACE;
					break;
				case 2:
					SlotAddress = SMSC_ETHERNET_BASE_U_VIRTUAL;
					break;
				default:
					SlotAddress = SMSC_ETHERNET_BASE_U_VIRTUAL;
					break;
			}
			break;
		case BOOT_DEVICE_SLOT0:
			SlotAddress = SLOT0_ATT_SPACE;
			break;
		case BOOT_DEVICE_SLOT1:
			SlotAddress = SLOT1_ATT_SPACE;
			break;
		case BOOT_DEVICE_SMC:
			SlotAddress = SMSC_ETHERNET_BASE_U_VIRTUAL;
			break;
		default:
			SlotAddress = SMSC_ETHERNET_BASE_U_VIRTUAL;
			break;
	}

	if ((SlotAddress == SLOT0_ATT_SPACE) || (SlotAddress == SLOT1_ATT_SPACE))
	{
		if (LocateCard(SlotAddress))
		{
			if (DetermineCardType(SlotAddress))
			{
				//if ( ((BLR->pcmcia0_srcr & PCMCIA_POWER == PCMCIA_VCC5V_VPP0V) && (SlotAddress == SLOT0_ATT_SPACE)) ||
				//	 ((BLR->pcmcia1_srcr & PCMCIA_POWER == PCMCIA_VCC5V_VPP0V) && (SlotAddress == SLOT1_ATT_SPACE) ) )
				if (v_pGPIOReg->GPLR2 & (1<<18))	//hzh
				{
					EdbgOutputDebugString("5.0V Card detected in slot %d.\r\n", ((SlotAddress == SLOT0_ATT_SPACE)?0:1));

					uByte = 0x21;
 					Offset = CIS_R0;
 					pAttr = (PUCHAR) SlotAddress;
 					pAttr += Offset; 
 					*pAttr = uByte;

 					uByte = 0x1;			
 					Offset = CIS_R0 + 2;
  					pAttr = (PUCHAR) SlotAddress;
  					pAttr += Offset; 
  					*pAttr = uByte;
				}
				else 
				{
					EdbgOutputDebugString("3.3V Card detected in slot %d.\r\n", ((SlotAddress == SLOT0_ATT_SPACE)?0:1));
					uByte = 0x20;			
 					Offset = CIS_R0;
  					pAttr = (PUCHAR) SlotAddress;
  					pAttr += Offset; 
  					*pAttr = uByte;
        		}
				EbootDeviceAddress = (SlotAddress == SLOT0_ATT_SPACE)?SLOT0_IO_WINDOW:SLOT1_IO_WINDOW;

				// init the card
				if(NE2000Init( (BYTE *) EbootDeviceAddress, 1, MyAddr->wMAC))
				{
					pfnEDbgInit           = NE2000Init;
					pfnEDbgEnableInts     = NE2000EnableInts;     
					pfnEDbgDisableInts    = NE2000DisableInts;    
					pfnEDbgGetPendingInts = NE2000GetPendingInts; 
					pfnEDbgGetFrame       = NE2000GetFrame;       
					pfnEDbgSendFrame      = NE2000SendFrame;      
					pfnEDbgReadEEPROM     = NE2000ReadEEPROM;     
					pfnEDbgWriteEEPROM    = NE2000WriteEEPROM;    
					pfnEDbgSetOptions     = NE2000SetOptions;

					#ifdef IMGSHAREETH
						pfnCurrentPacketFilter = NULL;
						pfnMulticastList       = NULL;
					#endif

					pDriverGlobals->uninit_misc.EbootDevice = (SlotAddress == SLOT0_ATT_SPACE)?BOOT_DEVICE_SLOT0:BOOT_DEVICE_SLOT1;
					EdbgOutputDebugString("NE2000 Ethernet controller initialized.\n");

					return (EDBG_ADAPTER_NE2000);
				}
			}
		}
		return NONE;
	}
	
	EbootDeviceAddress = SMSC_ETHERNET_BASE_U_VIRTUAL;

	EdbgOutputDebugString("Checking for LAN91C111 Ethernet controller...\r\n");
	
	XllpEthernetSWInit((void *)EbootDeviceAddress);
	MyAddr->wMAC[0] = 0x8000; MyAddr->wMAC[1] = 0x1248; MyAddr->wMAC[2] = 0x5634;	//hzh, set mac
	if (XllpEthernetHWSetup((P_XLLP_UINT16_T) MyAddr->wMAC, TRUE, TRUE, XLLP_ETHERNET_LOOPBACK_DISABLE) == 0)
	{
		EdbgOutputDebugString("LAN91C111 Ethernet controller initialized.\r\n");

		pfnEDbgInit           = SMCInit;
		pfnEDbgEnableInts     = SMCEnableInts;     
		pfnEDbgDisableInts    = SMCDisableInts;    
		pfnEDbgGetPendingInts = SMCGetPendingInterrupts; 
		pfnEDbgGetFrame       = SMCGetFrame;       
		pfnEDbgSendFrame      = SMCSendFrame;      
		pfnEDbgReadEEPROM     = SMCReadEEPROM;     
		pfnEDbgWriteEEPROM    = SMCWriteEEPROM;
		pfnEDbgSetOptions     = SMCSetOptions;

		#ifdef IMGSHAREETH
			pfnCurrentPacketFilter = SMCCurrentPacketFilter;
			pfnMulticastList       = SMCMulticastList;
		#endif

		pDriverGlobals->uninit_misc.EbootDevice = BOOT_DEVICE_SMC;

		return (EDBG_ADAPTER_SMC9000);
	}

	return NONE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -