PCI (Peripheral Component Interconnect)
Purpose: replace the ISA standard with three main goals:
1. better performance between peripherals, 2. platform independent, 3. simplify adding/removing devices.
PCI devices are jumperless (不懂?), and are automatically configured at boot time.
- Identification of a device
PCI定義三個參數來決定一個device:
1. bus number: device所屬的bus
2. device number: bus所指定的一個unique number, 每個bus最多可指定32個devices
3. function number: 多個device可以共用一個PCI slot, 利用function number來區分.
每個bus可以有32 devices, 每個device可以有multifunction board, 最多八個function (identified by 16-bit address).
- Address space
Purpose: replace the ISA standard with three main goals:
1. better performance between peripherals, 2. platform independent, 3. simplify adding/removing devices.
PCI devices are jumperless (不懂?), and are automatically configured at boot time.
- Identification of a device
PCI定義三個參數來決定一個device:
1. bus number: device所屬的bus
2. device number: bus所指定的一個unique number, 每個bus最多可指定32個devices
3. function number: 多個device可以共用一個PCI slot, 利用function number來區分.
Much used in laptops are multifunction chipsets, which are attached to the PCI and integrate a whole range of expansions (IDE controller, USB controller, modem, network, etc.) in a minimum of space [ref2]
4. pci domain: Each PCI domain can host up to 256 buses.每個bus可以有32 devices, 每個device可以有multifunction board, 最多八個function (identified by 16-bit address).
- Address space
PCI使用三個address space來跟device溝通
1. I/O space: described by 32 bits address
2. Data space (memory locations): 32 byte or 64 byte are available for data space, depending on the processor type
3. Configuration space: contains type and characteristics of the individual devices. 256 byte for each device function.
*每個pci bus使用同一個I/O space and data space, 每一個device有自己的configuration space.
*
from fig 6.1, ref1
1. I/O space: described by 32 bits address
2. Data space (memory locations): 32 byte or 64 byte are available for data space, depending on the processor type
3. Configuration space: contains type and characteristics of the individual devices. 256 byte for each device function.
*每個pci bus使用同一個I/O space and data space, 每一個device有自己的configuration space.
*
from fig 6.1, ref1
PCI address space and configuration header
每一個PCI device都一個configuration header 存在他的address space, 系統根據PCI topology來決定此address space的位址 (tied to the physical PCI device location, which PCI slot it locates)
每一個PCI slot都有一個對應到的PCI configuration header 和offset. 所以系統可以從第一個offset去讀所有的offset來偵測PCI device, 並屆由vendor ID來判斷type.
From: ref2
Class code: 決定哪種device, ex: SCSI = 0x0100
BAR (Base Address Registers): 用來設定device可使用哪些PCI I/O and PCI memory
Interrupt Pin: 有四個pin可用來產生interrupt, ABCD.
Interrupt Line: 用來決定當interrupt發生時要執行那個interrupt handler.
六個Base address (32 bit each)用來定義PCI和其他系統溝通用的位址, 如果是64 bit, 那就要用兩個base addresses.
PCI I/O and PCI Memory address:
PCI device和driver溝通所使用的address space.
PCI-ISA bridge:
用來轉換PCI I/O and memory address to ISA I/O and memory address for legacy ISA devices.
PCI-PCI bridge:
Devices that glue PCI buses of the system together. PCI bus 可以支援的device數量有限, 所以利用PCI-PCI bridge來連接多個devices. 利用兩種cycles: Type 0 and type 1來設定PCI-PCI bridges.
"The PCI-PCI bridges must be programmed with a base and limit for PCI I/O and PCI Memory space access that they have to pass from their primary bus onto their secondary bus. Once the PCI-PCI Bridges in a system have been configured then so long as the Linux device drivers only access PCI I/O and PCI Memory space via these windows, the PCI-PCI Bridges are invisible." [ref1]
PCI-PCI bridge會被設定有一個memory map window, 讓device driver直接透過window去讀寫PCI I/O and memory space, 這樣讓系統感覺不到PCI-PCI bridge的存在.
PCI configuration cycle: A cycle is just an address as it appears on the PCI bus.
Type 0: fig 6.3
沒有bus number, interpret as PCI configuration address.
Type 1: fig 6.4
用來設定PCI-PCI bridge.
每個PCI-PCI bridge有三個值1) primary bus number: the upstream bus. 2) secondary bus number: the downstream bus. 3) subordinary bus number: the highest number of all buses that can be reached downstream of the bridge.
如果PCI-PCI bridge收到type 1 frame.
1. If bus number > subordinary number: ignore
2. If bus number == secondary number: 表示device在secondary bus上, convert to type 0
3. If subordinary > bus number > secondary: pass to the secondary interface.
Linux PCI Initialization:
Linux Kernel PCI data structure:
- each pci device is described by pci_dev struct
- the result is a tree topology from root to all leaf nodes
- pci_root points to pci_bus, pci_bus is PCI-PCI bridge as PCI bus can only be reached by PCI-PCI bridge.
Fig 6.5 from ref1:
- a function of the OS called at system initialization.
- the PCI init code scan all the PCI buses looking for PCI devices
- 利用PCI bios code去確認是否PCI slot上有裝置, if yes, setup the pci_dev.
- 每個pci bus存在struct pci_bus
PCI Device driver: pseudo-device driver searches the PCI system starting at BUS 0 and allocates all PCI devices and bridges. A PCI topology is built by a linked list of data structure. 接下來要做PCI-PCI bridge numbering, 用來偵測整個PCI topology和決定primary, secondary, and subordinary number for PCI-PCI bridge.
BIOS: 好像只是一些functions.
Fixup: system specific fixup code.
ref1: http://tldp.org/LDP/tlk/dd/pci.html
ref2: The professional linux kernel
ref3: Linux Device Driver, chapter 12
ref3: Linux Device Driver, chapter 12
沒有留言:
張貼留言