From patchwork Tue Jul 1 18:43: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: 32930 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1BF55203C0 for ; Tue, 1 Jul 2014 18:46:10 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id tr6sf62255607ieb.7 for ; Tue, 01 Jul 2014 11:46:09 -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:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=3QhfyLVlXGi9gVIh2Qe81ZqHUQce6kFH6X9pQC/n/Sg=; b=BnD9ClOOUy1VBmHFOG9Vso5zP9k91QsORURweUSZIKYQQXaCeusQq3hGadbqIE3+q+ OgK6BkSkJq5VV2T9o7+M/raCZr+1U1SVAha/biBm/ASXaLNHMj8T6yikzvhjN78FHwD5 UBlofFCocBVB1AlFKrFv7xZpgFT/zBPAOG+pSHr6WwupPvbamFL/pMklA4uo8EJtJztB RegOnpQxWgIt8N8i0aq8SB4phIpbfZZ09Hq6d+bhUirHJ0HzSWEtdWsDA5BUt9Ztxjea p+H1KwxoH3dEkpipWS945lqItYGx7q/o0RNP4wzHAOj3htFGVBtuI0Pm6c8fn0OpdyHV MUxg== X-Gm-Message-State: ALoCoQkxhGrkZXIcce93GLi3/gTplpcsmCoYszycnszLGlnaEzHKBpxJ+ljY4XO0rKw9SxlKORvZ X-Received: by 10.50.98.69 with SMTP id eg5mr19997814igb.7.1404240369282; Tue, 01 Jul 2014 11:46:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.168 with SMTP id h37ls674902qgd.62.gmail; Tue, 01 Jul 2014 11:46:09 -0700 (PDT) X-Received: by 10.220.183.4 with SMTP id ce4mr1948429vcb.54.1404240369114; Tue, 01 Jul 2014 11:46:09 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id pz3si11791394vec.56.2014.07.01.11.46.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Jul 2014 11:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hy4so9403189vcb.34 for ; Tue, 01 Jul 2014 11:46:09 -0700 (PDT) X-Received: by 10.58.29.164 with SMTP id l4mr44846465veh.8.1404240369005; Tue, 01 Jul 2014 11:46:09 -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 tc5csp236990vcb; Tue, 1 Jul 2014 11:46:08 -0700 (PDT) X-Received: by 10.68.211.164 with SMTP id nd4mr64109425pbc.44.1404240368078; Tue, 01 Jul 2014 11:46:08 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id rb7si27870014pbb.89.2014.07.01.11.46.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Jul 2014 11:46:08 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2332-0006uv-Hl; Tue, 01 Jul 2014 18:44:56 +0000 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X232S-0006as-5g for linux-arm-kernel@lists.infradead.org; Tue, 01 Jul 2014 18:44:22 +0000 Received: from e106497-lin.cambridge.arm.com (e106497-lin.cambridge.arm.com [10.1.195.170]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s61IhYJY027921; Tue, 1 Jul 2014 19:43:38 +0100 From: Liviu Dudau To: linux-pci , Bjorn Helgaas , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Arnd Bergmann , linaro-kernel , Tanmay Inamdar , Grant Likely , Sinan Kaya , Jingoo Han , Kukjin Kim , Suravee Suthikulanit Subject: [PATCH v8 4/9] pci: OF: Fix the conversion of IO ranges into IO resources. Date: Tue, 1 Jul 2014 19:43:29 +0100 Message-Id: <1404240214-9804-5-git-send-email-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1404240214-9804-1-git-send-email-Liviu.Dudau@arm.com> References: <1404240214-9804-1-git-send-email-Liviu.Dudau@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140701_114420_596896_2298B50D X-CRM114-Status: GOOD ( 15.49 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [217.140.96.21 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Device Tree ML , LKML , LAKML X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.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.175 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 The ranges property for a host bridge controller in DT describes the mapping between the PCI bus address and the CPU physical address. The resources framework however expects that the IO resources start at a pseudo "port" address 0 (zero) and have a maximum size of IO_SPACE_LIMIT. The conversion from pci ranges to resources failed to take that into account. In the process move the function into drivers/of/address.c as it now depends on pci_address_to_pio() code and make it return an error message. Signed-off-by: Liviu Dudau Tested-by: Tanmay Inamdar --- drivers/of/address.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_address.h | 13 ++----------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 1345733..cbbaed2 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -872,3 +872,50 @@ bool of_dma_is_coherent(struct device_node *np) return false; } EXPORT_SYMBOL_GPL(of_dma_is_coherent); + +/* + * of_pci_range_to_resource - Create a resource from an of_pci_range + * @range: the PCI range that describes the resource + * @np: device node where the range belongs to + * @res: pointer to a valid resource that will be updated to + * reflect the values contained in the range. + * + * Returns EINVAL if the range cannot be converted to resource. + * + * Note that if the range is an IO range, the resource will be converted + * using pci_address_to_pio() which can fail if it is called too early or + * if the range cannot be matched to any host bridge IO space (our case here). + * To guard against that we try to register the IO range first. + * If that fails we know that pci_address_to_pio() will do too. + */ +int of_pci_range_to_resource(struct of_pci_range *range, + struct device_node *np, struct resource *res) +{ + int err; + res->flags = range->flags; + res->parent = res->child = res->sibling = NULL; + res->name = np->full_name; + + if (res->flags & IORESOURCE_IO) { + unsigned long port = -1; + err = pci_register_io_range(range->cpu_addr, range->size); + if (err) + goto invalid_range; + port = pci_address_to_pio(range->cpu_addr); + if (port == (unsigned long)-1) { + err = -EINVAL; + goto invalid_range; + } + res->start = port; + } else { + res->start = range->cpu_addr; + } + res->end = res->start + range->size - 1; + return 0; + +invalid_range: + res->start = (resource_size_t)OF_BAD_ADDR; + res->end = (resource_size_t)OF_BAD_ADDR; + return err; +} + diff --git a/include/linux/of_address.h b/include/linux/of_address.h index ac4aac4..33c0420 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -23,17 +23,8 @@ struct of_pci_range { #define for_each_of_pci_range(parser, range) \ for (; of_pci_range_parser_one(parser, range);) -static inline void of_pci_range_to_resource(struct of_pci_range *range, - struct device_node *np, - struct resource *res) -{ - res->flags = range->flags; - res->start = range->cpu_addr; - res->end = range->cpu_addr + range->size - 1; - res->parent = res->child = res->sibling = NULL; - res->name = np->full_name; -} - +extern int of_pci_range_to_resource(struct of_pci_range *range, + struct device_node *np, struct resource *res); /* Translate a DMA address from device space to CPU space */ extern u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr);