none
Multiple devices and WdfDeviceCreateDeviceInterface RRS feed

  • Question

  • Hi experts

    In KMDF we created a bus extended driver and we create a tool to interact with driver through ioctl, so if the machine has the multiple card how can we reach the specific card interface and how can we handle multiple instance with a single driver, if we have a same multiple pci card.
    so i can get the specific PFDO of a specific card by passing BDF of the card.

    Thanks

    Saturday, March 19, 2016 7:32 AM

Answers

  • There is only one instance of a driver, there are multiple device objects but only one driver object.  So if you want a list in the driver you can use a global variable, or a member of the driver object context to do this.  In user space, the device interface enumeration will allow you to do this.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by Rajganesh006 Tuesday, March 22, 2016 1:55 PM
    Saturday, March 19, 2016 1:36 PM

All replies

  • What do you mean by BDF?  That is not a term I normally see.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Saturday, March 19, 2016 11:26 AM
  • Bus No., Device No., Func No
    Saturday, March 19, 2016 12:38 PM
  • Create a device interface with WdfDeviceCreateDeviceInterface with the reference string being an encoding of the three values (Bus Number, Device Number, Func Number) 

    You can then enumerate the interfaces and get the correct one.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Saturday, March 19, 2016 12:58 PM
  • but how can i maintain a list of device pfdo that is created by multiple instances of driver
    Saturday, March 19, 2016 1:30 PM
  • There is only one instance of a driver, there are multiple device objects but only one driver object.  So if you want a list in the driver you can use a global variable, or a member of the driver object context to do this.  In user space, the device interface enumeration will allow you to do this.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by Rajganesh006 Tuesday, March 22, 2016 1:55 PM
    Saturday, March 19, 2016 1:36 PM
  • Usermode does not need help of the driver to get bus, device, function. This is in Location Information property of each device. Just enumerate all your devices and query the property.

    --pa

    Saturday, March 19, 2016 8:23 PM
  • why do you need to maintain that list? typically each device is independent. as soon as you start tracking different device instances in a global list, life becomes much more complicated.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Sunday, March 20, 2016 6:58 AM
  • Thanks a lot for clarifying my doubts on driver instance.

    and i have done some change in code

    I have created a device interface with WdfDeviceCreateDeviceInterface with the reference string being an encoded with Func Number in driver.

    In the user app how can i connect to the specific hardware (with the reference string ) encoded

    hardwareDeviceInfo = SetupDiGetClassDevs(
            (LPGUID)&GUID_MYDEVICE,
            NULL, // Define no enumerator (global)
            NULL, // Define no
            (DIGCF_PRESENT | // Only Devices present
            DIGCF_DEVICEINTERFACE)); // Function class devices.

        deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

        bResult = SetupDiEnumDeviceInterfaces(hardwareDeviceInfo,
            0,
            (LPGUID)&GUID_MYDEVICE,
            0,
            &deviceInterfaceData);

        printf("Calling SetupDiGetDeviceInterfaceDetail()....\n");

        SetupDiGetDeviceInterfaceDetail(
            hardwareDeviceInfo,
            &deviceInterfaceData,
            NULL,
            0,
            &RequiredLength,
            NULL
            );


        deviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)
            LocalAlloc(LMEM_FIXED, RequiredLength);

        deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

        predictedLength = RequiredLength;

        bResult = SetupDiGetDeviceInterfaceDetail(
            hardwareDeviceInfo,
            &deviceInterfaceData,
            deviceInterfaceDetailData,
            predictedLength,
            &RequiredLength,
            NULL);

        printf(" SetupDiGetDeviceInterfaceDetail() bResult=0x%x....\n", bResult);

        *handle= CreateFile(deviceInterfaceDetailData->DevicePath,
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL, // no SECURITY_ATTRIBUTES structure
            OPEN_EXISTING, // No special create flags
            0, // No special attributes
            NULL); // No template file
        
        if (DeviceIoControl(handle,
            MYDEVICE_FW_IOCTL_BDF,
            &pci_addr,
            sizeof(test_pci_addr_t),
            NULL,
            NULL,
            &bytes,
            NULL))

    Through this, I can hit the driver, but even though if I give the wrong function number its hitting the driver ioctl, where I am missing to add the reference string in user code.

    Thanks for your help


    • Edited by Rajganesh006 Tuesday, March 22, 2016 2:04 PM removed error check codes
    Tuesday, March 22, 2016 1:55 PM
  • In the driver you need to support file objects, see https://msdn.microsoft.com/en-us/library/windows/hardware/ff542144%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, March 22, 2016 2:00 PM
  • Thanks Pavel

    My aim is to hit a specific PCI hardware through the BDF as the CLI in user app, so i can hit the specific ioctl and i will get the relevant PFDO 

    Tuesday, March 22, 2016 2:11 PM