Bridge Window trong PCIe là gì?
Giải thích Bridge Window trong PCIe: memory window, prefetchable window, I/O window, bus number, BAR forwarding và debug endpoint sau bridge mất.
Bạn thấy endpoint phía sau một PCIe Root Port. BAR của endpoint đã được assign, ví dụ BAR0 = 0x90000000. Command Register của endpoint cũng bật Memory Space Enable. Nhưng driver đọc MMIO vẫn ra 0xFFFFFFFF. Khi dump bridge/root port config, bạn phát hiện Memory Base/Limit của bridge không bao phủ 0x90000000. Đây là lỗi Bridge Window.
Nói ngắn gọn: Bridge Window là dải I/O hoặc MMIO mà PCI-to-PCI bridge/root port forward từ bus phía trên xuống bus phía dưới. Endpoint BAR phía sau bridge chỉ access được nếu address của BAR nằm trong bridge window của mọi bridge trên đường đi.
Bridge Window nằm ở đâu?
Bridge Window trong PCIe topology
CPU / Root Complex
└─ Root Bridge MMIO aperture
└─ Root Port / PCI-to-PCI Bridge
├─ Primary Bus = 00
├─ Secondary Bus = 02
├─ Subordinate Bus = 05
├─ Memory Window
│ └─ Non-prefetchable BARs phía dưới
├─ Prefetchable Memory Window
│ └─ Prefetchable / large BARs phía dưới
├─ I/O Window
│ └─ Legacy I/O BARs phía dưới
└─ Downstream endpoints
├─ 02:00.0 BAR0
└─ 03:00.0 BAR0 Bridge window là “cổng địa chỉ” của bridge. CPU access vào một địa chỉ MMIO chỉ được forward xuống bus dưới nếu địa chỉ đó nằm trong window phù hợp.
Bridge Window trong access flow
CPU reads MMIO address
Driver access BAR register address.
Root bridge aperture match
Address nằm trong PCIe MMIO resource của root bridge.
Bridge window match
Root port hoặc PCI bridge kiểm tra Memory/Prefetch/I/O window.
Forward downstream
Transaction được forward xuống secondary bus.
Endpoint BAR decodes
Endpoint nhận transaction nếu address thuộc BAR.
Device register returns data
Driver nhận register value.
Các loại Bridge Window
| Window | Dùng cho | Bug nếu sai |
|---|---|---|
| I/O Window | I/O BAR legacy phía sau bridge | I/O access fail |
| Memory Window | Non-prefetchable MMIO BARs | MMIO register access fail |
| Prefetchable Memory Window | Prefetchable MMIO BARs | Large BAR/framebuffer fail |
| 32-bit Window | Resource below 4G | Không chứa BAR above 4G |
| 64-bit Prefetchable Window | Large/64-bit prefetchable BAR | GPU/accelerator BAR fail |
| Bus Window | Secondary/Subordinate bus range | Không scan được downstream device |
| Root Bridge Aperture | Nguồn resource tổng thể | Bridge window không thể cấp ngoài aperture |
| Window Chain | Tất cả bridges upstream | Một bridge sai là toàn path fail |
Bridge Header Type 1
PCI-to-PCI bridge thường dùng Header Type 1. Các register base/limit trong header này mô tả bus number và resource windows.
| Field | Ý nghĩa | Debug khi lỗi |
|---|---|---|
| Primary Bus Number | Bus phía trên bridge | Hierarchy sai nếu không đúng |
| Secondary Bus Number | Bus đầu tiên phía dưới bridge | Endpoint không có BDF |
| Subordinate Bus Number | Bus cuối cùng phía dưới bridge | Switch sâu/hotplug mất |
| I/O Base/Limit | I/O window | I/O BAR không forward |
| Memory Base/Limit | Non-prefetchable MMIO window | Control BAR access fail |
| Prefetchable Base/Limit | Prefetchable MMIO window | Large/prefetch BAR fail |
| Prefetchable Base/Limit Upper 32 bits | 64-bit prefetch window high address | Above 4G window sai |
| Bridge Control | Bridge behavior/reset/error control | Decode/reset/error policy issue |
| Command Register | Bridge decode enables | Window đúng nhưng bridge không forward |
| Secondary Status | Status phía downstream | Error/debug bus phía dưới |
Bus Number cũng là một loại window
Bridge không chỉ forward address. Nó còn định nghĩa bus number range phía dưới: Primary, Secondary, Subordinate.
Bus number window
Bridge 00:1C.0
├─ Primary Bus = 00
├─ Secondary Bus = 02
├─ Subordinate Bus = 05
└─ Downstream bus range = 02-05
├─ Bus 02: endpoint
├─ Bus 03: switch
├─ Bus 04: endpoint
└─ Bus 05: endpoint | Field | Vai trò | Bug nếu sai |
|---|---|---|
| Primary | Bus phía upstream | Bridge hierarchy/log khó hiểu |
| Secondary | Bus đầu tiên downstream | Không scan được bus dưới |
| Subordinate | Bus cuối downstream | Switch sâu bị mất |
| Temporary bus | Firmware set tạm khi scan | Log giữa phase dễ gây nhầm |
| Final bus | Bus sau enumeration | OS/driver thấy BDF cuối |
| Hotplug reserve | Bus để dành cho thiết bị hotplug | Hotplug fail nếu thiếu |
| Root bridge range | Giới hạn tổng bus | Bridge subordinate không thể vượt range |
| ACPI MCFG/_CRS | OS biết bus range | OS thấy khác UEFI nếu sai |
Bridge Window và BAR
Endpoint BAR phải được cấp trong đúng loại window của bridge.
| BAR type | Bridge window cần dùng | Nếu đặt sai |
|---|---|---|
| I/O BAR | I/O Window | I/O transaction không forward |
| Memory BAR non-prefetchable | Memory Window | MMIO register fail |
| Memory BAR prefetchable | Prefetchable Memory Window nếu allocator chọn vậy | Prefetch BAR fail |
| 32-bit Memory BAR | Window below 4G phù hợp | Above 4G invalid nếu BAR không 64-bit |
| 64-bit Memory BAR | Có thể dùng 64-bit aperture/window | Truncate hoặc không forward |
| Large BAR | Thường cần 64-bit/prefetch window lớn | EFI_OUT_OF_RESOURCES |
| Resizable BAR | Window phải resize theo selected BAR size | BAR size/window mismatch |
| BAR sau nhiều bridges | Mọi bridge upstream phải chứa range | Một tầng sai là fail |
Bridge Window allocation
PCI Bus Driver thường gom resource request của tất cả endpoint phía dưới bridge, rồi cấp window đủ lớn cho bridge.
Scan downstream devices
PCI Bus Driver phát hiện endpoint và bridge phía dưới.
Probe downstream BARs
Tính I/O, MMIO, prefetch resource cần.
Aggregate requirements
Cộng resource theo subtree phía sau bridge.
Apply window alignment
Round theo granularity của bridge windows.
Allocate upstream resource
Xin range từ root bridge hoặc bridge phía trên.
Program bridge base/limit
Ghi Memory/Prefetch/I/O Base và Limit.
Program endpoint BARs
Đặt BAR bên trong window đã cấp.
Window granularity và alignment
Bridge window registers thường encode base/limit theo granularity nhất định, không phải byte-level tùy ý.
| Window | Đặc điểm | Debug |
|---|---|---|
| I/O Window | Granularity riêng, có upper bits với 32-bit I/O | Legacy I/O issue |
| Memory Window | Thường encode theo 1MB granularity | Base/limit bị round |
| Prefetchable Window | Có thể 32-bit hoặc 64-bit | High 32-bit cần đúng |
| Alignment | Base phải aligned theo window granularity | Range nhỏ có thể bị làm tròn lớn |
| Limit | Limit thường inclusive theo encoding | Off-by-one range bug |
| Disabled window | Base > Limit hoặc zero policy | Window không forward |
| Nested bridge | Window của bridge cha phải chứa bridge con | Path fail ở tầng cha |
| Resource waste | Round up làm tốn aperture | Out of resources dù BAR nhỏ |
Bridge Window và Prefetchable Memory
Prefetchable memory window thường dùng cho BAR có prefetchable bit, ví dụ framebuffer hoặc large memory region. Control registers thường non-prefetchable.
| Khía cạnh | Ý nghĩa | Bug nếu sai |
|---|---|---|
| Prefetchable BAR | BAR cho phép prefetch/cache policy đặc biệt | Cần window phù hợp |
| Non-prefetchable BAR | Control register MMIO | Không nên đưa vào prefetch window bừa |
| 64-bit support | Prefetch window có high 32-bit registers | Above 4G window sai nếu high bits sai |
| Large BAR | Thường cần prefetchable 64-bit window | GPU/accelerator fail |
| Cache policy | OS/firmware mapping phải đúng | Ordering/data issue |
| Bridge chain | Mọi bridge upstream cần prefetch window chứa range | Access fail |
| Resource split | Prefetch và non-prefetch tách riêng | Allocator thiếu một loại resource |
| Debug | Dump BAR bit 3 và bridge prefetch window | Biết BAR thuộc window nào |
Bridge Window và Command Register
Bridge cũng có Command Register. Nếu decode không bật, window có thể được program nhưng transaction không forward.
| Bit | Ý nghĩa | Bug nếu thiếu |
|---|---|---|
| I/O Space Enable | Bridge forward I/O transactions | I/O BAR phía sau fail |
| Memory Space Enable | Bridge forward memory transactions | MMIO BAR phía sau fail |
| Bus Master Enable | Bridge/bus mastering behavior tùy device | DMA/bridge behavior issue |
| SERR Enable | System error reporting | Error không báo |
| Parity Error Response | Error handling | Parity/status issue |
| Bridge Control | Reset/error/forwarding controls | Secondary bus reset hoặc error policy |
| Read-modify-write | Preserve bits khi enable | Ghi hardcode clear nhầm |
| Endpoint command | Endpoint cũng cần enable | Bridge đúng nhưng endpoint không decode |
Debug Diary: BAR có base nhưng MMIO vẫn fail
Triệu chứng:
Endpoint BAR0 = 0x90000000
Memory Space Enable bật
MMIO read -> 0xFFFFFFFF
Bridge Memory Window = 0x80000000-0x8FFFFFFF
Checklist BAR ngoài bridge window
Debug Diary: Endpoint sau bridge không xuất hiện
Triệu chứng:
Root Port thấy ở 00:1C.0
Endpoint phía sau không có BDF/PciIo
Checklist endpoint sau bridge mất
Debug Diary: Large BAR phía sau bridge fail
Triệu chứng:
GPU/accelerator sau root port có large BAR
Resource allocation fail hoặc BAR = 0
Checklist large BAR bridge window fail
Debug Diary: UEFI OK nhưng OS fail
Triệu chứng:
UEFI driver access MMIO OK
OS driver load lên thì device fail
Checklist bridge window UEFI/OS mismatch
Anti-pattern khi debug Bridge Window
| Anti-pattern | Vì sao sai | Cách sửa |
|---|---|---|
| Chỉ kiểm tra endpoint BAR | Bridge có thể không forward | Trace mọi bridge upstream |
| Bỏ qua prefetchable window | Large/prefetch BAR fail | Check BAR bit 3 và prefetch window |
| Không check high 32-bit | Above 4G window sai | Dump 64-bit window đầy đủ |
| Không check bus numbers | Endpoint không scan được | Dump Primary/Secondary/Subordinate |
| Ghi window hardcode | Overlap/resource conflict | Dùng allocator |
| Không check Command Register | Window có nhưng decode tắt | Enable Memory/I/O đúng |
| Không so ACPI/OS | OS reassign hoặc không biết resource | Compare UEFI vs OS dump |
| Parse Type 1 như Type 0 | Đọc sai registers | Check Header Type |
Instrumentation nên có
| Vị trí | Nên log | Mục tiêu |
|---|---|---|
| Bridge discovery | BDF + class + header type | Biết đúng bridge |
| Bus numbers | Primary/Secondary/Subordinate | Debug downstream visibility |
| I/O window | Base/limit | Debug I/O BAR |
| Memory window | Base/limit | Debug non-prefetch MMIO |
| Prefetch window | Low/high base/limit | Debug large/64-bit BAR |
| Endpoint BAR | BAR base/length/type | Check nằm trong window |
| Command Register | Bridge and endpoint command bits | Decode enable |
| Resource allocator | Window request/assigned/status | Allocation fail |
| ACPI/OS compare | UEFI vs OS bridge config | Handoff debug |
| Good/bad diff | Bridge config diff | Regression |
Bridge Window debug playbook
Bridge Window debug playbook
Security checklist
Security checklist cho Bridge Window
Khi đọc bridge log nên tìm gì?
| Cần hiểu | Tìm trong log | Câu hỏi |
|---|---|---|
| Bridge identity | BDF + class/header | Đúng PCI-to-PCI bridge không? |
| Bus range | Primary/Secondary/Subordinate | Downstream bus hợp lệ không? |
| Endpoint BAR | Base/length/type | BAR cần window nào? |
| Memory window | Base/limit | Non-prefetch BAR nằm trong không? |
| Prefetch window | Base/limit/high bits | Prefetch/64-bit BAR nằm trong không? |
| I/O window | Base/limit | I/O BAR nằm trong không? |
| Command bits | Memory/I/O enable | Bridge có forward không? |
| Root aperture | Root resource range | Bridge window nằm trong root không? |
| Allocator status | Window request/assigned | Fail vì thiếu gì? |
| OS compare | OS bridge config | Có bị reassign/mismatch không? |
Câu hỏi tự kiểm tra
Tự kiểm tra sau khi đọc note này
Blog seeds
- Bridge Window trong PCIe là gì?
- Vì sao BAR đúng nhưng MMIO vẫn fail?
- Memory Window và Prefetchable Window trong PCI bridge
- Primary Secondary Subordinate Bus trong PCIe bridge
- Debug endpoint sau PCIe switch không xuất hiện
Bài liên quan
- PCI/PCIe Architecture Overview
- PCI Resource Allocation là gì?
- BAR trong PCIe là gì?
- MMIO là gì?
- PCI Bus Driver là gì?
- PCI Root Bridge là gì?
- PCI Configuration Space là gì?
- PCI I/O Protocol là gì?
- BDF trong PCIe là gì?
- EFI Out of Resources
Nguồn tham khảo public
- PCI-SIG Specifications
- UEFI Specification
- UEFI Platform Initialization Specification
- ACPI Specification
- Tianocore EDK II
- EDK II Driver Writer’s Guide
Bài viết này hữu ích với bạn?
Bạn có thể chia sẻ cho người đang học firmware, BIOS/UEFI, embedded systems hoặc ủng hộ tác giả.
Nội dung liên quan
Một số bài viết, ghi chú hoặc project có liên quan đến nội dung bạn vừa đọc.
PCI Resource Allocation là gì?
Giải thích PCI Resource Allocation trong UEFI: BAR sizing, MMIO/I/O aperture, bridge windows, Above 4G, allocation fail và debug BAR bằng 0.
BAR trong PCIe là gì?
Giải thích BAR trong PCIe: Base Address Register, MMIO/I/O BAR, 32-bit/64-bit BAR, prefetchable, sizing, resource allocation và debug MMIO fail.
MMIO là gì?
Giải thích MMIO trong PCIe/firmware: memory-mapped I/O, BAR mapping, cache attribute, ordering, bridge window và debug register read fail.
Biến note thành bài viết hoàn chỉnh
Notes là nơi ghi nhanh khái niệm.