From patchwork Mon Nov 10 16:41:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 40517 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 35375203C0 for ; Mon, 10 Nov 2014 16:42:07 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id n15sf4265992lbi.10 for ; Mon, 10 Nov 2014 08:42:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=tQvMNGtjQvv4YDdjy+kcqdCxFXfJN3/7Z1JjG3YwsTw=; b=K4q8x/HAu+JUvc/gKplI+sERz6VZr+XN63esxuxR8c8V7Y0TpA3xHtBS879lDYhKMo spER2rwihNEJ/+M2djVF686wli9jF+rA8r5kGTuVM/6Z9V15h1vnPC1j8Cu5q5r94YQI wTjS0EvNrq2/dQpFYwH19gbiy8/3M4ZzIiiXcJOCdZyfC8Yvm1MLcfAwYDn7NCQyUvvU CFig4KPsmTQNvEj/yAi7iapg4BgnNv5+pKMx7nrn5n+K5IZln3qgLIa0EjwypYee1K/c y68agIMeVKhawYKElcvkbsKpwhv1GXHaPnkJ5hRlntfPsbko8ORchXx5PgrdPABnXljv Y1Bw== X-Gm-Message-State: ALoCoQlZ7b74nEVm3hmnN9W5qWkDVt9QAG+s6VtxirhAVorjNZO1KAwHoW9TSEV/9J8nGebwNAwy X-Received: by 10.152.27.38 with SMTP id q6mr1085047lag.5.1415637721664; Mon, 10 Nov 2014 08:42:01 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.72 with SMTP id q8ls369745laq.98.gmail; Mon, 10 Nov 2014 08:42:01 -0800 (PST) X-Received: by 10.112.87.162 with SMTP id az2mr30027222lbb.15.1415637721518; Mon, 10 Nov 2014 08:42:01 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id c5si27613244lah.117.2014.11.10.08.41.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 08:41:59 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id n15so6223905lbi.18 for ; Mon, 10 Nov 2014 08:41:59 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr21081311lbc.66.1415637719443; Mon, 10 Nov 2014 08:41:59 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp121033lbc; Mon, 10 Nov 2014 08:41:58 -0800 (PST) X-Received: by 10.66.168.238 with SMTP id zz14mr8588468pab.62.1415637717820; Mon, 10 Nov 2014 08:41:57 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id by7si16940439pab.179.2014.11.10.08.41.56 for ; Mon, 10 Nov 2014 08:41:57 -0800 (PST) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751781AbaKJQlx (ORCPT + 4 others); Mon, 10 Nov 2014 11:41:53 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:55626 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753798AbaKJQlw (ORCPT ); Mon, 10 Nov 2014 11:41:52 -0500 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id D8DFA66; Mon, 10 Nov 2014 10:41:48 -0600 (CST) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 8788E5FAD7; Mon, 10 Nov 2014 10:41:46 -0600 (CST) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.203.137]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 24A6213F6EE; Mon, 10 Nov 2014 10:41:45 -0600 (CST) From: Lorenzo Pieralisi To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org Cc: Lorenzo Pieralisi , Arnd Bergmann , Liviu Dudau , Bjorn Helgaas , Rob Herring , Catalin Marinas Subject: [RFC PATCH v2] drivers: pci: move PCI domain assignment to generic PCI code Date: Mon, 10 Nov 2014 16:41:46 +0000 Message-Id: <1415637706-2195-1-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.1.2 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lorenzo.pieralisi@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The current logic used for PCI domain assignment in arm64 pci_bus_assign_domain_nr() is flawed in that, depending on the host controllers configuration for a platform and the respective initialization sequence, core code may end up allocating PCI domain numbers from both DT and the core code generic domain counter, which would result in PCI domain allocation aliases/errors. This patch fixes the logic behind the PCI domain number assignment and moves the resulting code to generic PCI core code so that the same domain allocation logic is used on all platforms selecting CONFIG_PCI_DOMAINS_GENERIC instead of resorting to an arch specific implementation that might end up duplicating the PCI domain assignment logic wrongly. Cc: Arnd Bergmann Cc: Liviu Dudau Cc: Bjorn Helgaas Cc: Rob Herring Cc: Catalin Marinas Signed-off-by: Lorenzo Pieralisi Acked-by: Liviu Dudau Acked-by: Arnd Bergmann --- v1 => v2: - Moved generic pci_bus_assign_domain_nr() code to PCI core instead of adding an OF layer API - Updated commit log and code comments arch/arm64/kernel/pci.c | 22 ---------------------- drivers/pci/pci.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index ce5836c..6f93c24 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -46,25 +46,3 @@ int pcibios_add_device(struct pci_dev *dev) return 0; } - - -#ifdef CONFIG_PCI_DOMAINS_GENERIC -static bool dt_domain_found = false; - -void pci_bus_assign_domain_nr(struct pci_bus *bus, struct device *parent) -{ - int domain = of_get_pci_domain_nr(parent->of_node); - - if (domain >= 0) { - dt_domain_found = true; - } else if (dt_domain_found == true) { - dev_err(parent, "Node %s is missing \"linux,pci-domain\" property in DT\n", - parent->of_node->full_name); - return; - } else { - domain = pci_get_new_domain_nr(); - } - - bus->domain_nr = domain; -} -#endif diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 625a4ac..2279414 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -4447,6 +4449,54 @@ int pci_get_new_domain_nr(void) { return atomic_inc_return(&__domain_nr); } + +#ifdef CONFIG_PCI_DOMAINS_GENERIC + +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); + + /* + * Check DT domain and use_dt_domains values. + * + * If DT domain property is valid (domain >= 0) and + * use_dt_domains != 0, the DT assignment is valid since this means + * we have not previously allocated a domain number by using + * pci_get_new_domain_nr(); we should also update use_dt_domains to + * 1, to indicate that we have just assigned a domain number from + * DT. + * + * If DT domain property value is not valid (ie domain < 0), and we + * have not previously assigned a domain number from DT + * (use_dt_domains != 1) we should assign a domain number by + * using the: + * + * pci_get_new_domain_nr() + * + * API and update the use_dt_domains value to keep track of method we + * are using to assign domain numbers (use_dt_domains = 0). + * + * All other combinations imply we have a platform that is trying + * to mix domain numbers obtained from DT and pci_get_new_domain_nr(), + * which is a recipe for domain mishandling and it is prevented by + * invalidating the domain value (domain = -1) and printing a + * corresponding error. + */ + if (domain >= 0 && use_dt_domains) { + use_dt_domains = 1; + } else if (domain < 0 && use_dt_domains != 1) { + use_dt_domains = 0; + domain = pci_get_new_domain_nr(); + } else { + dev_err(parent, "Node %s has inconsistent \"linux,pci-domain\" property in DT\n", + parent->of_node->full_name); + domain = -1; + } + + bus->domain_nr = domain; +} +#endif #endif /**