Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


PCIe Configuration Space Access in UMDF

RichSRichS Member Posts: 3

Hello,

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"

Thanks in advance.

Richard

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,166

    I’ve done this a million times in KMDF, but never in UMDF. So, having said that...

    But, honestly, I don’t see why building such a Request and sending it with WdfRequestSend to your Local I/O Target wouldn’t work.

    I realize it’s only marginally useful to have somebody guess.

    Anybody personally done this?

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • RichSRichS Member Posts: 3

    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.

    Richard

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,166
    edited October 16

    Well, glad you got it working.

    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;
    }
    

    Peter

    Post edited by Peter_Viscarola_(OSR) on

    Peter Viscarola
    OSR
    @OSRDrivers

  • RichSRichS Member Posts: 3

    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.

    Thank you for your help.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE