2022年8月30日 星期二

初學 PCIe System (一) - PCIe介紹及其配置空間

第二部分在這:初學 PCIe System (二) - 如何訪問PCIe設備的配置空間

PCI Express 介紹

PCI Express (PCIe) 屬於第三代的高效能 I/O 匯流排,PCIe Spec對其的介紹是:

PCI Express is a high performance, general purpose I/O interconnect defined for a wide variety of future computing and communication platforms. 

PCI Express 為各種未來的計算和通信平台所定義的高性能、通用互連 I/O 。

因此一個PCIe 系統就是指由許多設備相互透過 PCIe 點對點連接所組成的。如下圖範例,其結構是大多是由一個Root Complex (RC)、多個Endpoints、Bridge和Switches所組成



Root Complex (RC):I/O 層次結構的根,負責將 CPU/Memory子系統連接至 I/O ,可視為一虛擬的PCIe Bus(Bus-0)。RC 比較偏向軟體的概念,在x86 架構伺服器上,硬體部分是由CPU和PCH所共同實現。

Switch:多個虛擬 PCI-to-PCI 橋設備的邏輯組合

Endpoints:指一種Function 類型,可作為 PCIe 交易(Transaction)的請求者(Requester)或完成者(Completer)。

*Transaction 中文我一直不知道怎麼翻譯會比較好,在電腦科學中,訊息傳送通常是點對點的,傳送端和接收端的一次完整訊息溝通,包含了事前握手、訊息交換、和結束溝通,整個過程就稱之為Transaction。 


系統在上電之後,會透過深度優先演算法(DFS)去掃描目前系統上有哪些PCIe Device,並為他們定址。PCIe Device的地址是由兩個byte,並分為三個部分所組成的:


Bus Number(8 bits) :PCI Express 將邏輯 PCI 總線編號映射到 PCI Express Link

Device Number(5 bits) : 對於非 ARI 設備,PCI Express 組件僅限於在其主接口(上行端口)上實現單個設備編號

Function Number(3 bits) :PCI 被允許在該設備編號內實現多達八個獨立的功能

因此一個PCIe Device的地址 = bus << 8 | dev << 5 | func


PCIe 配置空間 (PCIe Configuration Space)

PCIe Spec中定義:每個PCIe Function都有 4096 Byte 的配置空間(Configuration Space)。前256 Bytes 是和 PCI 兼容的空間,剩餘的為PCIe 擴展配置空間(Extended Configuration Space)。其中前 256 Bytes PCI 兼容的空間是為software-driven的初始化和配置提供的,通常可以透過I/O Programming 或是 Direct Memory Access (DMA) 訪問




另外,在offset 0x00-0x3F的空間為Header(藍色框部分), 他的內容格式可分為type 0 和 type 1兩種,上色部分為他們共同的部分

Type 0 主要為Endpoints,例如PCI Express Endpoint、Legacy PCI Express Endpoint、RCiEP、Root Complex Event Collector


Type 1主要為Root Complex、Switch和Bridge


我們可以透過訪問Configuration Space Header得到許多重要的資訊,例如:

Vendor ID Register (Offset 00h):Vendor ID是 HwInit,標示函數的製造商,可以從Member Companies | PCI-SIG (pcisig.com) 輸入ID查找製造商

Device ID Register (Offset 02h):Device ID 是 HwInit,標示函數的功能。Device ID 與Vendor ID 和Revision ID 一起用作應加載哪個驅動程序的一種機制。

Command Register (Offset 04h):Individual bits in the Command Register may or may not be implemented depending on the feature set supported by the Function.

Status Register (Offset 06h):Functions may not need to implement all bits, depending on the feature set supported by the Function.

Revision ID Register (Offset 08h) :Revision ID 是 HwInit。Device ID 與Vendor ID 和Revision ID 一起用作應加載哪個驅動程序的一種機制。

Class Code Register (Offset 09h):是read-only的,用於標示Function的通用操作。由三個Byte組成:


Class Code 需要另外對照PCI-Code-and-ID 這份Spec,這邊用DMTF  Redfish Resource and Schema Guide (dmtf.org) 中的範例來解釋,這邊第三個Byte-Base Class Code為0x02,因此這個Function是一個NetworkController

Header Type Register (Offset 0Eh):標示設備是否可能包含多個功能。 

---

以上就是PCIe Configuration Space Header 的資訊內容大概,至於如何訪問,會在第二部分介紹

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。