Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5464674rdb; Wed, 13 Dec 2023 09:18:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCnP3SBIIpQ256uf7efZMdSY+EUWeqcSseZR21IXAWZx/Wjzv4+oDBIpH9M+Jkf6/CiM1i X-Received: by 2002:a17:902:e88f:b0:1d0:8876:7078 with SMTP id w15-20020a170902e88f00b001d088767078mr5059467plg.44.1702487928042; Wed, 13 Dec 2023 09:18:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702487928; cv=none; d=google.com; s=arc-20160816; b=Odxgg9CXBRNCd+2dWilvhwZmUMkI2usoW1YKE1LqFZeidzDzE5hhzVnYKL0uUUJwGH FwQhp0Uf5VZseg2clLd+XZXg3bX6ekz36JU/+L+zn1qigV4Mg1e/66dYi+hDcVMZpebS VVGiK9ZyJ5AYEBF/L3omzYOciH4X+jaV0sKNSuPrZWusutuYlHNUfra7lDeT9BVA463l k2pC07W5g9fnern+5SxDS7qQAJewOGyO8JKcrPtVYK1+Md8Vfs36wq2DNp1uvc3woi37 x/mAfkLXRcbTBmeAno4kVQ7E0Iaj5aGAWr32g9s29Zf5lxqE+BfSmVaKFzYsIAQ+VqsJ pRXw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iQiTMx3J3cLOCsOlaKLL/b2Z1rii2peq4fKUzFDBlM4=; fh=GJ1PANsXexk7H82iWwbLkoddLQ1QGjX0jddvZkCL7kQ=; b=p81RU8qVxoKYkSZrRIm091ljpFIcgZHhm6lLmYPByhQ6Yng7CQVn5AkfLUuGmPPXmL kxyUk0+6N7416RBMAqM4jZOIRo8knx/IP9Z42dLVVkcJzQc1ap+hCYkfs5gHZMe/QQ5V v1aDxYl/2PaA4wRtqzeH92MVVp6amBiZrUcfWEmUlaGn7dquikR3PmK5rYiYzHArZy0Q iy45FBWIWm2O5cO48xdy6YVmVZuRzzpPDGMXKujZDNWq1xPvVf9vvafYDqqkPdbCQszj 6y8wVQEVW/pERW8SFZhqRve3iokl+vmNSJFeSIob4GBxA602HAfhgNG0BKyk+WHLgpic O5nQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y8-20020a17090322c800b001d33c67dc76si2853558plg.249.2023.12.13.09.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 09:18:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9359E827AC92; Wed, 13 Dec 2023 09:18:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379094AbjLMRS1 (ORCPT + 99 others); Wed, 13 Dec 2023 12:18:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235522AbjLMRSZ (ORCPT ); Wed, 13 Dec 2023 12:18:25 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B6EAAB; Wed, 13 Dec 2023 09:18:30 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E9621576; Wed, 13 Dec 2023 09:19:16 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B3323F762; Wed, 13 Dec 2023 09:18:26 -0800 (PST) From: Robin Murphy To: Joerg Roedel , Christoph Hellwig Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Rob Herring , Jason Gunthorpe Subject: [PATCH v2 2/7] OF: Simplify DMA range calculations Date: Wed, 13 Dec 2023 17:17:55 +0000 Message-Id: <368a546e36235bd0008f66838d0c8edcd864ab94.1702486837.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 09:18:42 -0800 (PST) Juggling start, end, and size values for a range is somewhat redundant and a little hard to follow. Consolidate down to just using inclusive start and end, which saves us worrying about size overflows for full 64-bit ranges (note that passing a potentially-overflowed value through to arch_setup_dma_ops() is benign for all current implementations, and this is working towards removing that anyway). Acked-by: Rob Herring Reviewed-by: Jason Gunthorpe Signed-off-by: Robin Murphy --- drivers/of/device.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 526a42cdf66e..51062a831970 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -97,7 +97,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, const struct bus_dma_region *map = NULL; struct device_node *bus_np; u64 dma_start = 0; - u64 mask, end, size = 0; + u64 mask, end = 0; bool coherent; int ret; @@ -118,17 +118,15 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, return ret == -ENODEV ? 0 : ret; } else { const struct bus_dma_region *r = map; - u64 dma_end = 0; /* Determine the overall bounds of all DMA regions */ for (dma_start = ~0; r->size; r++) { /* Take lower and upper limits */ if (r->dma_start < dma_start) dma_start = r->dma_start; - if (r->dma_start + r->size > dma_end) - dma_end = r->dma_start + r->size; + if (r->dma_start + r->size > end) + end = r->dma_start + r->size; } - size = dma_end - dma_start; } /* @@ -142,16 +140,15 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, dev->dma_mask = &dev->coherent_dma_mask; } - if (!size && dev->coherent_dma_mask) - size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); - else if (!size) - size = 1ULL << 32; + if (!end && dev->coherent_dma_mask) + end = dev->coherent_dma_mask; + else if (!end) + end = (1ULL << 32) - 1; /* * Limit coherent and dma mask based on size and default mask * set by the driver. */ - end = dma_start + size - 1; mask = DMA_BIT_MASK(ilog2(end) + 1); dev->coherent_dma_mask &= mask; *dev->dma_mask &= mask; @@ -177,7 +174,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, dev_dbg(dev, "device is%sbehind an iommu\n", iommu ? " " : " not "); - arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); + arch_setup_dma_ops(dev, dma_start, end - dma_start + 1, iommu, coherent); if (!iommu) of_dma_set_restricted_buffer(dev, np); -- 2.39.2.101.g768bb238c484.dirty