PCIe接口相對(duì)來(lái)講還是打交道比較多的接口。無(wú)論是Intel還是Xilinx的IP也都接觸到過(guò)。談及PCIe,就不可避免地涉及Bar空間。當(dāng)然廠商的IP還是包裝的可以的,我們直接配置就行。但在使用時(shí)關(guān)于Bar空間的配置,往往牽涉到這么幾個(gè)概念:
IO/Mem
Prefetchable
32位/64位
早前這東西不假思索,抄抄之前的設(shè)計(jì)照著配置就好了。乍看pcieext-cocotb中的實(shí)現(xiàn),不禁思索,這些參數(shù)軟件是如何識(shí)別的呢?像下面EP常涉及的配置空間:
配置空間中所涉及到的只有6個(gè)Base Address Registers,似乎并無(wú)很明顯的指示~ 》協(xié)議解讀
先來(lái)看看Spec中關(guān)于Base Address Registers的定義:
關(guān)于如何區(qū)分是Mem空間還是IO空間,Spec中定義了:
bit0:為1表示Memory Space,為0則表示I/O Space。
(I/O空間僅支持32位,且現(xiàn)在PCIe設(shè)備里也較少使用,這里不再展開(kāi),感興趣小伙伴可自行翻看Spec)
對(duì)于Memory類型空間,bit[3:0]均為只讀。在bit[2:1]中定義了Memory類型空間
可見(jiàn),當(dāng)bit[2]為1時(shí)表示64位地址空間,否則為32位地址空間。
而當(dāng)bit[3]為1時(shí),表示該Bar空間為Prefetchable,為0則不是非prefetchable。
看到這里,上面的疑問(wèn)也基本可以解答了。在cocotbext-pcie中的配置方式也有所驗(yàn)證:
》Prefetchable
關(guān)于Prefetchable這個(gè)屬性,一直也沒(méi)有非常清晰的認(rèn)識(shí)。按照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設(shè)備里,Bar空間基本用于實(shí)現(xiàn)寄存器讀寫,是基本符合上面所描述的情況的,所以配置成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中的原話,總結(jié)起來(lái):盡可能配置成64 bit prefetchable.
》Bar空間的初始化
對(duì)于Bar空間,其核心除了上述的屬性檢測(cè)外另一重點(diǎn)便是為Bar空間分配指定大小的地址空間。
對(duì)于Base Address Registers,Bar空間的大小只能配置成2的n次方。以32位Memory 空間為例,其可配置的范圍是16Byte~2GB(低四bit用于設(shè)置Bar空間屬性)。
對(duì)于指定大小所占用的位,其只讀并且始終為0,若沒(méi)有被使用,則其會(huì)返回全0。在初始化時(shí)軟件可以向Bar空間寫全1然后回讀。
對(duì)于讀會(huì)的數(shù)據(jù),將低4bit清零,然后所有bit取反后加1即為對(duì)應(yīng)的Bar空間大小。分配好地址空間好將Base地址寫回到Base Address Registers中~
審核編輯:劉清
-
寄存器
+關(guān)注
關(guān)注
31文章
5294瀏覽量
119814 -
PCI
+關(guān)注
關(guān)注
4文章
662瀏覽量
130139 -
PCIe
+關(guān)注
關(guān)注
15文章
1200瀏覽量
82352 -
PCIe接口
+關(guān)注
關(guān)注
0文章
120瀏覽量
9665
原文標(biāo)題:PCIe——Bar空間是怎么生效的
文章出處:【微信號(hào):Spinal FPGA,微信公眾號(hào):Spinal FPGA】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論