【UEFI】PCIE Vital Product Data (VPD)

1 篇文章 0 订阅
1 篇文章 0 订阅

概要

本文将介绍VPD信息,以及UEFI中的读取方式。

提示:Vital Product Data (VPD) is the information that uniquely defines items such as the hardware, software, and microcode elements of a system. The VPD provides the system with information on various FRUs (Field Replaceable Unit) including Part Number, Serial Number, and other detailed information. VPD also provides a mechanism for storing information such as performance and failure data on the device being monitored. The objective, from a system point of view, is to collect this information by reading it from the hardware, software, and microcode components. Support of VPD within add-in cards is optional depending on the manufacturer. Though support of VPD is optional, add-in card manufacturers are encouraged to provide VPD due to its inherent benefits for the add-in card, system manufacturers, and for Plug and Play.

Spec:

《NCB-PCI_Express_Base_6.0.pdf》。
怎么读取PCIe设备的VPD信息?

数据结构定义介绍

都在spec里面。

VPD的主要格式(Ascii码值):

关键字+长度+数据。关键字是2Byte,比如“PN”,0B是’P’,1B是’N’,2B是Length,随后就是数据块了(Byte 3 到 N + 2)。那么“EC”亦是如此:N + 3 B就是 ‘E’…。
VPD Format
exmple
感觉上图是不是少了Byte 2 ?

完整举例:

OffsetItem Value
0Large Resource Type ID String Tag (02h) 82h “Product Name”
1Length 0021h
3Data “ABCD Super-Fast Widget Controller”
36Large Resource Type VPD-R Tag (10h) 90h
37Length 0059h
39VPD Keyword “PN”
41Length 08h
42Data “6181682A”
50VPD Keyword “EC”
52Length 0Ah
53Data “4950262536”
63VPD Keyword “SN”
65Length 08h
66Data “00000194”
74VPD Keyword “MN”
76Length 04h
77Data “1037”
81VPD Keyword “RV”
83Length 2Ch
84Data Checksum
85Data Reserved (00h)
128Large Resource Type VPD-W Tag (11h) 91h
129Length 007Ch
131VPD Keyword “V1”
133Length 05h
134Data “65A01”
139VPD Keyword “Y1”
141Length 0Dh
142Data “Error Code 26”
155VPD Keyword “RW”
157Length 61h
158Data Reserved (00h)
255Small Resource Type End Tag (0Fh) 78h

Vital Product Data Capability (VPD Capability)

VPD Capability Structure

如何获取VPD Address Register?

VPD Capability ID 是固定的值:0x03
EDK 2中定义如下:

//
// PCI Capability List IDs and records
//
#define EFI_PCI_CAPABILITY_ID_PMI     0x01
#define EFI_PCI_CAPABILITY_ID_AGP     0x02
**#define EFI_PCI_CAPABILITY_ID_VPD     0x03**
#define EFI_PCI_CAPABILITY_ID_SLOTID  0x04
#define EFI_PCI_CAPABILITY_ID_MSI     0x05
#define EFI_PCI_CAPABILITY_ID_HOTPLUG 0x06
#define EFI_PCI_CAPABILITY_ID_PCIX    0x07

我们现在知道了它在0x03处,但是在哪里的0x03呢?
因此需要继续探索。
没错的就是在PCI配置空间中的Capability Pointer(0x34)。
配置空间详见:【UEFI】PCIE学习笔记
UINT8 CapIdPtr;。
因此我们需要读取Capability Pointer == CapIdPtr 首地址,然后依次 CapIdPtr + 1 延申读取,直到CapId == 0x03。
EDK2 中有很多例子可以找到类似的读取CapId的实例,如下,将PCI_CAPABILITY_ID_DEBUG_PORT 替换成 EFI_PCI_CAPABILITY_ID_VPD即可,当然最好要判断一下这个设备有没有VPD。
如:

  //
  // Get Pointer To Capability List
  //
  CapabilityPtr = PciRead8 (PCI_CAPBILITY_POINTER_OFFSET);

  //
  // Find Capability ID 0xA, Which Is For Debug Port
  //
  while (CapabilityPtr != 0) {
    CapabilityId = PciRead8 (CapabilityPtr);
    if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) {
      break;
    }
    CapabilityPtr = PciRead8 (CapabilityPtr + 1);
  }

  //
  // No Debug Port Capability Found
  //
  if (CapabilityPtr == 0) {
    return RETURN_UNSUPPORTED;
  }

获取到CapIdPtr后如何操作?

根据Spec
![Read/Writer](https://img-blog.csdnimg.cn/direct/20ab56260ab04134aab692a534edb3d3.png
在这里插入图片描述

我们主要是想读取数据,所以下面的writer就不讨论了。
因此,需要用到Pci.writer();Pci.read();两个函数。

由 Vital Product Data Capability (VPD Capability)下的图可知
VPD Address Register 在offset 0x02处,占两个字节。
VPD Data Register 在offset 0x04处,占四个字节。

再参考博客:怎么读取PCIe设备的VPD信息?
VPD Address Register
DWORD
首次写操作:

UINT16 Value = 0;
UINT8 DataValue = 0;
PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, CapIdPtr + 0x02, 1, &Value);//这里 + 0x02,写两个字节(DWORD),然后低 2 bit 需要为0。因此 0000,1000...就是文献中说的在写下一个地址时要加4。
//写完后,再读取一遍看看F bit的值是否为1.
PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, CapIdPtr + 0x02, 1, &Value);
//然后就是读取 0x04位置的Data Address 中的内容。
PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, CapIdPtr + 0x4, 1, &DataValue + );
//第一次读取数据成功,接下来就是下一个了,也就是 Value + 4;依次类推....

读取完毕后,即可根据Format 来收集 PN/SN等内容了。

技术名词解释

例如:

  • Part Number :PN
  • Engineering Change :EC
  • Serial Number :SN
  • Manufacture ID :MN
  • see spec part:Read-Only Fields

技术细节

提示:UEFI,PCIE,Address,Capability Pointer...

小结

提示:一串数据集,存储着该PCIE设备的基本信息,如PN,SN,EC,RV等等,一次读取出来,然后根据格式分析出来即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值