SRIOV_GET_RESOURCE_FOR_BAR callback function (pcivirt.h)

Gets the translated resource for a specific Base Address Register (BAR)

Syntax

SRIOV_GET_RESOURCE_FOR_BAR SriovGetResourceForBar;

NTSTATUS SriovGetResourceForBar(
  [in]  PVOID Context,
  [in]  USHORT VfIndex,
  [in]  USHORT BarIndex,
  [out] PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource
)
{...}

Parameters

[in] Context

A pointer to a driver-defined context.

[in] VfIndex

A zero-based index of the VF that is being queried.

[in] BarIndex

The index of the BAR (between 0 and 5).

[out] Resource

A pointer to a CM_PARTIAL_RESOURCE_DESCRIPTOR structure that is filled with the translated hardware resources for the specified BAR.

Return value

Return STATUS_SUCCESS if the operation succeeds. Otherwise, return an appropriate NTSTATUS error code.

Remarks

This callback function is implemented by the physical function (PF) driver. It is invoked when the system wants to access the translated hardware resources of a particular BAR of a virtual function.

The PF driver registers its implementation by setting the GetResourceForBar member of the SRIOV_DEVICE_INTERFACE_STANDARD, configuring a WDF_QUERY_INTERFACE_CONFIG structure, and calling WdfDeviceAddQueryInterface.

Here is an example implementation of this callback function.


NTSTATUS
Virtualization_GetResourceForBar(
    __inout     PVOID             Context,
    __in        USHORT            VfIndex,
    __in        USHORT            BarIndex,
    __out       PCM_PARTIAL_RESOURCE_DESCRIPTOR Resource
    )

{
    PDEVICE_CONTEXT  deviceContext;

    PAGED_CODE();

    deviceContext = (PDEVICE_CONTEXT)Context;

    TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INTERFACE,
        "Virtualization_GetResourceForBar received with"
        "VFIndex = %d, BarIndex = %d\n",
        VfIndex, BarIndex);

    NT_ASSERT(BarIndex < PCI_TYPE0_BAR_COUNT);

    if(VfIndex >= deviceContext->NumVFs)
    {
        NT_ASSERT(FALSE);
        return STATUS_INVALID_DEVICE_REQUEST;
    }

    //
    // Copy the descriptor for all VFs at the given Bar index
    // to the output descriptor.
    //

    *Resource = deviceContext->AssignedVfBarResources[BarIndex];

    if(Resource->Type == CmResourceTypeMemory ||
       Resource->Type == CmResourceTypeMemoryLarge)
    {
        NT_ASSERT((Resource->u.Memory.Length % deviceContext->NumVFs) == 0);
        Resource->u.Memory.Length /= deviceContext->NumVFs;
        Resource->u.Memory.Start.QuadPart += (Resource->u.Memory.Length * VfIndex);
    }

    return STATUS_SUCCESS;
}


Requirements

Requirement Value
Minimum supported client Windows 10
Minimum supported server Windows Server 2016
Target Platform Windows
Header pcivirt.h
IRQL PASSIVE_LEVEL