Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1791111lqe; Mon, 8 Apr 2024 23:29:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUA7kFJ1YElISy+iv/P/yWBuHLMmFR04a71DNRfmT37hk0v8cTB2o4nxx0C22Kp99oipGFDF+/KRBP01dDnPOqHVPyxeftT0v9iQqVZjQ== X-Google-Smtp-Source: AGHT+IE7JmCmyYRwld4noFmSWS54FGJt8VHka4sx8twF/5ukZ9cusNcntxJ+8uiz5HOSOB+tQmSX X-Received: by 2002:a05:6358:7299:b0:186:431:d9d6 with SMTP id w25-20020a056358729900b001860431d9d6mr11407948rwf.17.1712644152532; Mon, 08 Apr 2024 23:29:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712644152; cv=pass; d=google.com; s=arc-20160816; b=N5yyZ4WLG6vZA988M/bN+9z190zYkvIbXX0tv2hgl/4XecZp4WCsrZoFSzHbx0fReO 0o+acJwmBA1hUlNWIdLlylZxYF9zCpdIgoz4uw6UsVDOizEgrcYjAOdB3xD577QVXf99 ObNlAgFVgr3qQVUbWjiGWIh26E+g7PSoO8w+Eo+j58EYm4owkZ4zsO/MR69mNQ37WNxz 24qipyEgS1YofaXcJcjPowrCJcmW/qr+VpqJxCDkDpuqQ7QuOuEluq4kj28UOWLWd8wB 3hCIgo3YxNJLbdp179gjgZMBjPJeVJEqGJtyDs7LYRBzuaKvAmtTkcyGBIaEJzUNlqmN VPcw== 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:dkim-signature; bh=EYyIkRpjnRY7tI28Y5H0wFiihRhYSA4rwr/imf8JIew=; fh=W01kooGlvR+YDsYzxDGIyNTz6+GmZIMqcuUKjhMGsWY=; b=zIRfBSSvk0Mc/5lu1bOECRoWY7LXMoW3D6l8sj3z0lCubmjFk+ylzGz+DY5eWtR0zh Ix4Ciz+MRIFkQnaD63BmqrGkBjfegm9m92bcSx2hLG2svZHCA5FD4OMB7c//UPeM6BRp z75J9c42bdxgREZC04VvoKNJIvsFJHG7ADD/gM2eRRpTHp89ejivSwmm5JjcZBAlgOh2 HsoCoJuF1C+nxeyIjfQvoUFaFMWFI/wqAed0/AMrYWCaYwbYV3LNGBm5Zl1vGjNkyZ5a VnCThljrzpePPBJh4me+ZqBTARrtbl3fWoiG9+rcskEcFOPRG6OfFMV9bRfNiMQxQcyd dJwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=n3qLjVAj; arc=pass (i=1 spf=pass spfdomain=tkos.co.il dkim=pass dkdomain=tkos.co.il dmarc=pass fromdomain=tkos.co.il); spf=pass (google.com: domain of linux-kernel+bounces-136299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id g14-20020a63564e000000b005dc4e366f46si7800263pgm.127.2024.04.08.23.29.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 23:29:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=n3qLjVAj; arc=pass (i=1 spf=pass spfdomain=tkos.co.il dkim=pass dkdomain=tkos.co.il dmarc=pass fromdomain=tkos.co.il); spf=pass (google.com: domain of linux-kernel+bounces-136299-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136299-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2896BB232C6 for ; Tue, 9 Apr 2024 06:26:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 686A37C080; Tue, 9 Apr 2024 06:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="n3qLjVAj" Received: from mail.tkos.co.il (guitar.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58D747442A; Tue, 9 Apr 2024 06:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.110.109.230 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712643941; cv=none; b=hZb875hmGBpkvzlH+AUeMCavHYCIWn7jsfPjJIGmayfShpo5x31DjPLUZbrAzBUbana+TvJHws8W/x+X6FwbyWNFC8aMd2/zxgBiipNGFStcJdufNssOQZe99c1VXEQfjohusfhsvgPI3FWiK3rzubN1DkaVHqdCyER1Cy+AHdE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712643941; c=relaxed/simple; bh=EIw24HYGCi1y+d787B1Nwod7ac/kZ5Ydc0E1Leu5myU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QfOyHcTUvqGj+qA98s2Tad+wSW2Tv6oHcIsGj1F2FBHJgstUJEp+cuUMkievwlXWIY9h08njkR/ugPC50WGRyzw78ZgrGZtwrLF/0ErRUKVfnwX76V0eQ/rlccbu9k0hYnoazKQTVTcHMVSqVbyrTuMttwSih8zYbMOXJDnlKHQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il; spf=pass smtp.mailfrom=tkos.co.il; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b=n3qLjVAj; arc=none smtp.client-ip=84.110.109.230 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il Received: from tarshish.tkos.co.il (unknown [10.0.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 3F5CC4402AC; Tue, 9 Apr 2024 09:17:43 +0300 (IDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1712643463; bh=EIw24HYGCi1y+d787B1Nwod7ac/kZ5Ydc0E1Leu5myU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3qLjVAj+4pF4UYTEPUfy6hDZc7RQUJl12cdtSQ67feuraSJIcxEnkhhz7svNCZev WiFYZlsATBak209c0SBVa1hf/ggF4S1N16dWH1g9juf38FTb5MKzO5N4stpAdIfAna XycYLYvSezvjE/+xRKgPwwodUZL59zZpOmzpRgcA8BeKfxbYcgVXPCzwMXLGQnMVtk DlpOc9jsgwHZKnFO4YYjqd/gi7etpfY1VBFuqgqhNIsBfzzBbuDvzQy9zRlq1zfL6E VmsQN9vAyrAP78oOAToGaJR2hb+bhccZVs3Bzit89jiGKrOwxaHmKOAsR2I+1vBZUA 1zf1LjaNsJl3Q== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Saravana Kannan , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= , Ramon Fried , Elad Nachman Subject: [PATCH RFC v2 2/5] of: get dma area lower limit Date: Tue, 9 Apr 2024 09:17:55 +0300 Message-ID: <230ea13ef8e9f576df849e1b03406184ca890ba8.1712642324.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.43.0 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 of_dma_get_max_cpu_address() returns the highest CPU address that devices can use for DMA. The implicit assumption is that all CPU addresses below that limit are suitable for DMA. However the 'dma-ranges' property this code uses also encodes a lower limit for DMA that is potentially non zero. Rename to of_dma_get_cpu_limits(), and extend to retrieve also the lower limit for the same 'dma-ranges' property describing the high limit. Update callers of of_dma_get_max_cpu_address(). No functional change intended. Signed-off-by: Baruch Siach --- arch/arm64/mm/init.c | 2 +- drivers/of/address.c | 38 +++++++++++++++++++++++++++----------- drivers/of/unittest.c | 8 ++++---- include/linux/of.h | 11 ++++++++--- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 00508c69ca9e..77e942ca578b 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -128,7 +128,7 @@ static void __init zone_sizes_init(void) #ifdef CONFIG_ZONE_DMA acpi_zone_dma_limit = acpi_iort_dma_get_max_cpu_address(); - dt_zone_dma_limit = of_dma_get_max_cpu_address(NULL); + of_dma_get_cpu_limits(NULL, &dt_zone_dma_limit, NULL); zone_dma_limit = min(dt_zone_dma_limit, acpi_zone_dma_limit); arm64_dma_phys_limit = max_zone_phys(zone_dma_limit); max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); diff --git a/drivers/of/address.c b/drivers/of/address.c index ae46a3605904..ac009b3bb63b 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -964,21 +964,25 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) #endif /* CONFIG_HAS_DMA */ /** - * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA + * of_dma_get_cpu_limits - Gets highest CPU address suitable for DMA * @np: The node to start searching from or NULL to start from the root + * @max: Pointer to high address limit or NULL if not needed + * @min: Pointer to low address limit or NULL if not needed * * Gets the highest CPU physical address that is addressable by all DMA masters - * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no - * DMA constrained device is found, it returns PHYS_ADDR_MAX. + * in the sub-tree pointed by np, or the whole tree if @np in NULL. If no + * DMA constrained device is found, @*max is PHYS_ADDR_MAX, and @*low is 0. */ -phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np) +void __init of_dma_get_cpu_limits(struct device_node *np, + phys_addr_t *max, phys_addr_t *min) { phys_addr_t max_cpu_addr = PHYS_ADDR_MAX; struct of_range_parser parser; - phys_addr_t subtree_max_addr; + phys_addr_t min_cpu_addr = 0; struct device_node *child; struct of_range range; const __be32 *ranges; + u64 cpu_start = 0; u64 cpu_end = 0; int len; @@ -988,21 +992,33 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np) ranges = of_get_property(np, "dma-ranges", &len); if (ranges && len) { of_dma_range_parser_init(&parser, np); - for_each_of_range(&parser, &range) - if (range.cpu_addr + range.size > cpu_end) + for_each_of_range(&parser, &range) { + if (range.cpu_addr + range.size > cpu_end) { cpu_end = range.cpu_addr + range.size - 1; + cpu_start = range.cpu_addr; + } + } - if (max_cpu_addr > cpu_end) + if (max_cpu_addr > cpu_end) { max_cpu_addr = cpu_end; + min_cpu_addr = cpu_start; + } } for_each_available_child_of_node(np, child) { - subtree_max_addr = of_dma_get_max_cpu_address(child); - if (max_cpu_addr > subtree_max_addr) + phys_addr_t subtree_max_addr, subtree_min_addr; + + of_dma_get_cpu_limits(child, &subtree_max_addr, &subtree_min_addr); + if (max_cpu_addr > subtree_max_addr) { max_cpu_addr = subtree_max_addr; + min_cpu_addr = subtree_min_addr; + } } - return max_cpu_addr; + if (max) + *max = max_cpu_addr; + if (min) + *min = min_cpu_addr; } /** diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 6b5c36b6a758..2d632d4ec5b1 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -921,7 +921,7 @@ static void __init of_unittest_changeset(void) #endif } -static void __init of_unittest_dma_get_max_cpu_address(void) +static void __init of_unittest_dma_get_cpu_limits(void) { struct device_node *np; phys_addr_t cpu_addr; @@ -935,9 +935,9 @@ static void __init of_unittest_dma_get_max_cpu_address(void) return; } - cpu_addr = of_dma_get_max_cpu_address(np); + of_dma_get_cpu_limits(np, &cpu_addr, NULL); unittest(cpu_addr == 0x4fffffff, - "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %x)\n", + "of_dma_get_cpu_limits: wrong CPU addr %pad (expecting %x)\n", &cpu_addr, 0x4fffffff); } @@ -4109,7 +4109,7 @@ static int __init of_unittest(void) of_unittest_changeset(); of_unittest_parse_interrupts(); of_unittest_parse_interrupts_extended(); - of_unittest_dma_get_max_cpu_address(); + of_unittest_dma_get_cpu_limits(); of_unittest_parse_dma_ranges(); of_unittest_pci_dma_ranges(); of_unittest_bus_ranges(); diff --git a/include/linux/of.h b/include/linux/of.h index a0bedd038a05..7756441d3ce0 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -454,7 +454,8 @@ int of_map_id(struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); -phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); +void of_dma_get_cpu_limits(struct device_node *np, phys_addr_t *max, + phys_addr_t *min); struct kimage; void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, @@ -880,9 +881,13 @@ static inline int of_map_id(struct device_node *np, u32 id, return -EINVAL; } -static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) +static inline void of_dma_get_cpu_limits(struct device_node *np, + phys_addr_t *max, phys_addr_t *min) { - return PHYS_ADDR_MAX; + if (max) + *max = PHYS_ADDR_MAX; + if (min) + *min = 0; } static inline const void *of_device_get_match_data(const struct device *dev) -- 2.43.0