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

📄 tmpnp.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*---------------------------------------------------------------------------- 
COPYRIGHT (c) 1995 by Philips Semiconductors

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN 
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE 
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES 
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. 

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. 

PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/
/*
	HISTORY
	#define	TR	Tilakraj Roy
	960325	TR 	Created
	960325	TR 	Due to the PnP bug in TM-CTC we use the PCI Bios rather than
				Win95 for retrieving PnP Settings.
	960326	TR	Added conditional code for USE_CM
	960404	TR	Added code for handling configuration
	960620	TR	Added comments and remomed TMPNP_OBJECT dependency on TM_CONFIG

*/

/*----------------------------------------------------------------------------
          SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
#define WANTVXDWRAPS
#include <basedef.h>
#include <vmm.h>
#include <vxdwraps.h>
#include <vpicd.h>
#include <configmg.h>
#include <mmdevldr.h>
#include <vwin32.h>

/*----------------------------------------------------------------------------
          DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "vxstd.h"
#include "vxwin.h"
#include "vxdbg.h"
#include "tmwincom.h"

#include "tmshare.h"
#include "tmpnp.h"

#pragma VxD_LOCKED_CODE_SEG
#pragma	VxD_LOCKED_DATA_SEG

#define SDRAM_LENGTH	(8 * 1024 * 1024)
#define MMIO_LENGTH		(2 * 1024 * 1024)
/*----------------------------------------------------------------------------
          NT DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/

#define PCI_MAX_DEVICES                     32
#define PCI_MAX_FUNCTION                    8

#define PCI_INVALID_VENDORID                0xFFFF

DWORD	GLOBALCount = 0;
/*----------------------------------------------------------------------------
          GENERIC PNP FUNCTIONS
----------------------------------------------------------------------------*/
CONFIGRET CM_SYSCTRL
vxdConfigRegisterHandlerC ( DWORD dwDevNode, PVOID pvContext )
{
	LOAD_TYPE LoadType = (LOAD_TYPE)pvContext;

	if ( ((PINIT_OBJECT)(pDriverObject->pInitObj))->dwDisablePnP )
		return(CR_DEFAULT);



	switch (LoadType) 
	{
		case DLVXD_LOAD_ENUMERATOR:
			return(CR_DEFAULT);

		case DLVXD_LOAD_DRIVER:
			return 	CM_Register_Device_Driver(dwDevNode, vxdPnPConfigHandler, 0, 0);

		case DLVXD_LOAD_DEVLOADER:
			return(CR_DEFAULT);

		default:
			return(CR_DEFAULT);
	}

}

BOOL	pnpPCICheck ( VOID )
{
	if ( pciCheckBIOS () != TRUE )
	{
		DP(0,"TM:pnpInit:pciCheckBIOS:FAIL\n");
		return FALSE;
	}
	else
		return TRUE;

}
/*
	pnpGetFrameBuffer
	this function is universally invoked and is not linked to nay particular
	board. so it does not a pnp object to be passed to it.

STATUS	pnpGetFrameBuffer ( PDWORD pdwLinear, PDWORD pdwPhysical, 
	PDWORD pdwSize )
{
	BYTE	bBus, bDevFunc;
	DWORD	dwDeviceVendor;
	CONFIGRET	Result;
	CMCONFIG	Config;
	DWORD		dwLargest = 0;
	WORD		wIdxOfLargest;
	DWORD		dwDevNode;
	WORD		wIdx;

	//get the physical and logical address of the graphics frame buffer
	if ( pciFindClass ( 0x00030000, 0, &bBus, &bDevFunc ) == FALSE )
	{
		DP(0,"TM:pnpGetFrameBuffer:BIOS:FAIL\n");
		return (TM_STATUS(TMPNP_ERR_INVALIDSDRAMBASE ));
	}

	if ( pciReadConfigDW ( bBus, bDevFunc, (WORD)0x0, 
		&dwDeviceVendor ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:SDRAM Base Retrieve:FAIL\n");
		return (TM_STATUS(TMPNP_ERR_INVALIDSDRAMBASE));
	}

	pnpDevNodeGet ( ((PWORD)&dwDeviceVendor)[0], 
		((PWORD)&dwDeviceVendor)[1],  0, &dwDevNode );

	if ( ( Result = CM_Get_Alloc_Log_Conf ( 
		&Config, dwDevNode, 0  )) != CR_SUCCESS )
	{
		DP(0,"TM:pnpConfigStart:CM_Get_Alloc_Log_Config:FAIL\n");
		return (TM_STATUS(TMPNP_ERR_NODEVNODECONFIG));
	}

	// try the largest apperture and hope it's the frame buffer
	for ( wIdx = 0 ; wIdx < Config.wNumMemWindows ; wIdx ++)
	{
		if ( dwLargest < Config.dMemLength[wIdx] )
		{
			dwLargest = Config.dMemLength[wIdx];
			wIdxOfLargest = wIdx;
		}
	}

	*pdwLinear = _MapPhysToLinear ( 
		Config.dMemBase[wIdxOfLargest],
		Config.dMemLength[wIdxOfLargest], 0 );

	*pdwPhysical = Config.dMemBase[wIdxOfLargest];
	*pdwSize = Config.dMemLength[wIdxOfLargest];

	return TMOK;
}
*/
/*
	pnpDevNodeGet

	Retrieves the dev node for the given PCI device and stores
	it the pConfig structure.
	This function will not be used when the Pnp configuration works properly
	and the drivers are insatlled via an .inf file.
	This function is called once for every TM board present in the bus.
*/ 
STATUS	pnpDevNodeGet ( WORD wVendor, WORD wDevice, DWORD dwIdx, 
		DEVNODE *pDevNode )
{
	CHAR			szPNPID[256]; 
	CHAR			bBus, bDevFunc;

	if ( pciFindDevice ( wDevice, wVendor, (WORD)dwIdx,
		&bBus, &bDevFunc ) != TRUE )
	{
		DP(0,"TM:pnpDevNodeGet:pciFindDevice:FAIL\n");
		return ( TM_STATUS ( TMPNP_ERR_NODEVICE ) );
	}

	pnpPCINameGet ( wVendor, wDevice, bBus, bDevFunc, szPNPID);
	
	DP(10,"TM:pnpGetDevNode:[%s]\n", szPNPID);

	if ( ( CM_Locate_DevNode ( (PDEVNODE)pDevNode,
		szPNPID, (DWORD)0 ) ) != CR_SUCCESS )
	{
		DP(0,"TM:pnpGetDevNode:CM_Locate_DevNode:FAIL\n");
		return ( TM_STATUS ( TMPNP_ERR_NODEVNODE ) );
	}
	return (TMOK);
}


