Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3475236pxu; Sun, 11 Oct 2020 11:01:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkb/7nQpSBnOPSZVBpJJ4SnlMAICeJ4g/3knUNGcBkpmeJmfK8LNxC5nLTuHTeRFy938dZ X-Received: by 2002:a05:6402:74f:: with SMTP id p15mr10379777edy.69.1602439290454; Sun, 11 Oct 2020 11:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602439290; cv=none; d=google.com; s=arc-20160816; b=LNR1VzFmNB7szGia4XAJ5lrLNoD9h4gIW/uB0mOjscBvbnMCbB6OicUSdLt2EuEg2M Vt+FERueWm0mI7hahfqTZ09o6M+yLbabyjgTESEnI3KDvOHx7VCFR9crjbC9aa6hvFtA LtaDr0Xhr5zfYdgZu1hsxSY8uFyOzrRNKQ07HmPwS2HJfNTS7gD2zzp0rLC8d76lRXRK ELf8FY8AwNskTblBgGGmJTVYu21P4FTbDd4vuSGT26xgqPn/4PBuey+uKpymK/0IW2sh Zu31hO6yhZhQRaJ0hJXpEgYaCag/orV0O3UQAeCU0Cjlk8IIxqpVJrzdNuQLasqvhUvS vGLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UIVQbW5cVHt/peq9z2cstVj39ZrDBcXCXIxGxFI2LGs=; b=CYHxDOmP1v/KInLzzvIXqlCghJuZ7CJsrLSkrUlJ5VUDU87h+m2t51T83qwR+POwyw DhkWtw6KyKOO3cfAxL9neU7m0M09OaXQEvL+6b1oKdD5Kzl6PiwZlvlFNh1ZrjeoxK2l G1gX50MuqoJHULIaCyngq4HJqEAM/c1mHAwqIa7X8izte60lS1OpOn/wY5cvWeCg//VU zCCnfqWqXt0fALb1pqlZVKimZdYI9Gi4v40hqI69F5ATJppOCjlU6Jk1foNUcTXEBfw0 G1japnwx3proyQAbZaKvVOzaTFzZQjGSP4Ns4dYYRFsdGF+Jh9pLUdWCLoGvskFWcc5W Rc8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="v/c/sPXg"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da5si13441647edb.344.2020.10.11.11.01.07; Sun, 11 Oct 2020 11:01:30 -0700 (PDT) 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=@kernel.org header.s=default header.b="v/c/sPXg"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729014AbgJKHrT (ORCPT + 99 others); Sun, 11 Oct 2020 03:47:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbgJKHrT (ORCPT ); Sun, 11 Oct 2020 03:47:19 -0400 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4E90721655; Sun, 11 Oct 2020 07:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602402438; bh=LeMk4xJlrd34ez5NF8BLWNvKsm7wmDmT9qOElPmUWJE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=v/c/sPXgnEOq4jJilWSpg55W4tKtlomIYm1wAbddQ2HT95xbpKy1cqZuTe19B0HXa vXtH1ypj1myh2B5wxSb07CcHyn/W0XRokJ8BC/2+18WZAtTserlel3yq1lSoDlkCya siAgTAnuorrjI5JTy0j7BmFwcMGRtGYCNnXGXOu4= Received: by mail-oi1-f176.google.com with SMTP id c13so15217421oiy.6; Sun, 11 Oct 2020 00:47:18 -0700 (PDT) X-Gm-Message-State: AOAM5316OYFJQBItAJwUum5moAVDWxtXLuNal9MS+I6KNN8Ah4O+7iFF Bj1ZblS/5FRRyY3AZCzLNVYhMmOzRagb0zZQMkw= X-Received: by 2002:aca:d845:: with SMTP id p66mr7029591oig.47.1602402437582; Sun, 11 Oct 2020 00:47:17 -0700 (PDT) MIME-Version: 1.0 References: <20201010151235.20585-1-nsaenzjulienne@suse.de> <20201010151235.20585-3-nsaenzjulienne@suse.de> In-Reply-To: <20201010151235.20585-3-nsaenzjulienne@suse.de> From: Ard Biesheuvel Date: Sun, 11 Oct 2020 09:47:06 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/5] of/address: Introduce of_dma_lower_bus_limit() To: Nicolas Saenz Julienne Cc: Rob Herring , Catalin Marinas , Christoph Hellwig , Linux Kernel Mailing List , Frank Rowand , Robin Murphy , Linux ARM , linux-rpi-kernel@lists.infradead.org, Jeremy Linton , iommu@lists.linux-foundation.org, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nicolas, $SUBJECT is out of sync with the patch below. Also, for legibility, it helps if the commit log is intelligible by itself, rather than relying on $SUBJECT being the first line of the first paragraph. On Sat, 10 Oct 2020 at 17:12, Nicolas Saenz Julienne wrote: > > The function provides the CPU physical address addressable by the most > constrained bus in the system. It might be useful in order to > dynamically set up memory zones during boot. > > Signed-off-by: Nicolas Saenz Julienne > --- > drivers/of/address.c | 34 ++++++++++++++++++++++++++++++++++ > include/linux/of.h | 7 +++++++ > 2 files changed, 41 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index eb9ab4f1e80b..755e97b65096 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -1024,6 +1024,40 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) > } > #endif /* CONFIG_HAS_DMA */ > > +/** > + * of_dma_safe_phys_limit - Get system wide DMA safe address space > + * > + * Gets the CPU physical address limit for safe DMA addressing system wide by > + * searching for the most constraining dma-range. Otherwise it returns ~0ULL. > + */ > +u64 __init of_dma_safe_phys_limit(void) I don't think 'safe' strikes the right tone here. You are looking for the highest CPU address that is addressable by all DMA masters in the system. Something like of_dma_get_max_cpu_address(void) perhaps? Also, since this is generic code, phys_addr_t is probably a better type to return. > +{ > + struct device_node *np = NULL; > + struct of_range_parser parser; > + const __be32 *ranges = NULL; I think you can drop these NULL initializers. > + u64 phys_dma_limit = ~0ULL; PHYS_ADDR_MAX > + struct of_range range; > + int len; > + > + for_each_of_allnodes(np) { > + dma_addr_t cpu_end = 0; > + > + ranges = of_get_property(np, "dma-ranges", &len); > + if (!ranges || !len) > + continue; > + > + 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; > + > + if (phys_dma_limit > cpu_end) > + phys_dma_limit = cpu_end; > + } > + > + return phys_dma_limit; > +} > + > /** > * of_dma_is_coherent - Check if device is coherent > * @np: device node > diff --git a/include/linux/of.h b/include/linux/of.h > index 481ec0467285..958c64cffa92 100644 > --- a/include/linux/of.h > +++ b/include/linux/of.h > @@ -558,6 +558,8 @@ int of_map_id(struct device_node *np, u32 id, > const char *map_name, const char *map_mask_name, > struct device_node **target, u32 *id_out); > > +u64 of_dma_safe_phys_limit(void); > + > #else /* CONFIG_OF */ > > static inline void of_core_init(void) > @@ -995,6 +997,11 @@ static inline int of_map_id(struct device_node *np, u32 id, > return -EINVAL; > } > > +static inline u64 of_dma_safe_phys_limit(void) > +{ > + return ~0ULL; > +} > + > #define of_match_ptr(_ptr) NULL > #define of_match_node(_matches, _node) NULL > #endif /* CONFIG_OF */ > -- > 2.28.0 >