Skip to contentSkip to conversation

Simple ACPI based PCI support for arm64

RFC PATCH Superseded Jayachandran C 1 participant 5 messages Dec 7, 2015

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Simple ACPI based PCI support for arm64

This is a very simple and generic implementation of a PCI host controller based on ACPI. This approach does not pull in the MMCONFIG and ECAM code from x86. The MCFG table is a simple ACPI table, and there is no need to move the complex code from x86 (sorted linked list with a lot of global vars) to acpi for parsing it.

The config space access is done with pci-host-generic style simple mapping and generic PCI config read/write.

This is tested with arm64 QEMU and OVMF. Comments are very welcome.

I would also add that I am posting this as an option, if another implementation is accepted upstream, I would happily drop this.

Thanks,
JC.

v1->v2:
- use CONFIG_PCI_MMCONFIG on arm64, provide a weak implementation of pci_mmcfg_late_init for arm64.
- The real implementation of pci_mmcfg_late_init is in pci-host-acpi.c and it will save the MCFG table entries to an array. Earlier this was done with an arch_init call
- remove unneeded pci_bus_add_devices call and fix MCFG saving code
- Added a patch to ACPI pci_root.c to handle arm64 PCI IO resources

Jayachandran C (4):
arm64: pci: Add ACPI support
PCI: Handle NULL parent in pci_bus_assign_domain_nr
PCI: ACPI: Add a generic ACPI based host controller
ACPI: PCI: Support platforms that need pci_remap_iospace

 arch/arm64/Kconfig               |   3 +
 arch/arm64/kernel/pci.c          |  50 +++++++++-
 drivers/acpi/pci_root.c          |  62 +++++++++++-
 drivers/acpi/resource.c          |   2 +
 drivers/pci/host/Kconfig         |   7 ++
 drivers/pci/host/Makefile        |   1 +
 drivers/pci/host/pci-host-acpi.c | 209 +++++++++++++++++++++++++++++++++++++++
 drivers/pci/pci.c                |   7 +-
 8 files changed, 335 insertions(+), 6 deletions(-)
 create mode 100644 drivers/pci/host/pci-host-acpi.c
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH v2 1/4 arm64: pci: Add ACPI support

Add functions needed for ACPI support on arm64.

pci_acpi_scan_root(struct acpi_pci_root *root) is marked as weak so that it can be implemented by the generic acpi pci driver. pcibios_root_bridge_prepare is defined and it assumes that the sysdata is struct acpi_pci_root_info.

pcibios_enable_device and pcibios_disable_device handle acpi irq enable and disable. And, pcibios_add_bus and pcibios_remove_bus have been added call the corresponding acpi functions.

---
 arch/arm64/Kconfig      |  3 +++
 arch/arm64/kernel/pci.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 3 deletions(-)
arch/arm64/Kconfig +3 -0
index 871f217..8c93af2 100644
@@ -203,6 +203,9 @@ config PCI_DOMAINS_GENERIC
 config PCI_SYSCALL
 	def_bool PCI
 
+config PCI_MMCONFIG
+	def_bool PCI && ACPI
+
 source "drivers/pci/Kconfig"
 source "drivers/pci/pcie/Kconfig"
 source "drivers/pci/hotplug/Kconfig"
arch/arm64/kernel/pci.c +47 -3

72 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

RFC PATCH v2 2/4 PCI: Handle NULL parent in pci_bus_assign_domain_nr

In reply to Jayachandran C

pci_create_root_bus is called with NULL as parent in ACPI. On arm64 this ends up calling pci_bus_assign_domain_nr, which crashes when dereferencing parent.

To fix this, update pci_bus_assign_domain_nr to return if parent is NULL. Setting up the domain number will be handled from pcibios_root_bridge_prepare on arm64 when booted with ACPI.

---
 drivers/pci/pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/pci.c +6 -1
