获取BUS_INTERFACE_STANDARD

在WDF程序可以通过WdfFdoQueryForInterface函数得到BUS_INTERFACE_STANDARD

而WDM驱动可以通过下面的函数获得

 

static NTSTATUS
GetPCIBusInterfaceStandard(
    __in  PDEVICE_OBJECT DeviceObject,
    __out PBUS_INTERFACE_STANDARD    BusInterfaceStandard
    )
/*++
Routine Description:

    This routine gets the bus interface standard information from the PDO.

Arguments:
    DeviceObject - Device object to query for this information.
    BusInterface - Supplies a pointer to the retrieved information.

Return Value:

    NT status.

--*/
{
    KEVENT event;
    NTSTATUS status;
    PIRP irp;
    IO_STATUS_BLOCK ioStatusBlock;
    PIO_STACK_LOCATION irpStack;
    PDEVICE_OBJECT targetObject;

    PAGED_CODE();

    KeInitializeEvent( &event, NotificationEvent, FALSE );

    targetObject = IoGetAttachedDeviceReference( DeviceObject );

    irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
                                        targetObject,
                                        NULL,
                                        0,
                                        NULL,
                                        &event,
                                        &ioStatusBlock );
    if (irp == NULL) {
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto End;
    }

    irpStack = IoGetNextIrpStackLocation( irp );
    irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
    irpStack->Parameters.QueryInterface.InterfaceType =
                        (LPGUID) &GUID_BUS_INTERFACE_STANDARD ;
    irpStack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
    irpStack->Parameters.QueryInterface.Version = 1;
    irpStack->Parameters.QueryInterface.Interface =
                                        (PINTERFACE)BusInterfaceStandard;

    irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;

    // Initialize the status to error in case the bus driver does not
    // set it correctly.
    irp->IoStatus.Status = STATUS_NOT_SUPPORTED ;

    status = IoCallDriver( targetObject, irp );
    if (status == STATUS_PENDING) {

        status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL);
        ASSERT(NT_SUCCESS(status));
        status = ioStatusBlock.Status;

    }

End:
    // Done with reference
    ObDereferenceObject( targetObject );
    return status;

}

转载于:https://www.cnblogs.com/fanzi2009/archive/2011/06/15/2081309.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用BUS_INTERFACE_STANDARD总线方式访问pcie配置空间的示例代码: ```c // 定义PCI设备的地址 #define PCI_CONFIG_ADDR(bus, dev, func, reg) ((unsigned int)( \ (unsigned int)(bus) << 16 | \ (unsigned int)(dev) << 11 | \ (unsigned int)(func) << 8 | \ (unsigned int)(reg) << 2 | \ (unsigned int)0x80000000) ) // 从PCI配置空间读取一个32位的值 unsigned int ReadPCIConfigDword(BUS_INTERFACE_STANDARD* pBusIntf, unsigned int bus, unsigned int device, unsigned int function, unsigned int reg) { unsigned int addr = PCI_CONFIG_ADDR(bus, device, function, reg); unsigned int value = 0; pBusIntf->ReadBusData(pBusIntf->Context, EfiPciWidthUint32, addr, 1, &value); return value; } // 向PCI配置空间写入一个32位的值 void WritePCIConfigDword(BUS_INTERFACE_STANDARD* pBusIntf, unsigned int bus, unsigned int device, unsigned int function, unsigned int reg, unsigned int value) { unsigned int addr = PCI_CONFIG_ADDR(bus, device, function, reg); pBusIntf->WriteBusData(pBusIntf->Context, EfiPciWidthUint32, addr, 1, &value); } ``` 在上面的代码中,我们首先定义了一个宏来生成PCI设备的地址,然后实现了读取和写入32位值的函数。这些函数使用了EFI的BUS_INTERFACE_STANDARD总线接口来访问PCI配置空间。具体来说,`ReadBusData`和`WriteBusData`函数被用来读取和写入数据。这些函数需要传入总线接口的上下文指针、数据宽度、地址、数据数量和数据缓冲区。在本例中,我们只读写了一个32位的值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值