From patchwork Thu Jan 14 07:32:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jayachandran C." X-Patchwork-Id: 8030421 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 34A189F6FA for ; Thu, 14 Jan 2016 07:17:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4D91D20499 for ; Thu, 14 Jan 2016 07:17:11 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B14F20490 for ; Thu, 14 Jan 2016 07:17:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJc6d-0000tr-LC; Thu, 14 Jan 2016 07:14:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aJc1I-0000hd-7S for xen-devel@lists.xenproject.org; Thu, 14 Jan 2016 07:08:32 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id FE/C5-24494-F6947965; Thu, 14 Jan 2016 07:08:31 +0000 X-Env-Sender: jchandra@broadcom.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1452755309!15756846!1 X-Originating-IP: [216.31.210.63] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49509 invoked from network); 14 Jan 2016 07:08:30 -0000 Received: from mail-gw2-out.broadcom.com (HELO mail-gw2-out.broadcom.com) (216.31.210.63) by server-4.tower-206.messagelabs.com with SMTP; 14 Jan 2016 07:08:30 -0000 X-IronPort-AV: E=Sophos;i="5.22,293,1449561600"; d="scan'208";a="85545385" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw2-out.broadcom.com with ESMTP; 13 Jan 2016 23:49:13 -0800 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.235.1; Wed, 13 Jan 2016 23:08:28 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.235.1; Wed, 13 Jan 2016 23:08:28 -0800 Received: from netl-snoppy.ban.broadcom.com (unknown [10.132.128.129]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 58C7B4101A; Wed, 13 Jan 2016 23:04:40 -0800 (PST) From: Jayachandran C To: , Bjorn Helgaas , , Arnd Bergmann , , "Rafael J. Wysocki" Date: Thu, 14 Jan 2016 13:02:38 +0530 Message-ID: <1452756761-29584-3-git-send-email-jchandra@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452756761-29584-1-git-send-email-jchandra@broadcom.com> References: <1452756761-29584-1-git-send-email-jchandra@broadcom.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 14 Jan 2016 07:14:01 +0000 Cc: Tomasz Nowicki , Lorenzo Pieralisi , Jayachandran C , xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v6 2/5] PCI: Handle ACPI companion and domain number X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 a way to set the ACPI domain number and ACPI companion in PCI code. We define pci_acpi_set_companion() to set the ACPI companion pointer and acpi_pci_get_segment() and to get the PCI domain number. This is just defined for the generic ACPI PCI controller, using the corresponding sysdata. pci_bus_assign_domain_nr is updated to call acpi_pci_get_segment() to get the domain number to set on the root bus, in case of ACPI. Signed-off-by: Jayachandran C --- drivers/pci/pci.c | 15 ++++++++++++++- drivers/pci/probe.c | 2 ++ include/linux/pci-acpi.h | 28 +++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 314db8c..39d2bcc 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -4772,9 +4773,21 @@ 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) { + bus->domain_nr = acpi_pci_get_segment(bus->sysdata); + 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 #include #include +#include #include #include #include @@ -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..f8d62e3 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 void pci_acpi_set_companion(struct pci_host_bridge *bridge) +{ + struct pci_bus *b = bridge->bus; + struct acpi_pci_root_info *ci = (struct acpi_pci_root_info *)b->sysdata; + + ACPI_COMPANION_SET(&bridge->dev, ci->bridge); +} + +static inline u16 acpi_pci_get_segment(void *sysdata) +{ + struct acpi_pci_root_info *ci = (struct acpi_pci_root_info *)sysdata; + + return ci->root->segment; +} +#else +static inline void pci_acpi_set_companion(struct pci_host_bridge *bridge) +{ + /* leave it to the platform for now */ +} + +static inline u16 acpi_pci_get_segment(void *sysdata) +{ + return 0; +} +#endif + #ifdef CONFIG_ACPI_APEI extern bool aer_acpi_firmware_first(void); #else