Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp626801pxx; Thu, 29 Oct 2020 10:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDYfDSzm4/2KyLZCQF44xl90Ggm+LMtU4nr9abQB2KbtVFwrJc0ekyfNEewQ4iYJ128WX1 X-Received: by 2002:a17:907:435b:: with SMTP id oc19mr4963213ejb.311.1603992480187; Thu, 29 Oct 2020 10:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603992480; cv=none; d=google.com; s=arc-20160816; b=Qk/Yw3QRA5WnGFyCVF1pTZv7j9R8f5NJq3XZdGhy9eU7NdlQ2N/PPIkHDoEm4ERqLw BSU6zWnziAuPGh+kPd2JN4ms0O+PQHzPNQi/dX9vZ9je49FFGEp2UJiDcTc+j71OPw5Z nu1kVhtG54FqBHejrYzQG5eyeUddP2e1gg1emSuODVq+/L+NANwNinrAbVh4lORMrXIq 7IPgEzRKU45XW/d1TABmYiOfSyD+AiCMaEOafONrjnmcinNWNkNY010mvG6Q2/rwyMde JSufth3eNP5MMvfu0L3jraVaMeI5aevsns18Yl3suOLBALy3HCnhoJ2M2/O1ZwAuYcgj kKRQ== 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=7tJ0WwzBKR3Hro2q5A9DpTJ7LbRgenIGFcy/lS80ztU=; b=g/yexmHc6ADd7iRP/kZNtC8bfs4C47+sc6X7iRerszU/94XPyJgJOptOxI+BrBZAON H1esk3hrdlbYBg8j6tVuuTf7YDZb0G+YolB384fQI4Q7bpXzA/ixI4wc2tUflP7y5+rw g1LouiWvmQaBCnAoWkRRtypV0WRwIIjoyeKeTikiwTnLivj0NrbEGwNPHAyhnpeTnQnw 8N+z06UYYCeShmhXMN1x2Cu9NRFQTEkoTdjBYBqm1VTPS5DuuAc6QohNbu2TS+19G1ig 0HkcS82eFEE8ieq80yaGpTB3VKZS9WE3QZ82O9whGWj11R3ZvDZW2kIFl/1SObopnJ1O PD4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df7si3160341edb.283.2020.10.29.10.27.36; Thu, 29 Oct 2020 10:28:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727952AbgJ2R0I (ORCPT + 99 others); Thu, 29 Oct 2020 13:26:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:56322 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727765AbgJ2R0F (ORCPT ); Thu, 29 Oct 2020 13:26:05 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 07032ADAD; Thu, 29 Oct 2020 17:26:04 +0000 (UTC) From: Nicolas Saenz Julienne To: robh+dt@kernel.org, catalin.marinas@arm.com, hch@lst.de, ardb@kernel.org, linux-kernel@vger.kernel.org Cc: robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, jeremy.linton@arm.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, will@kernel.org, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, Nicolas Saenz Julienne Subject: [PATCH v5 5/7] arm64: mm: Set ZONE_DMA size based on devicetree's dma-ranges Date: Thu, 29 Oct 2020 18:25:48 +0100 Message-Id: <20201029172550.3523-6-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201029172550.3523-1-nsaenzjulienne@suse.de> References: <20201029172550.3523-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We recently introduced a 1 GB sized ZONE_DMA to cater for platforms incorporating masters that can address less than 32 bits of DMA, in particular the Raspberry Pi 4, which has 4 or 8 GB of DRAM, but has peripherals that can only address up to 1 GB (and its PCIe host bridge can only access the bottom 3 GB) The DMA layer also needs to be able to allocate memory that is guaranteed to meet those DMA constraints, for bounce buffering as well as allocating the backing for consistent mappings. This is why the 1 GB ZONE_DMA was introduced recently. Unfortunately, it turns out the having a 1 GB ZONE_DMA as well as a ZONE_DMA32 causes problems with kdump, and potentially in other places where allocations cannot cross zone boundaries. Therefore, we should avoid having two separate DMA zones when possible. So, with the help of of_dma_get_max_cpu_address() get the topmost physical address accessible to all DMA masters in system and use that information to fine-tune ZONE_DMA's size. In the absence of addressing limited masters ZONE_DMA will span the whole 32-bit address space, otherwise, in the case of the Raspberry Pi 4 it'll only span the 30-bit address space, and have ZONE_DMA32 cover the rest of the 32-bit address space. Signed-off-by: Nicolas Saenz Julienne --- Changes since v4: - Use fls64 as we're now using the max address (as opposed to the limit) Changes since v3: - Simplify code for readability. Changes since v2: - Updated commit log by shamelessly copying Ard's ACPI commit log arch/arm64/mm/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 410721fc4fc0..a2ce8a9a71a6 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -42,8 +42,6 @@ #include #include -#define ARM64_ZONE_DMA_BITS 30 - /* * We need to be able to catch inadvertent references to memstart_addr * that occur (potentially in generic code) before arm64_memblock_init() @@ -188,9 +186,11 @@ static phys_addr_t __init max_zone_phys(unsigned int zone_bits) static void __init zone_sizes_init(unsigned long min, unsigned long max) { unsigned long max_zone_pfns[MAX_NR_ZONES] = {0}; + unsigned int __maybe_unused dt_zone_dma_bits; #ifdef CONFIG_ZONE_DMA - zone_dma_bits = ARM64_ZONE_DMA_BITS; + dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL)); + zone_dma_bits = min(32U, dt_zone_dma_bits); arm64_dma_phys_limit = max_zone_phys(zone_dma_bits); max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); #endif -- 2.29.0