注意遍历过程中不能使用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;
}
执行结果如下图