Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp797485pxu; Wed, 14 Oct 2020 14:08:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp6B0GIqJw47bS/3hFvOxdXHmFRthSoVnf26Dy0PosKiu75EX+lGSF+RHD9tfv0QRz1DNW X-Received: by 2002:a05:6402:1c04:: with SMTP id ck4mr961708edb.274.1602709731470; Wed, 14 Oct 2020 14:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602709731; cv=none; d=google.com; s=arc-20160816; b=Hk74OigKBJi4UMvLt0k2H6kHuO5q3dHJ3jobH0fSDzNi1qtby8WniDWaP9asxl4DNL m+8cmpOGkiYzZUcJFkE8rYR+BjhkuMfMd9vpJqO3nM34omH7on5lcn/A6olVrvCRPL0A vpvao63h9awjQind34az+ABK2azGqKsyWrE/5bNws6dOTAqKQrR0QolGyRxFLSach1MG bgKTlkdkyj/wYnq0Ky39wrrjLXhaVc9ndV25H8Pve6AgY4TO+dTw/26qUo3/+7Y79lHE dGS1EaqBhIsFKAvWvR2Pu6NMAgjpJYJa19w3qI+hsbqwGBaypHstM8sgk/t1/cIyteBh uiJw== 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=GGkragOBnacq4g0NQ/y7nkIbWl8rO39XOBnyzByRXkk=; b=HgpnEU0/zuEdPKk+S6O5zUnkcWP1OZgrtziNu1FJjHfLAqtE15U+Pdm34PoWMc4oc+ 0rTygALH9uPsLB850CI0CF9NydtGxiuEaVUYbVqdJC0CsfW+ZGcvYZeawzmEbePQxnU1 QKY1Iv1WGcPV44PqIL8FyDBk1hyEWXkSe7LRr1ba+6T+MoXS+zEHBvgtdmMUTL6PwyUR RuRS2Cqt1Y1dJvlITkPW9R+OPxLtXd1sHKXeuQ9ovE0fDd0/1PBM4/lUzsFm2mWgMqyb vi4vJLbyhHpk1M25PNdZ0Dbmeery9L2CIE2P1PCf11DpVX/aJ+HtcLaVociwKWx3gUbu Y8rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TMTgWqc2; 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 y2si449579edw.497.2020.10.14.14.08.29; Wed, 14 Oct 2020 14:08:51 -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=TMTgWqc2; 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 S1729162AbgJNMYr (ORCPT + 99 others); Wed, 14 Oct 2020 08:24:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:41594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729548AbgJNMYF (ORCPT ); Wed, 14 Oct 2020 08:24:05 -0400 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 DC8E12222A; Wed, 14 Oct 2020 12:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602678245; bh=t0IBPBNo+yYO11jhv9fM4cJG+wfMTFGo8MY5tqsXG5U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TMTgWqc23Fp8S68g+EvPHtyVYNZmNP+z9x9jAytDBLk4QMUzqVyPKEIwZja6i1w/V ybqg/7GHRaA/08pwv902eetV+9kH5fhw/n5TFlL5PPESAYu1KwG0J/AEdYl6TPgSYb anMWS3fr1jbXFcPH9vs8yiRtnplOtBuDc621PUqI= Received: by mail-ot1-f50.google.com with SMTP id f37so3180771otf.12; Wed, 14 Oct 2020 05:24:04 -0700 (PDT) X-Gm-Message-State: AOAM5314dnij2y7ClmZMfBfCnU3H0Ej6J9RI3/5ypa1/jjmDw0X1949U OMK39btaZloBuimwJB08pHZ6CMELi0ORKcuikw== X-Received: by 2002:a9d:5e14:: with SMTP id d20mr3002538oti.107.1602678244026; Wed, 14 Oct 2020 05:24:04 -0700 (PDT) MIME-Version: 1.0 References: <20201010151235.20585-1-nsaenzjulienne@suse.de> <20201010151235.20585-3-nsaenzjulienne@suse.de> <6740c49b73b11aaf1d74d216dc6e055e0a0ceac3.camel@suse.de> In-Reply-To: <6740c49b73b11aaf1d74d216dc6e055e0a0ceac3.camel@suse.de> From: Rob Herring Date: Wed, 14 Oct 2020 07:23:53 -0500 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: Catalin Marinas , Christoph Hellwig , Ard Biesheuvel , "linux-kernel@vger.kernel.org" , Frank Rowand , Robin Murphy , linux-arm-kernel , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" , Jeremy Linton , Linux IOMMU , devicetree@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2020 at 6:52 AM Nicolas Saenz Julienne wrote: > > Hi Rob, > > On Mon, 2020-10-12 at 10:25 -0500, Rob Herring wrote: > > On Sat, Oct 10, 2020 at 10:12 AM 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) > > > +{ > > > + struct device_node *np = NULL; > > > + struct of_range_parser parser; > > > + const __be32 *ranges = NULL; > > > + u64 phys_dma_limit = ~0ULL; > > > + 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; > > > > This doesn't work if you have more than one level of dma-ranges. The > > address has to be translated first. It should be okay to do that on > > the start or end address (if not, your DT is broken). > > for_each_of_range() calls of_pci_range_parser_one() which utimately populates > range.cpu_addr with of_translate_dma_address() results. Isn't that good enough? Indeed. I guess I was remembering the cases not using for_each_of_range which forgot to do that... Rob