Skip to content

Commit c453bf6

Browse files
Russell KingLorenzo Pieralisi
authored andcommitted
PCI: pci-bridge-emul: Re-arrange register tests
Re-arrange the tests for which sets of registers are being accessed so that it is easier to add further regions later. No functional change. [pali: Fix reading old value in pci_bridge_emul_conf_write] Link: https://lore.kernel.org/r/20220222155030.988-2-pali@kernel.org Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <kabel@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1 parent c3bd7dc commit c453bf6

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

drivers/pci/pci-bridge-emul.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -422,25 +422,25 @@ int pci_bridge_emul_conf_read(struct pci_bridge_emul *bridge, int where,
422422
__le32 *cfgspace;
423423
const struct pci_bridge_reg_behavior *behavior;
424424

425-
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END) {
426-
*value = 0;
427-
return PCIBIOS_SUCCESSFUL;
428-
}
429-
430-
if (!bridge->has_pcie && reg >= PCI_BRIDGE_CONF_END) {
425+
if (reg < PCI_BRIDGE_CONF_END) {
426+
/* Emulated PCI space */
427+
read_op = bridge->ops->read_base;
428+
cfgspace = (__le32 *) &bridge->conf;
429+
behavior = bridge->pci_regs_behavior;
430+
} else if (!bridge->has_pcie) {
431+
/* PCIe space is not implemented, and no PCI capabilities */
431432
*value = 0;
432433
return PCIBIOS_SUCCESSFUL;
433-
}
434-
435-
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) {
434+
} else if (reg < PCI_CAP_PCIE_END) {
435+
/* Our emulated PCIe capability */
436436
reg -= PCI_CAP_PCIE_START;
437437
read_op = bridge->ops->read_pcie;
438438
cfgspace = (__le32 *) &bridge->pcie_conf;
439439
behavior = bridge->pcie_cap_regs_behavior;
440440
} else {
441-
read_op = bridge->ops->read_base;
442-
cfgspace = (__le32 *) &bridge->conf;
443-
behavior = bridge->pci_regs_behavior;
441+
/* Beyond our PCIe space */
442+
*value = 0;
443+
return PCIBIOS_SUCCESSFUL;
444444
}
445445

446446
if (read_op)
@@ -484,11 +484,27 @@ int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
484484
__le32 *cfgspace;
485485
const struct pci_bridge_reg_behavior *behavior;
486486

487-
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_END)
488-
return PCIBIOS_SUCCESSFUL;
487+
ret = pci_bridge_emul_conf_read(bridge, reg, 4, &old);
488+
if (ret != PCIBIOS_SUCCESSFUL)
489+
return ret;
489490

490-
if (!bridge->has_pcie && reg >= PCI_BRIDGE_CONF_END)
491+
if (reg < PCI_BRIDGE_CONF_END) {
492+
/* Emulated PCI space */
493+
write_op = bridge->ops->write_base;
494+
cfgspace = (__le32 *) &bridge->conf;
495+
behavior = bridge->pci_regs_behavior;
496+
} else if (!bridge->has_pcie) {
497+
/* PCIe space is not implemented, and no PCI capabilities */
491498
return PCIBIOS_SUCCESSFUL;
499+
} else if (reg < PCI_CAP_PCIE_END) {
500+
/* Our emulated PCIe capability */
501+
reg -= PCI_CAP_PCIE_START;
502+
write_op = bridge->ops->write_pcie;
503+
cfgspace = (__le32 *) &bridge->pcie_conf;
504+
behavior = bridge->pcie_cap_regs_behavior;
505+
} else {
506+
return PCIBIOS_SUCCESSFUL;
507+
}
492508

493509
shift = (where & 0x3) * 8;
494510

@@ -501,21 +517,6 @@ int pci_bridge_emul_conf_write(struct pci_bridge_emul *bridge, int where,
501517
else
502518
return PCIBIOS_BAD_REGISTER_NUMBER;
503519

504-
ret = pci_bridge_emul_conf_read(bridge, reg, 4, &old);
505-
if (ret != PCIBIOS_SUCCESSFUL)
506-
return ret;
507-
508-
if (bridge->has_pcie && reg >= PCI_CAP_PCIE_START) {
509-
reg -= PCI_CAP_PCIE_START;
510-
write_op = bridge->ops->write_pcie;
511-
cfgspace = (__le32 *) &bridge->pcie_conf;
512-
behavior = bridge->pcie_cap_regs_behavior;
513-
} else {
514-
write_op = bridge->ops->write_base;
515-
cfgspace = (__le32 *) &bridge->conf;
516-
behavior = bridge->pci_regs_behavior;
517-
}
518-
519520
/* Keep all bits, except the RW bits */
520521
new = old & (~mask | ~behavior[reg / 4].rw);
521522

0 commit comments

Comments
 (0)