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

📄 tmpnp.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		else
		{
			//***The length should equal to the two complement of the return value
			if (!pciReadConfigDW ( pConfig->bBusNum,
								pConfig->bDevFuncNum, 
								(WORD)0x10, 
								&pConfig->dwSDRAMLength))
				pConfig->dwSDRAMLength = SDRAM_LENGTH;//***Something wrong set default
			else
				pConfig->dwSDRAMLength = ~pConfig->dwSDRAMLength + 1;
		}

		//***Now make sure rewrite back to correct base address
		if (!pciWriteConfigDW(pConfig->bBusNum,
									 pConfig->bDevFuncNum,
									 (WORD)0x10,
									 pConfig->dwSDRAMBase))
		{
			return CR_FAILURE;
		}

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

		//***Write all 1's into this base address
		if (!pciWriteConfigDW (pConfig->bBusNum, 
								pConfig->bDevFuncNum,
							   (WORD)0x14,
								0xffffffff))
			pConfig->dwMMIOLength = MMIO_LENGTH;//***Something wrong set default
		else
		{
			//***The length should equal to the two complement of the return value
			if (!pciReadConfigDW ( pConfig->bBusNum,
								pConfig->bDevFuncNum, 
								(WORD)0x14, 
								&pConfig->dwMMIOLength))
				pConfig->dwMMIOLength = MMIO_LENGTH;//***Something wrong set default
			else
				pConfig->dwMMIOLength = ~pConfig->dwMMIOLength + 1;
		}

		//***Now make sure rewrite back to correct base address
		if (!pciWriteConfigDW(pConfig->bBusNum,
									 pConfig->bDevFuncNum,
									 (WORD)0x14,
									 pConfig->dwMMIOBase))
		{
			return CR_FAILURE;
		}

		// read the IRQ setting
		if ( pciReadConfigDW ( pConfig->bBusNum,
			pConfig->bDevFuncNum, (WORD)0x3c, 
			&dwIRQ ) == FALSE )
		{
			DP(0,"TM:pnpConfigStart:BIOS:IRQ Retrieve:FAIL\n");
			return CR_FAILURE;
		}

		pConfig->bIRQ = (BYTE)(dwIRQ & 0x0000000f);
	}

	// read the hardware revision ID
	if ( pciReadConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0x8, &RevisionID ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Revision ID Retrieve:FAIL\n");
		return CR_FAILURE;
	}
	

	pConfig->bRevision = (BYTE)RevisionID;

	if ( pciReadConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0xc, &LatencyTimer ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Latency Timer Retrive:FAIL\n");
		return CR_FAILURE;
	}

	// read the subsystem and subsystem vendor ID.
	if ( pciReadConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0x2c, &pConfig->dwSubsystemID ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Subsystem ID Retrieve:FAIL\n");
		return CR_FAILURE;
	}
	

/*
	// according to zcw latency 0f 0 is the maximum
	LatencyTimer |=  ( ( 5 << 11) & ( ( 0 ) << 11 ) );

	if ( pciWriteConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0xc, LatencyTimer ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Latency Timer Write:FAIL\n");
		return CR_FAILURE;
	}
*/

	// on some machine intel does not set the MA bit - so go ahead
	// and set it.
	if ( pciReadConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0x4, &CommandStatus ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Command Status Retrieve:FAIL\n");
		return CR_FAILURE;
	}


	CommandStatus |=  1 << 1;

	if ( pciWriteConfigDW (pConfig->bBusNum,
		pConfig->bDevFuncNum, (WORD)0x4, CommandStatus ) == FALSE )
	{
		DP(0,"TM:pnpConfigStart:BIOS:Command Status Write:FAIL\n");
		return CR_FAILURE;
	}

	pConfig->dwSDRAMLength = 
		((PINIT_OBJECT)pDriverObject->pInitObj)->dwSDRAMSize;

	DP( 10,"TM:pnpConfigStart:SDRAMBase[%x]:SDRAMLenL[%x]\n",
		pConfig->dwSDRAMBase, pConfig->dwSDRAMLength );

	DP( 10,"TM:pnpConfigStart:MMIOBase[%x]:MMIOLen[%x]\n",
		pConfig->dwMMIOBase, pConfig->dwMMIOLength );
		 
	DP( 10,"TM:pnpConfigStart:IRQ[%x]\n",
		pConfig->bIRQ );


	
	if ( Status = boardCreate (pConfig,  &pBoard ) != TMOK )
	{
		return CR_FAILURE;
	}

	/* insert this device into the driver device list */
	vxdAddDevice ( pBoard );

	return CR_SUCCESS;
}	


/*
	vxdPnpConfigHandler

	The generic Plug and Play configuration handler.
	call the pnpConfigXXX on receiving CONFIG_XXXX notifications.
*/

