Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'remotes/lorenzo/pci/bridge-emul'

- Make emulated ROM BAR read-only by default (Pali Rohár)

- Make some emulated legacy PCI bits read-only for PCIe devices (Pali
Rohár)

- Update reserved bits in emulated PCIe Capability (Pali Rohár)

- Allow drivers to emulate different PCIe Capability versions (Pali Rohár)

- Set emulated Capabilities List bit for all PCIe devices, since they must
have at least a PCIe Capability (Pali Rohár)

* remotes/lorenzo/pci/bridge-emul:
PCI: pci-bridge-emul: Set PCI_STATUS_CAP_LIST for PCIe device
PCI: pci-bridge-emul: Correctly set PCIe capabilities
PCI: pci-bridge-emul: Fix definitions of reserved bits
PCI: pci-bridge-emul: Properly mark reserved PCIe bits in PCI config space
PCI: pci-bridge-emul: Make expansion ROM Base Address register read-only

+65 -17
+3 -1
drivers/pci/controller/pci-aardvark.c
··· 883 883 return PCI_BRIDGE_EMUL_HANDLED; 884 884 } 885 885 886 - case PCI_CAP_LIST_ID: 887 886 case PCI_EXP_DEVCAP: 888 887 case PCI_EXP_DEVCTL: 889 888 case PCI_EXP_DEVCAP2: ··· 969 970 970 971 /* Support interrupt A for MSI feature */ 971 972 bridge->conf.intpin = PCIE_CORE_INT_A_ASSERT_ENABLE; 973 + 974 + /* Aardvark HW provides PCIe Capability structure in version 2 */ 975 + bridge->pcie_conf.cap = cpu_to_le16(2); 972 976 973 977 /* Indicates supports for Completion Retry Status */ 974 978 bridge->pcie_conf.rootcap = cpu_to_le16(PCI_EXP_RTCAP_CRSVIS);
+8
drivers/pci/controller/pci-mvebu.c
··· 723 723 static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port) 724 724 { 725 725 struct pci_bridge_emul *bridge = &port->bridge; 726 + u32 pcie_cap = mvebu_readl(port, PCIE_CAP_PCIEXP); 727 + u8 pcie_cap_ver = ((pcie_cap >> 16) & PCI_EXP_FLAGS_VERS); 726 728 727 729 bridge->conf.vendor = PCI_VENDOR_ID_MARVELL; 728 730 bridge->conf.device = mvebu_readl(port, PCIE_DEV_ID_OFF) >> 16; ··· 736 734 bridge->conf.iobase = PCI_IO_RANGE_TYPE_32; 737 735 bridge->conf.iolimit = PCI_IO_RANGE_TYPE_32; 738 736 } 737 + 738 + /* 739 + * Older mvebu hardware provides PCIe Capability structure only in 740 + * version 1. New hardware provides it in version 2. 741 + */ 742 + bridge->pcie_conf.cap = cpu_to_le16(pcie_cap_ver); 739 743 740 744 bridge->has_pcie = true; 741 745 bridge->data = port;
+54 -16
drivers/pci/pci-bridge-emul.c
··· 139 139 .ro = GENMASK(7, 0), 140 140 }, 141 141 142 + /* 143 + * If expansion ROM is unsupported then ROM Base Address register must 144 + * be implemented as read-only register that return 0 when read, same 145 + * as for unused Base Address registers. 146 + */ 142 147 [PCI_ROM_ADDRESS1 / 4] = { 143 - .rw = GENMASK(31, 11) | BIT(0), 148 + .ro = ~0, 144 149 }, 145 150 146 151 /* ··· 176 171 [PCI_CAP_LIST_ID / 4] = { 177 172 /* 178 173 * Capability ID, Next Capability Pointer and 179 - * Capabilities register are all read-only. 174 + * bits [14:0] of Capabilities register are all read-only. 175 + * Bit 15 of Capabilities register is reserved. 180 176 */ 181 - .ro = ~0, 177 + .ro = GENMASK(30, 0), 182 178 }, 183 179 184 180 [PCI_EXP_DEVCAP / 4] = { 185 - .ro = ~0, 181 + /* 182 + * Bits [31:29] and [17:16] are reserved. 183 + * Bits [27:18] are reserved for non-upstream ports. 184 + * Bits 28 and [14:6] are reserved for non-endpoint devices. 185 + * Other bits are read-only. 186 + */ 187 + .ro = BIT(15) | GENMASK(5, 0), 186 188 }, 187 189 188 190 [PCI_EXP_DEVCTL / 4] = { 189 - /* Device control register is RW */ 190 - .rw = GENMASK(15, 0), 191 + /* 192 + * Device control register is RW, except bit 15 which is 193 + * reserved for non-endpoints or non-PCIe-to-PCI/X bridges. 194 + */ 195 + .rw = GENMASK(14, 0), 191 196 192 197 /* 193 198 * Device status register has bits 6 and [3:0] W1C, [5:4] RO, 194 - * the rest is reserved 199 + * the rest is reserved. Also bit 6 is reserved for non-upstream 200 + * ports. 195 201 */ 196 - .w1c = (BIT(6) | GENMASK(3, 0)) << 16, 202 + .w1c = GENMASK(3, 0) << 16, 197 203 .ro = GENMASK(5, 4) << 16, 198 204 }, 199 205 200 206 [PCI_EXP_LNKCAP / 4] = { 201 - /* All bits are RO, except bit 23 which is reserved */ 202 - .ro = lower_32_bits(~BIT(23)), 207 + /* 208 + * All bits are RO, except bit 23 which is reserved and 209 + * bit 18 which is reserved for non-upstream ports. 210 + */ 211 + .ro = lower_32_bits(~(BIT(23) | PCI_EXP_LNKCAP_CLKPM)), 203 212 }, 204 213 205 214 [PCI_EXP_LNKCTL / 4] = { 206 215 /* 207 216 * Link control has bits [15:14], [11:3] and [1:0] RW, the 208 - * rest is reserved. 217 + * rest is reserved. Bit 8 is reserved for non-upstream ports. 209 218 * 210 219 * Link status has bits [13:0] RO, and bits [15:14] 211 220 * W1C. 212 221 */ 213 - .rw = GENMASK(15, 14) | GENMASK(11, 3) | GENMASK(1, 0), 222 + .rw = GENMASK(15, 14) | GENMASK(11, 9) | GENMASK(7, 3) | GENMASK(1, 0), 214 223 .ro = GENMASK(13, 0) << 16, 215 224 .w1c = GENMASK(15, 14) << 16, 216 225 }, ··· 343 324 344 325 if (bridge->has_pcie) { 345 326 bridge->conf.capabilities_pointer = PCI_CAP_PCIE_START; 327 + bridge->conf.status |= cpu_to_le16(PCI_STATUS_CAP_LIST); 346 328 bridge->pcie_conf.cap_id = PCI_CAP_ID_EXP; 347 - /* Set PCIe v2, root port, slot support */ 348 - bridge->pcie_conf.cap = 349 - cpu_to_le16(PCI_EXP_TYPE_ROOT_PORT << 4 | 2 | 350 - PCI_EXP_FLAGS_SLOT); 329 + bridge->pcie_conf.cap |= cpu_to_le16(PCI_EXP_TYPE_ROOT_PORT << 4); 351 330 bridge->pcie_cap_regs_behavior = 352 331 kmemdup(pcie_cap_regs_behavior, 353 332 sizeof(pcie_cap_regs_behavior), ··· 354 337 kfree(bridge->pci_regs_behavior); 355 338 return -ENOMEM; 356 339 } 340 + /* These bits are applicable only for PCI and reserved on PCIe */ 341 + bridge->pci_regs_behavior[PCI_CACHE_LINE_SIZE / 4].ro &= 342 + ~GENMASK(15, 8); 343 + bridge->pci_regs_behavior[PCI_COMMAND / 4].ro &= 344 + ~((PCI_COMMAND_SPECIAL | PCI_COMMAND_INVALIDATE | 345 + PCI_COMMAND_VGA_PALETTE | PCI_COMMAND_WAIT | 346 + PCI_COMMAND_FAST_BACK) | 347 + (PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK | 348 + PCI_STATUS_DEVSEL_MASK) << 16); 349 + bridge->pci_regs_behavior[PCI_PRIMARY_BUS / 4].ro &= 350 + ~GENMASK(31, 24); 351 + bridge->pci_regs_behavior[PCI_IO_BASE / 4].ro &= 352 + ~((PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK | 353 + PCI_STATUS_DEVSEL_MASK) << 16); 354 + bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].rw &= 355 + ~((PCI_BRIDGE_CTL_MASTER_ABORT | 356 + BIT(8) | BIT(9) | BIT(11)) << 16); 357 + bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].ro &= 358 + ~((PCI_BRIDGE_CTL_FAST_BACK) << 16); 359 + bridge->pci_regs_behavior[PCI_INTERRUPT_LINE / 4].w1c &= 360 + ~(BIT(10) << 16); 357 361 } 358 362 359 363 if (flags & PCI_BRIDGE_EMUL_NO_PREFETCHABLE_BAR) {