How the KMDF to support multiple PCIe devices?

Reported
hl kuang 0 Reputation points
2023-10-30T11:15:41.58+00:00
  • Here is code entry in KMDF driver:
NTSTATUS
DriverEntry(
    __in PDRIVER_OBJECT  DriverObject,
    __in PUNICODE_STRING RegistryPath
)
{
    WDF_DRIVER_CONFIG config;
    NTSTATUS status;
    WDF_OBJECT_ATTRIBUTES attributes;
    WDFDRIVER driver;
    DTRACE("DriverEntry Called");

    //
    // Register a cleanup callback so that we can call WPP_CLEANUP when
    // the framework driver object is deleted during driver unload.
    //
    WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
    attributes.EvtCleanupCallback = RcardDrvEvtCleanup;
    attributes.EvtDestroyCallback = RcardDrvEvtDestroyCallback;
    WDF_DRIVER_CONFIG_INIT(&config,
        RcardDrvEvtDeviceAdd
    );
    status = WdfDriverCreate(DriverObject,
        RegistryPath,
        &attributes,
        &config,
        &driver
    );
    if (!NT_SUCCESS(status)) {
        DERROR("Failed in DriverEntry %x\n", status);
        return status;
    }

    //WdfObjectReference(DriverObject);
    DTRACE("Driver Create Success DriverEntry %x\n", status);
    return status;
}

NTSTATUS
RcardDrvEvtDeviceAdd(
    __in    WDFDRIVER       Driver,
    __inout PWDFDEVICE_INIT DeviceInit
)
/*++
Routine Description:

    EvtDeviceAdd is called by the framework in response to AddDevice
    call from the PnP manager. We create and initialize a device object to
    represent a new instance of the device.

Arguments:

    Driver - Handle to a framework driver object created in DriverEntry

    DeviceInit - PoINTer to a framework-allocated WDFDEVICE_INIT structure.

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS                     status = STATUS_SUCCESS;
    WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
    WDF_OBJECT_ATTRIBUTES        attributes;
    WDFDEVICE                    device;
    PRPP_DEVICE_CONTEXT          devContext = NULL;
    UNICODE_STRING                      symbolicLinkName;
    USHORT                              symbolicLinkNameBuf[256] = { 0 };
    WDF_IO_QUEUE_CONFIG          queueConfig;
    WDFQUEUE                     queue;
    UNREFERENCED_PARAMETER(Driver);
    PAGED_CODE();
    DTRACE(" Device Add called \n");

    //
    // Zero out the PnpPowerCallbacks structure.
    //
    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);

    // 
    // Set Callbacks for any of the functions we are INTerested in.
    // If no callback is set, Framework will take the default action
    // by itself.
    //
    pnpPowerCallbacks.EvtDevicePrepareHardware = RcardEvtDevicePrepareHardware;
    pnpPowerCallbacks.EvtDeviceReleaseHardware = RcardEvtDeviceReleaseHardware;

    //
    // These two callbacks set up and tear down hardware state that must be
    // done every time the device moves in and out of the D0-working state.
    //
    pnpPowerCallbacks.EvtDeviceD0Entry = RcardEvtDeviceD0Entry;
    pnpPowerCallbacks.EvtDeviceD0Exit = RcardEvtDeviceD0Exit;

    // Register the PnP Callbacks..
    WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);

    // Initialize Fdo Attributes.
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, RCARD_DEVICE_CONTEXT);

    WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoDirect);
    ...
  • Compile the code and install the drivers, but there only one card can work. And two devices exist, one card is error. Like this:

Error_爱奇艺

  • I need the KMDF driver, which are required to support for multiple devices(Rpp Device) working simultaneously. Can you provide me with some complete KMDF PCIe driver cases for reference? I try to find useful information in Microsoft (github.com) and 使用 WDF 开发驱动程序 - Windows drivers | Microsoft Learn, but I can't search any demos using KMDF to work two/three... and more cards.
  • Just like the picture, I have taked one cards to work normally. Now I need KMDF driver support more same devices(Rpp Device).
  • Hope your help, thanks.
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
9,484 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,063 questions
0 comments No comments