diff mbox

[v4,2/5] PCI: Handle ACPI companion and domain number

Message ID 1450958252-29892-3-git-send-email-jchandra@broadcom.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jayachandran C. Dec. 24, 2015, 11:57 a.m. UTC
pci_create_root_bus is called with NULL as parent in ACPI. This
ends up calling pci_bus_assign_domain_nr with a NULL parent, which
crashes when dereferencing parent.

Fix this by providing away to set the ACPI domain number, we define
acpi_pci_sysdata_to_root_info() to get the acpi root info from
sysdata. This is a simple cast the generic ACPI PCI implementation.

Similarly, setting up the ACPI companion in case of generic ACPI PCI
implementation is staright forward.

Signed-off-by: Jayachandran C <jchandra@broadcom.com>
---
 drivers/pci/pci.c        | 19 ++++++++++++++++++-
 drivers/pci/probe.c      |  2 ++
 include/linux/pci-acpi.h | 28 +++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 2 deletions(-)

Comments

kernel test robot Dec. 24, 2015, 1:03 p.m. UTC | #1
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
Hi Jayachandran,

[auto build test ERROR on pm/linux-next]
[also build test ERROR on v4.4-rc6 next-20151223]
[cannot apply to pci/next]

url:    https://github.com/0day-ci/linux/commits/Jayachandran-C/ACPI-based-PCI-support-for-arm64/20151224-193703
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: arm-imx_v6_v7_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All errors (new ones prefixed by >>):

   drivers/pci/pci.c: In function 'pci_bus_assign_domain_nr':
>> drivers/pci/pci.c:4789:23: error: dereferencing pointer to incomplete type
       bus->domain_nr = ci->root->segment;
                          ^

vim +4789 drivers/pci/pci.c

  4783		 */
  4784		if (!parent || !parent->of_node) {
  4785			struct acpi_pci_root_info *ci;
  4786	
  4787			ci = acpi_pci_sysdata_to_root_info(bus->sysdata);
  4788			if (ci)
> 4789				bus->domain_nr = ci->root->segment;
  4790			return;
  4791		}
  4792	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 314db8c..f578af4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -20,6 +20,7 @@ 
 #include <linux/string.h>
 #include <linux/log2.h>
 #include <linux/pci-aspm.h>
+#include <linux/pci-acpi.h>
 #include <linux/pm_wakeup.h>
 #include <linux/interrupt.h>
 #include <linux/device.h>
@@ -4772,9 +4773,25 @@  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;
 
 	/*
+	 * Handle ACPI early
+	 *
+	 * the companion is not set at this point, and ACPI sets parent to
+	 * NULL, we have to try to get the segment from acpi root info.
+	 */
+	if (!parent || !parent->of_node) {
+		struct acpi_pci_root_info *ci;
+
+		ci = acpi_pci_sysdata_to_root_info(bus->sysdata);
+		if (ci)
+			bus->domain_nr = ci->root->segment;
+		return;
+	}
+
+	domain = of_get_pci_domain_nr(parent->of_node);
+	/*
 	 * Check DT domain and use_dt_domains values.
 	 *
 	 * If DT domain property is valid (domain >= 0) and
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index edb1984..5af66496 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -13,6 +13,7 @@ 
 #include <linux/module.h>
 #include <linux/cpumask.h>
 #include <linux/pci-aspm.h>
+#include <linux/pci-acpi.h>
 #include <linux/aer.h>
 #include <linux/acpi.h>
 #include <asm-generic/pci-bridge.h>
@@ -2105,6 +2106,7 @@  struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 	bridge->dev.parent = parent;
 	bridge->dev.release = pci_release_host_bridge_dev;
 	dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
+	pci_acpi_set_companion(bridge);
 	error = pcibios_root_bridge_prepare(bridge);
 	if (error) {
 		kfree(bridge);
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index e9450ef..79448ce 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -138,12 +138,38 @@  extern struct list_head pci_mmcfg_list;
 
 #define PCI_MMCFG_BUS_OFFSET(bus)      ((bus) << 20)
 #define PCI_MMCFG_OFFSET(bus, devfn)   ((bus) << 20 | (devfn) << 12)
-
 #else	/* CONFIG_ACPI */
 static inline void acpi_pci_add_bus(struct pci_bus *bus) { }
 static inline void acpi_pci_remove_bus(struct pci_bus *bus) { }
 #endif	/* CONFIG_ACPI */
 
+#if defined(CONFIG_ACPI) && defined(CONFIG_ACPI_PCI_HOST_GENERIC)
+static inline struct acpi_pci_root_info *acpi_pci_sysdata_to_root_info(void *sd)
+{
+	return (struct acpi_pci_root_info *)sd;
+}
+
+static inline void pci_acpi_set_companion(struct pci_host_bridge *bridge)
+{
+	struct pci_bus *b = bridge->bus;
+	struct acpi_pci_root_info *ci;
+
+	ci = acpi_pci_sysdata_to_root_info(b->sysdata);
+	if (ci)
+		ACPI_COMPANION_SET(&bridge->dev, ci->bridge);
+}
+#else
+static inline struct acpi_pci_root_info *acpi_pci_sysdata_to_root_info(void *sd)
+{
+	return NULL;
+}
+
+static inline void pci_acpi_set_companion(struct pci_host_bridge *bridge)
+{
+	/* leave it to the platform for now */
+}
+#endif
+
 #ifdef CONFIG_ACPI_APEI
 extern bool aer_acpi_firmware_first(void);
 #else