【93】PCI Expansion ROM

下面内容来自

PCI Firmware Specification Revision 3.3

1、Expansion ROM

    PCIe、PCI设备可以提供Expansion ROM,Expansion ROM中存在设备初始化或者system boot的code。SystemBIOS在POST(Power-on Self Test)阶段,会枚举PCI设备,并判断有设备是否支持Expansion ROM,如果支持Expansion ROM,这把Expansion ROM code拷贝到RAM中并执行。

2、配置空间中Expansion ROM BAR位置

    Type 0的0x30位置是存放设备的Expansion ROM BAR的位置,Expansion ROM BAR的枚举和其他BAR没有太大区别,都是写全1然后回读获取BAR大小,唯一的区别就是systemBIOS要去对应的地址拷贝Expansion ROM code,并校验、执行。

3、PCI Expansion ROM内容

    PCIe Expansion ROM可能有很多份code image,每一份image都是512 byte boundary对齐的,并且每一份image都必须包含PCI Expansion ROM header。每次一份image的起始地址都依赖上一份image的大小(Image_N_header_offset=Image_N-1_header_offset+ Image_N-1_length*512)。最后一份image在last image indicator(0x15)字段标记出来。

3.1、PCI Expansion ROM Header格式

PCI Expansion ROM Header格式如上图,其中0x18~0x19指向PCI Data Structure。

3.2、PCI Data structure格式

    其中vendor identification(0x4)/device identification(0x6)和class code(0xd)三者表示了本image code支持的设备ID(match和PCI 子系统查找probe函数的match函数类似)。

    PCI data structure length(0xA)代表本image中的PCI data structure的length,单位是byte。

    Image length(0x10)代表本image的大小,单位是512byte。

    Code type(0x14)代表本image执行的CPU架构。

    Last image indicator(0x15),bit7代表本image是否是ROM中的last image。bit7为1代表是last image,为0代表不是last image。

4、Linux kernel中PCI Expansion ROM相关实现

    在sys文件系统中有对应PCIe设备的expansion ROM的binary。

    在drivers/pci/pci-sysfs.c中有pci_read_rom和pci_write_rom的实现。

    在drivers/pci/pci-sysfs.c中有访问Expansion ROM BAR的实现。

    可以看到pci_write_rom相对来说简单一些,只是根据输入参数设置了一下pci_dev->rom_atter_enable。

    在使用需要先echo 1 > rom,否则read是会返回Invalid argument。

4.1 pci_read_rom实现

pci_read_rom-->pci_map_rom------->pci_enable_rom

                            ----->io_remap

                            ----->pci_get_rom_size

            -->memcpy_fromio

            -->pci_unmap_rom-----> io_unmap

                            ----->pci_disable_rom

5、实际例子

    我们拿82599网卡的Expansion ROM举个例子。82599网卡的Expansion ROM BAR size为64K,起始地址为0xa6c10000。我们使能command reg的memory access enable和expansion ROM enable后就可以访问expansion ROM BAR了。

    从PCI Expansion ROM Header 的0x18看,PCI Data Structure在0x40的位置

    0x40(offset 0x0)(signature)是0x52494350,0x52在ASCII对应的symbol是R,0x49在ASCII对应的symbol是I,0x43在ASCII对应的symbol是C,0x50在ASCII对应的symbol是P。signature是PCIR。

    0x44(offset 0x4)(Vendor Identification)~0x46(Device Identification)对应的是0x8086和0x10FB,是intel的82599网卡。

    0x4A(offset 0xA)(PCI Data Structure Length)为0x1C,代表该image中,PCI data structure到0x5C(0x40+0x1C)后面就是run time code和initialization code。

    0x4D(offset 0xD)(Class Code)为0x020000,0x02代表Network controller,0x0000代表Ethernet controller。

    0x50(offset 0x10)(Image Length)为0x78,说明下一个image的headeroffset=0x00(当前image的header)+0x78*512=0xF000

    0x54 (offset: 0x14)(Code Type)为0x00,代表该image是intel X86,PC-AT compatible的。

    0x55(offset 0x15)(Last Image Indicator)为0x80,bit7为1,代表当前image是last image。

    0x56(offset 0x16)(maximum runtime image length)为0x8,代表

The Image Length field is a two-byte field that represents the maximum length of the image after the initialization code has been executed,单位是512byte,只有当PCI Data Structure Revision(offset 0xC)是3或者之后的版本,maximum runtime image length才有意义

6、Firmware Power-on Self Test (POST) Firmware

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linjiasen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值