From patchwork Mon Apr 18 19:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 1618542 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=PpwrCaZi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KhyGN6LWRz9sG6 for ; Tue, 19 Apr 2022 05:50:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C33E7838F0; Mon, 18 Apr 2022 21:50:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="PpwrCaZi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 73CE2838F0; Mon, 18 Apr 2022 21:50:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A07C782FA8 for ; Mon, 18 Apr 2022 21:50:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tommaso.merciai@amarulasolutions.com Received: by mail-ej1-x635.google.com with SMTP id i27so28711286ejd.9 for ; Mon, 18 Apr 2022 12:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8W4JvjnssEQyMSZy+HrjEbTbjuY0PZ4eK5T5lTabnwU=; b=PpwrCaZi3zhf+hwHFXsDphMCNNQUdsdmCFftN8MxaQ2AAb08OR6TJYCAwL7mw7eB5o XCorzOROaG9iH+mZ3g9L8DBY7YVJ0SpwNql8bl3kjRgc2nw4S3SserVPLYZn1qs2jbPc Evw6oxx+/Okw1bJT79K2QMdShH1GKVUr0zrm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8W4JvjnssEQyMSZy+HrjEbTbjuY0PZ4eK5T5lTabnwU=; b=PQ3DvxtVFeZW89DKuD1Mz2LOVCWx2s5mZDcsoYTWB3V2PCOMGMr41DJBhMJXkGJQRH swZdhLPtjnqGoAkRP3zqDgJ3Ck8IBiwkjDoJ0RU2kkBsClfXERNfiST7cmwffZRH+vNl 8Q08OgihDrDibZeCg0Oa8sy6tmc4OxpVeaF5nbH3G570D4WDGaWdN1dgZ4OunoRqcA+d lMNi8WiqRpY1CLT9fF73fgZaV4cnuV1pSBe7NxxEDwaKiU9u9d9GopnPIT8c4r6/NptU X95dSG1+e0ZBDG31dk5zlxwsTB3D6yaiqtqkqsd0K0Rf1tjjj/rz0ysllv3r1/dngudv +buQ== X-Gm-Message-State: AOAM531CfBvS58x63778Qxegwa6DqXhaHBm2njC15xcdmr3Jt8O14Gpa o0tQ+KfRh4/dBLRX24sWmyHBnQ== X-Google-Smtp-Source: ABdhPJyL8xiWpn3HEe9f7wuJB1upo1HkWjE//w8fKtmwOolkdpP+mVm5k7TqJaUrRJVCiJtdAdgP+Q== X-Received: by 2002:a17:907:d8d:b0:6df:b214:392a with SMTP id go13-20020a1709070d8d00b006dfb214392amr10441451ejc.669.1650311429256; Mon, 18 Apr 2022 12:50:29 -0700 (PDT) Received: from tom-ThinkPad-T14s-Gen-2i.station (net-188-217-56-163.cust.vodafonedsl.it. [188.217.56.163]) by smtp.gmail.com with ESMTPSA id o3-20020a170906774300b006e79ea98369sm4882406ejn.151.2022.04.18.12.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 12:50:29 -0700 (PDT) From: Tommaso Merciai To: Cc: tommaso.merciai@amarulasolutions.com, linux-amarula@amarulasolutions.com, Michael Trimarchi , Simon Glass , u-boot@lists.denx.de Subject: [PATCH] common: fdt: introduce fdt_fixup_reserved_memory Date: Mon, 18 Apr 2022 21:50:26 +0200 Message-Id: <20220418195027.11407-1-tommaso.merciai@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean The intent of fdt_fixup_reserved_memory is to reserve memory and prevent it from being included in the kernel's linear map from U-Boot. This is done by creating a no-map zone into reserved-memory region no-map (optional) - empty property Indicates the operating system must not create a virtual mapping of the region as part of its standard mapping of system memory, nor permit speculative access to it under any circumstances other than under the control of the device driver using the region. References: - Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt Signed-off-by: Tommaso Merciai Developed-by: Michael Trimarchi Tested-by: Tommaso Merciai --- common/fdt_support.c | 53 +++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 11 +++++++++ 2 files changed, 64 insertions(+) diff --git a/common/fdt_support.c b/common/fdt_support.c index ea18ea3f04..7cfaf4310c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -412,6 +412,59 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, return p - (char *)buf; } +int fdt_fixup_reserved_memory(void *blob, const char *name, u64 start[], u64 size[]) +{ + int offs, len, err; + const char *subpath; + const char *path = "/reserved-memory"; + fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(blob, 0)); + fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(blob, 0)); + u8 temp[16]; /* Up to 64-bit address + 64-bit size */ + + offs = fdt_path_offset(blob, path); + if (offs < 0) { + debug("Node %s not found\n", path); + path = "/"; + subpath = "reserved-memory"; + offs = fdt_path_offset(blob, path); + offs = fdt_add_subnode(blob, offs, subpath); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return -1; + } + path = "/reserved-memory"; + offs = fdt_path_offset(blob, path); + + fdt_setprop(blob, offs, "#address-cells", &address_cells, sizeof(address_cells)); + fdt_setprop(blob, offs, "#size-cells", &size_cells, sizeof(size_cells)); + fdt_setprop(blob, offs, "ranges", NULL, 0); + } + + offs = fdt_add_subnode(blob, offs, name ? : "private"); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return -1; + } + + err = fdt_setprop(blob, offs, "no-map", NULL, 0); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "no-map", fdt_strerror(err)); + return err; + } + + len = fdt_pack_reg(blob, temp, start, size, 1); + + err = fdt_setprop(blob, offs, "reg", temp, len); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "reg", fdt_strerror(err)); + return err; + } + + return 0; +} + #if CONFIG_NR_DRAM_BANKS > 4 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS #else diff --git a/include/fdt_support.h b/include/fdt_support.h index ac76939e81..0ade91a08f 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -93,6 +93,17 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, */ int fdt_fixup_memory(void *blob, u64 start, u64 size); +/** + * Setup the memory reserved node in the DT. Creates one if none was existing before. + * + * @param blob FDT blob to update + * @param name Reserved area name + * @param start Begin of DRAM mapping in physical memory + * @param size Size of the single memory bank + * @return 0 if ok, or -1 or -FDT_ERR_... on error + */ +int fdt_fixup_reserved_memory(void *blob, const char *name, u64 start[], u64 size[]); + /** * Fill the DT memory node with multiple memory banks. * Creates the node if none was existing before.