From patchwork Mon Sep 8 13:54:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 36988 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1D4CA2054D for ; Mon, 8 Sep 2014 14:06:41 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id uq10sf71188332igb.7 for ; Mon, 08 Sep 2014 07:06:40 -0700 (PDT) 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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=s0yeJIYOdgYNBlri/beSV2vidKhggtQN/dSJwHzOiZY=; b=IGKw7kjH9t8nY4rqEsQkFgsw5ewk+yaoXirg0qlAyr/XQLYZM1vFacEYRt31Axviea hYY7r1BLuDdcZh93OuYD6mtNj0uestanOMmcUXlxthuwJ5P7JaAUDn4yCU0R2jOrCwbm 4nVaChtkWPZd02TbBuhm6MD4nrF8lIVrrRTb8Yy54hB+QGVYuDJp8nnW/4h9VCelHm+1 R9O3rLSRgSwHIJUMljnyWJ4OVvaRe3eF64OqRLU/aB8iE+WOEONKJ7Z/ZdoG5VJpVi5D HzjDSsQPmDdGTzjGz8jwx6Xb8oXa4C+1QdhLJw5FKOP3msdKhBWqiGKJrLv0LoMcU/y2 KU6w== X-Gm-Message-State: ALoCoQk1+5CI3kmV47azoR3CaUsuSL827HYXnN2bB8jtsF0XRN+M1KgF27z2BPLLdnsccz/o9+Lf X-Received: by 10.50.57.111 with SMTP id h15mr12873733igq.3.1410185200678; Mon, 08 Sep 2014 07:06:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.181 with SMTP id e50ls257680qga.20.gmail; Mon, 08 Sep 2014 07:06:40 -0700 (PDT) X-Received: by 10.220.169.72 with SMTP id x8mr853017vcy.45.1410185200511; Mon, 08 Sep 2014 07:06:40 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sq9si4500983vdb.90.2014.09.08.07.06.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Sep 2014 07:06:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hy4so829149vcb.1 for ; Mon, 08 Sep 2014 07:06:40 -0700 (PDT) X-Received: by 10.220.88.76 with SMTP id z12mr9684326vcl.14.1410185200365; Mon, 08 Sep 2014 07:06:40 -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 uj3csp139250vcb; Mon, 8 Sep 2014 07:06:39 -0700 (PDT) X-Received: by 10.66.191.230 with SMTP id hb6mr2301213pac.72.1410185199395; Mon, 08 Sep 2014 07:06:39 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id er15si15294870pad.86.2014.09.08.07.06.38 for ; Mon, 08 Sep 2014 07:06:39 -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 S1754195AbaIHOGM (ORCPT + 26 others); Mon, 8 Sep 2014 10:06:12 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:54150 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753947AbaIHOGJ (ORCPT ); Mon, 8 Sep 2014 10:06:09 -0400 Received: from e106497-lin.cambridge.arm.com (e106497-lin.cambridge.arm.com [10.1.195.53]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s88DsW8K017520; Mon, 8 Sep 2014 14:54:35 +0100 From: Liviu Dudau To: Bjorn Helgaas , Arnd Bergmann , Rob Herring , Jason Gunthorpe , Benjamin Herrenschmidt , Catalin Marinas , Will Deacon , Russell King , linux-pci , Linus Walleij Cc: Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit , linux-arch , LKML , Device Tree ML , LAKML , Grant Likely Subject: [PATCH v10 07/10] OF: Introduce helper function for getting PCI domain_nr Date: Mon, 8 Sep 2014 14:54:29 +0100 Message-Id: <1410184472-17630-8-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1410184472-17630-1-git-send-email-Liviu.Dudau@arm.com> References: <1410184472-17630-1-git-send-email-Liviu.Dudau@arm.com> 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.170 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: , 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); + } + + 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)