CONFIGRET	pnpOnConfigStop ( DEVNODE DevNode )
{
	return CR_SUCCESS;
}
CONFIGRET	pnpOnConfigTest ( DEVNODE DevNode )
{
	return CR_SUCCESS;
}
CONFIGRET	pnpOnConfigRemove ( DEVNODE DevNode )
{
	PVOID	pBoard;
	pBoard = vxdGetDeviceFromDevNode ( DevNode );
	vxdRemoveDevice ( pBoard );
	boardDestroy ( pBoard );
	return CR_SUCCESS;
}

/*
	pnpConfigStart

	This function retrieves the allocated logical configuration for 
	the enumerated PCI device. It populates the config structure.
	It can either retrieve the configuration from the BIOS or from the
	Config Manager.

*/
CONFIGRET	pnpOnConfigStart ( 
	DEVNODE DevNode, 
	DWORD BusNumber, 
	DWORD DeviceNumber, 
	DWORD FunctionNumber )
{

	TMPNP_CONFIG Config;
	PTMPNP_CONFIG pConfig = &Config;
	STATUS	Status;
	DWORD	RevisionID, LatencyTimer, CommandStatus;
	PVOID	pBoard = NULL;
	DWORD  dwIRQ;

	CONFIGRET	CMResult;
	CMCONFIG	CMConfig;

	pConfig->wVendorID = TMPNP_PCI_VENDOR_ID; // HARDCODED
	pConfig->wDeviceID = TMPNP_PCI_DEVICE_ID; //HARDCODED

	if ( ! ((PINIT_OBJECT)(pDriverObject->pInitObj))->dwDisablePnP )
	{

		/* find the bus and the device/function numer */
		//***Uhm! Multiple boards with different revision of chips this 
		//***could be misleading!
		if ( pciFindDevice ( pConfig->wDeviceID, pConfig->wVendorID, GLOBALCount,
			&pConfig->bBusNum, &pConfig->bDevFuncNum ) != TRUE )
		{
			DP(0,"TM:pnpOnConfigStart:pciFindDevice:FAIL\n");
			return CR_FAILURE;
		}

		GLOBALCount++;
	}
	else
	{
		pConfig->bBusNum	= (BYTE)BusNumber;
		pConfig->bDevFuncNum		= 
			(BYTE)( ( ( DeviceNumber << 3 ) & 0xf8 ) | ( FunctionNumber & 0x7 ) );

	}

	if ( ! ((PINIT_OBJECT)(pDriverObject->pInitObj))->dwDisablePnP )
	{

		pConfig->dwDevNode = DevNode;

		if ( ( CMResult = CM_Get_Alloc_Log_Conf ( 
			&CMConfig, pConfig->dwDevNode, 0  ))
			!= CR_SUCCESS )
		{
			DP(0,"TM:pnpConfigStart:CM_Get_Alloc_Log_Config:FAIL\n");
			return CR_FAILURE;
		}

		// validate the resources - we have to have this to work
		if ( ( CMConfig.wNumMemWindows != 2 ) ||
			( CMConfig.wNumIRQs != 1 ) )
		{
			DP(0,"TM:pnpConfigStart:iResource Validation:FAIL\n");
			return CR_FAILURE;
		}

		pConfig->dwSDRAMBase = CMConfig.dMemBase[0];
		// Bug in CTC SDRAM length is being returned as 32M fix in TM1
		pConfig->dwSDRAMLength = CMConfig.dMemLength[0];

		pConfig->dwMMIOBase = CMConfig.dMemBase[1];
		pConfig->dwMMIOLength = CMConfig.dMemLength[1];

		pConfig->bIRQ = CMConfig.bIRQRegisters[0];
	}
	else
	{
	

		// read the SDRAM base
		if ( pciReadConfigDW ( pConfig->bBusNum,
			pConfig->bDevFuncNum, (WORD)0x10, 
			&pConfig->dwSDRAMBase ) == FALSE )
		{
			DP(0,"TM:pnpConfigStart:BIOS:SDRAM Base Retrieve:FAIL\n");
			return CR_FAILURE;
		}

		//***Write all 1's into this base address
		if (!pciWriteConfigDW (pConfig->bBusNum, 
								pConfig->bDevFuncNum,
							   (WORD)0x10,
								0xffffffff))
			pConfig->dwMMIOLength = SDRAM_LENGTH;//***Something wrong set default

⌨️ 快捷键说明

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