Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp772218lqt; Fri, 19 Apr 2024 09:55:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGKs3afd6J1cLZan4g+ud010y5JSSqUsBAyBU6W1+7UN+iZTO8s1jbD+kSuj6ynXInHsEbmos63u+g5LCzAJXkR6VJgOJhlAcTocx0bA== X-Google-Smtp-Source: AGHT+IEruLJ4/13Zl4BdJhI6zqGcizjskw6F+jQxpiYmATGPiAmQIDAArNpS07ya/NN2eNISkZtG X-Received: by 2002:a17:906:39c1:b0:a46:3ce4:5acb with SMTP id i1-20020a17090639c100b00a463ce45acbmr1938626eje.75.1713545739237; Fri, 19 Apr 2024 09:55:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713545739; cv=pass; d=google.com; s=arc-20160816; b=Xz6QNbevEnRgjB5KKxljIvY5wjmZKK4TZIb8D3PXmS+kvwJRdBSoQBvBcJtGq34CJr tgbMP5tJ4724POdd2xsMhHyBX2XoG9UxlcGQorH4hnxdEGavmcsMBEIQgyvYnbTuFX3I Oe/qhQpv1m8JomEgXGePve4YhdaXO0nTKEvA8PacFvqblk6VCtkW112DvNipBqdDZEQO UC1IPZjmsOge4EVWCS8ywrLt0ToFS/mkgWx1eNGlkwgZ575/AaN6F6Ud/Maz58bKGSo0 1rPEcGBMPMIEMltFDI914wNb21q7uBa0mLHlP9pXOfrWzQha51zK3P/DhP+5b2rdmwGg Jpbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=pfeUXw+IXP+I3UVG2ii+itrHqgDTs/CpdRW5iE0+swg=; fh=GJ1PANsXexk7H82iWwbLkoddLQ1QGjX0jddvZkCL7kQ=; b=e2+PGtc0dK2GgmXMBvoL/96MMglwohs+VLi3SCanFW5fsH8v60d7BK7PTe5dhNz2cy iRA94jISNoK1bPc2OT2hlvK8xCuENwGKXhdbqg7X614OPLgLWWPjm73r75WSyMxl5RPU OOIdNihBZHFlhRKBIWIcUjZoglpyAuQxXZ80aApc9o2DwrqfBtAWNvY6ChY4nxDWbjbv CRUut0e9mX1FhCc7vHQVvEBQlNAHAOaNQpzdqD2I2LR7ezwIXTCgRvTlAX0U2nLTeP2G oreq2OUZRt6GQO9+owssT9PdQZhe1LVy4pMeelCFKeEZ0CFQ1FDpeAfweHLWWBUGqEFL hDAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-151786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hs40-20020a1709073ea800b00a5220605595si2501249ejc.571.2024.04.19.09.55.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 09:55:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-151786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E6FA91F234F6 for ; Fri, 19 Apr 2024 16:55:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31EA3137927; Fri, 19 Apr 2024 16:55:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36848137920; Fri, 19 Apr 2024 16:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713545715; cv=none; b=skGtbvhLsWEJoOJzXgeRc5Vn3tnUSjiyLKcKgn4Y64iUGvhap5sFpIsg1rE6HM1KuNBcLFBaVIlhHWlzPq4vnjWerMf3DPSacS44q+HtvhCMFSZwDgvM8bNEDU/5X4WXswyXX0EwO0xR9OdvoXhCUUTBGgPJIOIma1r58inn36w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713545715; c=relaxed/simple; bh=pOu8SkBP1o2YI89QRW9IkEizSqtcRRWP9wRbqkcsIYk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hJjZO5Dr8FClb481XaoMGCZCfnGNTrbs+Hh7t1HO/0UQphrF83iJRwB3Xx4DdXKsQ6xjWtEcZW6r6jwqBBpBdLc5egzLm8A0oiZcp/M3f/M0lkF7KPmgvr9RgLQ6qbegrYn4T5pVneIUQuVIBPd1tK566RRA4NGdRGHCBdaHBb8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 01596106F; Fri, 19 Apr 2024 09:55:42 -0700 (PDT) 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 C13D73F792; Fri, 19 Apr 2024 09:55:08 -0700 (PDT) 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 v4 2/7] OF: Simplify DMA range calculations Date: Fri, 19 Apr 2024 17:54:41 +0100 Message-Id: <3e0a72fe3d79eae660e4284bb32f2cb39868ccd7.1713523152.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 a988bee2ee5a..841ccd3a19d1 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -96,7 +96,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 iommu_ret; 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; @@ -185,7 +182,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, } else dev_dbg(dev, "device is behind an iommu\n"); - arch_setup_dma_ops(dev, dma_start, size, coherent); + arch_setup_dma_ops(dev, dma_start, end - dma_start + 1, coherent); if (iommu_ret) of_dma_set_restricted_buffer(dev, np); -- 2.39.2.101.g768bb238c484.dirty