CONFIGRET  CM_HANDLER vxdPnPConfigHandler(
	CONFIGFUNC cfFuncName,
	SUBCONFIGFUNC scfSubFuncName,
	DEVNODE	dnToDevNode,
	DWORD dwRefData,
	ULONG ulFlags)
{

    REFERENCE(ulFlags);
    REFERENCE(dwRefData);

    switch (cfFuncName)
	{
		case CONFIG_FILTER:
		return CR_SUCCESS;

		case CONFIG_START:
		switch (scfSubFuncName)
		{
			case CONFIG_START_FIRST_START:
			case CONFIG_START_DYNAMIC_START:
			{ 	
				return pnpOnConfigStart ( dnToDevNode, 0 , 0, 0  );
			}
			break;

			default:
				return CR_DEFAULT;
		}
		break;

		case CONFIG_TEST:
		switch (scfSubFuncName)
		{
			case CONFIG_TEST_CAN_STOP:
			case CONFIG_TEST_CAN_REMOVE:
			return pnpOnConfigTest ( dnToDevNode );

			default:
			break;
		}
		break;


		case CONFIG_STOP:
		return pnpOnConfigStop ( dnToDevNode );

		case CONFIG_REMOVE:
		return pnpOnConfigRemove ( dnToDevNode );
		

		default:
		return CR_DEFAULT;
	}
}



VOID	pnpPCINameGet ( WORD VendorID, WORD DeviceID,
	BYTE Bus, BYTE DeviceFunction, PCHAR Name )
{
	_Sprintf ( Name, "PCI\\VEN_%04X&DEV_%04X\\BUS_%02X&DEV_%02X&FUNC_%02X\0",
		VendorID, DeviceID,
		Bus, ( (DeviceFunction) >> 3 ),	( (DeviceFunction) & 0x7 ) );
}


BOOL	pnpFindPCIDevices ( 
	IN USHORT wVendor, 
	IN USHORT wDevice )
{
	ULONG				BusNumber, DeviceNumber, FunctionNumber;
	ULONG				DeviceVendorID;
	USHORT				VendorID, DeviceID;
	CHAR				szPNPID[256]; 
	DEVNODE				DevNode;	

    for ( BusNumber = 0;
		BusNumber < 4 ;
		BusNumber++ ) 
	{

        for ( DeviceNumber = 0 ; 
			DeviceNumber < PCI_MAX_DEVICES ; 
			DeviceNumber++ ) 
		{
            for ( FunctionNumber = 0 ; 
				FunctionNumber < PCI_MAX_FUNCTION ; 
				FunctionNumber ++) 
			{
				UCHAR	DeviceFunction;

				DeviceFunction = 
					(UCHAR)( ( DeviceNumber << 3 ) & 0xf8 ) | 
					( FunctionNumber & 0x7 );

				// read the hardware revision ID
				if ( pciReadConfigDW (
					BusNumber,
					DeviceFunction, 
					(WORD)0x0, 
					&DeviceVendorID ) == FALSE )
				{
					DP(0,"TM:pnpConfigStart:BIOS:Revision ID Retrieve:FAIL\n");
					return FALSE;
				}

				DeviceID = (USHORT)( ( DeviceVendorID >> 16 ) & 0xffff );
				VendorID = (USHORT)( ( DeviceVendorID ) & 0xffff );
                if (VendorID != PCI_INVALID_VENDORID) 
				{
                    // Nothing in this slot, skip to next slot
				DP (0, 
					"pnpFindPCIDevices:[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x]\n",
					BusNumber,DeviceNumber,FunctionNumber,VendorID,DeviceID );
                }
                if ( ( VendorID == wVendor ) &&  ( DeviceID == wDevice ) ) 
				{

				/*
					DPF ((1, 
					"pnpFindPCIDevices:[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x]\n",
					BusNumber, i, j, PciData.VendorID, PciData.DeviceID ));
				*/
				/*
					pnpPCINameGet ( 
						wVendor, 
						wDevice, 
						(UCHAR)BusNumber, 
						(UCHAR)DeviceFunction, 
						szPNPID);
	
					DP(10,"TM:pnpGetDevNode:[%s]\n", szPNPID);

					if ( ( CM_Locate_DevNode ( (PDEVNODE)&DevNode,
						szPNPID, (DWORD)0 ) ) != CR_SUCCESS )
					{
						DP(0,"TM:pnpGetDevNode:CM_Locate_DevNode:FAIL\n");
						return FALSE;
					}
				*/
					// found device node
					// make a unique key and call it devnode so that remove
					// can perform a search based on this
					DevNode = 
						( ( ( BusNumber << 16 ) & 0xffff0000 ) | 
						( DeviceFunction & 0x0000ffff ) );

					pnpOnConfigStart ( 
						DevNode, /* not used */
						BusNumber,
						DeviceNumber,
						FunctionNumber );
				}
			}
		}
	}
	return TRUE;
}

⌨️ 快捷键说明

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