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

📄 tmpnp.c

📁 PNX系列设备驱动 PNX系列设备驱动
💻 C
字号:
/*---------------------------------------------------------------------------- 
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
----------------------------------------------------------------------------*/
#include "ntddk.h"

/*----------------------------------------------------------------------------
          DRIVER SPECIFIC INCLUDE FILES
----------------------------------------------------------------------------*/
#include "tmmanapi.h"
#include "tmmanlib.h"
#include "platform.h"

#define SDRAM_LENGTH	(8 * 1024 * 1024)
#define MMIO_LENGTH		(2 * 1024 * 1024)

/*----------------------------------------------------------------------------
          GENERIC PNP FUNCTIONS
----------------------------------------------------------------------------*/

BOOLEAN	pnpOnConfigStart ( 	
	IN ULONG BusNumber, 
	IN PCI_SLOT_NUMBER SlotNumber );

// added SubSystemID/SubVendorID based enumeration option
BOOLEAN	pnpFindPCIDevices ( 
	IN USHORT wVendor, 
	IN USHORT wDevice,
	IN PULONG pulTMSubSystemIDAccepted)
{
    ULONG				n;
    BOOLEAN				fNotDone;
    PCI_COMMON_CONFIG	PciData;
    NTSTATUS			Status = STATUS_UNSUCCESSFUL;
    ULONG				i = 0, j = 0, Idx;
    ULONG				ulTmp;
	ULONG				BusNumber = 0;
	PCI_SLOT_NUMBER		SlotNumber;

	BusNumber = 0;
	SlotNumber.u.bits.DeviceNumber = 0;
	SlotNumber.u.bits.FunctionNumber = 0;
	SlotNumber.u.bits.Reserved = 0;


    for (BusNumber = 0, fNotDone = TRUE; fNotDone ; BusNumber++) 
	{

        for ( i = 0 ; i < PCI_MAX_DEVICES  &&  fNotDone ; i++ ) 
		{
            for ( j = 0 ; j < PCI_MAX_FUNCTION ; j++) 
			{
				SlotNumber.u.bits.DeviceNumber = i;
				SlotNumber.u.bits.FunctionNumber = j;

                n = HalGetBusData (
                    PCIConfiguration,
                    BusNumber,
                    SlotNumber.u.AsULONG,
                    &PciData,
                    PCI_COMMON_HDR_LENGTH
                    );
				/*
				DPF (0, 
					("pnpFindPCIDevices:[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x]\n",
					BusNumber, i, j, PciData.VendorID, PciData.DeviceID ));
				*/

                if (n == 0) 
				{
                    // out of buses
                    fNotDone = FALSE;
                    break;
                }

                if (PciData.VendorID == PCI_INVALID_VENDORID) 
				{
                    // Nothing in this slot, skip to next slot
                    break;
                }

                if ( ( PciData.VendorID == wVendor ) &&  ( PciData.DeviceID == wDevice ) ) 
				{
					// added SubSystemID/SubVendorID based enumeration option
					// Verify if this Device is accepted
					if(pulTMSubSystemIDAccepted)
					{
						int i = 0;
						while(pulTMSubSystemIDAccepted[i] && (pulTMSubSystemIDAccepted[i] != (PciData.u.type0.SubVendorID  + (PciData.u.type0.SubSystemID << 16))))
						{
							i++;
						}
						if(pulTMSubSystemIDAccepted[i] != ((PciData.u.type0.SubVendorID  + (PciData.u.type0.SubSystemID << 16))))
						{
							// this devies isn't accepted
							DPF (1,("[pnpFindPCIDevices:PCI CONFIG SPACE DUMP]\n" ));
							DPF (1,("[The following device isn't accepted see registry (TMSubSystemID key)]\n"));
							DPF (1,("[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x][SubVendor:%x][Subsystem:%x]\n", BusNumber, i, j, PciData.VendorID, PciData.DeviceID, PciData.u.type0.SubVendorID, PciData.u.type0.SubSystemID ));
							break;
						}
					}


					DPF (1,("[pnpFindPCIDevices:PCI CONFIG SPACE DUMP]\n" ));
					
					DPF (1,("[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x][SubVendor:%x][Subsystem:%x]\n",
						BusNumber, i, j, PciData.VendorID, PciData.DeviceID, PciData.u.type0.SubVendorID, PciData.u.type0.SubSystemID ));
					

					DPF (1,("[Cmd:%x][Sts:%x][BaseCls:%x][SubCls:%x][ProgIf:%x][RevID:%x]\n",
						PciData.Command,                    // Device control
						PciData.Status,
						PciData.BaseClass,                 // (ro)
						PciData.SubClass,                     // (ro)
						PciData.ProgIf,                   // (ro)
						PciData.RevisionID ));

					DPF (1,("[BIST:%x][HeaderType:%x][LatencyTimer:%x][CacheLineSize:%x]\n",
						PciData.BIST,                    // Device control
						PciData.HeaderType,
						PciData.LatencyTimer,                 // (ro)
						PciData.CacheLineSize ));                     // (ro)

					for ( Idx = 0 ; Idx < PCI_TYPE0_ADDRESSES ; Idx++ )
					{
						DPF (1,("[BaseAddresses:%x]\n",
							PciData.u.type0.BaseAddresses[Idx] ));
					}

					DPF (1,("[MaximumLatency:%x][MinimumGrant:%x][InterruptPin:%x][InterruptLine:%x]\n",
						PciData.u.type0.MaximumLatency,
						PciData.u.type0.MinimumGrant,
						PciData.u.type0.InterruptPin,
						PciData.u.type0.InterruptLine ));

					// found device node
					pnpOnConfigStart ( BusNumber, SlotNumber );
				}

				// if device is single function then don't check for non-zero function codes
                if ( ( PciData.HeaderType & 0x80 ) != 0x80 ) 
				{
                    // skip to next slot
                    break;
                }

			}
		}
	}
 	return FALSE;;
}



