From patchwork Tue Aug 12 16:25:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 35287 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1D016203C5 for ; Tue, 12 Aug 2014 16:26:58 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf45016694obc.4 for ; Tue, 12 Aug 2014 09:26:57 -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=55tGi6dNdogPzCDq7Fj3Ljw75kcNJec+sT75DCX0ra8=; b=QkQfU8dcRywNW4pIfLOl4oLfr579SrVcL8xml71PVzkQPOm4NmaiuQbBDdVziZo9G+ 9pXkFJPi2e+a2kLNl8fcMZnZo2bDPmvqyRdF12M5WVlNabcTLJs2N+UK8HpQKLBtpnDr gu9VQmufKbnRlq90XaZEcDCXd225rrzEv5VRSPVCjhFfpPMH8TiWyIqLyo9xnUCEToz8 RKkelm7Rfn9z1EX01KD8lxVgFb3XMlDL07JPkY07AcdzVbpFAmmMtgnskUrodzkcqXPp Ow8xwXGNGhqNiUNo4o2KRPLJtAsTc0/WapqBoXh2SZYwND/l3DTqu5nH+spTDoWcquwf +l6g== X-Gm-Message-State: ALoCoQmgVbpXXsbD8zv2Y2nAWtIstc17UvTLSLSZZoWIvyoIIJ5AATV1XN5ceUPe5qc8zdDqrgY1 X-Received: by 10.182.32.1 with SMTP id e1mr2942001obi.11.1407860817721; Tue, 12 Aug 2014 09:26:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.45 with SMTP id l42ls187414qga.61.gmail; Tue, 12 Aug 2014 09:26:57 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr5097549vcb.18.1407860817549; Tue, 12 Aug 2014 09:26:57 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id yi17si8520237vdb.55.2014.08.12.09.26.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Aug 2014 09:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so13359269vcb.5 for ; Tue, 12 Aug 2014 09:26:57 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr4810254vdb.27.1407860817430; Tue, 12 Aug 2014 09:26:57 -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.37.5 with SMTP id tc5csp262544vcb; Tue, 12 Aug 2014 09:26:56 -0700 (PDT) X-Received: by 10.70.90.237 with SMTP id bz13mr5241904pdb.110.1407860816423; Tue, 12 Aug 2014 09:26:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pj8si12835044pdb.54.2014.08.12.09.26.55 for ; Tue, 12 Aug 2014 09:26:56 -0700 (PDT) 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 S1753678AbaHLQ0x (ORCPT + 6 others); Tue, 12 Aug 2014 12:26:53 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:54724 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753065AbaHLQ0v (ORCPT ); Tue, 12 Aug 2014 12:26:51 -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 s7CGPPgd026280; Tue, 12 Aug 2014 17:25:28 +0100 From: Liviu Dudau To: Bjorn Helgaas , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Arnd Bergmann , Russell King , Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit , linux-pci Cc: linux-arch , LKML , Device Tree ML , LAKML Subject: [PATCH v9 09/12] OF: Introduce helper function for getting PCI domain_nr Date: Tue, 12 Aug 2014 17:25:22 +0100 Message-Id: <1407860725-25202-10-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1407860725-25202-1-git-send-email-Liviu.Dudau@arm.com> References: <1407860725-25202-1-git-send-email-Liviu.Dudau@arm.com> 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: 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.174 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 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)