From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 586F5C433DF for ; Wed, 14 Oct 2020 12:24:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECC7420BED for ; Wed, 14 Oct 2020 12:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602678290; bh=t0IBPBNo+yYO11jhv9fM4cJG+wfMTFGo8MY5tqsXG5U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=JqJhgNoP2kusOiIw3gg5K1JkdzFJH7qPpscB/maOl92H+SbEj6bP3CV7gWGnrcreC QwPtK5IwadE9p7Q17uQqwMlbuADMi6wGV7Vov6ZQ5cFUFMo9dYFH174Kwm5BIICqdY 6HlIyv22XuBv043faTWCZWcZVY+NJXCFP+Y3Qg6A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729858AbgJNMYr (ORCPT ); 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-Google-Smtp-Source: ABdhPJy9xd9p7AIQ89atOIFtAtTvVkcZBoUqHoM2d76WPGxs9lK5Ru8GlYDbiDS8fYIzTNRaOfPecpecUgbDqkGL+7A= 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A424DC433E7 for ; Wed, 14 Oct 2020 12:24:10 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC05A20BED for ; Wed, 14 Oct 2020 12:24:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="TMTgWqc2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC05A20BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2EAF020412; Wed, 14 Oct 2020 12:24:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gpdGSPF4SM7P; Wed, 14 Oct 2020 12:24:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id E72DD2036C; Wed, 14 Oct 2020 12:24:07 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C9D39C0052; Wed, 14 Oct 2020 12:24:07 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id C2122C0051 for ; Wed, 14 Oct 2020 12:24:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B464E20412 for ; Wed, 14 Oct 2020 12:24:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B5mkxyRS-lFB for ; Wed, 14 Oct 2020 12:24:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by silver.osuosl.org (Postfix) with ESMTPS id 8941A2036C for ; Wed, 14 Oct 2020 12:24:05 +0000 (UTC) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 D644022203 for ; 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-f43.google.com with SMTP id f10so3214810otb.6 for ; Wed, 14 Oct 2020 05:24:04 -0700 (PDT) X-Gm-Message-State: AOAM5327vr9IbzaH++sPCehAYxVxm2c0d0jn2o1roQA8v+q7Q6dDsLl0 MzLJi8MTkKpZcQrN5v29/1TW0wb/0nyq5PvuZg== X-Google-Smtp-Source: ABdhPJy9xd9p7AIQ89atOIFtAtTvVkcZBoUqHoM2d76WPGxs9lK5Ru8GlYDbiDS8fYIzTNRaOfPecpecUgbDqkGL+7A= 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: devicetree@vger.kernel.org, Frank Rowand , Catalin Marinas , "linux-kernel@vger.kernel.org" , Jeremy Linton , Ard Biesheuvel , Linux IOMMU , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" , Robin Murphy , Christoph Hellwig , linux-arm-kernel X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A8A4C433E7 for ; Wed, 14 Oct 2020 12:25:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA30F20848 for ; Wed, 14 Oct 2020 12:25:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="C+RrQERb"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="TMTgWqc2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA30F20848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OlArfnbbymY8cxG3VayFV3oM7jaGPY68uMKamdVGluo=; b=C+RrQERb8o+TYsPDJ2Da2n5+6 7V/1l6/8teejb4efZCFze+LUvU/p7K+1CLjeJ5ySTaZyZ9hE69yOvoVk6Fa8+xjzQ2DeG1Wf3IlGP CJh59kn7Cn3C1+foijt4gGHyJX883p7wG+8SsiNyPWcTJImguZqkb1Sf2C1soSgTHM6yg3ImFtjie 8zRYb8UbbOWyXOHHqR45AjDwjrDS8Ar0rFvTtcn30PBKrkMODN+t5clDjwzzxagP4GPBO2FmEd4eF M+w/6paKR7azvxMxw8soBcETI4cHZCbfAQRehH5b9nlw9DryQeosmkoYukH54w+5dQ9C3gnpUwZgo k13FJ/+hQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSfpB-0004IO-9V; Wed, 14 Oct 2020 12:24:09 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSfp8-0004HM-Tp; Wed, 14 Oct 2020 12:24:07 +0000 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 D3D2222201; 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-f43.google.com with SMTP id n61so3176588ota.10; Wed, 14 Oct 2020 05:24:04 -0700 (PDT) X-Gm-Message-State: AOAM5333gbYwbz44kYa1aB1D+DCX78XBXuc7wwakxMYytjfrvqyTiNlg 6qm3/b0zBtuEzVaPdV4uvE5K4UaiS5EUM1/WXw== X-Google-Smtp-Source: ABdhPJy9xd9p7AIQ89atOIFtAtTvVkcZBoUqHoM2d76WPGxs9lK5Ru8GlYDbiDS8fYIzTNRaOfPecpecUgbDqkGL+7A= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201014_082407_115411_343D2256 X-CRM114-Status: GOOD ( 28.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Frank Rowand , Catalin Marinas , "linux-kernel@vger.kernel.org" , Jeremy Linton , Ard Biesheuvel , Linux IOMMU , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" , Robin Murphy , Christoph Hellwig , linux-arm-kernel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel