BIOS遍历PCIe设备(暴力版)代码备份

注意遍历过程中不能使用break,编号不是按照顺序排列的。

下面展示一些 内联代码片

#include <Uefi.h>
#include <stdio.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/IoLib.h>
#include <Library/ShellLib.h>
#include <Library/ShellCEntryLib.h>
#include <Library/BaseLib/BaseLibInternals.h>
#include <Library/PcdLib.h>

UINT32 GetDID_VID(int Bus,int Device,int Function)
{
	UINTN PciAddress;
	UINT32 Value;
	UINTN PcieBaseAddress = 0xC0000000;
	PciAddress = (((Bus) & 0xff) << 20) | (((Device) & 0x1f) << 15) | (((Function) & 0x07) << 12) | (((0x00) & 0xfff));
	Value = MmioRead32(PcieBaseAddress  + PciAddress ); //读取数据
	return Value;
}
UINT16 GetVID(int Bus,int Device,int Function)
{
	UINTN PciAddress;
	UINT16 Value;
	UINTN PcieBaseAddress = 0xC0000000;
	PciAddress = (((Bus) & 0xff) << 20) | (((Device) & 0x1f) << 15) | (((Function) & 0x07) << 12) | (((0x00) & 0xfff));
	Value = MmioRead16(PcieBaseAddress  + PciAddress ); //读取数据
	return Value;
}

UINT16 GetDID(int Bus,int Device,int Function)
{
	UINTN PciAddress;
	UINT16 Value;
	UINTN PcieBaseAddress = 0xC0000000;
	PciAddress = (((Bus) & 0xff) << 20) | (((Device) & 0x1f) << 15) | (((Function) & 0x07) << 12) | (((0x02) & 0xfff));
	Value = MmioRead16(PcieBaseAddress  + PciAddress ); //读取数据
	return Value;
}

INTN ShellAppMain(IN UINTN Argc,IN CHAR16 **Argv)
{
	UINT32 DID_VID;
	UINT16 DID,VID;
	int b,d,f;
	for( b = 0;b < 256;b++)//bus
	{
		for( d = 0;d < 32;d++)//device
		{
			for( f = 0;f < 8;f++)//function
			{
				DID_VID = GetDID_VID(b,d,f);
				if (DID_VID == 0xFFFFFFFF)
				{
					//break;
					continue;
				}
				else
				{
					DID = GetDID(b,d,f);
					VID = GetVID(b,d,f);
					Print(L"Bus:%d   Device:%d   Function:%d    DID:%x    VID:  %x\n",b,d,f,DID,VID);
				}
				/*if (DID_VID != 0xFFFFFFFF)
				{
					DID = GetDID(b,d,f);
					VID = GetVID(b,d,f);
					Print(L"Bus:%d   Device:%d   Function:%d    DID:%x    VID:  %x\n",b,d,f,DID,VID);
				}*/
			}
		}
	}
	//Print(L"bus0,dev0,fun0:%x.....\n",Value);
	return 0;

}

执行结果如下图
在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值