/*
	pnpOnConfigStart

	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.

*/

BOOLEAN	pnpOnConfigStart ( 	
	IN ULONG BusNumber, 
	IN PCI_SLOT_NUMBER SlotNumber )
{
	NTSTATUS Status;

	halParameters	Config;
	PCI_COMMON_CONFIG PCIConfig;
	PCM_RESOURCE_LIST pAllocatedResources;
    ULONG				i, j;
	PVOID				AllocatedDevice;

	//ULONG SlotInfo = (ULONG)SlotNumber;

    pAllocatedResources = NULL;

    Status = HalAssignSlotResources (
         &TMManGlobal->DriverRegistryPath,
         NULL, //DriverClassName,
         TMManGlobal->DriverObject,
         NULL, //DeviceObject,
         PCIBus, //BusType,
         BusNumber, //BusNumber,
         SlotNumber.u.AsULONG, //SlotNumber,
         &pAllocatedResources );

    if (!NT_SUCCESS(Status))
	{
		DPF (0,("HalAssignSlotResources:FAIL[%x]", Status));
		return FALSE;
	}

    // look at the structure from hell
    if (pAllocatedResources == NULL) 
	{
		DPF (0,("pAllocatedResources == NULL"));
		return FALSE;
	}


	// the following code jsut dumps the resource descriptors - can be removed

    DPF (0,("CM_RESOURCE_LIST:Count[%x]\n", pAllocatedResources->Count ));

    for (i = 0; i < pAllocatedResources->Count; i++) 
	{
        DPF (1,("CM_FULL_RESOURCE_DESCRIPTOR#[%x]:InterfaceType[%x]:BusNumber[%x]\n",
			i,
			pAllocatedResources->List[i].InterfaceType,
			pAllocatedResources->List[i].BusNumber ));

        DPF (1,("CM_PARTIAL_RESOURCE_LIST:Version[%x]:Revision[%x]:Count[%x]\n",
            pAllocatedResources->List[i].PartialResourceList.Version,
            pAllocatedResources->List[i].PartialResourceList.Revision,
            pAllocatedResources->List[i].PartialResourceList.Count));

        for (j = 0; j < pAllocatedResources->List[i].PartialResourceList.Count; j++) 
		{
            DPF (1,("CM_PARTIAL_RESOURCE_DESCRIPTOR#[%x]:Type[%x]:ShareDisposition[%x]:Flags[%x]\n",
				j,
				pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].Type,
				pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].ShareDisposition,
				pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].Flags ));

            switch (pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].Type) 
			{
	            case CmResourceTypePort:
                DPF (1,("CmResourceTypePort:Start[%x]:Length[%x]\n",
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Port.Start,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Port.Length));
                break;

		        case CmResourceTypeInterrupt:
                DPF (1,("CmResourceTypeInterrupt:Level[%x]:Vector[%x]:Affininty[%x]\n",
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Level,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Vector,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Affinity));
                break;

			    case CmResourceTypeMemory:
                DPF (1,("CmResourceTypeMemory:Start[%x]:Length[%x]\n",
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Start,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Length ));
                break;

				case CmResourceTypeDma:
                DPF (1,("CmResourceTypeDma:Channel[%x]:Port[%x]:Reserved1[%x]\n",
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Channel,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Port,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Reserved1 ));
                break;

				case CmResourceTypeDeviceSpecific:
                DPF (1,("CmResourceTypeDeviceSpecific:DataSize[%x]:Reserved1[%x]:Reserved2[%x]\n",
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.DataSize,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.Reserved1,
                    pAllocatedResources->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.Reserved2 ));
                break;

				default:
                DPF (0,("bad type\n"));
                break;
            } // end switch
        } // end for partial resource descriptors
    } // end for full resource descriptors


	// read the hardware revision ID
	HalGetBusData(
		PCIConfiguration,
		BusNumber,
		SlotNumber.u.AsULONG,
		&PCIConfig,
		sizeof ( PCI_COMMON_CONFIG ) );


	// we haven't GOne MAD yet.

	Config.BusNumber = BusNumber;
	Config.SlotNumber = SlotNumber;


	Config.BusNumber			= pAllocatedResources->List[0].BusNumber;
	Config.InterruptLevel		= 
		pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Level,
	Config.InterruptVector		= 
		pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector,
	Config.InterruptAffinity	= 
		pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity;


	if ( ( PCIConfig.VendorID == constTMMANDECBridgeVendorID ) && 
		( PCIConfig.DeviceID ==  constTMMANDECBridgeDeviceID) )
    {

	    ((PUSHORT)&Config.BridgeDeviceVendorID)[0] =  PCIConfig.VendorID;
		((PUSHORT)&Config.BridgeDeviceVendorID)[1] =  PCIConfig.DeviceID;

		((PUSHORT)&Config.BridgeSubsystemID)[0] =  PCIConfig.u.type0.SubVendorID;
		((PUSHORT)&Config.BridgeSubsystemID)[1] =  PCIConfig.u.type0.SubSystemID;

		((PUCHAR)&Config.BridgeClassRevisionID)[0] =  PCIConfig.RevisionID;
		((PUCHAR)&Config.BridgeClassRevisionID)[1] =  PCIConfig.ProgIf;
		((PUCHAR)&Config.BridgeClassRevisionID)[2] =  PCIConfig.SubClass;
		((PUCHAR)&Config.BridgeClassRevisionID)[3] =  PCIConfig.BaseClass;

		Config.SDRAMAddrPhysical		= 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[3].u.Memory.Start;
		Config.SDRAMLength			= 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[3].u.Memory.Length;
		Config.MMIOAddrPhysical  = 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[4].u.Memory.Start;
		Config.MMIOLength  = 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[4].u.Memory.Length;

    }
	else
	{
	    ((PUSHORT)&Config.TMDeviceVendorID)[0] =  PCIConfig.VendorID;
		((PUSHORT)&Config.TMDeviceVendorID)[1] =  PCIConfig.DeviceID;

		((PUCHAR)&Config.TMClassRevisionID)[0] =  PCIConfig.RevisionID;
		((PUCHAR)&Config.TMClassRevisionID)[1] =  PCIConfig.ProgIf;
		((PUCHAR)&Config.TMClassRevisionID)[2] =  PCIConfig.SubClass;
		((PUCHAR)&Config.TMClassRevisionID)[3] =  PCIConfig.BaseClass;

		((PUSHORT)&Config.TMSubsystemID)[0] =  PCIConfig.u.type0.SubVendorID;
		((PUSHORT)&Config.TMSubsystemID)[1] =  PCIConfig.u.type0.SubSystemID;

		Config.BridgeDeviceVendorID = 0;
		Config.BridgeSubsystemID = 0;
		Config.BridgeClassRevisionID = 0;

		Config.SDRAMAddrPhysical		= 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Memory.Start;

        Config.SDRAMLength			= 
            pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Memory.Length;

		Config.MMIOAddrPhysical  = 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Memory.Start;
		Config.MMIOLength  = 
			pAllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Memory.Length;
	}


	HalGetBusData (
		PCIConfiguration,
		BusNumber,
		SlotNumber.u.AsULONG,
		Config.PCIRegisters,
		sizeof ( ULONG ) * constTMMANPCIRegisters );

	if ( ( AllocatedDevice = tmmanInit ( 
		TMManGlobal->DeviceCount , &Config ) ) == NULL )
	{
		ExFreePool ( pAllocatedResources );
		return FALSE;
	}

	// insert the device we have just created into the global device list for this driver
	TMManGlobal->DeviceList[TMManGlobal->DeviceCount] = AllocatedDevice;
	TMManGlobal->DeviceCount++;

	ExFreePool ( pAllocatedResources );
	return TRUE;
}	
/*
BOOLEAN	pnpOnConfigStop ( 
	IN ULONG BusNumber, 
	IN PCI_SLOT_NUMBER SlotNumber )
{
	tmmanExit( );

	TMManGlobal->DeviceObjectList[TMManGlobal->DeviceCount] = NULL;
	TMManGlobal->DeviceCount--;
}

*/

⌨️ 快捷键说明

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