Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp679852pxb; Tue, 3 Nov 2020 09:34:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaG8VisC2hTPxXESePyX4yQI+HnwllCz5bwmlZftLPOYXSHpjGkYaW7SniR1Zht/mUQmfz X-Received: by 2002:a17:906:36cd:: with SMTP id b13mr21977617ejc.235.1604424861840; Tue, 03 Nov 2020 09:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604424861; cv=none; d=google.com; s=arc-20160816; b=s0YpMHFI7Ta3zk7BIlTWvXkKZnjJwQFnjZ3N6hFpLadV8wZQAKf9o/+66TwMTms7kv YuU+yZcL0nuZYRpYJRZejck7ZhSkXk46t3zH6Oq+miT7CYpfpeaUeJndphnYG/uRmHZH UEZmL614l25xYklYnp5gGGYSbgArfwoYVjMeSRpkUAwbIu7/+WUbLjFyRZlBmRjQBCbi kD9GrdKCu456/kkIufWXh9yC1CjBBy/llnn+RAa1p+Xov/sB8vImleuMHTQiJfuSew4x 5dsBMNDZi7wept075f00YfQkA/kE5SgLvyOnPGZaAxb0u1BfFUyOhsb9l5hnB+eUIBfE NKeg== 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=jWCf5osvX7oSqOCIfTNIVvWbkfphgKn8Ckww55xxhxk=; b=eoItGrkMSgu9vi2eiEGSkWuYPY/osqjhoEl1yWmwAicYCa9sbKVoJH4OgE5U38WYac w+Un+lY0iAX1ryWwOfCxAAUJvwlvq5rY2sHg15Nz1RyX5KKmeTxrUK32g8Vt1us9abCX M1JgG8ORYhhUSF8PTJCnO2DM6ftFkMcRBw/Gs+7TkVwSpWTsfSvK0v2VnxBfXDUMOahm OFVuybXXACZwNuLYscwgjaf6I8VvFKICBYadeu8LVmaknw/bC+6HpsgqzjlAARY3ecst 87wEKTAGdXt7jY6UxcrvfFEugDTI23zJH+yPa7tmHaZUDCCCq3lhIkaT2Noe5cy9tS2q 0Rlg== 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 d22si7727584ejr.471.2020.11.03.09.33.58; Tue, 03 Nov 2020 09:34:21 -0800 (PST) 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 S1728902AbgKCRcN (ORCPT + 99 others); Tue, 3 Nov 2020 12:32:13 -0500 Received: from mx2.suse.de ([195.135.220.15]:34096 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728851AbgKCRcL (ORCPT ); Tue, 3 Nov 2020 12:32:11 -0500 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 8D8EDAD5F; Tue, 3 Nov 2020 17:32:09 +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 v6 5/7] arm64: mm: Set ZONE_DMA size based on devicetree's dma-ranges Date: Tue, 3 Nov 2020 18:31:56 +0100 Message-Id: <20201103173159.27570-6-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201103173159.27570-1-nsaenzjulienne@suse.de> References: <20201103173159.27570-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.1