PCI Express

From OSDev.wiki
Revision as of 21:37, 9 April 2010 by osdev>54616e6e6572 (Added "In Progress" notice, adjusted the page description, added layout for what needs to/will be added.)
Jump to navigation Jump to search

The PCI Express bus is a high performance, general purpose I/O interconnect bus, and was designed for a range of computing platforms. One of the key improvements of PCI Express, over the PCI Local Bus, is that it now uses a serial interface (compared to the parallel interface used by PCI). This improvement can be compared to the similiar serialization of the ATA interface.

This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.

PCI Express Link

The PCI Express bus connects each device directly to the CPU and other system devices through a pair of high speed unidirectional differential links (transmit and recieve, respectively). These links operate at an effective rate of 2.5 GB/s and a single device may have multiple links. A single device may have x1, x2, x4, x8, x12, x16, or x32 links and can achieve a maximum bandwidth of 80 GB/s by utilizing x32 links.

Initialization

Extended Configuration Space

The PCI Express bus extends the Configuration Space from 256 bytes to 4096 bytes. This extended configuration space *cannot* be accessed using the legacy PCI method (through ports 0xCF8 and 0xCFC). Instead, an enhanced configuration mechanism is provided.

Enhanced Configuration Mechanism

The enhanced configuration mechanism makes use of a flat memory-mapped address space to access it's device configuration registers. Put simply, the memory address is used to determine the register accessed. On the x86 and x64 platforms, the memory range's base address can be determined by reading Model Specific Register 0xC0010058 and masking all but bits 31:20 or bits 47:20, respectively. Note that if all but bits 5:2 are masked you can determine the number of busses in the MMIO configuration space. After determining the MMIO base address and the total number of busses in the address space, you can read from the extended configuration address space. To access a specific register, you must use the following formula: Address = MMIO_BASE + { bus number[28:20], device number[19:15], function number[14:12], extended register number[11:8], register number[7:2], offset [1:0] }.

getPCIBusRange:
    mov ecx, 0xC0010058    ; Set ECX to the register we need to read
    rdmsr                  ; Read the MMIO Configuratio Base Address Register
    and al, 0x3C           ; Mask everything but the bus range (bits 5:2)
    shr al, 2              ; Adjust to the proper value
    mov ah, 1              ; set AH to 1
    shl ah, al             ; AH <<= AL
    movzx eax, ah          ; Save the number of buses into EAX
    ret                    ; Return to the calling code

getMMIOBase:
    mov ecx, 0xC0010058    ; Set ECX to the register we need to read
    rdmsr                  ; Read the MMIO Configuratio Base Address Register
    xor ax, ax             ; Mask everythin but the base address (bits 47:20)
    ret                    ; Return to the calling code

readECS_BYTE:
    mov al, [esi]          ; Read byte from MMIO Address [ESI] into AL
    ret                    ; Return to the calling code

readECS_WORD:
    mov ax, [esi]          ; Read word from MMIO Address [ESI] into AX
    ret                    ; Return to the calling code

readECS_DWORD:
    mov eax, [esi]         ; Read dword from MMIO Address [ESI] into EAX
    ret                    ; Return to the calling code

writeECS_BYTE:
    mov [esi], al          ; Write byte from AL into MMIO Address [ESI]
    ret                    ; Return to the calling code

writeECS_WORD:
    mov [esi], ax          ; Write word from AX into MMIO Address [ESI]
    ret                    ; Return to the calling code

writeECS_DWORD:
    mov [esi], eax         ; Write dword from EAX into MMIO Address [ESI]
    ret                    ; Return to the calling code

System Architecture

Transaction Layer

Data Link Layer

Physical Layer

Power Management

See Also

References

  • PCI Express Base Specification, revision 1.1, PCI Special Interest Group, March 28, 2005

External Links