From patchwork Fri Sep 27 00:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 174562 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2787779ill; Thu, 26 Sep 2019 17:25:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk5vhy5r8e8AdnvvF2rbFIN8tmURzNjUBsU9ENug0xGLSC6WucCz87zXhOLoSb7nCDurDU X-Received: by 2002:a17:906:c5b:: with SMTP id t27mr5503004ejf.180.1569543934014; Thu, 26 Sep 2019 17:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569543934; cv=none; d=google.com; s=arc-20160816; b=nznxymwLryi+qxdeSrhJoWwhLo1H0lZyCgX06nNuii31lFQx5QYmRizI3IivLOeffJ xNSrT4b5CXsil+SxzLma64EQ34fIVq5Q9liempTAjM/gZFLGY0upuMYtD2u2X6uwIjiz YFwz/s3x8oHD4FvDarYkfiNxQG35up0SuHVrc9vGByTVN9NcKaYbq94IAZE+K71iP9q7 pz44a4j5Qm7V1Su7/nXqziMrJRLVSMfjP1FZz2Gts8NfVR8fWq79nX8szxXV3vO3fqGb 1No5/FHhSArwMGPwBCQF0evJcltbwYrxhRmLWf58vM9Lxtu6eRp09EBt8j7qEE6JpQjv 3jIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+t0HPsSboHAO+BoQ/6wZRtvX50rdRybsdCc4k/BGGOU=; b=BvdGPw4SsFmcPyFsTKFukUZmaTcDtXwF8LlLMuZZdDvPSQxW6vyR2/M+MU5TgP/2xa 0VGaAgpoWG/k9KR6r8KnwdKcWqTSf/Q0zQp2APLqJVzlx1KLWHf8zksrbeGNZ/3CGZYZ rKAvyG+NC4iGs7rCxnpBEoUNmJNNunS1D+vM2vpPr0igbTHRDzoLeeIMrWP8PLQLpT6y cSVBTIExcu4AsUsPOHA/rMvfBhIu3G81XtdH3tZgMKaIJhm/Z/bmRkTA1YFc2M/RhzrG 48FbJy5Dvp8dRjQZLurBRWqNalRxqdQq0IizvG5td/+Vvb/dgRF7NiR1cdQb65h3uTVt o55w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si565704edh.242.2019.09.26.17.25.33; Thu, 26 Sep 2019 17:25:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728261AbfI0AZ3 (ORCPT + 8 others); Thu, 26 Sep 2019 20:25:29 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:40639 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbfI0AZL (ORCPT ); Thu, 26 Sep 2019 20:25:11 -0400 Received: by mail-ot1-f65.google.com with SMTP id y39so772543ota.7; Thu, 26 Sep 2019 17:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+t0HPsSboHAO+BoQ/6wZRtvX50rdRybsdCc4k/BGGOU=; b=Y2hs8wibHQWRr9khsCPMVE7x/hYmz8VyFMKZ7nsDW7EIqQ7FLtWyycylbMydY2OFwx Pdys6HOTJedGiOWVIt1qrvcRZniQPMhkminsdr3hZF0IOJ09Tc42bo7be1VJn0Co5eUX pWRbgyP/b4IUJWS92vjTzh0ubYwn/c4EN87ALJWhSeAFKTYV1rPEEBhDZkFCigjCAKLq BxApUizG0eaTvxc8xGbRKee0L5Xb0b7rZbcag6mWLMIY9O7fSZBw4m00kNdJ9pgOAIOD PvtYZE3xsca4YaRzP5yQh2XBW74ebhCI9kq5c55PPAfg5fo0kc4QaqjrMBqikEZsk0Te BT7A== X-Gm-Message-State: APjAAAWMH2ouL60j8rvfksR3DOLTw5q4EsclXPIgapS167oZhIn2X4um pm6eqnyUsRrgBl1uV3nvNv22SCY= X-Received: by 2002:a05:6830:4a5:: with SMTP id l5mr991746otd.150.1569543910071; Thu, 26 Sep 2019 17:25:10 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id j11sm339866otk.80.2019.09.26.17.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:09 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Robin Murphy , Florian Fainelli , Stefan Wahren , Frank Rowand , Arnd Bergmann , Marek Vasut , Geert Uytterhoeven , Simon Horman , Lorenzo Pieralisi , Oza Pawandeep Subject: [PATCH 09/11] of: Make of_dma_get_range() work on bus nodes Date: Thu, 26 Sep 2019 19:24:53 -0500 Message-Id: <20190927002455.13169-10-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190927002455.13169-1-robh@kernel.org> References: <20190927002455.13169-1-robh@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Robin Murphy Since the "dma-ranges" property is only valid for a node representing a bus, of_dma_get_range() currently assumes the node passed in is a leaf representing a device, and starts the walk from its parent. In cases like PCI host controllers on typical FDT systems, however, where the PCI endpoints are probed dynamically the initial leaf node represents the 'bus' itself, and this logic means we fail to consider any "dma-ranges" describing the host bridge itself. Rework the logic such that of_dma_get_range() works correctly starting from a bus node containing "dma-ranges". Signed-off-by: Robin Murphy [robh: Allow for the bus child node to still be passed in] Signed-off-by: Rob Herring --- drivers/of/address.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/drivers/of/address.c b/drivers/of/address.c index 887c0413f648..e918001c7798 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -922,18 +922,9 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz if (!node) return -EINVAL; - while (1) { - struct device_node *parent; - - naddr = of_n_addr_cells(node); - nsize = of_n_size_cells(node); - - parent = __of_get_dma_parent(node); - of_node_put(node); - - node = parent; - if (!node) - break; + while (node) { + naddr = of_bus_n_addr_cells(node); + nsize = of_bus_n_size_cells(node); ranges = of_get_property(node, "dma-ranges", &len); @@ -941,12 +932,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz if (ranges && len > 0) break; - /* - * At least empty ranges has to be defined for parent node if - * DMA is supported - */ - if (!ranges) - break; + node = of_get_next_dma_parent(node); } if (!ranges) { @@ -965,7 +951,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz * size : nsize cells */ dmaaddr = of_read_number(ranges, naddr); - *paddr = of_translate_dma_address(np, ranges); + *paddr = of_translate_dma_address(node, ranges + naddr); if (*paddr == OF_BAD_ADDR) { pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n", dmaaddr, np);