From patchwork Tue Dec 3 12:04:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 1203741 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="quWPbD5k"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 47S46H6xZQz9sP3 for ; Wed, 4 Dec 2019 01:26:15 +1100 (AEDT) Received: by phobos.denx.de (Postfix, from userid 109) id 4F981816B3; Tue, 3 Dec 2019 15:25:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7465581709; Tue, 3 Dec 2019 13:43:44 +0100 (CET) Authentication-Results: mail.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: mail.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="quWPbD5k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 284C48176F; Tue, 3 Dec 2019 13:32:32 +0100 (CET) Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) (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 613B9817F6 for ; Tue, 3 Dec 2019 13:17:58 +0100 (CET) Authentication-Results: mail.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: mail.denx.de; spf=pass smtp.mailfrom=igor.opaniuk@gmail.com Received: by mail-lj1-f194.google.com with SMTP id d20so3485323ljc.12 for ; Tue, 03 Dec 2019 04:17:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l7NI4I/bZRgkzSWI0huQLhbY7fvItmVpD+13cD0qP1Q=; b=quWPbD5k5Zu0LJ5sDK47VNQYSSbGEkxxW0NfDlvrp52b1zjWPs6quixlLKIJjRTLc4 X4ryxpp1J4G5eEcApoVF2WADMIgc2Q8ScFroHvPrzrBlZ8BAY2z2Ncbf721w+alGnyhG 4W0c8O+mkCnUNw2wRKnJmf92SgEK86gavHUWMk1xtO8EQ26TbXtkASdGnXeKG6DaQ7Ah YZw2UOYwfZFXoHSACG1b4zVGJ4K/O+sAdeVHd4ivPuE6JpGyUuutVbN7D8A17gsudH1n aTwcBqesTWHFEDhBDS+pGnkDebhZoVmJo1WiEMasXmzeT+jfQrT1Xjq1fT3cVJqI0b1P 4kJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l7NI4I/bZRgkzSWI0huQLhbY7fvItmVpD+13cD0qP1Q=; b=RwL0kaadp1Xgxg6ZUzlBPTcIqbdA9N2haNBUMrIGj3ApSCaOIyu0i/sykT1dFTseC4 +hmhJ5TTx6Ih4BY4fIfOVqYlmzo1qT9bgR9QsvGfPBniaWb/c4YMVWjc9w+BSatSredt yAb/FhS4wWZEIESzFBcJTzvT9p0M/QD/8qncT1BmtYLXdm3HtqQ8u8BZpui9ed8EwxBW 3wTLnDGofujwk9dIVV3kju8T5To62XdTJEmihxUrdtmoO7OUINirF1blKk9q1xIgZFW9 4tuBsIwN+YFdTleN6CbQh31lzK15ewGZBiN7ltB/o9m/Ibl0ZwrieZQU1AupeALjSExR QMEw== X-Gm-Message-State: APjAAAU50mAaatD+vj6Qw0tLSeEJK9+PqDY+chdDts/0LWDQlEDSsDwY cVVd8dHb3CaCDpKMyBO5O1tqPSjPtJc= X-Google-Smtp-Source: APXvYqzZoukQNf+prYA/96cAR0sCI4X9UHQMVZJnDg2ON9SKbaxdQVewiZZYVZgydQ8qlVLIEXXOBA== X-Received: by 2002:a2e:a0c6:: with SMTP id f6mr2407940ljm.46.1575374698129; Tue, 03 Dec 2019 04:04:58 -0800 (PST) Received: from localhost (ip.82.144.210.51.stat.volia.net. [82.144.210.51]) by smtp.gmail.com with ESMTPSA id i4sm1215792ljg.102.2019.12.03.04.04.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2019 04:04:57 -0800 (PST) From: Igor Opaniuk To: u-boot@lists.denx.de Subject: [PATCH v2 1/2] common: fdt_support: add support for setting usable memory Date: Tue, 3 Dec 2019 14:04:46 +0200 Message-Id: <20191203120447.24820-2-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191203120447.24820-1-igor.opaniuk@gmail.com> References: <20191203120447.24820-1-igor.opaniuk@gmail.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sanchayan Maity , Igor Opaniuk , Stefan Agner Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at mail.denx.de X-Virus-Status: Clean From: Igor Opaniuk Add support for setting linux,usable-memory property in the memory node of device tree for the kernel [1]. 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. [1] https://www.kernel.org/doc/Documentation/devicetree/bindings/chosen.txt Signed-off-by: Igor Opaniuk Signed-off-by: Sanchayan Maity Signed-off-by: Stefan Agner Reviewed-by: Oleksandr Suvorov --- common/fdt_support.c | 35 +++++++++++++++++++++++++++++++++++ include/fdt_support.h | 1 + 2 files changed, 36 insertions(+) diff --git a/common/fdt_support.c b/common/fdt_support.c index 6834399039..02cf5c6241 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -467,6 +467,41 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) } return 0; } + +int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int areas) +{ + int err, nodeoffset; + int len; + u8 tmp[8 * 16]; /* Up to 64-bit address + 64-bit size */ + + if (areas > 8) { + printf("%s: num areas %d exceeds hardcoded limit %d\n", + __func__, areas, 8); + return -1; + } + + err = fdt_check_header(blob); + if (err < 0) { + printf("%s: %s\n", __func__, fdt_strerror(err)); + return err; + } + + /* find or create "/memory" node. */ + nodeoffset = fdt_find_or_add_subnode(blob, 0, "memory"); + if (nodeoffset < 0) + return nodeoffset; + + len = fdt_pack_reg(blob, tmp, start, size, areas); + + err = fdt_setprop(blob, nodeoffset, "linux,usable-memory", tmp, len); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "reg", fdt_strerror(err)); + return err; + } + + return 0; +} #endif int fdt_fixup_memory(void *blob, u64 start, u64 size) diff --git a/include/fdt_support.h b/include/fdt_support.h index cefb2b2cce..2286ea7793 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -94,6 +94,7 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size); */ #ifdef CONFIG_ARCH_FIXUP_FDT_MEMORY int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); +int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int banks); #else static inline int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)