全球最实用的IT互联网信息网站!

AI人工智能P2P分享&下载搜索网页发布信息网站地图

当前位置:诺佳网 > 电子/半导体 > 接口/总线/驱动 >

PCIe—Bar空间是怎么生效的

时间:2023-06-05 10:47

人气:

作者:admin

标签: PCIe接口  PCI  寄存器  PCIe 

导读:PCIe接口相对来讲还是打交道比较多的接口。无论是Intel还是Xilinx的IP也都接触到过。...

PCIe接口相对来讲还是打交道比较多的接口。无论是Intel还是Xilinx的IP也都接触到过。谈及PCIe,就不可避免地涉及Bar空间。当然厂商的IP还是包装的可以的,我们直接配置就行。但在使用时关于Bar空间的配置,往往牵涉到这么几个概念:

IO/Mem

Prefetchable

32位/64位

早前这东西不假思索,抄抄之前的设计照着配置就好了。乍看pcieext-cocotb中的实现,不禁思索,这些参数软件是如何识别的呢?像下面EP常涉及的配置空间:

019adca8-034b-11ee-90ce-dac502259ad0.jpg

配置空间中所涉及到的只有6个Base Address Registers,似乎并无很明显的指示~ 》协议解读

先来看看Spec中关于Base Address Registers的定义:

01a0dab8-034b-11ee-90ce-dac502259ad0.jpg

关于如何区分是Mem空间还是IO空间,Spec中定义了:

bit0:为1表示Memory Space,为0则表示I/O Space。

(I/O空间仅支持32位,且现在PCIe设备里也较少使用,这里不再展开,感兴趣小伙伴可自行翻看Spec)

对于Memory类型空间,bit[3:0]均为只读。在bit[2:1]中定义了Memory类型空间

01a8ab6c-034b-11ee-90ce-dac502259ad0.jpg

可见,当bit[2]为1时表示64位地址空间,否则为32位地址空间。

而当bit[3]为1时,表示该Bar空间为Prefetchable,为0则不是非prefetchable。

看到这里,上面的疑问也基本可以解答了。在cocotbext-pcie中的配置方式也有所验证:

01aecfba-034b-11ee-90ce-dac502259ad0.png

》Prefetchable

关于Prefetchable这个属性,一直也没有非常清晰的认识。按照Spec中的定义:

A Function is permittedto mark a range as prefetchable if there are no side effects on reads, the Function returns all bytes on reads regardless ofthe byte enables, and host bridges can merge processor writes into this rangewithout causing errors.

Any device that has a range that behaves like normal memory should mark the range as prefetchable. A linear frame buffer in a graphics device is an exampleof a range that should be marked prefetchable.

一般而言,在PCIe设备里,Bar空间基本用于实现寄存器读写,是基本符合上面所描述的情况的,所以配置成prefetchable还是有必要的。而且在spec中,也提到了: PCI Express adapters with Memory Space BARs that request a large amount of non-prefetchable Memory Space(e.g., over 64 MB) may cause shortages of that Space on certain scalable platforms, since many platforms supporta total of only 1 GB or less of non-prefetchable Memory Space.This may limit the number of such adapters that

can be supported on those platforms. For this reason, it is especially encouraged for BARs requesting largeamounts of Memory Space to have their Prefetchable bit Set, since prefetchable Memory Space is more bountifulon most scalable platforms.

On PCI Express systems that meet the criteria enumerated below, setting the Prefetchable bit in a candidate BARwill still permit correct operation even if the BAR’s range includes some locations that have read side-effects orcannot tolerate write merging. This is primarily due to the fact that PCI Express Memory Reads always contain an

explicit length, and PCI Express Switches never prefetch or do byte merging. Generally only 64-bit BARs are goodcandidates, since only Legacy Endpoints are permitted to set the Prefetchable bit in 32-bit BARs, and mostscalable platforms map all 32-bit Memory BARs into non-prefetchable Memory Space regardless of thePrefetchable bit value.

这里贴上Spec中的原话,总结起来:尽可能配置成64 bit prefetchable.

》Bar空间的初始化

对于Bar空间,其核心除了上述的属性检测外另一重点便是为Bar空间分配指定大小的地址空间。

对于Base Address Registers,Bar空间的大小只能配置成2的n次方。以32位Memory 空间为例,其可配置的范围是16Byte~2GB(低四bit用于设置Bar空间属性)。

对于指定大小所占用的位,其只读并且始终为0,若没有被使用,则其会返回全0。在初始化时软件可以向Bar空间写全1然后回读。

对于读会的数据,将低4bit清零,然后所有bit取反后加1即为对应的Bar空间大小。分配好地址空间好将Base地址写回到Base Address Registers中~





审核编辑:刘清

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信