Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4270161pxt; Wed, 11 Aug 2021 01:53:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwap42/ytMUYpBYsBoMGGlA0Na8YZpFLSR8Gd+sZdpw2aKnn/i1YbOG7nf1SDJgKIDXfo4c X-Received: by 2002:a50:9b52:: with SMTP id a18mr369407edj.165.1628672027351; Wed, 11 Aug 2021 01:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628672027; cv=none; d=google.com; s=arc-20160816; b=Av4QjpO6+C37cJYkAdzX/8Be3dfXlTKJKSGUqSVlU21LFd7HinGAJ+QG1qkMsZTEB4 r0uKKysZOtQ94IoKgh5++QVgUBRPutRMOvhlf7czAGvHCY4oLBDqgQtp37EY3PCDYJrk Yq1wr+Cqsv3cqDpr504kQ6ahMHO9PLTksAm/+IR2sP0sAlf78qHNnSyBivtx3/DEKFR1 3Y9UAqaqRmEtRD1VeQOY0Q3T+VPdxfnBeCMZXHB76l1xfHMW1C5b0D2Sd1xG91uqENRm SoZVVNc06/Iybx1lJQ1Go1imTpABhmo+84+y6h06/21B5CooruBbiPr8qr5i17qrbz8g Pe4g== 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=hZwk8fZyG7IF1jCrKoeGIcVllWVY4axf4olt1wyVnOI=; b=PBhpJPLqMDRY/dViOpKlVqpIaqkJB3+uhExO1rkZHAYV0OL/U2ZqwKnvpTLSG6EKnV 8wbRYdKOJjARMz15h/60OZFadHahMeTwHRUNRqQy44+CLvw+AEQFvxFP6yLstBmKOf31 2nbpt20Enm2XGYq7mV6x2Exb29Ap4LFMeBa+XE7g+qaO8SQTEN6Jj0VOqggyRgzn3HIo 0by4NsAEoY5cWx+h2OqR9THnxdEismYdt17odlonx6ah5tp0bz2ju9iucxzBZsiRNt/q 2nN0PhUY8Rs/JmwfbK1Ar1mfTY2bNkoG98Un/44O94zu0VrxwdcxwHP2Yd7Vnoyo1Wok ATqg== 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 p7si25485257ejf.317.2021.08.11.01.53.24; Wed, 11 Aug 2021 01:53:47 -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 S236668AbhHKIwJ (ORCPT + 99 others); Wed, 11 Aug 2021 04:52:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236481AbhHKIwA (ORCPT ); Wed, 11 Aug 2021 04:52:00 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE296C0617A5 for ; Wed, 11 Aug 2021 01:51:35 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:438:1ff1:1071:f524]) by xavier.telenet-ops.be with bizsmtp id g8rG2500m1gJxCh018rGUb; Wed, 11 Aug 2021 10:51:32 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mDjxE-001yaA-I3; Wed, 11 Aug 2021 10:51:16 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mDjxD-0058x3-C2; Wed, 11 Aug 2021 10:51:15 +0200 From: Geert Uytterhoeven To: Rob Herring , Russell King , Nicolas Pitre , Ard Biesheuvel , Linus Walleij , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , Nick Kossifidis , Paul Walmsley , Palmer Dabbelt , Albert Ou , Frank Rowand , Dave Young Cc: Baoquan He , Vivek Goyal , Mike Rapoport , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, kexec@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v5 4/9] of: fdt: Add generic support for handling usable memory range property Date: Wed, 11 Aug 2021 10:51:02 +0200 Message-Id: <3bd69bada93ee59b7d23c38b3527fc1654e19343.1628670468.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for handling the "linux,usable-memory-range" property in the "/chosen" node to the FDT core code. This can co-exist safely with the architecture-specific handling, until the latter has been removed. Signed-off-by: Geert Uytterhoeven --- About the change to chosen.txt: I have a similar change for schemas/chosen.yaml in dt-schema. v5: - Handle the actual capping in generic code, too, v4: - New. --- Documentation/devicetree/bindings/chosen.txt | 6 ++-- drivers/of/fdt.c | 30 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt index 5b0b94eb2d04e79d..1cc3aa10dcb10588 100644 --- a/Documentation/devicetree/bindings/chosen.txt +++ b/Documentation/devicetree/bindings/chosen.txt @@ -79,9 +79,9 @@ a different secondary CPU release mechanism) linux,usable-memory-range ------------------------- -This property (arm64 only) holds a base address and size, describing a -limited region in which memory may be considered available for use by -the kernel. Memory outside of this range is not available for use. +This property holds a base address and size, describing a limited region in +which memory may be considered available for use by the kernel. Memory outside +of this range is not available for use. This property describes a limitation: memory within this range is only valid when also described through another mechanism that the kernel diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 99be3e03af29089f..bc041d8141e86e62 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -956,6 +956,32 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) elfcorehdr_addr, elfcorehdr_size); } +static phys_addr_t cap_mem_addr; +static phys_addr_t cap_mem_size; + +/** + * early_init_dt_check_for_usable_mem_range - Decode usable memory range + * location from flat tree + * @node: reference to node containing usable memory range location ('chosen') + */ +static void __init early_init_dt_check_for_usable_mem_range(unsigned long node) +{ + const __be32 *prop; + int len; + + pr_debug("Looking for usable-memory-range property... "); + + prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); + if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells))) + return; + + cap_mem_addr = dt_mem_next_cell(dt_root_addr_cells, &prop); + cap_mem_size = dt_mem_next_cell(dt_root_size_cells, &prop); + + pr_debug("cap_mem_start=%pa cap_mem_size=%pa\n", &cap_mem_addr, + &cap_mem_size); +} + #ifdef CONFIG_SERIAL_EARLYCON int __init early_init_dt_scan_chosen_stdout(void) @@ -1104,6 +1130,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, early_init_dt_check_for_initrd(node); early_init_dt_check_for_elfcorehdr(node); + early_init_dt_check_for_usable_mem_range(node); /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l); @@ -1258,6 +1285,9 @@ void __init early_init_dt_scan_nodes(void) /* Setup memory, calling early_init_dt_add_memory_arch */ of_scan_flat_dt(early_init_dt_scan_memory, NULL); + + /* Handle linux,usable-memory-range property */ + memblock_cap_memory_range(cap_mem_addr, cap_mem_size); } bool __init early_init_dt_scan(void *params) -- 2.25.1