31,7 → 31,8 |
//------------------------------------------------------------------------- |
// INCLUDES |
// |
|
#include <initguid.h> |
#include <wdmguid.h> |
#include <ntddk.h> |
#include <devioctl.h> |
#include <pcivme_drv.h> |
41,7 → 42,6 |
#include <pcivme.h> |
#include <pciif.h> |
#include <pcivme_fifo.h> |
|
//------------------------------------------------------------------------ |
// DEFINES |
// |
143,8 → 143,7 |
|
KdPrint(("PCIVMEUnload() InitState %d \n", ext->nInitState )); |
|
//if (ext->LowerDeviceObject) IoDetachDevice(ext->LowerDeviceObject); |
//IoDeleteDevice(driverObj->DeviceObject); |
|
if (ext->nInitState!=100) return; |
|
switch (ext->nInitState) |
202,6 → 201,7 |
IoDeleteSymbolicLink( &symbol_name); |
|
// delete the deviceObject |
|
if (ext->LowerDeviceObject) IoDetachDevice(ext->LowerDeviceObject); |
IoDeleteDevice(driverObj->DeviceObject); |
} |
580,18 → 580,90 |
} |
#endif |
|
|
// http://read.pudn.com/downloads148/sourcecode/windows/vxd/640413/agp/agplib/init.c__.htm |
NTSTATUS |
QueryBusInterface( |
IN PDEVICE_OBJECT DeviceObject, |
OUT PBUS_INTERFACE_STANDARD BusInterface |
) |
/*++ |
|
Routine Description: |
|
Sends a query-interface IRP to the specified device object |
to obtain the BUS_INTERFACE_STANDARD interface. |
|
Arguments: |
|
DeviceObject - Supplies the device object to send the BUS_INTERFACE_STANDARD to |
|
BusInterface - Returns the bus interface |
|
Return Value: |
|
STATUS_SUCCESS if successful |
NTSTATUS if unsuccessful |
|
--*/ |
|
{ |
PIRP Irp; |
KEVENT Event; |
PIO_STACK_LOCATION IrpSp; |
IO_STATUS_BLOCK IoStatusBlock; |
NTSTATUS Status; |
// ULONG ReturnLength; |
|
KeInitializeEvent( &Event, NotificationEvent, FALSE ); |
Irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, |
DeviceObject, |
NULL, |
0, |
NULL, |
&Event, |
&IoStatusBlock ); |
if (Irp == NULL) { |
return(STATUS_INSUFFICIENT_RESOURCES); |
} |
|
IrpSp = IoGetNextIrpStackLocation( Irp ); |
ASSERT(IrpSp != NULL); |
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED ; |
IrpSp->MajorFunction = IRP_MJ_PNP; |
IrpSp->MinorFunction = IRP_MN_QUERY_INTERFACE; |
IrpSp->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD; |
IrpSp->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD); |
IrpSp->Parameters.QueryInterface.Version = 1; |
IrpSp->Parameters.QueryInterface.Interface = (PINTERFACE) BusInterface; |
IrpSp->Parameters.QueryInterface.InterfaceSpecificData = NULL; |
|
Status = IoCallDriver(DeviceObject, Irp); |
if (Status == STATUS_PENDING) { |
KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL ); |
Status = Irp->IoStatus.Status; |
} |
|
return(Status); |
} |
|
//------------------------------------------------------------------------ |
// search for pciada's |
// |
|
NTSTATUS SearchDevices(PDEVICE_OBJECT device_Obj) |
{ |
PCI_SLOT_NUMBER SlotNumber; |
PCI_COMMON_CONFIG pci_config; |
PBUS_INTERFACE_STANDARD busInterface; |
PCIADA *pciada; |
ULONG length; |
|
ULONG propertyAddress, length; |
USHORT FunctionNumber, DeviceNumber; |
int *found; |
int i,j,k; |
|
int i; |
NTSTATUS status; |
int BytesRead; |
KdPrint(("SearchDevices()\n")); |
|
// prepare structures ---------------------------------------- |
607,21 → 679,26 |
|
// search for pciada's --------------------------------------- |
SlotNumber.u.bits.Reserved = 0; |
|
for (j = 0; j < PCI_MAX_BUSES; j++) |
busInterface = (PBUS_INTERFACE_STANDARD)ExAllocatePool(NonPagedPool, |
sizeof(BUS_INTERFACE_STANDARD)); |
if (busInterface == NULL) |
{ |
for (i = 0; i < PCI_MAX_DEVICES; i++) |
{ |
SlotNumber.u.bits.DeviceNumber = i; |
for (k = 0; k < PCI_MAX_FUNCTION; k++) |
{ |
SlotNumber.u.bits.FunctionNumber = k; |
length = HalGetBusData( PCIConfiguration, // Bustype |
j, // PCI-Busnumber |
SlotNumber.u.AsULONG, // Slotnumber |
(PVOID) &(pci_config), // Pointer for the PCI-Information |
sizeof(PCI_COMMON_CONFIG) ); |
return STATUS_INSUFFICIENT_RESOURCES; |
} |
((DEVICE_EXT*)(device_Obj->DeviceExtension))->busInterface = busInterface; |
status = QueryBusInterface(device_Obj, busInterface); |
BytesRead = busInterface->GetBusData(busInterface->Context, PCI_WHICHSPACE_CONFIG, &pci_config, 0, PCI_COMMON_HDR_LENGTH); |
|
pciada = &((DEVICE_EXT*)(device_Obj->DeviceExtension))->pciada[0]; |
|
//http://www.hollistech.com/Resources/Misc%20articles/getbusdata.htm |
//IoGetDeviceProperty |
//There are other differnt methods to send a request to lower layer. One method is |
//by sending IRP_MN_READ_CONFIG to lower driver. You will recieve |
//PCI_COMMON_CONFIG structure. |
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff536890(v=vs.85).aspx |
// http://www.rdos.net/svn/tags/V9.2.5/watcom/bld/src/win32/miniwdm/dev/wdmdev.c |
|
if ((pci_config.VendorID == PCIVME_VENDOR_ID) && |
(pci_config.DeviceID == PCIVME_DEVICE_ID) && |
(pci_config.u.type0.SubSystemID == PCIVME_SUBSYS_ID) && |
631,17 → 708,31 |
pciada = &((DEVICE_EXT*)(device_Obj->DeviceExtension))->pciada[*found]; |
|
memcpy(&pciada->PCIDevice, &pci_config, sizeof(pci_config)); |
pciada->Slot = SlotNumber; |
pciada->Bus = j; |
|
IoGetDeviceProperty(device_Obj, |
DevicePropertyBusNumber, |
sizeof(ULONG), |
(PVOID)&(pciada->Bus), |
&length); |
|
IoGetDeviceProperty(device_Obj, |
DevicePropertyAddress, |
sizeof(ULONG), |
(PVOID)&propertyAddress, |
&length); |
// |
// For PCI, the DevicePropertyAddress has device number |
// in the high word and the function number in the low word. |
// |
FunctionNumber = (USHORT)((propertyAddress)& 0x0000FFFF); |
DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x0000FFFF); |
pciada->Slot.u.AsULONG = DeviceNumber; |
KdPrint(("PCIADA found @ Bus/Slot %d/%d.\n", pciada->Bus, pciada->Slot.u.AsULONG)); |
|
(*found)++; |
if (*found >= PCIVME_MAX_PCIADA) return STATUS_SUCCESS; |
} |
} |
} |
} |
|
} |
KdPrint(("SearchDevices() found %d devices\n", (*found))); |
return STATUS_SUCCESS; |
} |
656,9 → 747,10 |
int i; |
ULONG dwData; |
PCIADA *pciada; |
PBUS_INTERFACE_STANDARD busInterface; |
|
KdPrint(("PLX9050BugFix()\n")); |
|
busInterface = DeviceExtension->busInterface; |
for (i = 0; i < DeviceExtension->nPCIADAs; i++) |
{ |
pciada = &DeviceExtension->pciada[i]; |
673,17 → 765,12 |
pciada->PCIDevice.u.type0.BaseAddresses[4]; |
pciada->PCIDevice.u.type0.BaseAddresses[4] = dwData; |
|
if (HalSetBusDataByOffset(PCIConfiguration, pciada->Bus, |
pciada->Slot.u.AsULONG, |
(PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[0], |
0x10, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
if (HalSetBusDataByOffset(PCIConfiguration, pciada->Bus, |
pciada->Slot.u.AsULONG, |
(PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[4], |
0x20, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
if (busInterface->SetBusData(busInterface->Context, PCI_WHICHSPACE_CONFIG, (PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[0], 0x10, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
if (busInterface->SetBusData(busInterface->Context, PCI_WHICHSPACE_CONFIG, (PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[4], 0x20, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
} |
|
if ((dwData = pciada->PCIDevice.u.type0.BaseAddresses[1]) & 0x80) |
696,17 → 783,12 |
pciada->PCIDevice.u.type0.BaseAddresses[5]; |
pciada->PCIDevice.u.type0.BaseAddresses[5] = dwData; |
|
if (HalSetBusDataByOffset(PCIConfiguration, pciada->Bus, |
pciada->Slot.u.AsULONG, |
(PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[1], |
0x14, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
if (HalSetBusDataByOffset(PCIConfiguration, pciada->Bus, |
pciada->Slot.u.AsULONG, |
(PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[5], |
0x24, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
if (busInterface->SetBusData(busInterface->Context, PCI_WHICHSPACE_CONFIG, (PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[1], 0x14, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
if (busInterface->SetBusData(busInterface->Context, PCI_WHICHSPACE_CONFIG, (PVOID)&pciada->PCIDevice.u.type0.BaseAddresses[5], 0x24, 4) != 4) |
return STATUS_UNSUCCESSFUL; |
|
} |
} |
|
969,28 → 1051,6 |
|
|
//------------------------------------------------------------------------ |
// free resources from PCIADAs |
// |
NTSTATUS PCIVMEFreeResources(PDEVICE_OBJECT device_Obj) |
{ |
CM_RESOURCE_LIST ResList; |
BOOLEAN bConflict; |
UNICODE_STRING DriverClassName; |
|
KdPrint(("PCIVMEFreeResources()\n")); |
|
RtlInitUnicodeString(&DriverClassName, L"PCIVME"); |
|
ResList.Count = 0; |
|
IoReportResourceUsage(&DriverClassName, device_Obj->DriverObject, |
&ResList, sizeof(ResList), device_Obj, |
NULL, 0, FALSE, &bConflict); |
return STATUS_SUCCESS; |
}; |
|
|
//------------------------------------------------------------------------ |
// translate memory resources to neutral for PCIADAs |
// |
NTSTATUS PCIVMETranslateBusAddresses(PDEVICE_OBJECT device_Obj, PIRP irp) |
1198,7 → 1258,11 |
// delete the symbolicLink in the registry |
IoDeleteSymbolicLink(&symbol_name); |
DEVICE_EXT *ext = (DEVICE_EXT*)(fdo->DeviceExtension); |
// delete the deviceObject |
// delete the busInterface and deviceObject |
if (ext->busInterface) { |
(*ext->busInterface->InterfaceDereference)(ext->busInterface->Context); |
ext->busInterface = NULL; |
} |
if (ext->LowerDeviceObject) IoDetachDevice(ext->LowerDeviceObject); |
IoDeleteDevice(fdo); |
KdPrint(("HandleStopDevice (OK)\n")); |
1244,8 → 1308,9 |
KdPrint(( "PCIVMEDispatchPnp - IRP_MJ_PNP (%2.2X)\n", fcn)); |
|
static NTSTATUS(*fcntab[])(PDEVICE_OBJECT, PIRP) = { |
HandleStartDevice, // IRP_MN_START_DEVICE |
HandleStopDevice // IRP_MN_QUERY_REMOVE_DEVICE |
HandleStartDevice, // IRP_MN_START_DEVICE |
// DefaultPnpHandler, // IRP_MN_QUERY_REMOVE_DEVICE |
HandleStopDevice // IRP_MN_REMOVE_DEVICE |
}; |
|
if (fcn >= arraysize(fcntab)) |