index 314db8c..a96c356 100644
@@ -4772,8 +4772,13 @@ int pci_get_new_domain_nr(void)
 void pci_bus_assign_domain_nr(struct pci_bus *bus, struct device *parent)
 {
 	static int use_dt_domains = -1;
-	int domain = of_get_pci_domain_nr(parent->of_node);
+	int domain;
 
+	/* in case of ACPI, parent is NULL */
+	if (parent == NULL)
+		return;
+
+	domain = of_get_pci_domain_nr(parent->of_node);
 	/*
 	 * Check DT domain and use_dt_domains values.
 	 *
Signature · 1 line
1.9.1
#3 lore raw

RFC PATCH v2 3/4 PCI: ACPI: Add a generic ACPI based host controller

In reply to Jayachandran C

Add a simple ACPI based PCI host controller. This is done by providing a simple implementation for pci_acpi_scan_root(). The MCFG table is parsed early and saved so that it can be mapped when ACPI calls pci_acpi_scan_root.

This is enabled only for ARM64 now.

---
 drivers/pci/host/Kconfig         |   7 ++
 drivers/pci/host/Makefile        |   1 +
 drivers/pci/host/pci-host-acpi.c | 209 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 217 insertions(+)
 create mode 100644 drivers/pci/host/pci-host-acpi.c
drivers/pci/host/Kconfig +7 -0
index f131ba9..8321efc 100644
@@ -53,6 +53,13 @@ config PCI_RCAR_GEN2_PCIE
 	help
 	  Say Y here if you want PCIe controller support on R-Car Gen2 SoCs.
 
+config PCI_HOST_GENERIC_ACPI
+	bool "Generic ACPI PCI host controller"
+	depends on ARM64 && ACPI
+	help
+	  Say Y here if you want to support a simple generic ACPI PCI host
+	  controller.
+
 config PCI_HOST_GENERIC
 	bool "Generic PCI host controller"
 	depends on (ARM || ARM64) && OF
drivers/pci/host/Makefile +1 -0
index 9d4d3c6..bc31852 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
 obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
 obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o
 obj-$(CONFIG_PCI_RCAR_GEN2_PCIE) += pcie-rcar.o
+obj-$(CONFIG_PCI_HOST_GENERIC_ACPI) += pci-host-acpi.o
 obj-$(CONFIG_PCI_HOST_GENERIC) += pci-host-generic.o
 obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
 obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
drivers/pci/host/pci-host-acpi.c new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

RFC PATCH v2 4/4 ACPI: PCI: Support platforms that need pci_remap_iospace

In reply to Jayachandran C

On some platforms (in this case ARM64), the PCI iospace needs to be mapped with pci_remap_iospace and the resources have to be adjusted for the iospace physical address.

This has to be done before acpi_pci_root_validate_resources() checks and removes resource windows. Handle this by adding a function acpi_pci_root_remap_iospace that is called in acpi_pci_probe_root_resources(), before the validate call.

Also fix the address check in acpi_dev_ioresource_flags for similar platforms.

---
 drivers/acpi/pci_root.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++--
 drivers/acpi/resource.c |  2 ++
 2 files changed, 62 insertions(+), 2 deletions(-)
drivers/acpi/pci_root.c +60 -2
index 850d7bf..58093ba 100644
@@ -720,6 +720,61 @@ next:
 	}
 }
 
+#ifdef PCI_IOBASE
+/*
+ * The IO ports are mapped to a memory range, fixup IO resources to
+ * handle that
+ */
+static int acpi_pci_root_remap_iospace(struct acpi_pci_root_info *ci)
+{
+	struct resource_entry *entry;
+	struct resource iores;
+	resource_size_t iostart;
+	int err;
+
+	iores.flags = IORESOURCE_IO;
+	iores.start = (resource_size_t)-1;
+	iores.end = 0;
+	resource_list_for_each_entry(entry, &ci->resources) {
+		if (entry->res->flags & IORESOURCE_IO) {
+			iores.start = min(entry->res->start, iores.start);
+			iores.end = max(entry->res->end, iores.end);
+		}
+	}
+	if (iores.end == 0)
+		return 0;
+	iostart = iores.start;
+
+	resource_list_for_each_entry(entry, &ci->resources) {
+		if (entry->res->flags & IORESOURCE_IO) {
+			entry->res->start -= iostart;
+			entry->res->end -= iostart;
+			entry->offset -= iostart;
+		}
+	}
+	iores.start -= iostart;
+	iores.end -= iostart;
+
+	err = pci_remap_iospace(&iores, iostart);
+	if (err) {
+		pr_err("PCI: ACPI: err %d mapping IO %pR\n", err, &iores);
+		return -ENODEV;
+	}
+	pr_info(PREFIX "Mapped %pR at %#lx for IO.\n",
+			&iores, (unsigned long)iostart);
+	return 0;
+}
+#else
+/*
+ * The IO ports are mapped to a memory range, fixup IO resources to
+ * handle that
+ */
+static int acpi_pci_root_remap_iospace(struct acpi_pci_root_info *ci)
+{
+	return 0;
+}
+#endif /* PCI_IOBASE */
+
 int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info)
 {
 	int ret;
@@ -745,10 +800,13 @@ int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info)
 			else
 				entry->res->name = info->name;
 		}
-		acpi_pci_root_validate_resources(&device->dev, list,
+		ret = acpi_pci_root_remap_iospace(info);
+		if (ret >= 0) {
+			acpi_pci_root_validate_resources(&device->dev, list,
 						 IORESOURCE_MEM);
-		acpi_pci_root_validate_resources(&device->dev, list,
+			acpi_pci_root_validate_resources(&device->dev, list,
 						 IORESOURCE_IO);
+		}
 	}
 
 	return ret;
drivers/acpi/resource.c +2 -0
index cdc5c25..530cad4 100644
@@ -126,8 +126,10 @@ static void acpi_dev_ioresource_flags(struct resource *res, u64 len,
 	if (!acpi_dev_resource_len_valid(res->start, res->end, len, true))
 		res->flags |= IORESOURCE_DISABLED | IORESOURCE_UNSET;
 
+#ifndef PCI_IOBASE
 	if (res->end >= 0x10003)
 		res->flags |= IORESOURCE_DISABLED | IORESOURCE_UNSET;
+#endif
 
 	if (io_decode == ACPI_DECODE_16)
 		res->flags |= IORESOURCE_IO_16BIT_ADDR;
Signature · 1 line
1.9.1