Skip to content

Commit 1299808

Browse files
paliLorenzo Pieralisi
authored andcommitted
PCI: pci-bridge-emul: Fix definitions of reserved bits
Some bits in PCI_EXP registers are reserved for non-root ports. Driver pci-bridge-emul.c implements PCIe Root Port device therefore it should not allow setting reserved bits of registers. Properly define non-reserved bits for all PCI_EXP registers. Link: https://lore.kernel.org/r/[email protected] Fixes: 23a5fba ("PCI: Introduce PCI bridge emulated config space common logic") Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Cc: [email protected]
1 parent 7b067ac commit 1299808

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

drivers/pci/pci-bridge-emul.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,41 +176,55 @@ struct pci_bridge_reg_behavior pcie_cap_regs_behavior[PCI_CAP_PCIE_SIZEOF / 4] =
176176
[PCI_CAP_LIST_ID / 4] = {
177177
/*
178178
* Capability ID, Next Capability Pointer and
179-
* Capabilities register are all read-only.
179+
* bits [14:0] of Capabilities register are all read-only.
180+
* Bit 15 of Capabilities register is reserved.
180181
*/
181-
.ro = ~0,
182+
.ro = GENMASK(30, 0),
182183
},
183184

184185
[PCI_EXP_DEVCAP / 4] = {
185-
.ro = ~0,
186+
/*
187+
* Bits [31:29] and [17:16] are reserved.
188+
* Bits [27:18] are reserved for non-upstream ports.
189+
* Bits 28 and [14:6] are reserved for non-endpoint devices.
190+
* Other bits are read-only.
191+
*/
192+
.ro = BIT(15) | GENMASK(5, 0),
186193
},
187194

188195
[PCI_EXP_DEVCTL / 4] = {
189-
/* Device control register is RW */
190-
.rw = GENMASK(15, 0),
196+
/*
197+
* Device control register is RW, except bit 15 which is
198+
* reserved for non-endpoints or non-PCIe-to-PCI/X bridges.
199+
*/
200+
.rw = GENMASK(14, 0),
191201

192202
/*
193203
* Device status register has bits 6 and [3:0] W1C, [5:4] RO,
194-
* the rest is reserved
204+
* the rest is reserved. Also bit 6 is reserved for non-upstream
205+
* ports.
195206
*/
196-
.w1c = (BIT(6) | GENMASK(3, 0)) << 16,
207+
.w1c = GENMASK(3, 0) << 16,
197208
.ro = GENMASK(5, 4) << 16,
198209
},
199210

200211
[PCI_EXP_LNKCAP / 4] = {
201-
/* All bits are RO, except bit 23 which is reserved */
202-
.ro = lower_32_bits(~BIT(23)),
212+
/*
213+
* All bits are RO, except bit 23 which is reserved and
214+
* bit 18 which is reserved for non-upstream ports.
215+
*/
216+
.ro = lower_32_bits(~(BIT(23) | PCI_EXP_LNKCAP_CLKPM)),
203217
},
204218

205219
[PCI_EXP_LNKCTL / 4] = {
206220
/*
207221
* Link control has bits [15:14], [11:3] and [1:0] RW, the
208-
* rest is reserved.
222+
* rest is reserved. Bit 8 is reserved for non-upstream ports.
209223
*
210224
* Link status has bits [13:0] RO, and bits [15:14]
211225
* W1C.
212226
*/
213-
.rw = GENMASK(15, 14) | GENMASK(11, 3) | GENMASK(1, 0),
227+
.rw = GENMASK(15, 14) | GENMASK(11, 9) | GENMASK(7, 3) | GENMASK(1, 0),
214228
.ro = GENMASK(13, 0) << 16,
215229
.w1c = GENMASK(15, 14) << 16,
216230
},

0 commit comments

Comments
 (0)