From patchwork Fri Feb 9 16:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp985517dyd; Fri, 9 Feb 2024 08:55:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvQSTzVp75W3fWz+3HO+TAVcbfUQbY0v/TzihvziX79whUQWQbtEVPCZHCHY7It7fcO8ktLvxHtX1woKrx5Lvj32y7Qw== X-Google-Smtp-Source: AGHT+IG07Vgq4Fl/MF2wudeF1KIwwYBGSD3wcApfTBxc6RXqbO47CWFmC6u+snGKublILuLV3gEP X-Received: by 2002:a17:906:d97c:b0:a38:80a3:6692 with SMTP id rp28-20020a170906d97c00b00a3880a36692mr1617005ejb.30.1707497724150; Fri, 09 Feb 2024 08:55:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497724; cv=pass; d=google.com; s=arc-20160816; b=DC+GpK7jIZ0SBp5w2ZYaxxoUj3fAwrjHvYdz6wN8zvqYt7wKvVtjCbNzNAfSiv1Yqi 7WGBFa2GLJiMeK97sYPo5mwiIiS7IbreZnyaRz/xREL5mS7s2JOkY7Buef6NLmgfRdcM ti7nhn9Jsg9QwDrgtlpJrIIgp2tftn87TgcYgApYbxXYNx5Pmig3dFCSkRI3PWmmiqMv nR0Ik6IxDvNn3ArOqr/yFYzHGZZrUJaBE4lrwA73henKuS1JgR3mxz2NCMbLns1TWvQB a7tdpowvy9DS5Hd9Gp1K7sF+rbiOu0Z3dF7z6jfcEBTXk+J4LPMJjCEq8are9AxpwwqI FP4w== 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=/VBm/t2YxLowDtqQrVicaYZvuFQ4q3qypObbhlUhFr8=; b=LVyZiIVShquV2pl1eGTxzALymttlyiHxkZ5UcDzR+YZnY8VpmvGGCT9VK/ij0+9vp5 ykjzvHJruxplkyMouNsVsSIHLRTkfhpfWmhmSE1d2u8OpiFrVeLFLudN+CccjDpbYSis 03QzO7lfFxK3Jc6fjHNJi1mAJ0uHjknqGQ7tZrKWq7y5UoqwOOKlRNC7PhPBkOtqcDMf 6c9vv3OKlV8TC6S4mtvbfzLs78fF0dGBx1Caky24U29wgK7ymKG09/Su8VyPfFCiP0OI 5yQAPA5r1lKLMYMAvWyNnOLP4CT8fwD6zTPUQjJ/qYzaKLvNO5Fuk9aO7a84UqVhBQH8 hgtQ==; 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-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVQ8ozjZynrBgyyr1H8XWLdkl9bncFS/nnl2jcWjWOjkFiMEdByeD68N9FgbYGP3Sf3aLmatSgOwC6UtX6l+Ql4nyWm/g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s24-20020a170906455800b00a385cf0e6besi1027942ejq.53.2024.02.09.08.55.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:55:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59674-ouuuleilei=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 C31C01F21608 for ; Fri, 9 Feb 2024 16:55:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9469A80BF7; Fri, 9 Feb 2024 16:50:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58C478288F; Fri, 9 Feb 2024 16:50:31 +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=1707497433; cv=none; b=mvVH7/VjY6p3PZSiRILX4ZBhCVyhK+SEWtnMVYbo8Dn/Kq4hpl3Ky4YwrLYmvc7gqeZ7IitHmq8xSpB0RrOPcEd91NaoXquKZJ2IyAg06D9Um3aCoS8dKw01+kuJxflSBiGUZMOESPxy2zN7FVf804Vlgg0ZIKq6wnjlEMC0Mi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497433; c=relaxed/simple; bh=pOu8SkBP1o2YI89QRW9IkEizSqtcRRWP9wRbqkcsIYk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FprqiAZ+MvoFbuav9dpLRdAPv0zJ0jGlHw0ApYnDt8BraHsZUOXE58+g4JNc8ZOzaCiG8Wex8eoZQWzEPTkWGMtC4m6qQ0CfdRbWHmSIzrJzFxVd2mdel3Kro4Yacs/Q0GDv/OUN/ceeqxGRrTqlj8eSlJuma4GsbjuaXMCC6+M= 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 C5B9F1570; Fri, 9 Feb 2024 08:51:12 -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 D72AC3F7F5; Fri, 9 Feb 2024 08:50:26 -0800 (PST) From: Robin Murphy To: 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 v3 2/7] OF: Simplify DMA range calculations Date: Fri, 9 Feb 2024 16:49:59 +0000 Message-Id: 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441133461677568 X-GMAIL-MSGID: 1790441133461677568 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);