Files
RedBear-OS/local/recipes/system/redbear-quirks/source/quirks.d/06-pci-header-quirks.toml
T
vasilito 86902d4819 quirks: implement R0-R5 — data-driven PCI/USB/DMI bitmask system
Foundational data-driven hardware-quirk system with all entries through
Phase R5. Source of truth: Linux 7.1 DECLARE_PCI_FIXUP_* and PCI_DEV_FLAGS_*
conventions. Targets AMD64 bare metal, QEMU, and modern peripherals.

Code (redox-driver-sys/src/quirks/):
- PciQuirkFlags: 46 bits used (0-45), 18 reserved
- UsbQuirkFlags + XhciControllerQuirkFlags tables
- PciConfigWriter trait + QuirkAction enum (7 variants)
- 14 named callbacks (intel_no_aspm_l0s, amd_ide_class_fix,
  ht_enable_msi_mapping, p64h2_1k_io, intel_ntb_bar_fix, 7 DMA-alias
  callbacks, amd_fe_gate_ordering, amd_8131_mmrbc)
- lookup_pci_quirks_full, lookup_pci_quirks, lookup_usb_quirks,
  lookup_xhci_controller_quirks, lookup_dmi_rules
- find_standard_capability for PCI cap walks
- TOML loader with [[pci_quirk]] / [[usb_quirk]] / [[dmi_rule]] sections
- 75 tests pass (mod.rs + toml_loader + dmi + others)

Phase R5 adds (2026-06-07):
- 10 new flag bits (36-45): BROKEN_INTX_MASKING, NO_PME, PCI_PROBLEM_*,
  PCI_AGP_FAIL, BUS_NO_MMRBC
- 2 new callbacks: cb_amd_fe_gate_ordering (AMD-762 two-register write),
  cb_amd_8131_mmrbc (rev-gated < 0x12, sets BUS_NO_MMRBC)
- Inline ClearBit/SetBit actions for Mellanox, Cyrix, Intel, VIA
- 18 new Phase R5 tests (10 mod.rs + 8 toml_loader)

TOML (10 files, 244 entries in 07-pci-final-quirks.toml total):
  00-core.toml                  (41)
  05-pcie-quirks.toml           (52)
  06-pci-header-quirks.toml     (37)
  07-pci-final-quirks.toml      (64)  — R5 DECLARE_PCI_FIXUP_FINAL
  10-gpu.toml                   (33)
  15-audio.toml                  (7)

Verified: 38 distinct flag names used, 46 defined, 0 undefined references.

Docs: local/docs/QUIRKS-SYSTEM.md — R0-R5 implementation reports (2424 lines)
2026-06-07 09:18:40 +03:00

349 lines
11 KiB
TOML

