We are aiming to write a UMDF driver for a PCIe device and need to access configuration space to read and write a value during initialization.
From searching here and the MS documentation this does not appear to be possible as there is no mechanism in UMDF to send an IRP down the device stack with IRP_MJ_PNP and IRP_MN_READ/WRITE_CONFIG. Would it be possible for somemone more experienced in this area to confirm this for us so that we can move on
We are able to install a KMDF lower filter and send it an Ioctl that it could convert to an IRP and pass-on. This is our “Plan B”
To clarify, the Wdf functions to send an IRP down the stack such as WdfRequestWdmFormatUsingStackLocation() are shown in the MS documentation as [Applies to KMDF only] and do not appear in the UMDF version of the include files. I was wondering if it could be done under UMDF.
I have now got it working via a KMDF lower filter, thanks to other posts on this site.
If you’re doing it from Kernel-Mode, I hope you’re doing it with GetBusData (as opposed to sending the IRP)… Unless, of course, you only need to access Config space occasionally. In which case, it doesn’t really matter.
ULONG
UtilReadConfigSpace(
PDEVICE_CONTEXT DevContext,
ULONG Offset,
ULONG Length,
PVOID BufferPointer)
{
ULONG bytesRead = 0;
PBUS_INTERFACE_STANDARD busInterface;
//
// Make things easier to read
//
busInterface = &DevContext->BusInterface;
if (busInterface->GetBusData != nullptr) {
bytesRead = busInterface->GetBusData(busInterface->Context,
PCI_WHICHSPACE_CONFIG,
BufferPointer,
Offset,
Length);
if (bytesRead != Length) {
DbgPrint( "Failed to read 0x%x bytes! 0x%x\n",
Length,
bytesRead);
}
} else {
DbgPrint( "PciConfigSpace not open on read!\n");
}
return bytesRead;
}
I had gone down the IRP route as we are not expecting mnay calls but the Get/SetBusData approach is so much neater and quicker under the hood that I have converted to it.