Extracting Device ID in KMDF function driver

I have function in existing WDM driver, which extracts DeviceID from PDO. I need to do the same in KMDF driver. Is there KMDF way to do this? If not, how can I get low-level driver PDO in a KMDF driver? Having this PDO, I can use existing function.

This is function code. pdx->Pdo is PDO from AddDevice (PDEVICE_OBJECT pdo parameter), kept in device extension.

NTSTATUS ReadPciConfigSpace(IN PDEVICE_EXTENSION pdx)
{
KEVENT event;
NTSTATUS status;
PIRP Irp;
IO_STATUS_BLOCK StatusBlock;
PIO_STACK_LOCATION stack;
PDEVICE_OBJECT target;
PCI_COMMON_CONFIG PciConfig;

PAGED_CODE();

KeInitializeEvent( &event, NotificationEvent, FALSE );

// pdx->Pdo is PDEVICE_OBJECT pdo passed to AddDevice
target = IoGetAttachedDeviceReference(pdx->Pdo);

Irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
target,
NULL,
0,
NULL,
&event,
&StatusBlock);
if(Irp == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
stack = IoGetNextIrpStackLocation( Irp );
stack->MinorFunction = IRP_MN_READ_CONFIG;
stack->Parameters.ReadWriteConfig.WhichSpace = PCI_WHICHSPACE_CONFIG;
stack->Parameters.ReadWriteConfig.Buffer = &PciConfig;
stack->Parameters.ReadWriteConfig.Offset = 0;
stack->Parameters.ReadWriteConfig.Length = sizeof PCI_COMMON_CONFIG;

Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;

status = IoCallDriver( target, Irp);

if(status == STATUS_PENDING)
{
KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL);
status = StatusBlock.Status;
}

// Handle PciConfig here:
// extracting DeviceID from it.

}

ObDereferenceObject(target);
return status;
}

Found solution in the pcidrv KMDF sample, NICGetDeviceInformation function.

xxxxx@yahoo.com wrote:

I have function in existing WDM driver, which extracts DeviceID from PDO. I need to do the same in KMDF driver. Is there KMDF way to do this? If not, how can I get low-level driver PDO in a KMDF driver? Having this PDO, I can use existing function.

Well, you can either use the framework routines to fetch the next-lower
I/O target (WdfDeviceGetIoTarget), then create and format a WDFREQUEST
and submit it using WdfIoTargetSentIoctlSynchronously, or you can fetch
its device object using WdfDeviceWdmGetAttachedDevice and submit the IRP
the old-fashioned way, as you are currently doing it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.