2005-10-14 18:29:55 +00:00
|
|
|
/*
|
2001-09-16 13:18:24 +00:00
|
|
|
* PROJECT: ReactOS PCI bus driver
|
|
|
|
* FILE: pdo.c
|
|
|
|
* PURPOSE: Child device object dispatch routines
|
|
|
|
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 10-09-2001 CSH Created
|
|
|
|
*/
|
2003-12-12 21:54:42 +00:00
|
|
|
|
|
|
|
#include "pci.h"
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2014-01-04 11:06:54 +00:00
|
|
|
#include <initguid.h>
|
|
|
|
#include <wdmguid.h>
|
|
|
|
|
2001-09-16 13:18:24 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2014-11-02 11:30:14 +00:00
|
|
|
#if 0
|
|
|
|
#define DBGPRINT(...) DbgPrint(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DBGPRINT(...)
|
|
|
|
#endif
|
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
#define PCI_ADDRESS_MEMORY_ADDRESS_MASK_64 0xfffffffffffffff0ull
|
|
|
|
#define PCI_ADDRESS_IO_ADDRESS_MASK_64 0xfffffffffffffffcull
|
|
|
|
|
2001-09-16 13:18:24 +00:00
|
|
|
/*** PRIVATE *****************************************************************/
|
|
|
|
|
2004-08-16 09:13:00 +00:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryDeviceText(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
UNICODE_STRING String;
|
|
|
|
NTSTATUS Status;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Called\n");
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
switch (IrpSp->Parameters.QueryDeviceText.DeviceTextType)
|
|
|
|
{
|
|
|
|
case DeviceTextDescription:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceDescription,
|
|
|
|
&String);
|
|
|
|
|
|
|
|
DPRINT("DeviceTextDescription\n");
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeviceTextLocationInformation:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceLocation,
|
|
|
|
&String);
|
|
|
|
|
|
|
|
DPRINT("DeviceTextLocationInformation\n");
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Status;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
2001-09-16 13:18:24 +00:00
|
|
|
PdoQueryId(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2001-09-16 13:18:24 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
UNICODE_STRING String;
|
|
|
|
NTSTATUS Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Called\n");
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
// Irp->IoStatus.Information = 0;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
RtlInitUnicodeString(&String, NULL);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
switch (IrpSp->Parameters.QueryId.IdType)
|
|
|
|
{
|
|
|
|
case BusQueryDeviceID:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->DeviceID,
|
|
|
|
&String);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("DeviceID: %S\n", String.Buffer);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
case BusQueryHardwareIDs:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->HardwareIDs,
|
|
|
|
&String);
|
2004-06-09 14:22:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
2004-06-09 14:22:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
case BusQueryCompatibleIDs:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->CompatibleIDs,
|
|
|
|
&String);
|
2004-06-09 14:22:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
case BusQueryInstanceID:
|
|
|
|
Status = PciDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
|
|
|
|
&DeviceExtension->InstanceID,
|
|
|
|
&String);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InstanceID: %S\n", String.Buffer);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)String.Buffer;
|
|
|
|
break;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
case BusQueryDeviceSerialNumber:
|
|
|
|
default:
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-16 09:13:00 +00:00
|
|
|
static NTSTATUS
|
2004-03-12 19:40:05 +00:00
|
|
|
PdoQueryBusInformation(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-03-12 19:40:05 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PPNP_BUS_INFORMATION BusInformation;
|
2004-03-12 19:40:05 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
DPRINT("Called\n");
|
2004-03-12 19:40:05 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
2015-03-27 18:03:39 +00:00
|
|
|
BusInformation = ExAllocatePoolWithTag(PagedPool, sizeof(PNP_BUS_INFORMATION), TAG_PCI);
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
|
|
|
|
if (BusInformation != NULL)
|
|
|
|
{
|
|
|
|
BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI;
|
|
|
|
BusInformation->LegacyBusType = PCIBus;
|
|
|
|
BusInformation->BusNumber = DeviceExtension->PciDevice->BusNumber;
|
2004-03-12 19:40:05 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-03-12 19:40:05 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2004-03-14 17:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-16 09:13:00 +00:00
|
|
|
static NTSTATUS
|
2004-03-14 17:10:43 +00:00
|
|
|
PdoQueryCapabilities(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-03-14 17:10:43 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PDEVICE_CAPABILITIES DeviceCapabilities;
|
|
|
|
ULONG DeviceNumber, FunctionNumber;
|
2004-03-14 17:10:43 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
DPRINT("Called\n");
|
2004-03-14 17:10:43 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
|
2004-03-14 17:10:43 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (DeviceCapabilities->Version != 1)
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceNumber = DeviceExtension->PciDevice->SlotNumber.u.bits.DeviceNumber;
|
|
|
|
FunctionNumber = DeviceExtension->PciDevice->SlotNumber.u.bits.FunctionNumber;
|
2007-06-27 18:05:04 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceCapabilities->UniqueID = FALSE;
|
|
|
|
DeviceCapabilities->Address = ((DeviceNumber << 16) & 0xFFFF0000) + (FunctionNumber & 0xFFFF);
|
|
|
|
DeviceCapabilities->UINumber = MAXULONG; /* FIXME */
|
2004-03-14 17:10:43 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-03-12 19:40:05 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 09:13:00 +00:00
|
|
|
static BOOLEAN
|
2015-03-01 07:52:32 +00:00
|
|
|
PdoReadPciBar(PPDO_DEVICE_EXTENSION DeviceExtension,
|
|
|
|
ULONG Offset,
|
|
|
|
PULONG OriginalValue,
|
|
|
|
PULONG NewValue)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
ULONG Size;
|
2015-03-01 07:52:32 +00:00
|
|
|
ULONG AllOnes;
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Read the original value */
|
|
|
|
Size = HalGetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
OriginalValue,
|
|
|
|
Offset,
|
|
|
|
sizeof(ULONG));
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != sizeof(ULONG))
|
|
|
|
{
|
|
|
|
DPRINT1("Wrong size %lu\n", Size);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Write all ones to determine which bits are held to zero */
|
|
|
|
AllOnes = MAXULONG;
|
|
|
|
Size = HalSetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
&AllOnes,
|
|
|
|
Offset,
|
|
|
|
sizeof(ULONG));
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != sizeof(ULONG))
|
|
|
|
{
|
|
|
|
DPRINT1("Wrong size %lu\n", Size);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Get the range length */
|
2015-03-01 07:52:32 +00:00
|
|
|
Size = HalGetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
NewValue,
|
|
|
|
Offset,
|
|
|
|
sizeof(ULONG));
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != sizeof(ULONG))
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT1("Wrong size %lu\n", Size);
|
|
|
|
return FALSE;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
/* Restore original value */
|
2015-03-01 07:52:32 +00:00
|
|
|
Size = HalSetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
OriginalValue,
|
|
|
|
Offset,
|
|
|
|
sizeof(ULONG));
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != sizeof(ULONG))
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT1("Wrong size %lu\n", Size);
|
|
|
|
return FALSE;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
static BOOLEAN
|
|
|
|
PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
|
|
|
|
UCHAR Bar,
|
|
|
|
PULONGLONG Base,
|
|
|
|
PULONGLONG Length,
|
|
|
|
PULONG Flags,
|
|
|
|
PUCHAR NextBar,
|
|
|
|
PULONGLONG MaximumAddress)
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ULONG Bar0;
|
|
|
|
ULONG Bar1;
|
|
|
|
} Bars;
|
|
|
|
ULONGLONG Bar;
|
|
|
|
} OriginalValue;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ULONG Bar0;
|
|
|
|
ULONG Bar1;
|
|
|
|
} Bars;
|
|
|
|
ULONGLONG Bar;
|
|
|
|
} NewValue;
|
|
|
|
ULONG Offset;
|
2023-01-04 16:58:39 +00:00
|
|
|
ULONGLONG Size;
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Compute the offset of this BAR in PCI config space */
|
|
|
|
Offset = 0x10 + Bar * 4;
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Assume this is a 32-bit BAR until we find wrong */
|
|
|
|
*NextBar = Bar + 1;
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Initialize BAR values to zero */
|
|
|
|
OriginalValue.Bar = 0ULL;
|
|
|
|
NewValue.Bar = 0ULL;
|
|
|
|
|
|
|
|
/* Read the first BAR */
|
|
|
|
if (!PdoReadPciBar(DeviceExtension, Offset,
|
|
|
|
&OriginalValue.Bars.Bar0,
|
|
|
|
&NewValue.Bars.Bar0))
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
return FALSE;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Check if this is a memory BAR */
|
|
|
|
if (!(OriginalValue.Bars.Bar0 & PCI_ADDRESS_IO_SPACE))
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Write the maximum address if the caller asked for it */
|
|
|
|
if (MaximumAddress != NULL)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_32BIT)
|
|
|
|
{
|
|
|
|
*MaximumAddress = 0x00000000FFFFFFFFULL;
|
|
|
|
}
|
|
|
|
else if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_20BIT)
|
|
|
|
{
|
|
|
|
*MaximumAddress = 0x00000000000FFFFFULL;
|
|
|
|
}
|
|
|
|
else if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_64BIT)
|
|
|
|
{
|
|
|
|
*MaximumAddress = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Check if this is a 64-bit BAR */
|
|
|
|
if ((OriginalValue.Bars.Bar0 & PCI_ADDRESS_MEMORY_TYPE_MASK) == PCI_TYPE_64BIT)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
/* We've now consumed the next BAR too */
|
|
|
|
*NextBar = Bar + 2;
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
/* Read the next BAR */
|
|
|
|
if (!PdoReadPciBar(DeviceExtension, Offset + 4,
|
|
|
|
&OriginalValue.Bars.Bar1,
|
|
|
|
&NewValue.Bars.Bar1))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
2015-03-01 07:52:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Write the maximum I/O port address */
|
|
|
|
if (MaximumAddress != NULL)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
*MaximumAddress = 0x00000000FFFFFFFFULL;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
2015-03-01 07:52:32 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
if (NewValue.Bar == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Unused address register\n");
|
|
|
|
*Base = 0;
|
|
|
|
*Length = 0;
|
|
|
|
*Flags = 0;
|
|
|
|
return TRUE;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2015-09-06 08:54:20 +00:00
|
|
|
|
2017-09-27 22:59:48 +00:00
|
|
|
*Base = ((OriginalValue.Bar & PCI_ADDRESS_IO_SPACE)
|
|
|
|
? (OriginalValue.Bar & PCI_ADDRESS_IO_ADDRESS_MASK_64)
|
|
|
|
: (OriginalValue.Bar & PCI_ADDRESS_MEMORY_ADDRESS_MASK_64));
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2023-01-04 16:58:39 +00:00
|
|
|
Size = (NewValue.Bar & PCI_ADDRESS_IO_SPACE)
|
|
|
|
? (NewValue.Bar & PCI_ADDRESS_IO_ADDRESS_MASK_64)
|
|
|
|
: (NewValue.Bar & PCI_ADDRESS_MEMORY_ADDRESS_MASK_64);
|
|
|
|
*Length = Size & ~(Size - 1);
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2015-03-01 07:52:32 +00:00
|
|
|
*Flags = (NewValue.Bar & PCI_ADDRESS_IO_SPACE)
|
|
|
|
? (NewValue.Bar & ~PCI_ADDRESS_IO_ADDRESS_MASK_64)
|
|
|
|
: (NewValue.Bar & ~PCI_ADDRESS_MEMORY_ADDRESS_MASK_64);
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return TRUE;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryResourceRequirements(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PCI_COMMON_CONFIG PciConfig;
|
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST ResourceList;
|
|
|
|
PIO_RESOURCE_DESCRIPTOR Descriptor;
|
|
|
|
ULONG Size;
|
|
|
|
ULONG ResCount = 0;
|
|
|
|
ULONG ListSize;
|
2015-03-01 07:52:32 +00:00
|
|
|
UCHAR Bar;
|
|
|
|
ULONGLONG Base;
|
|
|
|
ULONGLONG Length;
|
2013-11-23 22:08:48 +00:00
|
|
|
ULONG Flags;
|
2015-03-01 07:52:32 +00:00
|
|
|
ULONGLONG MaximumAddress;
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
DPRINT("PdoQueryResourceRequirements() called\n");
|
|
|
|
|
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
/* Get PCI configuration space */
|
|
|
|
Size= HalGetBusData(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
&PciConfig,
|
|
|
|
PCI_COMMON_HDR_LENGTH);
|
|
|
|
DPRINT("Size %lu\n", Size);
|
|
|
|
if (Size < PCI_COMMON_HDR_LENGTH)
|
2004-08-18 08:25:58 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2004-08-18 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Command register: 0x%04hx\n", PciConfig.Command);
|
|
|
|
|
|
|
|
/* Count required resource descriptors */
|
|
|
|
ResCount = 0;
|
|
|
|
if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
|
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length != 0)
|
|
|
|
ResCount += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Check ROM address */
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (PciConfig.u.type0.InterruptPin != 0)
|
|
|
|
ResCount++;
|
|
|
|
}
|
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
|
2004-08-18 08:25:58 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length != 0)
|
|
|
|
ResCount += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
|
|
|
|
ResCount++;
|
|
|
|
}
|
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
|
|
|
|
{
|
|
|
|
/* FIXME: Count Cardbus bridge resources */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Unsupported header type %d\n", PCI_CONFIGURATION_TYPE(&PciConfig));
|
2004-08-18 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (ResCount == 0)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Calculate the resource list size */
|
|
|
|
ListSize = FIELD_OFFSET(IO_RESOURCE_REQUIREMENTS_LIST, List[0].Descriptors) +
|
|
|
|
ResCount * sizeof(IO_RESOURCE_DESCRIPTOR);
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("ListSize %lu (0x%lx)\n", ListSize, ListSize);
|
|
|
|
|
|
|
|
/* Allocate the resource requirements list */
|
|
|
|
ResourceList = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
ListSize,
|
|
|
|
TAG_PCI);
|
|
|
|
if (ResourceList == NULL)
|
2004-08-18 08:25:58 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2004-08-18 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
RtlZeroMemory(ResourceList, ListSize);
|
|
|
|
ResourceList->ListSize = ListSize;
|
|
|
|
ResourceList->InterfaceType = PCIBus;
|
|
|
|
ResourceList->BusNumber = DeviceExtension->PciDevice->BusNumber;
|
|
|
|
ResourceList->SlotNumber = DeviceExtension->PciDevice->SlotNumber.u.AsULONG;
|
|
|
|
ResourceList->AlternativeLists = 1;
|
|
|
|
|
|
|
|
ResourceList->List[0].Version = 1;
|
|
|
|
ResourceList->List[0].Revision = 1;
|
|
|
|
ResourceList->List[0].Count = ResCount;
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Descriptor = &ResourceList->List[0].Descriptors[0];
|
|
|
|
if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
|
2004-08-18 08:25:58 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
&MaximumAddress))
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
DPRINT1("PdoGetRangeLength() failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Length == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Unused address register\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set preferred descriptor */
|
|
|
|
Descriptor->Option = IO_RESOURCE_PREFERRED;
|
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
|
|
|
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
Descriptor->u.Port.Alignment = 1;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = Base;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = Base + Length - 1;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
Descriptor->u.Memory.Alignment = 1;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Memory.MinimumAddress.QuadPart = Base;
|
|
|
|
Descriptor->u.Memory.MaximumAddress.QuadPart = Base + Length - 1;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
Descriptor++;
|
|
|
|
|
|
|
|
/* Set alternative descriptor */
|
|
|
|
Descriptor->Option = IO_RESOURCE_ALTERNATIVE;
|
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
|
|
|
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
Descriptor->u.Port.Alignment = Length;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = 0;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = MaximumAddress;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
Descriptor->u.Memory.Alignment = Length;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = 0;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = MaximumAddress;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
Descriptor++;
|
|
|
|
}
|
2004-08-18 22:11:15 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* FIXME: Check ROM address */
|
|
|
|
|
|
|
|
if (PciConfig.u.type0.InterruptPin != 0)
|
|
|
|
{
|
|
|
|
Descriptor->Option = 0; /* Required */
|
|
|
|
Descriptor->Type = CmResourceTypeInterrupt;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareShared;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
|
|
|
|
|
|
|
|
Descriptor->u.Interrupt.MinimumVector = 0;
|
|
|
|
Descriptor->u.Interrupt.MaximumVector = 0xFF;
|
|
|
|
}
|
2004-08-18 08:25:58 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
|
2004-08-18 08:25:58 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
&MaximumAddress))
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
DPRINT1("PdoGetRangeLength() failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Length == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Unused address register\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set preferred descriptor */
|
|
|
|
Descriptor->Option = IO_RESOURCE_PREFERRED;
|
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
|
|
|
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
Descriptor->u.Port.Alignment = 1;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = Base;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = Base + Length - 1;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
Descriptor->u.Memory.Alignment = 1;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Memory.MinimumAddress.QuadPart = Base;
|
|
|
|
Descriptor->u.Memory.MaximumAddress.QuadPart = Base + Length - 1;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
Descriptor++;
|
|
|
|
|
|
|
|
/* Set alternative descriptor */
|
|
|
|
Descriptor->Option = IO_RESOURCE_ALTERNATIVE;
|
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
|
|
|
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
Descriptor->u.Port.Alignment = Length;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = 0;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = MaximumAddress;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
Descriptor->u.Memory.Alignment = Length;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->u.Port.MinimumAddress.QuadPart = 0;
|
|
|
|
Descriptor->u.Port.MaximumAddress.QuadPart = MaximumAddress;
|
2013-11-23 22:08:48 +00:00
|
|
|
}
|
|
|
|
Descriptor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
|
|
|
|
{
|
|
|
|
Descriptor->Option = 0; /* Required */
|
|
|
|
Descriptor->Type = CmResourceTypeBusNumber;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
|
|
|
|
ResourceList->BusNumber =
|
|
|
|
Descriptor->u.BusNumber.MinBusNumber =
|
|
|
|
Descriptor->u.BusNumber.MaxBusNumber = DeviceExtension->PciDevice->PciConfig.u.type1.SecondaryBus;
|
|
|
|
Descriptor->u.BusNumber.Length = 1;
|
|
|
|
Descriptor->u.BusNumber.Reserved = 0;
|
|
|
|
}
|
2004-08-18 08:25:58 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
|
2005-10-14 18:29:55 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
/* FIXME: Add Cardbus bridge resources */
|
2005-10-14 18:29:55 +00:00
|
|
|
}
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryResources(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PCI_COMMON_CONFIG PciConfig;
|
|
|
|
PCM_RESOURCE_LIST ResourceList;
|
|
|
|
PCM_PARTIAL_RESOURCE_LIST PartialList;
|
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
|
|
|
|
ULONG Size;
|
|
|
|
ULONG ResCount = 0;
|
|
|
|
ULONG ListSize;
|
2015-03-01 07:52:32 +00:00
|
|
|
UCHAR Bar;
|
|
|
|
ULONGLONG Base;
|
|
|
|
ULONGLONG Length;
|
2013-11-23 22:08:48 +00:00
|
|
|
ULONG Flags;
|
|
|
|
|
|
|
|
DPRINT("PdoQueryResources() called\n");
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(IrpSp);
|
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
/* Get PCI configuration space */
|
|
|
|
Size= HalGetBusData(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
&PciConfig,
|
|
|
|
PCI_COMMON_HDR_LENGTH);
|
|
|
|
DPRINT("Size %lu\n", Size);
|
|
|
|
if (Size < PCI_COMMON_HDR_LENGTH)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2004-08-18 08:25:58 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Command register: 0x%04hx\n", PciConfig.Command);
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Count required resource descriptors */
|
|
|
|
ResCount = 0;
|
|
|
|
if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
|
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length)
|
|
|
|
ResCount++;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if ((PciConfig.u.type0.InterruptPin != 0) &&
|
|
|
|
(PciConfig.u.type0.InterruptLine != 0) &&
|
|
|
|
(PciConfig.u.type0.InterruptLine != 0xFF))
|
|
|
|
ResCount++;
|
|
|
|
}
|
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
|
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length != 0)
|
|
|
|
ResCount++;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
|
|
|
|
ResCount++;
|
|
|
|
}
|
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
/* FIXME: Count Cardbus bridge resources */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Unsupported header type %d\n", PCI_CONFIGURATION_TYPE(&PciConfig));
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (ResCount == 0)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_SUCCESS;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2012-02-11 05:47:56 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Calculate the resource list size */
|
|
|
|
ListSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors) +
|
|
|
|
ResCount * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
|
|
|
|
|
|
|
|
/* Allocate the resource list */
|
|
|
|
ResourceList = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
ListSize,
|
|
|
|
TAG_PCI);
|
|
|
|
if (ResourceList == NULL)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
RtlZeroMemory(ResourceList, ListSize);
|
|
|
|
ResourceList->Count = 1;
|
|
|
|
ResourceList->List[0].InterfaceType = PCIBus;
|
|
|
|
ResourceList->List[0].BusNumber = DeviceExtension->PciDevice->BusNumber;
|
|
|
|
|
|
|
|
PartialList = &ResourceList->List[0].PartialResourceList;
|
|
|
|
PartialList->Version = 1;
|
|
|
|
PartialList->Revision = 1;
|
|
|
|
PartialList->Count = ResCount;
|
|
|
|
|
|
|
|
Descriptor = &PartialList->PartialDescriptors[0];
|
|
|
|
if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_DEVICE_TYPE)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE0_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Unused address register\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
2013-11-23 22:08:48 +00:00
|
|
|
Descriptor->u.Port.Start.QuadPart = (ULONGLONG)Base;
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
|
|
|
|
/* Enable IO space access */
|
|
|
|
DeviceExtension->PciDevice->EnableIoSpace = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
Descriptor->u.Memory.Start.QuadPart = (ULONGLONG)Base;
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
|
|
|
|
/* Enable memory space access */
|
|
|
|
DeviceExtension->PciDevice->EnableMemorySpace = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Descriptor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add interrupt resource */
|
|
|
|
if ((PciConfig.u.type0.InterruptPin != 0) &&
|
|
|
|
(PciConfig.u.type0.InterruptLine != 0) &&
|
|
|
|
(PciConfig.u.type0.InterruptLine != 0xFF))
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeInterrupt;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareShared;
|
|
|
|
Descriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
|
|
|
|
Descriptor->u.Interrupt.Level = PciConfig.u.type0.InterruptLine;
|
|
|
|
Descriptor->u.Interrupt.Vector = PciConfig.u.type0.InterruptLine;
|
|
|
|
Descriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow bus master mode */
|
|
|
|
DeviceExtension->PciDevice->EnableBusMaster = TRUE;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
|
2006-01-02 11:39:15 +00:00
|
|
|
{
|
2015-03-01 07:52:32 +00:00
|
|
|
for (Bar = 0; Bar < PCI_TYPE1_ADDRESSES;)
|
2013-11-23 22:08:48 +00:00
|
|
|
{
|
|
|
|
if (!PdoGetRangeLength(DeviceExtension,
|
2015-03-01 07:52:32 +00:00
|
|
|
Bar,
|
2013-11-23 22:08:48 +00:00
|
|
|
&Base,
|
|
|
|
&Length,
|
2015-03-01 07:52:32 +00:00
|
|
|
&Flags,
|
|
|
|
&Bar,
|
|
|
|
NULL))
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (Length == 0)
|
|
|
|
{
|
|
|
|
DPRINT("Unused address register\n");
|
|
|
|
continue;
|
|
|
|
}
|
2006-01-02 11:39:15 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Flags & PCI_ADDRESS_IO_SPACE)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypePort;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_PORT_IO |
|
|
|
|
CM_RESOURCE_PORT_16_BIT_DECODE |
|
|
|
|
CM_RESOURCE_PORT_POSITIVE_DECODE;
|
2013-11-23 22:08:48 +00:00
|
|
|
Descriptor->u.Port.Start.QuadPart = (ULONGLONG)Base;
|
|
|
|
Descriptor->u.Port.Length = Length;
|
|
|
|
|
|
|
|
/* Enable IO space access */
|
|
|
|
DeviceExtension->PciDevice->EnableIoSpace = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeMemory;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
2015-03-01 07:52:32 +00:00
|
|
|
Descriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE |
|
|
|
|
(Flags & PCI_ADDRESS_MEMORY_PREFETCHABLE) ? CM_RESOURCE_MEMORY_PREFETCHABLE : 0;
|
2013-11-23 22:08:48 +00:00
|
|
|
Descriptor->u.Memory.Start.QuadPart = (ULONGLONG)Base;
|
|
|
|
Descriptor->u.Memory.Length = Length;
|
|
|
|
|
|
|
|
/* Enable memory space access */
|
|
|
|
DeviceExtension->PciDevice->EnableMemorySpace = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Descriptor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
|
|
|
|
{
|
|
|
|
Descriptor->Type = CmResourceTypeBusNumber;
|
|
|
|
Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
|
|
|
|
ResourceList->List[0].BusNumber =
|
|
|
|
Descriptor->u.BusNumber.Start = DeviceExtension->PciDevice->PciConfig.u.type1.SecondaryBus;
|
|
|
|
Descriptor->u.BusNumber.Length = 1;
|
|
|
|
Descriptor->u.BusNumber.Reserved = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
|
|
|
|
{
|
|
|
|
/* FIXME: Add Cardbus bridge resources */
|
2006-01-02 11:39:15 +00:00
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-30 19:37:11 +00:00
|
|
|
static VOID NTAPI
|
|
|
|
InterfaceReference(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceReference(%p)\n", Context);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
|
|
|
InterlockedIncrement(&DeviceExtension->References);
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VOID NTAPI
|
|
|
|
InterfaceDereference(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceDereference(%p)\n", Context);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
|
|
|
InterlockedDecrement(&DeviceExtension->References);
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static TRANSLATE_BUS_ADDRESS InterfaceBusTranslateBusAddress;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2005-10-30 19:37:11 +00:00
|
|
|
InterfaceBusTranslateBusAddress(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN PHYSICAL_ADDRESS BusAddress,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN OUT PULONG AddressSpace,
|
|
|
|
OUT PPHYSICAL_ADDRESS TranslatedAddress)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceBusTranslateBusAddress(%p %p 0x%lx %p %p)\n",
|
|
|
|
Context, BusAddress, Length, AddressSpace, TranslatedAddress);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return HalTranslateBusAddress(PCIBus,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
BusAddress,
|
|
|
|
AddressSpace,
|
|
|
|
TranslatedAddress);
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static GET_DMA_ADAPTER InterfaceBusGetDmaAdapter;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static
|
|
|
|
PDMA_ADAPTER
|
|
|
|
NTAPI
|
2005-10-30 19:37:11 +00:00
|
|
|
InterfaceBusGetDmaAdapter(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN PDEVICE_DESCRIPTION DeviceDescription,
|
|
|
|
OUT PULONG NumberOfMapRegisters)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceBusGetDmaAdapter(%p %p %p)\n",
|
|
|
|
Context, DeviceDescription, NumberOfMapRegisters);
|
|
|
|
return (PDMA_ADAPTER)HalGetAdapter(DeviceDescription, NumberOfMapRegisters);
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static GET_SET_DEVICE_DATA InterfaceBusSetBusData;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
2005-10-30 19:37:11 +00:00
|
|
|
InterfaceBusSetBusData(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN ULONG DataType,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Offset,
|
|
|
|
IN ULONG Length)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
ULONG Size;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceBusSetBusData(%p 0x%lx %p 0x%lx 0x%lx)\n",
|
|
|
|
Context, DataType, Buffer, Offset, Length);
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (DataType != PCI_WHICHSPACE_CONFIG)
|
|
|
|
{
|
|
|
|
DPRINT("Unknown DataType %lu\n", DataType);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Get PCI configuration space */
|
|
|
|
Size = HalSetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
Buffer,
|
|
|
|
Offset,
|
|
|
|
Length);
|
|
|
|
return Size;
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static GET_SET_DEVICE_DATA InterfaceBusGetBusData;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
static
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
2005-10-30 19:37:11 +00:00
|
|
|
InterfaceBusGetBusData(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN ULONG DataType,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Offset,
|
|
|
|
IN ULONG Length)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
ULONG Size;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("InterfaceBusGetBusData(%p 0x%lx %p 0x%lx 0x%lx) called\n",
|
|
|
|
Context, DataType, Buffer, Offset, Length);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (DataType != PCI_WHICHSPACE_CONFIG)
|
|
|
|
{
|
|
|
|
DPRINT("Unknown DataType %lu\n", DataType);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Get PCI configuration space */
|
|
|
|
Size = HalGetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
Buffer,
|
|
|
|
Offset,
|
|
|
|
Length);
|
|
|
|
return Size;
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2005-11-18 22:32:44 +00:00
|
|
|
static BOOLEAN NTAPI
|
|
|
|
InterfacePciDevicePresent(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN USHORT VendorID,
|
|
|
|
IN USHORT DeviceID,
|
|
|
|
IN UCHAR RevisionID,
|
|
|
|
IN USHORT SubVendorID,
|
|
|
|
IN USHORT SubSystemID,
|
|
|
|
IN ULONG Flags)
|
2005-11-18 22:32:44 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PFDO_DEVICE_EXTENSION FdoDeviceExtension;
|
|
|
|
PPCI_DEVICE PciDevice;
|
|
|
|
PLIST_ENTRY CurrentBus, CurrentEntry;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
BOOLEAN Found = FALSE;
|
|
|
|
|
|
|
|
KeAcquireSpinLock(&DriverExtension->BusListLock, &OldIrql);
|
|
|
|
CurrentBus = DriverExtension->BusListHead.Flink;
|
|
|
|
while (!Found && CurrentBus != &DriverExtension->BusListHead)
|
2005-11-19 09:08:08 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
FdoDeviceExtension = CONTAINING_RECORD(CurrentBus, FDO_DEVICE_EXTENSION, ListEntry);
|
|
|
|
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
CurrentEntry = FdoDeviceExtension->DeviceListHead.Flink;
|
|
|
|
while (!Found && CurrentEntry != &FdoDeviceExtension->DeviceListHead)
|
2005-11-19 09:08:08 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PciDevice = CONTAINING_RECORD(CurrentEntry, PCI_DEVICE, ListEntry);
|
|
|
|
if (PciDevice->PciConfig.VendorID == VendorID &&
|
|
|
|
PciDevice->PciConfig.DeviceID == DeviceID)
|
|
|
|
{
|
|
|
|
if (!(Flags & PCI_USE_SUBSYSTEM_IDS) ||
|
|
|
|
(PciDevice->PciConfig.u.type0.SubVendorID == SubVendorID &&
|
|
|
|
PciDevice->PciConfig.u.type0.SubSystemID == SubSystemID))
|
|
|
|
{
|
|
|
|
if (!(Flags & PCI_USE_REVISION) ||
|
|
|
|
PciDevice->PciConfig.RevisionID == RevisionID)
|
|
|
|
{
|
|
|
|
DPRINT("Found the PCI device\n");
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
2005-11-19 09:08:08 +00:00
|
|
|
}
|
2005-11-18 22:32:44 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
CurrentBus = CurrentBus->Flink;
|
2005-11-19 09:08:08 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
KeReleaseSpinLock(&DriverExtension->BusListLock, OldIrql);
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Found;
|
2005-11-18 22:32:44 +00:00
|
|
|
}
|
|
|
|
|
2005-11-19 09:08:08 +00:00
|
|
|
|
|
|
|
static BOOLEAN
|
|
|
|
CheckPciDevice(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PPCI_COMMON_CONFIG PciConfig,
|
|
|
|
IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
|
2005-11-19 09:08:08 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
if ((Parameters->Flags & PCI_USE_VENDEV_IDS) &&
|
|
|
|
(PciConfig->VendorID != Parameters->VendorID ||
|
|
|
|
PciConfig->DeviceID != Parameters->DeviceID))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Parameters->Flags & PCI_USE_CLASS_SUBCLASS) &&
|
|
|
|
(PciConfig->BaseClass != Parameters->BaseClass ||
|
|
|
|
PciConfig->SubClass != Parameters->SubClass))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Parameters->Flags & PCI_USE_PROGIF) &&
|
|
|
|
PciConfig->ProgIf != Parameters->ProgIf)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Parameters->Flags & PCI_USE_SUBSYSTEM_IDS) &&
|
|
|
|
(PciConfig->u.type0.SubVendorID != Parameters->SubVendorID ||
|
|
|
|
PciConfig->u.type0.SubSystemID != Parameters->SubSystemID))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Parameters->Flags & PCI_USE_REVISION) &&
|
|
|
|
PciConfig->RevisionID != Parameters->RevisionID)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2005-11-19 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-18 22:32:44 +00:00
|
|
|
static BOOLEAN NTAPI
|
|
|
|
InterfacePciDevicePresentEx(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
|
2005-11-18 22:32:44 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PFDO_DEVICE_EXTENSION MyFdoDeviceExtension;
|
|
|
|
PFDO_DEVICE_EXTENSION FdoDeviceExtension;
|
|
|
|
PPCI_DEVICE PciDevice;
|
|
|
|
PLIST_ENTRY CurrentBus, CurrentEntry;
|
|
|
|
KIRQL OldIrql;
|
|
|
|
BOOLEAN Found = FALSE;
|
|
|
|
|
|
|
|
DPRINT("InterfacePciDevicePresentEx(%p %p) called\n",
|
|
|
|
Context, Parameters);
|
|
|
|
|
|
|
|
if (!Parameters || Parameters->Size != sizeof(PCI_DEVICE_PRESENCE_PARAMETERS))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)Context)->DeviceExtension;
|
|
|
|
MyFdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceExtension->Fdo->DeviceExtension;
|
|
|
|
|
|
|
|
if (Parameters->Flags & PCI_USE_LOCAL_DEVICE)
|
2005-11-19 09:08:08 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
return CheckPciDevice(&DeviceExtension->PciDevice->PciConfig, Parameters);
|
|
|
|
}
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
KeAcquireSpinLock(&DriverExtension->BusListLock, &OldIrql);
|
|
|
|
CurrentBus = DriverExtension->BusListHead.Flink;
|
|
|
|
while (!Found && CurrentBus != &DriverExtension->BusListHead)
|
|
|
|
{
|
|
|
|
FdoDeviceExtension = CONTAINING_RECORD(CurrentBus, FDO_DEVICE_EXTENSION, ListEntry);
|
|
|
|
if (!(Parameters->Flags & PCI_USE_LOCAL_BUS) || FdoDeviceExtension == MyFdoDeviceExtension)
|
2005-11-19 09:08:08 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
CurrentEntry = FdoDeviceExtension->DeviceListHead.Flink;
|
|
|
|
while (!Found && CurrentEntry != &FdoDeviceExtension->DeviceListHead)
|
|
|
|
{
|
|
|
|
PciDevice = CONTAINING_RECORD(CurrentEntry, PCI_DEVICE, ListEntry);
|
|
|
|
|
|
|
|
if (CheckPciDevice(&PciDevice->PciConfig, Parameters))
|
|
|
|
{
|
|
|
|
DPRINT("Found the PCI device\n");
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
}
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&FdoDeviceExtension->DeviceListLock);
|
|
|
|
}
|
|
|
|
CurrentBus = CurrentBus->Flink;
|
2005-11-19 09:08:08 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
KeReleaseSpinLock(&DriverExtension->BusListLock, OldIrql);
|
2005-11-19 09:08:08 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Found;
|
2005-11-18 22:32:44 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 19:37:11 +00:00
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryInterface(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
|
|
|
|
if (RtlCompareMemory(IrpSp->Parameters.QueryInterface.InterfaceType,
|
|
|
|
&GUID_BUS_INTERFACE_STANDARD, sizeof(GUID)) == sizeof(GUID))
|
|
|
|
{
|
|
|
|
/* BUS_INTERFACE_STANDARD */
|
|
|
|
if (IrpSp->Parameters.QueryInterface.Version < 1)
|
|
|
|
Status = STATUS_NOT_SUPPORTED;
|
|
|
|
else if (IrpSp->Parameters.QueryInterface.Size < sizeof(BUS_INTERFACE_STANDARD))
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PBUS_INTERFACE_STANDARD BusInterface;
|
|
|
|
BusInterface = (PBUS_INTERFACE_STANDARD)IrpSp->Parameters.QueryInterface.Interface;
|
|
|
|
BusInterface->Size = sizeof(BUS_INTERFACE_STANDARD);
|
|
|
|
BusInterface->Version = 1;
|
|
|
|
BusInterface->TranslateBusAddress = InterfaceBusTranslateBusAddress;
|
|
|
|
BusInterface->GetDmaAdapter = InterfaceBusGetDmaAdapter;
|
|
|
|
BusInterface->SetBusData = InterfaceBusSetBusData;
|
|
|
|
BusInterface->GetBusData = InterfaceBusGetBusData;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (RtlCompareMemory(IrpSp->Parameters.QueryInterface.InterfaceType,
|
|
|
|
&GUID_PCI_DEVICE_PRESENT_INTERFACE, sizeof(GUID)) == sizeof(GUID))
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
/* PCI_DEVICE_PRESENT_INTERFACE */
|
|
|
|
if (IrpSp->Parameters.QueryInterface.Version < 1)
|
|
|
|
Status = STATUS_NOT_SUPPORTED;
|
|
|
|
else if (IrpSp->Parameters.QueryInterface.Size < sizeof(PCI_DEVICE_PRESENT_INTERFACE))
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PPCI_DEVICE_PRESENT_INTERFACE PciDevicePresentInterface;
|
|
|
|
PciDevicePresentInterface = (PPCI_DEVICE_PRESENT_INTERFACE)IrpSp->Parameters.QueryInterface.Interface;
|
|
|
|
PciDevicePresentInterface->Size = sizeof(PCI_DEVICE_PRESENT_INTERFACE);
|
|
|
|
PciDevicePresentInterface->Version = 1;
|
|
|
|
PciDevicePresentInterface->IsDevicePresent = InterfacePciDevicePresent;
|
|
|
|
PciDevicePresentInterface->IsDevicePresentEx = InterfacePciDevicePresentEx;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
2005-11-18 22:32:44 +00:00
|
|
|
else
|
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Not a supported interface */
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Add a reference for the returned interface */
|
|
|
|
PINTERFACE Interface;
|
|
|
|
Interface = (PINTERFACE)IrpSp->Parameters.QueryInterface.Interface;
|
|
|
|
Interface->Context = DeviceObject;
|
|
|
|
Interface->InterfaceReference = InterfaceReference;
|
|
|
|
Interface->InterfaceDereference = InterfaceDereference;
|
|
|
|
Interface->InterfaceReference(Interface->Context);
|
2005-11-18 22:32:44 +00:00
|
|
|
}
|
2013-11-23 22:08:48 +00:00
|
|
|
|
|
|
|
return Status;
|
2005-10-30 19:37:11 +00:00
|
|
|
}
|
|
|
|
|
2010-04-02 17:07:38 +00:00
|
|
|
static NTSTATUS
|
|
|
|
PdoStartDevice(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2010-04-02 17:07:38 +00:00
|
|
|
{
|
2012-02-11 05:47:56 +00:00
|
|
|
PCM_RESOURCE_LIST RawResList = IrpSp->Parameters.StartDevice.AllocatedResources;
|
|
|
|
PCM_FULL_RESOURCE_DESCRIPTOR RawFullDesc;
|
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR RawPartialDesc;
|
|
|
|
ULONG i, ii;
|
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
UCHAR Irq;
|
|
|
|
USHORT Command;
|
2010-04-02 17:07:38 +00:00
|
|
|
|
2013-05-09 21:24:16 +00:00
|
|
|
UNREFERENCED_PARAMETER(Irp);
|
|
|
|
|
2012-02-11 05:47:56 +00:00
|
|
|
if (!RawResList)
|
|
|
|
return STATUS_SUCCESS;
|
2010-04-07 20:18:44 +00:00
|
|
|
|
2012-02-11 05:47:56 +00:00
|
|
|
/* TODO: Assign the other resources we get to the card */
|
2010-04-02 17:07:38 +00:00
|
|
|
|
2018-01-28 22:44:28 +00:00
|
|
|
RawFullDesc = &RawResList->List[0];
|
|
|
|
for (i = 0; i < RawResList->Count; i++, RawFullDesc = CmiGetNextResourceDescriptor(RawFullDesc))
|
2012-02-11 05:47:56 +00:00
|
|
|
{
|
|
|
|
for (ii = 0; ii < RawFullDesc->PartialResourceList.Count; ii++)
|
|
|
|
{
|
2018-01-28 22:44:28 +00:00
|
|
|
/* Partial resource descriptors can be of variable size (CmResourceTypeDeviceSpecific),
|
|
|
|
but only one is allowed and it must be the last one in the list! */
|
2012-02-11 05:47:56 +00:00
|
|
|
RawPartialDesc = &RawFullDesc->PartialResourceList.PartialDescriptors[ii];
|
|
|
|
|
|
|
|
if (RawPartialDesc->Type == CmResourceTypeInterrupt)
|
|
|
|
{
|
2014-11-02 11:30:14 +00:00
|
|
|
DPRINT("Assigning IRQ %u to PCI device 0x%x on bus 0x%x\n",
|
2012-02-11 05:47:56 +00:00
|
|
|
RawPartialDesc->u.Interrupt.Vector,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
DeviceExtension->PciDevice->BusNumber);
|
|
|
|
|
|
|
|
Irq = (UCHAR)RawPartialDesc->u.Interrupt.Vector;
|
|
|
|
HalSetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
&Irq,
|
|
|
|
0x3c /* PCI_INTERRUPT_LINE */,
|
|
|
|
sizeof(UCHAR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 17:07:38 +00:00
|
|
|
|
2012-02-11 06:56:10 +00:00
|
|
|
Command = 0;
|
|
|
|
|
2014-11-02 11:30:14 +00:00
|
|
|
DBGPRINT("pci!PdoStartDevice: Enabling command flags for PCI device 0x%x on bus 0x%x: ",
|
2012-02-11 05:47:56 +00:00
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
DeviceExtension->PciDevice->BusNumber);
|
|
|
|
if (DeviceExtension->PciDevice->EnableBusMaster)
|
|
|
|
{
|
|
|
|
Command |= PCI_ENABLE_BUS_MASTER;
|
2014-11-02 11:30:14 +00:00
|
|
|
DBGPRINT("[Bus master] ");
|
2012-02-11 05:47:56 +00:00
|
|
|
}
|
2010-04-02 17:07:38 +00:00
|
|
|
|
2012-02-11 05:47:56 +00:00
|
|
|
if (DeviceExtension->PciDevice->EnableMemorySpace)
|
|
|
|
{
|
|
|
|
Command |= PCI_ENABLE_MEMORY_SPACE;
|
2014-11-02 11:30:14 +00:00
|
|
|
DBGPRINT("[Memory space enable] ");
|
2012-02-11 05:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceExtension->PciDevice->EnableIoSpace)
|
|
|
|
{
|
|
|
|
Command |= PCI_ENABLE_IO_SPACE;
|
2014-11-02 11:30:14 +00:00
|
|
|
DBGPRINT("[I/O space enable] ");
|
2012-02-11 05:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Command != 0)
|
|
|
|
{
|
2014-11-02 11:30:14 +00:00
|
|
|
DBGPRINT("\n");
|
2012-02-11 05:47:56 +00:00
|
|
|
|
|
|
|
/* OR with the previous value */
|
|
|
|
Command |= DeviceExtension->PciDevice->PciConfig.Command;
|
|
|
|
|
|
|
|
HalSetBusDataByOffset(PCIConfiguration,
|
|
|
|
DeviceExtension->PciDevice->BusNumber,
|
|
|
|
DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
|
|
|
|
&Command,
|
|
|
|
FIELD_OFFSET(PCI_COMMON_CONFIG, Command),
|
|
|
|
sizeof(USHORT));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-03 16:16:26 +00:00
|
|
|
DBGPRINT("None\n");
|
2012-02-11 05:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2010-04-02 17:07:38 +00:00
|
|
|
}
|
2005-10-30 19:37:11 +00:00
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoReadConfig(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2005-10-30 19:37:11 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
ULONG Size;
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("PdoReadConfig() called\n");
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Size = InterfaceBusGetBusData(DeviceObject,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.WhichSpace,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Buffer,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Offset,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Length);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != IrpSp->Parameters.ReadWriteConfig.Length)
|
|
|
|
{
|
|
|
|
DPRINT1("Size %lu Length %lu\n", Size, IrpSp->Parameters.ReadWriteConfig.Length);
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = Size;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
PdoWriteConfig(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2004-08-16 09:13:00 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
ULONG Size;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT1("PdoWriteConfig() called\n");
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* Get PCI configuration space */
|
|
|
|
Size = InterfaceBusSetBusData(DeviceObject,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.WhichSpace,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Buffer,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Offset,
|
|
|
|
IrpSp->Parameters.ReadWriteConfig.Length);
|
2005-10-30 19:37:11 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Size != IrpSp->Parameters.ReadWriteConfig.Length)
|
|
|
|
{
|
|
|
|
DPRINT1("Size %lu Length %lu\n", Size, IrpSp->Parameters.ReadWriteConfig.Length);
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = Size;
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-16 09:13:00 +00:00
|
|
|
}
|
|
|
|
|
2010-04-04 00:00:21 +00:00
|
|
|
static NTSTATUS
|
|
|
|
PdoQueryDeviceRelations(
|
2013-11-23 22:08:48 +00:00
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
PIO_STACK_LOCATION IrpSp)
|
2010-04-04 00:00:21 +00:00
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PDEVICE_RELATIONS DeviceRelations;
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* We only support TargetDeviceRelation for child PDOs */
|
|
|
|
if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
|
|
|
|
return Irp->IoStatus.Status;
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* We can do this because we only return 1 PDO for TargetDeviceRelation */
|
2015-03-27 18:03:39 +00:00
|
|
|
DeviceRelations = ExAllocatePoolWithTag(PagedPool, sizeof(*DeviceRelations), TAG_PCI);
|
2013-11-23 22:08:48 +00:00
|
|
|
if (!DeviceRelations)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DeviceRelations->Count = 1;
|
|
|
|
DeviceRelations->Objects[0] = DeviceObject;
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
/* The PnP manager will remove this when it is done with the PDO */
|
|
|
|
ObReferenceObject(DeviceObject);
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
|
2010-04-04 00:00:21 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return STATUS_SUCCESS;
|
2010-04-04 00:00:21 +00:00
|
|
|
}
|
2004-08-16 09:13:00 +00:00
|
|
|
|
2001-09-16 13:18:24 +00:00
|
|
|
|
|
|
|
/*** PUBLIC ******************************************************************/
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
PdoPnpControl(
|
2013-11-23 22:08:48 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2001-09-16 13:18:24 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Handle Plug and Play IRPs for the child device
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to physical device object of the child device
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
NTSTATUS Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Called\n");
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_DEVICE_USAGE_NOTIFICATION:
|
|
|
|
DPRINT("Unimplemented IRP_MN_DEVICE_USAGE_NOTIFICATION received\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_EJECT:
|
|
|
|
DPRINT("Unimplemented IRP_MN_EJECT received\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_BUS_INFORMATION:
|
|
|
|
Status = PdoQueryBusInformation(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
|
|
|
Status = PdoQueryCapabilities(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
Status = PdoQueryDeviceRelations(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_DEVICE_TEXT:
|
|
|
|
DPRINT("IRP_MN_QUERY_DEVICE_TEXT received\n");
|
|
|
|
Status = PdoQueryDeviceText(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_ID:
|
|
|
|
DPRINT("IRP_MN_QUERY_ID received\n");
|
|
|
|
Status = PdoQueryId(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_PNP_DEVICE_STATE:
|
|
|
|
DPRINT("Unimplemented IRP_MN_QUERY_ID received\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
|
|
|
|
DPRINT("IRP_MN_QUERY_RESOURCE_REQUIREMENTS received\n");
|
|
|
|
Status = PdoQueryResourceRequirements(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_RESOURCES:
|
|
|
|
DPRINT("IRP_MN_QUERY_RESOURCES received\n");
|
|
|
|
Status = PdoQueryResources(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_SET_LOCK:
|
|
|
|
DPRINT("Unimplemented IRP_MN_SET_LOCK received\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_START_DEVICE:
|
|
|
|
Status = PdoStartDevice(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_STOP_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
2020-06-18 16:18:13 +00:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
2013-11-23 22:08:48 +00:00
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_QUERY_INTERFACE:
|
|
|
|
DPRINT("IRP_MN_QUERY_INTERFACE received\n");
|
|
|
|
Status = PdoQueryInterface(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_READ_CONFIG:
|
|
|
|
DPRINT("IRP_MN_READ_CONFIG received\n");
|
|
|
|
Status = PdoReadConfig(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_WRITE_CONFIG:
|
|
|
|
DPRINT("IRP_MN_WRITE_CONFIG received\n");
|
|
|
|
Status = PdoWriteConfig(DeviceObject, Irp, IrpSp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
|
|
|
|
DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS received\n");
|
|
|
|
/* Nothing to do */
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT1("Unknown IOCTL 0x%lx\n", IrpSp->MinorFunction);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-03 22:59:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
2012-02-03 22:59:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Leaving. Status 0x%X\n", Status);
|
2012-02-03 22:59:53 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
PdoPowerControl(
|
2013-11-23 22:08:48 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject,
|
|
|
|
PIRP Irp)
|
2001-09-16 13:18:24 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Handle power management IRPs for the child device
|
|
|
|
* ARGUMENTS:
|
|
|
|
* DeviceObject = Pointer to physical device object of the child device
|
|
|
|
* Irp = Pointer to IRP that should be handled
|
|
|
|
* RETURNS:
|
|
|
|
* Status
|
|
|
|
*/
|
|
|
|
{
|
2013-11-23 22:08:48 +00:00
|
|
|
PIO_STACK_LOCATION IrpSp;
|
2015-09-06 08:54:20 +00:00
|
|
|
NTSTATUS Status = Irp->IoStatus.Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Called\n");
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
switch (IrpSp->MinorFunction)
|
|
|
|
{
|
2015-09-06 08:54:20 +00:00
|
|
|
case IRP_MN_QUERY_POWER:
|
2013-11-23 22:08:48 +00:00
|
|
|
case IRP_MN_SET_POWER:
|
2015-09-06 08:54:20 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2013-11-23 22:08:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2015-09-06 08:54:20 +00:00
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
DPRINT("Leaving. Status 0x%X\n", Status);
|
2001-09-16 13:18:24 +00:00
|
|
|
|
2013-11-23 22:08:48 +00:00
|
|
|
return Status;
|
2001-09-16 13:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|