Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1708926pxb; Mon, 8 Mar 2021 04:36:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRxuzGL6eQ7Lj17RNuVYlnQeuQ4M2Bi55u0zS1qvYvFhJ2uZMB+fVH4lil6VVWDM8n/m1D X-Received: by 2002:aa7:c1d0:: with SMTP id d16mr21454976edp.153.1615206963385; Mon, 08 Mar 2021 04:36:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615206963; cv=none; d=google.com; s=arc-20160816; b=ljY0XHJaT4YYRntPu2+qeLrqpFsgFGU104RHk0KVK7M3W+hzdr9DLelHSrGaSXDKy5 gt1/6Gf7t1oNqep73YaZZdCDlizID8UY2ZCIAiAdNgTx7wleQ0x4x6GVTAGct3uVaCBg saGzV1Axk+wSrrlLfdkDMdfQA4xE4oQXDRLH0ztrG8INE5Au6cVE4bZFZ2SDplHQBrUh YDr5D/VgzPc8ThdLaqNwGhwdjsxkAWm2sRMofhBcuQYBlV7TKEfvubUS778kI6ybhcS7 phoe6dCJ65MGJjjVpiOumNLZYG+MRabQ/cQlPSTiyFv61u6kHMhTRK3COabbHz4oig5x z7BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fE5ueerfB64hTTuj5Z9a9leF/m8okB+GWtwK2Og0+8Y=; b=sh+fxjW2qhBaVpmtmaJzIT6GkkHU8OBXCBmLuHXX6xlXJ3KMnrjl4HleQGj8GrFLJr JAtPs6glGGAUxlh7Cf+f2fc7KwZHdLffqcWWe0E439vSQWEusAPxK2AkBkjXZ0bx9PLJ sItwfplfcG2Ee+qZHLE5QilSuH2Kkfd9JSXN9//oNwDFpGIrX9AB9GYEPTwkzpp2XF2W RWGW58qIBLfgT5AHs61A0bhHnrDQGgQpF2HsmGXWco6qcl+5MxuffbLEcJhguTT6Mwxs TTmGyHZ4Bg5vWVryVTk0qp8di8UKsM309qur1N5iEL6YgxsyNuMZ8Rg09Dt7F1P9eFDd L4Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hks8KXwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si3247413ejd.354.2021.03.08.04.35.40; Mon, 08 Mar 2021 04:36:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hks8KXwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbhCHMei (ORCPT + 99 others); Mon, 8 Mar 2021 07:34:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:42802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbhCHMeG (ORCPT ); Mon, 8 Mar 2021 07:34:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7631B651DC; Mon, 8 Mar 2021 12:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615206846; bh=8/sAaKwax+Ge2FF1sEl2qj5pzin6DpC3zaVom/++uhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hks8KXwzBiytI2jQLi6h6ciSkAQDqS4zsTrQ1CTjqNWxR/I8N78FRfrCrPtWKk0Ly FIOJ7yNZTUdaLNX9nL9CziptKbPuBmWxkp0E4r4vZBZG936oLiHR3iUQBalUvMuXcv MoeZEWJpRZ61/pcPO5qYKN0+QBM6Zit2IxlpsK4k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Saenz Julienne , Rob Herring , Catalin Marinas , Jing Xiangfeng Subject: [PATCH 5.10 26/42] of/address: Introduce of_dma_get_max_cpu_address() Date: Mon, 8 Mar 2021 13:30:52 +0100 Message-Id: <20210308122719.416632219@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210308122718.120213856@linuxfoundation.org> References: <20210308122718.120213856@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Saenz Julienne commit 964db79d6c186cc2ecc6ae46f98eed7e0ea8cf71 upstream Introduce of_dma_get_max_cpu_address(), which provides the highest CPU physical address addressable by all DMA masters in the system. It's specially useful for setting memory zones sizes at early boot time. Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20201119175400.9995-4-nsaenzjulienne@suse.de Signed-off-by: Catalin Marinas Cc: Signed-off-by: Jing Xiangfeng Signed-off-by: Greg Kroah-Hartman --- drivers/of/address.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 7 +++++++ 2 files changed, 49 insertions(+) --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -1025,6 +1025,48 @@ out: #endif /* CONFIG_HAS_DMA */ /** + * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA + * @np: The node to start searching from or NULL to start from the root + * + * Gets the highest CPU physical address that is addressable by all DMA masters + * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no + * DMA constrained device is found, it returns PHYS_ADDR_MAX. + */ +phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np) +{ + phys_addr_t max_cpu_addr = PHYS_ADDR_MAX; + struct of_range_parser parser; + phys_addr_t subtree_max_addr; + struct device_node *child; + struct of_range range; + const __be32 *ranges; + u64 cpu_end = 0; + int len; + + if (!np) + np = of_root; + + ranges = of_get_property(np, "dma-ranges", &len); + if (ranges && len) { + of_dma_range_parser_init(&parser, np); + for_each_of_range(&parser, &range) + if (range.cpu_addr + range.size > cpu_end) + cpu_end = range.cpu_addr + range.size - 1; + + if (max_cpu_addr > cpu_end) + max_cpu_addr = cpu_end; + } + + for_each_available_child_of_node(np, child) { + subtree_max_addr = of_dma_get_max_cpu_address(child); + if (max_cpu_addr > subtree_max_addr) + max_cpu_addr = subtree_max_addr; + } + + return max_cpu_addr; +} + +/** * of_dma_is_coherent - Check if device is coherent * @np: device node * --- a/include/linux/of.h +++ b/include/linux/of.h @@ -558,6 +558,8 @@ int of_map_id(struct device_node *np, u3 const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); +phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); + #else /* CONFIG_OF */ static inline void of_core_init(void) @@ -995,6 +997,11 @@ static inline int of_map_id(struct devic return -EINVAL; } +static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) +{ + return PHYS_ADDR_MAX; +} + #define of_match_ptr(_ptr) NULL #define of_match_node(_matches, _node) NULL #endif /* CONFIG_OF */