accessbus.c

来自「访问物理内存、端口和PCI配置空间」· C语言 代码 · 共 60 行

C
60
字号
/*++
access pci bus configuration
--*/

#include <ntddk.h>
#include <wdmguid.h>
#include "DebugPrint.h"

//gets the bus interface standard information from the PDO.
NTSTATUS GetBusInterface(IN PDEVICE_OBJECT pcifido,
	OUT PPCI_BUS_INTERFACE_STANDARD	busInterface)
{
	KEVENT event;
	NTSTATUS ntStatus;
	PIRP irp;
	IO_STATUS_BLOCK ioStatus;
	PIO_STACK_LOCATION irpStack;

	if (pcifido==NULL)
		return STATUS_UNSUCCESSFUL;

	KeInitializeEvent(&event, NotificationEvent, FALSE);

	irp=IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
									 pcifido,
									 NULL,
									 0,
									 NULL,
									 &event,
									 &ioStatus);

	if (irp==NULL)
	{
		return STATUS_INSUFFICIENT_RESOURCES;
	}

	irpStack=IoGetNextIrpStackLocation(irp);
	irpStack->MinorFunction=IRP_MN_QUERY_INTERFACE;
	irpStack->Parameters.QueryInterface.InterfaceType=(LPGUID)&GUID_PCI_BUS_INTERFACE_STANDARD;
	irpStack->Parameters.QueryInterface.Size=sizeof(PCI_BUS_INTERFACE_STANDARD);
	irpStack->Parameters.QueryInterface.Version=PCI_BUS_INTERFACE_STANDARD_VERSION;
	irpStack->Parameters.QueryInterface.Interface=(PINTERFACE)busInterface;
	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 ;

	ntStatus=IoCallDriver(pcifido, irp);

	if (ntStatus==STATUS_PENDING)
	{
		KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);

		ntStatus=ioStatus.Status;
	}

	return ntStatus;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?