最近在研究cocotbext-pcie的實(shí)現(xiàn),對(duì)于學(xué)習(xí)PCIe還是挺有幫助的,陸陸續(xù)續(xù)做個(gè)總結(jié),有時(shí)間也會(huì)在SpinalHDL下實(shí)現(xiàn)類似的方針功能。
》拋磚
PCIe接口相對(duì)來講還是打交道比較多的接口。無論是Intel還是Xilinx的IP也都接觸到過。談及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,似乎并無很明顯的指示~
》協(xié)議解讀
先來看看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è)備里也較少使用,這里不再展開,感興趣小伙伴可自行翻看Spec)
對(duì)于Memory類型空間,bit[3:0]均為只讀。在bit[2:1]中定義了Memory類型空間
可見,當(dāng)bit[2]為1時(shí)表示64位地址空間,否則為32位地址空間。
而當(dāng)bit[3]為1時(shí),表示該Bar空間為Prefetchable,為0則不是非prefetchable。
看到這里,上面的疑問也基本可以解答了。在cocotbext-pcie中的配置方式也有所驗(yàn)證:
》Prefetchable
關(guān)于Prefetchable這個(gè)屬性,一直也沒有非常清晰的認(rèn)識(shí)。按照Spec中的定義:
A Function is permitted to mark a range as prefetchable if there are no side effects on reads, the Function returns all bytes on reads regardless of the byte enables, and host bridges can merge processor writes into this range without 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 example of 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 support a 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 large amounts of Memory Space to have their Prefetchable bit Set, since prefetchable Memory Space is more bountiful on most scalable platforms.
On PCI Express systems that meet the criteria enumerated below, setting the Prefetchable bit in a candidate BAR will still permit correct operation even if the BAR’s range includes some locations that have read side-effects or cannot 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 good candidates, since only Legacy Endpoints are permitted to set the Prefetchable bit in 32-bit BARs, and most scalable platforms map all 32-bit Memory BARs into non-prefetchable Memory Space regardless of the Prefetchable bit value.
這里貼上Spec中的原話,總結(jié)起來:盡可能配置成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,若沒有被使用,則其會(huì)返回全0。在初始化時(shí)軟件可以向Bar空間寫全1然后回讀。對(duì)于讀會(huì)的數(shù)據(jù),將低4bit清零,然后所有bit取反后加1即為對(duì)應(yīng)的Bar空間大小。分配好地址空間好將Base地址寫回到Base Address Registers中~
-
HDL語(yǔ)言
+關(guān)注
關(guān)注
0文章
46瀏覽量
8905 -
PCIe接口
+關(guān)注
關(guān)注
0文章
120瀏覽量
9665
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論