From patchwork Wed Sep 10 13:04:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 37202 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D217E20491 for ; Wed, 10 Sep 2014 13:05:54 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id m1sf90625625oag.3 for ; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:in-reply-to:user-agent:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-disposition; bh=FzVFDzPxEB3gwcBWXN6xeMxEjE5Z2wvPFf5Ujm8qWTM=; b=YhXrwkAmymJx7/zTmp/oGT2v6wQUZUj2jD7KHHh37Wtq+/Cc2/stmFNE/EnRqN6R6a 8r82aOGPiEiSyDiSCxfV+RHL7ia8Niq6IE3nJJFC+N/PaulIcBxD/HKufrmfWkRqEA7X oXjCv+PeP68r5tZyADr+KU7JM9qof8l1rXoYeCiylHiRctShOH060D21/+PonTfFeZbq h76Rf783BOdOjUF0lpqSH2lUUFAyOUm+mrH4a36X3ZjinCz7UPSt5KkcAQrvYFx8GvVg RAHvu+Q3v5Ouv51lR+qe827aIS9Zv+Rj3eTecajJrei2FLETQvSjnLZB3DGoQCJoc0as CVwA== X-Gm-Message-State: ALoCoQl5etnaIROn+icu+dl0m71xsiBuvNUIvNgHXlDmGQ+ySbKDr02YWAtSlqo+5vDYjkqgRJVB X-Received: by 10.182.60.135 with SMTP id h7mr12503314obr.18.1410354354391; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.247 with SMTP id c110ls1893613qga.32.gmail; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) X-Received: by 10.220.116.196 with SMTP id n4mr35588094vcq.6.1410354354286; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id hf10si4945545vdb.57.2014.09.10.06.05.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Sep 2014 06:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ij19so4752572vcb.40 for ; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) X-Received: by 10.220.169.72 with SMTP id x8mr11177499vcy.45.1410354354189; Wed, 10 Sep 2014 06:05:54 -0700 (PDT) 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.221.45.67 with SMTP id uj3csp434249vcb; Wed, 10 Sep 2014 06:05:53 -0700 (PDT) X-Received: by 10.50.43.233 with SMTP id z9mr39194740igl.41.1410354352596; Wed, 10 Sep 2014 06:05:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fz4si17431986icb.65.2014.09.10.06.05.52 for ; Wed, 10 Sep 2014 06:05:52 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S1751344AbaIJNEn (ORCPT + 27 others); Wed, 10 Sep 2014 09:04:43 -0400 Received: from service87.mimecast.com ([91.220.42.44]:48563 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbaIJNEk (ORCPT ); Wed, 10 Sep 2014 09:04:40 -0400 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Wed, 10 Sep 2014 14:04:35 +0100 Received: from e106497-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 10 Sep 2014 14:04:33 +0100 Received: by e106497-lin.cambridge.arm.com (Postfix, from userid 1005) id 604131077BF6; Wed, 10 Sep 2014 14:04:32 +0100 (BST) Date: Wed, 10 Sep 2014 14:04:32 +0100 From: Liviu Dudau To: Rob Herring Cc: Bjorn Helgaas , Arnd Bergmann , Rob Herring , Jason Gunthorpe , Benjamin Herrenschmidt , Catalin Marinas , Will Deacon , Russell King , linux-pci , Linus Walleij , Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit , linux-arch , LKML , Device Tree ML , LAKML , "grant.likely@linaro.org" Subject: Re: [PATCH v10 07/10] OF: Introduce helper function for getting PCI domain_nr Message-ID: <20140910130432.GB27864@e106497-lin.cambridge.arm.com> References: <1410184472-17630-1-git-send-email-Liviu.Dudau@arm.com> <1410184472-17630-8-git-send-email-Liviu.Dudau@arm.com> <20140908145459.GO27864@e106497-lin.cambridge.arm.com> <20140908155931.GP27864@e106497-lin.cambridge.arm.com> MIME-Version: 1.0 In-Reply-To: <20140908155931.GP27864@e106497-lin.cambridge.arm.com> User-Agent: Mutt/1.5.22 (2013-10-16) X-OriginalArrivalTime: 10 Sep 2014 13:04:33.0624 (UTC) FILETIME=[C41CBD80:01CFCCF7] X-MC-Unique: 114091014043511901 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: liviu.dudau@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.220.181 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: , Content-Disposition: inline On Mon, Sep 08, 2014 at 04:59:31PM +0100, Liviu Dudau wrote: > On Mon, Sep 08, 2014 at 04:27:36PM +0100, Rob Herring wrote: > > On Mon, Sep 8, 2014 at 9:54 AM, Liviu Dudau wrote: > > > On Mon, Sep 08, 2014 at 03:27:56PM +0100, Rob Herring wrote: > > >> On Mon, Sep 8, 2014 at 8:54 AM, Liviu Dudau wrote: > > >> > Add of_pci_get_domain_nr() to retrieve the PCI domain number > > >> > of a given device from DT. If the information is not present, > > >> > the function can be requested to allocate a new domain number. > > >> > > > >> > Cc: Bjorn Helgaas > > >> > Cc: Arnd Bergmann > > >> > Cc: Grant Likely > > >> > Cc: Rob Herring > > >> > Reviewed-by: Catalin Marinas > > >> > Signed-off-by: Liviu Dudau > > >> > --- > > >> > drivers/of/of_pci.c | 34 ++++++++++++++++++++++++++++++++++ > > >> > include/linux/of_pci.h | 7 +++++++ > > >> > 2 files changed, 41 insertions(+) > > >> > > > >> > diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c > > >> > index 8481996..a107edb 100644 > > >> > --- a/drivers/of/of_pci.c > > >> > +++ b/drivers/of/of_pci.c > > >> > @@ -89,6 +89,40 @@ int of_pci_parse_bus_range(struct device_node *node, struct resource *res) > > >> > } > > >> > EXPORT_SYMBOL_GPL(of_pci_parse_bus_range); > > >> > > > >> > +static atomic_t of_domain_nr = ATOMIC_INIT(-1); > > >> > + > > >> > +/** > > >> > + * This function will try to obtain the host bridge domain number by > > >> > + * using of_alias_get_id() call with "pci-domain" as a stem. If that > > >> > + * fails, a local allocator will be used. The local allocator can > > >> > + * be requested to return a new domain_nr if the information is missing > > >> > + * from the device tree. > > >> > + * > > >> > + * @node: device tree node with the domain information > > >> > + * @allocate_if_missing: if DT lacks information about the domain nr, > > >> > + * allocate a new number. > > >> > + * > > >> > + * Returns the associated domain number from DT, or a new domain number > > >> > + * if DT information is missing and @allocate_if_missing is true. If > > >> > + * @allocate_if_missing is false then the last allocated domain number > > >> > + * will be returned. > > >> > + */ > > >> > +int of_pci_get_domain_nr(struct device_node *node, bool allocate_if_missing) > > >> > +{ > > >> > + int domain; > > >> > + > > >> > + domain = of_alias_get_id(node, "pci-domain"); > > >> > + if (domain == -ENODEV) { > > >> > + if (allocate_if_missing) > > >> > + domain = atomic_inc_return(&of_domain_nr); > > >> > + else > > >> > + domain = atomic_read(&of_domain_nr); > > >> > > >> This function seems a bit broken to me. It is overloaded with too many > > >> different outcomes. Think about how this would work if you have > > >> multiple PCI buses and a mixture of having pci-domain aliases or not. > > >> Aren't domain numbers global? Allocation should then start outside of > > >> the range of alias ids. > > >> > > >> Rob > > >> > > > > > > Rob, > > > > > > Would this version make more sense? > > > > No. > > Hi Rob, Here is an updated version of the patch. I have implemented a separate function for getting the max domain number from the device tree and use the result as the start value + 1 for the allocator. Best regards, Liviu >From 77257fceaa8fbd74d6132fcf57c3af14bd48c0ae Mon Sep 17 00:00:00 2001 From: Liviu Dudau Date: Mon, 4 Aug 2014 17:03:04 +0100 Subject: [PATCH v10 07/10] OF: Introduce helper function for getting PCI domain_nr Add of_pci_get_domain_nr() to retrieve the PCI domain number of a given device from DT. If the information is not present, the function can be requested to allocate a new domain number. Cc: Bjorn Helgaas Cc: Arnd Bergmann Cc: Grant Likely Cc: Rob Herring Reviewed-by: Catalin Marinas Signed-off-by: Liviu Dudau --- drivers/of/of_pci.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_pci.h | 7 ++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 8481996..3560401 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -3,6 +3,8 @@ #include #include +#include "of_private.h" + static inline int __of_pci_pci_compare(struct device_node *node, unsigned int data) { @@ -89,6 +91,66 @@ int of_pci_parse_bus_range(struct device_node *node, struct resource *res) } EXPORT_SYMBOL_GPL(of_pci_parse_bus_range); +static atomic_t of_domain_nr = ATOMIC_INIT(-1); + +/* + * Get the maximum value for a domain number from the device tree + */ +static int of_get_max_pci_domain_nr(void) +{ + struct alias_prop *app; + int max_domain = -1; + + mutex_lock(&of_mutex); + list_for_each_entry(app, &aliases_lookup, link) { + if (strncmp(app->stem, "pci-domain", 10) != 0) + continue; + + max_domain = max(max_domain, app->id); + } + mutex_unlock(&of_mutex); + + return max_domain; +} + +/** + * This function will try to obtain the host bridge domain number by + * using of_alias_get_id() call with "pci-domain" as a stem. If that + * fails, a local allocator will be used. The local allocator can + * be requested to return a new domain_nr if the information is missing + * from the device tree. + * + * @node: device tree node with the domain information + * @allocate_if_missing: if DT lacks information about the domain nr, + * allocate a new number. + * + * Returns the associated domain number from DT, or a new domain number + * if DT information is missing and @allocate_if_missing is true. If + * @allocate_if_missing is false then the last allocated domain number + * will be returned. + */ +int of_pci_get_domain_nr(struct device_node *node, bool allocate_if_missing) +{ + int domain; + + domain = atomic_read(&of_domain_nr); + if (of_domain_nr == -1) { + /* first run, get max defined domain nr in device tree */ + domain = of_get_max_pci_domain_nr(); + /* then set the start value for allocator to be max + 1 */ + atomic_set(&of_domain_nr, domain + 1); + } + domain = of_alias_get_id(node, "pci-domain"); + if (domain == -ENODEV) { + domain = atomic_read(&of_domain_nr); + if (allocate_if_missing) + atomic_inc(&of_domain_nr); + } + + return domain; +} +EXPORT_SYMBOL_GPL(of_pci_get_domain_nr); + #ifdef CONFIG_PCI_MSI static LIST_HEAD(of_pci_msi_chip_list); diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index dde3a4a..3a3824c 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h @@ -15,6 +15,7 @@ struct device_node *of_pci_find_child_device(struct device_node *parent, int of_pci_get_devfn(struct device_node *np); int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin); int of_pci_parse_bus_range(struct device_node *node, struct resource *res); +int of_pci_get_domain_nr(struct device_node *node, bool allocate_if_missing); #else static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq) { @@ -43,6 +44,12 @@ of_pci_parse_bus_range(struct device_node *node, struct resource *res) { return -EINVAL; } + +static inline int +of_pci_get_domain_nr(struct device_node *node, bool allocate_if_missing) +{ + return -1; +} #endif #if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI) -- 2.0.4