# Phase R3 (2026-06-07) — PCI Header Fixup entries mined from Linux 7.1
# Source: Linux 7.1 drivers/pci/quirks.c, DECLARE_PCI_FIXUP_HEADER() macros
#
# Flag bit map (see PciQuirkFlags in redox-driver-sys):
# bit 32: DMA_ALT
# bit 33: NO_PM_RESET
# bit 34: IO_1K
# bit 35: NTB_BAR_FIX
#
# This file targets the 25-30 most AMD64-relevant HEADER fixup entries
# out of 255 in Linux 7.1. Skipped entries are listed at the bottom
# of the doc/QUIRKS-SYSTEM.md Phase R3 implementation report.
#
# Phase R4 (2026-06-07) — added `action` field to entries whose Linux
# fixup needs imperative config-space writes. Entries that are pure
# flag-markers (NO_PM_RESET) remain action-less.
# ============================================================================
# WRONG_CLASS — forces IDE → AHCI class code change at header enumeration
# Linux: quirk_amd_ide_mode (drivers/pci/quirks.c)
# Reason: AMD Hudson-2 and ATI IXP600/700 SATA controllers report IDE
# class (0x0101) when wired in IDE compatibility mode, which causes
# the wrong driver to bind. The fixup rewrites the class code to
# 0x0106 (SATA) so AHCI driver attaches.
# Flag: WRONG_CLASS (bit 19, from R0) — signal that class has been
# rewritten and downstream drivers should re-read.
# ============================================================================
# ATI IXP600 SATA IDE controller
[[pci_quirk]]
vendor = 0x1002
device = 0x4380
flags = ["wrong_class"]
action = { kind = "callback", name = "amd_ide_class_fix" }
# ATI IXP700 SATA IDE controller
[[pci_quirk]]
vendor = 0x1002
device = 0x4390
flags = ["wrong_class"]
action = { kind = "callback", name = "amd_ide_class_fix" }
# AMD Hudson-2 SATA IDE
[[pci_quirk]]
vendor = 0x1022
device = 0x7800
flags = ["wrong_class"]
action = { kind = "callback", name = "amd_ide_class_fix" }
# AMD 0x7900 (pre-Hudson FCH) SATA IDE
[[pci_quirk]]
vendor = 0x1022
device = 0x7900
flags = ["wrong_class"]
action = { kind = "callback", name = "amd_ide_class_fix" }
# ============================================================================
# NO_ASPM — disable ASPM L0s on Intel ICH9/10/X58 PCIe endpoints
# Linux: quirk_disable_aspm_l0s (drivers/pci/quirks.c)
# Reason: certain Intel PCIe devices report ASPM L0s support in the
# Link Capabilities register but actually corrupt TLP data when L0s
# is enabled. The fixup clears PCI_EXP_LNKCTL_ASPM_L0S (bit 0) of
# the Link Control register before driver probe.
# Common on Core i5/i7 era boards and X58 workstations.
# Flag: NO_ASPM (bit 5, from R0).
# ============================================================================
[[pci_quirk]]
vendor = 0x8086
device = 0x10A7
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10A9
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10B6
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10C6
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10C7
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10C8
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10D6
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10DB
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10DD
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10E1
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10EC
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10F1
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x10F4
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
[[pci_quirk]]
vendor = 0x8086
device = 0x1508
flags = ["no_aspm"]
action = { kind = "callback", name = "intel_no_aspm_l0s" }
# ============================================================================
# DMA_ALT — DMA aliasing for bridges and devices that misreport requester ID
# Linux: quirk_use_pcie_bridge_dma_alias (drivers/pci/quirks.c)
# Reason: certain PCIe-to-PCI bridges (Asmedia, Tundra, ITE, Intel 82801)
# forward downstream requester IDs incorrectly during DMA, breaking
# IOMMU group assignment and causing DMA faults.
# Flag: DMA_ALT (bit 32, Phase R3).
# ============================================================================
# Asmedia ASM1083/1085 PCIe-PCI bridge — 0x1080
[[pci_quirk]]
vendor = 0x1B21
device = 0x1080
flags = ["dma_alt", "no_aspm"]
action = { kind = "callback", name = "asmedia_func0_dma_alias" }
# Tundra Semiconductor Tsi384 PCI-X-to-PCI-X bridge — 0x8113
# Used on some server platforms.
[[pci_quirk]]
vendor = 0x10E3
device = 0x8113
flags = ["dma_alt"]
action = { kind = "callback", name = "tundra_func0_dma_alias" }
# ITE IT8892 PCIe-PCI bridge
# https://bugzilla.kernel.org/show_bug.cgi?id=73551
[[pci_quirk]]
vendor = 0x1283
device = 0x8892
flags = ["dma_alt"]
action = { kind = "callback", name = "ite_func0_dma_alias" }
# ITE IT8893 — same problem as IT8892
[[pci_quirk]]
vendor = 0x1283
device = 0x8893
flags = ["dma_alt"]
action = { kind = "callback", name = "ite_func0_dma_alias" }
# Intel 82801 ICH8/9/10 PCIe root port — 0x244e
# https://bugzilla.kernel.org/show_bug.cgi?id=44881#c49
[[pci_quirk]]
vendor = 0x8086
device = 0x244E
flags = ["dma_alt"]
action = { kind = "callback", name = "intel_bridge_dma_alias" }
# ============================================================================
# DMA_ALT — function-0 DMA alias
# Linux: quirk_dma_func0_alias (drivers/pci/quirks.c)
# Reason: certain multi-function devices (Ricoh card readers, Glenfly
# GPUs) report their requester ID as function 0 regardless of which
# function initiated the DMA. This breaks device isolation in IOMMU
# groups. The fixup registers a function-0 alias.
# ============================================================================
# Ricoh R5C832 card reader
[[pci_quirk]]
vendor = 0x1180
device = 0xE832
flags = ["dma_alt"]
action = { kind = "callback", name = "ricoh_func0_dma_alias" }
# Ricoh R5C476 card reader
[[pci_quirk]]
vendor = 0x1180
device = 0xE476
flags = ["dma_alt"]
action = { kind = "callback", name = "ricoh_func0_dma_alias" }
# Glenfly GFX display adapter — function 0
[[pci_quirk]]
vendor = 0x6766
device = 0x3D40
flags = ["dma_alt"]
action = { kind = "callback", name = "glenfly_func0_dma_alias" }
# Glenfly GFX display adapter — function 1
[[pci_quirk]]
vendor = 0x6766
device = 0x3D41
flags = ["dma_alt"]
action = { kind = "callback", name = "glenfly_func0_dma_alias" }
# ============================================================================
# DMA_ALT — fixed DMA alias
# Linux: quirk_fixed_dma_alias (drivers/pci/quirks.c)
# Reason: Adaptec Series 2 RAID/HBA does not implement the standard
# function-level DMA aliasing. A fixed alias is registered based on
# a static lookup table.
# ============================================================================
# Adaptec Series 2 (0x9005/0x0285)
[[pci_quirk]]
vendor = 0x9005
device = 0x0285
flags = ["dma_alt"]
action = { kind = "callback", name = "adaptec2_func0_dma_alias" }
# ============================================================================
# NO_PM_RESET — Mellanox adapters that hang on PM reset
# Linux: quirk_no_pm_reset (drivers/pci/quirks.c)
# Reason: Mellanox ConnectX-3 and ConnectX-4 adapters report PCI PM
# reset capability but actually hang when PM reset is asserted.
# The fixup clears the PM reset capability bit.
# Flag: NO_PM_RESET (bit 33, Phase R3).
# ============================================================================
# Mellanox ConnectX-3 (0xcb84)
[[pci_quirk]]
vendor = 0x15B3
device = 0xCB84
flags = ["no_pm_reset"]
# Mellanox ConnectX-3 Pro (0xcf6c)
[[pci_quirk]]
vendor = 0x15B3
device = 0xCF6C
flags = ["no_pm_reset"]
# Mellanox ConnectX-4 (0xcf70)
[[pci_quirk]]
vendor = 0x15B3
device = 0xCF70
flags = ["no_pm_reset"]
# Mellanox ConnectX-4 Lx (0xcf80)
[[pci_quirk]]
vendor = 0x15B3
device = 0xCF80
flags = ["no_pm_reset"]
# ============================================================================
# MSI mapping enable on HyperTransport bridges
# Linux: ht_enable_msi_mapping (drivers/pci/quirks.c)
# Reason: ServerWorks HT1000 PXB and AMD 8132 bridges do not enable
# MSI mapping in their PCI config space by default, which blocks
# downstream devices from using MSI/MSI-X.
# The fixup forces the HT MSI mapping capability bit on.
# Flag: NO_MSI (bit 0) is the inverse — used to signal that MSI is
# not yet usable until the HT mapping fixup completes.
# ============================================================================
# ServerWorks HT1000 PCI-X Bridge
[[pci_quirk]]
vendor = 0x1166
device = 0x0036
flags = ["no_msi"]
action = { kind = "callback", name = "ht_enable_msi_mapping" }
# AMD 8132 PCI-X Bridge
[[pci_quirk]]
vendor = 0x1022
device = 0x7458
flags = ["no_msi"]
action = { kind = "callback", name = "ht_enable_msi_mapping" }
# ============================================================================
# IO_1K — Intel P64H2 1K I/O granularity enable
# Linux: quirk_p64h2_1k_io (drivers/pci/quirks.c)
# Reason: Intel P64H2 is a server-class PCIe switch that requires
# I/O space allocated at 1 KB granularity (not the 4 KB default)
# for downstream devices. The fixup sets the 1K bit.
# Flag: IO_1K (bit 34, Phase R3).
# ============================================================================
# Intel P64H2 PCI Express-to-PCI/PCI-X Bridge
[[pci_quirk]]
vendor = 0x8086
device = 0x1460
flags = ["io_1k"]
action = { kind = "callback", name = "p64h2_1k_io" }
# ============================================================================
# NTB_BAR_FIX — Intel Ivytown NTB BAR size misreport fix
# Linux: quirk_intel_ntb (drivers/pci/quirks.c)
# Reason: Intel Sandy Bridge Xeon NTB (Non-Transparent Bridge) hardware
# reports incorrect BAR sizes in the NTB config space. The fixup
# forces a PCI_COMMAND_MEMORY toggle so the driver re-evaluates with
# corrected sizes.
# Flag: NTB_BAR_FIX (bit 35, Phase R3).
# Action: intel_ntb_bar_fix (Phase R4) — imperative callback.
# ============================================================================
# Intel Xeon E5 NTB primary — 0x0e08
[[pci_quirk]]
vendor = 0x8086
device = 0x0E08
flags = ["ntb_bar_fix"]
action = { kind = "callback", name = "intel_ntb_bar_fix" }
# Intel Xeon E5 NTB secondary — 0x0e0d
[[pci_quirk]]
vendor = 0x8086
device = 0x0E0D
flags = ["ntb_bar_fix"]
action = { kind = "callback", name = "intel_ntb_bar_fix" }