Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5203708pxu; Wed, 21 Oct 2020 17:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweN58So1O3JY/iDWOPsu3pYT2FKqGtaNkTcb0DvgY6d7aBwsU6lrHADw4sVZqgXoaEpibP X-Received: by 2002:a05:6402:d6:: with SMTP id i22mr5348782edu.53.1603325130151; Wed, 21 Oct 2020 17:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603325130; cv=none; d=google.com; s=arc-20160816; b=cUBznbTk/nXzGlwYT5a3cyUjLiHZl1+/NyPYv/MhmirTjHy9pU6IgMS+skYVZYcxYI Lt/6nUO4V9DzntoL5QbNV/SmFBXKOGAhOSE53sSA20hEGYO5eYYFLCVaPXocJ5FDy+l8 Zsu2H1d2G4HL6sANoRYHUfpE6JS70O9bb5XxNnh0qD7hLearOvv817N5750iKnlp5Xq6 4urXgmI1lRCFGHHr3ULV5S3enMvDD/rSfn8CbN++h+0OU8NSttCzTo4/BN/jGZjWH0EE pbEc80lmlA6/ina4+uXi6Ub205A4H8m9XqLGUDiOjh9xMvzlSXF9iZpQ3uWuagb/I6sS 48Uw== 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=v6Yu3v00lnMMxrR+/62ErIAAFwr8CS13l/TkbqvCwqE=; b=f+ZmCtLaJX2hNjKG94QazA4L78i8mmmSSxTXWK5WZ8gCMTQxg4DbCuD/hw0dVYfpPd S8vtpSydtnlQuA8vF7/wOyXOGEZB1YdjmDd8abhQYgEFcaoo+vQBZ94OMmqijByr4rvS Mm5oSp9X5yf/MrCwIfqqB848JcxGpylrRLvo3y7VhEpBF+gz36OF3vG8BMbLbxZFAA8u wihHFQTkgLIjjxm3sCiyZmivCsTbhDdNhGBs1T83LHTQfPtR16+ykg44pB2ptaQzyEQe wIojKdaC7iV1A1TJ52ldYDucaPBRhcPBHHtbkJK0sZXI34E4eTDGGKGMIHfoHMwjdW++ Scog== 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 b15si2484958edk.374.2020.10.21.17.05.07; Wed, 21 Oct 2020 17:05:30 -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 S2442421AbgJUMfi (ORCPT + 99 others); Wed, 21 Oct 2020 08:35:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:50874 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2442398AbgJUMfe (ORCPT ); Wed, 21 Oct 2020 08:35:34 -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 D5D12AEB6; Wed, 21 Oct 2020 12:35:32 +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 v4 5/7] arm64: mm: Set ZONE_DMA size based on devicetree's dma-ranges Date: Wed, 21 Oct 2020 14:34:35 +0200 Message-Id: <20201021123437.21538-6-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201021123437.21538-1-nsaenzjulienne@suse.de> References: <20201021123437.21538-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 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..94e38f99748b 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 = ilog2(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.28.0