?? tmpnp.c
字號:
// create a device object for this physical hardware
strSprintf ( KernelDeviceName, "\\Device\\TriMedia%d",
DeviceNumber );
RtlInitAnsiString ( &KernelDeviceNameANSI, KernelDeviceName );
if ( RtlAnsiStringToUnicodeString(
&KernelDeviceNameUnicode,
&KernelDeviceNameANSI,
TRUE) != STATUS_SUCCESS )
{
DPF(0,("tmman:tmmanPnpAddDevice:RtlAnsiStringToUnicodeString:FAIL\n" ));
goto tmmanPnpAddDeviceExit1;
}
Status = IoCreateDevice(
DriverObject,
sizeof( TMManDeviceObject ),
&KernelDeviceNameUnicode,
FILE_DEVICE_UNKNOWN,
0, // No standard device characteristics
FALSE, // This isn't an exclusive device
&FunctionalDeviceObject );
RtlFreeUnicodeString ( &KernelDeviceNameUnicode );
if ( NT_SUCCESS(Status) )
{
break;
}
// this object alread exists - so pick up a new ID.
// Boghos added the "|| Status==STATUS_OBJECT_NAME_COLLISION" in the next line
// to correct the multi board support problem
// The problem was diagnosed to be a failure in creating the second device due to
// a name collision.
if ( Status == STATUS_OBJECT_NAME_EXISTS || Status==STATUS_OBJECT_NAME_COLLISION )
{
DPF(0,("tmman:halCreate:IoCreateDevice:STATUS_OBJECT_NAME_EXISTS\n" ));
continue;
}
if ( ! NT_SUCCESS(Status) )
{
DPF(0,("tmman:halCreate:IoCreateDevice:FAIL[%x]\n", Status ));
goto tmmanPnpAddDeviceExit1;
}
}
}
FunctionalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
DeviceExtension = FunctionalDeviceObject->DeviceExtension;
// Attach to the FDO to the PDO and retrieve the SDO
if ( ( StackDeviceObject =
IoAttachDeviceToDeviceStack(FunctionalDeviceObject, PhysicalDeviceObject) ) == NULL )
{
Status = STATUS_UNSUCCESSFUL;
DPF(0,("tmman:tmmanPnpAddDevice:IoAttachDeviceToDeviceStack:FAIL\n" ));
goto tmmanPnpAddDeviceExit2;
}
// populate the device extension
DeviceExtension->FunctionalDeviceObject = FunctionalDeviceObject;
DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
DeviceExtension->StackDeviceObject = StackDeviceObject;
DeviceExtension->DeviceState = constTMMan_DEVICE_STATE_NEVERSTARTED;
DeviceExtension->DSPNumber = DeviceNumber;
return STATUS_SUCCESS;
//tmmanPnpAddDeviceExit3:
// IoDetachDevice( StackDeviceObject );
tmmanPnpAddDeviceExit2:
IoDeleteDevice ( FunctionalDeviceObject );
tmmanPnpAddDeviceExit1:
return Status;
}
NTSTATUS
tmmanPnpRemoveDevice(
PDEVICE_OBJECT FunctionalDeviceObject )
{
PDEVICE_OBJECT StackDeviceObject =
((TMManDeviceObject*)FunctionalDeviceObject->DeviceExtension)->StackDeviceObject;
IoDetachDevice( StackDeviceObject );
IoDeleteDevice ( FunctionalDeviceObject );
return STATUS_SUCCESS;
}
NTSTATUS
tmmanPnpStartDevice(
PDEVICE_OBJECT FunctionalDeviceObject,
PIRP Irp )
{
TMManDeviceObject *DeviceExtension =
(TMManDeviceObject*)FunctionalDeviceObject->DeviceExtension;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
PIO_STACK_LOCATION IoStack;
PCM_RESOURCE_LIST ResourceList;
PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResourceDescriptor;
ULONG MemoryType = 0;
halParameters Config;
// ULONG i, j;
PVOID AllocatedDevice;
ULONG Idx;
PCI_COMMON_CONFIG PCIConfig;
// PCI_SLOT_NUMBER SlotNumber;
ULONG ReferenceAddress;
ULONG Temp;
IoStack = IoGetCurrentIrpStackLocation(Irp);
DPF (0,("tmmanPnpStartDevice:FunctionalDeviceObject[%x]:Irp[%x]\n", FunctionalDeviceObject, Irp ));
DPF (0,("tmmanPnpStartDevice:RAW RESOURCES[%x]\n",
IoStack->Parameters.StartDevice.AllocatedResources ));
DumpPNPResources ( IoStack->Parameters.StartDevice.AllocatedResources );
DPF (0,("tmmanPnpStartDevice:TRANSLATED RESOURCES[%x]\n",
IoStack->Parameters.StartDevice.AllocatedResourcesTranslated));
DumpPNPResources ( IoStack->Parameters.StartDevice.AllocatedResourcesTranslated );
Config.FunctionalDeviceObject = DeviceExtension->FunctionalDeviceObject;
Config.PhysicalDeviceObject = DeviceExtension->PhysicalDeviceObject;
Config.StackDeviceObject = DeviceExtension->StackDeviceObject;
Config.DSPNumber = DeviceExtension->DSPNumber;
// retrieve the first memory address that we are going to use a reference
// to match the resource list with the PCI Config space
ResourceList = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
FullResourceDescriptor = &ResourceList->List[0];
PartialResourceList = &FullResourceDescriptor->PartialResourceList;
for ( Idx = 0 ; Idx < PartialResourceList->Count ; Idx ++ )
{
PartialResourceDescriptor = &PartialResourceList->PartialDescriptors[Idx];
switch ( PartialResourceDescriptor->Type )
{
case CmResourceTypeMemory :
switch ( MemoryType++ )
{
case 0 :
ReferenceAddress= PartialResourceDescriptor->u.Memory.Start.LowPart;
break;
default :
break;
}
break;
default :
break;
}
}
// check for TM1000 or TM2000 or DEC bridge chip
if ( pnpGetPCIInformation (
constTMMANDECBridgeVendorID,
constTMMANDECBridgeDeviceID,
ReferenceAddress,
&Config.BusNumber,
&Config.SlotNumber ) != TRUE )
{
// check for TM1000 or TM2000
if ( pnpGetPCIInformation (
constTMMANTM1000VendorID,
constTMMANTM1000DeviceID,
ReferenceAddress,
&Config.BusNumber,
&Config.SlotNumber ) != TRUE )
{
if ( pnpGetPCIInformation (
constTMMANTM2000VendorID,
constTMMANTM2000DeviceID,
ReferenceAddress,
&Config.BusNumber,
&Config.SlotNumber ) != TRUE )
{
if ( pnpGetPCIInformation (
constTMMANTM1300VendorID,
constTMMANTM1300DeviceID,
ReferenceAddress,
&Config.BusNumber,
&Config.SlotNumber ) != TRUE )
{
DPF (0,("tmmanPnpStartDevice:No TriMedia Device Found:FAIL\n" ));
goto tmmanPnpStartDeviceExit1;
}
}
}
}
if ( HalGetBusData (
PCIConfiguration,
Config.BusNumber,
Config.SlotNumber.u.AsULONG,
&PCIConfig,
PCI_COMMON_HDR_LENGTH ) == 0 )
{
DPF (0,("tmmanPnpStartDevice:HalGetBusData:PCIConfig:FAIL\n" ));
goto tmmanPnpStartDeviceExit1;
}
for ( Idx = 0 ; Idx < constTMMANPCIRegisters ; Idx ++ )
{
Config.PCIRegisters[Idx] = ((PULONG)&PCIConfig)[Idx];
// FOR TESTING - BEGIN
if ( HalGetBusDataByOffset (
PCIConfiguration,
Config.BusNumber,
Config.SlotNumber.u.AsULONG,
&Temp,
(ULONG)Idx*4, // register offset in config space
sizeof (ULONG) ) != sizeof ( ULONG ) )
{
DPF(0,("InitTriMedia:HalGetBusDataByOffset:Secondary Vendor Device ID:FAIL\n"));
return FALSE;
}
// END
DPF (1,
("Register #0x%x = [0x%x]\n",
Idx, Temp )); //Config.PCIRegisters[Idx] ));
}
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;
ResourceList = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
FullResourceDescriptor = &ResourceList->List[0];
PartialResourceList = &FullResourceDescriptor->PartialResourceList;
MemoryType = 0;
for ( Idx = 0 ; Idx < PartialResourceList->Count ; Idx ++ )
{
PartialResourceDescriptor = &PartialResourceList->PartialDescriptors[Idx];
switch ( PartialResourceDescriptor->Type )
{
case CmResourceTypeMemory :
switch ( MemoryType++ )
{
case 0 :
break;
case 1 :
Config.SDRAMAddrPhysical = PartialResourceDescriptor->u.Memory.Start;
Config.SDRAMLength = PartialResourceDescriptor->u.Memory.Length;
break;
case 2 :
Config.MMIOAddrPhysical = PartialResourceDescriptor->u.Memory.Start;
Config.MMIOLength = PartialResourceDescriptor->u.Memory.Length;
break;
}
break;
case CmResourceTypeInterrupt :
Config.InterruptLevel = (KIRQL)PartialResourceDescriptor->u.Interrupt.Level;
Config.InterruptVector = PartialResourceDescriptor->u.Interrupt.Vector;
Config.InterruptAffinity = PartialResourceDescriptor->u.Interrupt.Affinity;
Config.InterruptMode =
(PartialResourceDescriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED) ? Latched : LevelSensitive;
break;
case CmResourceTypeBusNumber :
Config.BusNumber = PartialResourceDescriptor->u.BusNumber.Start;
break;
default :
break;
}
}
}
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;
ResourceList = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
FullResourceDescriptor = &ResourceList->List[0];
PartialResourceList = &FullResourceDescriptor->PartialResourceList;
MemoryType = 0;
for ( Idx = 0 ; Idx < PartialResourceList->Count ; Idx ++ )
{
PartialResourceDescriptor = &PartialResourceList->PartialDescriptors[Idx];
switch ( PartialResourceDescriptor->Type )
{
case CmResourceTypeMemory :
switch ( MemoryType++ )
{
case 0 :
Config.SDRAMAddrPhysical = PartialResourceDescriptor->u.Memory.Start;
Config.SDRAMLength = PartialResourceDescriptor->u.Memory.Length;
break;
case 1 :
Config.MMIOAddrPhysical = PartialResourceDescriptor->u.Memory.Start;
Config.MMIOLength = PartialResourceDescriptor->u.Memory.Length;
break;
}
break;
case CmResourceTypeInterrupt :
Config.InterruptLevel = (KIRQL)PartialResourceDescriptor->u.Interrupt.Level;
Config.InterruptVector = PartialResourceDescriptor->u.Interrupt.Vector;
Config.InterruptAffinity = PartialResourceDescriptor->u.Interrupt.Affinity;
Config.InterruptMode =
(PartialResourceDescriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED) ? Latched : LevelSensitive;
break;
case CmResourceTypeBusNumber :
Config.BusNumber = PartialResourceDescriptor->u.BusNumber.Start;
break;
}
}
}
if ( ( AllocatedDevice = tmmanInit (
DeviceExtension->DSPNumber , &Config ) ) == NULL )
{
DPF (0,("tmmanPnpStartDevice:tmmanInit:FAIL\n" ));
goto tmmanPnpStartDeviceExit1;
}
// insert the device we have just created into the global device list for this driver
TMManGlobal->DeviceList[DeviceExtension->DSPNumber] = AllocatedDevice;
TMManGlobal->DeviceCount++;
return STATUS_SUCCESS;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -