Skip to content

Commit 5c88ed7

Browse files
paliLorenzo Pieralisi
authored andcommitted
PCI: mvebu: Set PCI_BRIDGE_EMUL_NO_IO_FORWARD when IO is unsupported
This will make PCI bridge to return zeros when accessing IO base and limit registers, as required by PCIe base specification. This allows to remove adhoc checks around mvebu_pcie_handle_iobase_change() function for unsupported IO ranges. PCI_BRIDGE_EMUL_NO_IO_FORWARD ensures that there will be no non-zeros write to IO registers when IO is not supported. Link: https://lore.kernel.org/r/20220104153529.31647-8-pali@kernel.org Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Rob Herring <robh@kernel.org>
1 parent 7a02acd commit 5c88ed7

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

drivers/pci/controller/pci-mvebu.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,6 @@ static int mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port)
438438
return mvebu_pcie_set_window(port, port->io_target, port->io_attr,
439439
&desired, &port->iowin);
440440

441-
if (!mvebu_has_ioport(port)) {
442-
dev_WARN(&port->pcie->pdev->dev,
443-
"Attempt to set IO when IO is disabled\n");
444-
return -EOPNOTSUPP;
445-
}
446-
447441
/*
448442
* We read the PCI-to-PCI bridge emulated registers, and
449443
* calculate the base address and size of the address decoding
@@ -599,24 +593,18 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
599593

600594
switch (reg) {
601595
case PCI_COMMAND:
602-
if (!mvebu_has_ioport(port)) {
603-
conf->command = cpu_to_le16(
604-
le16_to_cpu(conf->command) & ~PCI_COMMAND_IO);
605-
new &= ~PCI_COMMAND_IO;
606-
}
607-
608596
mvebu_writel(port, new, PCIE_CMD_OFF);
609597
break;
610598

611599
case PCI_IO_BASE:
612-
if ((mask & 0xffff) && mvebu_pcie_handle_iobase_change(port)) {
600+
if ((mask & 0xffff) && mvebu_has_ioport(port) &&
601+
mvebu_pcie_handle_iobase_change(port)) {
613602
/* On error disable IO range */
614603
conf->iobase &= ~0xf0;
615604
conf->iolimit &= ~0xf0;
605+
conf->iobase |= 0xf0;
616606
conf->iobaseupper = cpu_to_le16(0x0000);
617607
conf->iolimitupper = cpu_to_le16(0x0000);
618-
if (mvebu_has_ioport(port))
619-
conf->iobase |= 0xf0;
620608
}
621609
break;
622610

@@ -630,14 +618,14 @@ mvebu_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
630618
break;
631619

632620
case PCI_IO_BASE_UPPER16:
633-
if (mvebu_pcie_handle_iobase_change(port)) {
621+
if (mvebu_has_ioport(port) &&
622+
mvebu_pcie_handle_iobase_change(port)) {
634623
/* On error disable IO range */
635624
conf->iobase &= ~0xf0;
636625
conf->iolimit &= ~0xf0;
626+
conf->iobase |= 0xf0;
637627
conf->iobaseupper = cpu_to_le16(0x0000);
638628
conf->iolimitupper = cpu_to_le16(0x0000);
639-
if (mvebu_has_ioport(port))
640-
conf->iobase |= 0xf0;
641629
}
642630
break;
643631

@@ -722,6 +710,7 @@ static const struct pci_bridge_emul_ops mvebu_pci_bridge_emul_ops = {
722710
*/
723711
static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
724712
{
713+
unsigned int bridge_flags = PCI_BRIDGE_EMUL_NO_PREFMEM_FORWARD;
725714
struct pci_bridge_emul *bridge = &port->bridge;
726715
u32 pcie_cap = mvebu_readl(port, PCIE_CAP_PCIEXP);
727716
u8 pcie_cap_ver = ((pcie_cap >> 16) & PCI_EXP_FLAGS_VERS);
@@ -735,6 +724,8 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
735724
/* We support 32 bits I/O addressing */
736725
bridge->conf.iobase = PCI_IO_RANGE_TYPE_32;
737726
bridge->conf.iolimit = PCI_IO_RANGE_TYPE_32;
727+
} else {
728+
bridge_flags |= PCI_BRIDGE_EMUL_NO_IO_FORWARD;
738729
}
739730

740731
/*
@@ -747,7 +738,7 @@ static int mvebu_pci_bridge_emul_init(struct mvebu_pcie_port *port)
747738
bridge->data = port;
748739
bridge->ops = &mvebu_pci_bridge_emul_ops;
749740

750-
return pci_bridge_emul_init(bridge, PCI_BRIDGE_EMUL_NO_PREFMEM_FORWARD);
741+
return pci_bridge_emul_init(bridge, bridge_flags);
751742
}
752743

753744
static inline struct mvebu_pcie *sys_to_pcie(struct pci_sys_data *sys)

0 commit comments

Comments
 (0)