From patchwork Thu Dec 24 11:57:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jayachandran C." X-Patchwork-Id: 7917291 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DCB06BEEE5 for ; Thu, 24 Dec 2015 11:35:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 003692052F for ; Thu, 24 Dec 2015 11:35:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02EBC2051A for ; Thu, 24 Dec 2015 11:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753250AbbLXLez (ORCPT ); Thu, 24 Dec 2015 06:34:55 -0500 Received: from mail-gw1-out.broadcom.com ([216.31.210.62]:27912 "EHLO mail-gw1-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753077AbbLXLex (ORCPT ); Thu, 24 Dec 2015 06:34:53 -0500 X-IronPort-AV: E=Sophos;i="5.20,473,1444719600"; d="scan'208";a="84224403" Received: from irvexchcas07.broadcom.com (HELO IRVEXCHCAS07.corp.ad.broadcom.com) ([10.9.208.55]) by mail-gw1-out.broadcom.com with ESMTP; 24 Dec 2015 06:03:36 -0800 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS07.corp.ad.broadcom.com (10.9.208.55) with Microsoft SMTP Server (TLS) id 14.3.235.1; Thu, 24 Dec 2015 03:34:53 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.235.1; Thu, 24 Dec 2015 03:34:52 -0800 Received: from netl-snoppy.ban.broadcom.com (unknown [10.132.128.129]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id BA4A740FE8; Thu, 24 Dec 2015 03:31:15 -0800 (PST) From: Jayachandran C To: , Bjorn Helgaas , , Arnd Bergmann , , "Rafael J. Wysocki" CC: Jayachandran C , Lorenzo Pieralisi , Tomasz Nowicki Subject: [PATCH v4 2/5] PCI: Handle ACPI companion and domain number Date: Thu, 24 Dec 2015 17:27:29 +0530 Message-ID: <1450958252-29892-3-git-send-email-jchandra@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450958252-29892-1-git-send-email-jchandra@broadcom.com> References: <1450958252-29892-1-git-send-email-jchandra@broadcom.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 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 --- drivers/pci/pci.c | 19 ++++++++++++++++++- drivers/pci/probe.c | 2 ++ include/linux/pci-acpi.h | 28 +++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) 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 #include #include +#include #include #include #include @@ -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 #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..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