根據PCI Local Bus Specification中有提及,讀取PCI暫存器資料有兩總方式,一是透過IO(CF8/CFC),另一種舊式透過MMIO。
IO Mapped (CF8/CFC)
首先我們必須透過PCI Function Address(PFA)算出
Memory Mapped
要透過MMIO去讀取PCI暫存器,就必須先取得PCIEBAR,PCIEBAR可以參考EDS中BUS 0/ DEV 0/ FUN 0 ,找出PCIEBAR Base Address。
以PCI Device例子來看:
假設有個PCI的Device它的PFA(PCI Function Address)為(0,6,0)[bus/dev/function]
我們想要對PCI Register 43h bit1寫入1
範例程式碼如下:
mov eax, 80003040h
mov dx, 0cf8h
out dx, eax
mov dx, 0cffh
in al, dx
or al, 00000010b
out dx, al
IO Port 0x0cf8/0x0cfc為PCI Config Address/Data Port
這種方式就是I/O Mapped I/O
如果是PCIe Device的話,原則上原本的0x0cf8/0x0cfc還是可以用,但它只能存取Offset 00h~FFh,
要存取100h以上的空間時,就必需要用MMIO了。
範例程式如下:
假設我們要讀取Device(4,0,0)的register 0,讀2bytes
mov ax,[50400000h]
假設0x50000000是PCIe的Memory Base Address
PCIe PFA[27:20]: Bus information
PCIe PFA[19:15]: Device information
PCIe PFA[14:12]: Function information
PCIe PFA[11: 8]: Extended Register
PCIe PFA[7:2]: DW number
PCIe PFA[1:0]: Byte enable
留言
張貼留言