From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2538EC433EF for ; Fri, 10 Sep 2021 20:48:17 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7088561208 for ; Fri, 10 Sep 2021 20:48:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7088561208 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7F9888371D; Fri, 10 Sep 2021 22:48:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mcEYPQds"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5CBE383718; Fri, 10 Sep 2021 22:48:10 +0200 (CEST) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 0D60D83701 for ; Fri, 10 Sep 2021 22:47:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.vasut@gmail.com Received: by mail-wr1-x431.google.com with SMTP id q11so4366384wrr.9 for ; Fri, 10 Sep 2021 13:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=reyTJX/T/Gd23Z4Le1FTmeDHOKXj+rWKL+7yUSZPupk=; b=mcEYPQdsg9wT0PccWLYaVeeNlFiQe+Al+GM+oxHCmxR/rVT0lihHRjmSCTpDYGJTqQ 4YXA2bifwrzHvZDb/0NFFzHZeIFiRQC+yh71PXo+jdFXaW1aqc72bxuX7Uvwq22uw739 OSEXaqJjiqXl+8rj5oz/lIdPJnViIcJT3dgckdGUuv09fOMAbWq7K2JgxrsTQzvrmYj9 ygbNgIxLWuPFcyJ5jmz2BwZkmNNUXXcJIX++MsR357bRaFs4PUqxmWAgIjb+B7uPBdOB rauVISpjHaQFNrVv6j/h3q3sKpTd4YKDMLP/CIazjQ3tG8evfeStP4fkyiBjeIGrCBkN 7tPg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=reyTJX/T/Gd23Z4Le1FTmeDHOKXj+rWKL+7yUSZPupk=; b=MIaUitZNI/K8+UTjcJWzzmpHPd7W1Low8Gk2GiZuimwuH+RVm5g9dL+MLAfKPO7Fb9 1EVdOj9pU6xEo89ncj3Jlvz5IqxZwqT8LPGGy5U0+blKAfMVXjnOhydjhQbcqOtWRVGE hbGUMcpGwsZ55P4FCMGxk8DcXBuqS7RQwFi034spkWz3h49WsI7torw1ii/7CnS/XQcn tsobdQGLYG5Sc6TcDDw9oglQ6hjJ8K9IBqZex+uC95iIFX7dfJzYwq7Wxvzb2nXrR7ky nTM5bvPBVLTCZvx0jAMR780xc10LMljaFFXv55Zwl/vLx48mfKD7G+L/eBhxegGo8lWc 0izw== X-Gm-Message-State: AOAM533lOf197Yz2bfGz234v6fk9A07UvqLAvihowthitO6K3XbnX49Q tuCWXQ4IKR66SkVjXpmj0i8FaZa4HV5U/w== X-Google-Smtp-Source: ABdhPJxNEccthty0shcbdKhDslLv1YuF0lk0DqCXZO5GbRi3SxC70VYX/J8TmziUfZSLKD7EYs+P6Q== X-Received: by 2002:adf:e384:: with SMTP id e4mr11826165wrm.64.1631306864636; Fri, 10 Sep 2021 13:47:44 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz. [89.176.112.137]) by smtp.gmail.com with ESMTPSA id p11sm5195948wma.16.2021.09.10.13.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:47:44 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Alexey Brodkin , Angelo Dureghello , Daniel Schwierzeck , Eugeniy Paltsev , Hai Pham , Michal Simek , Simon Goldschmidt , Tom Rini , Wolfgang Denk Subject: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic() Date: Fri, 10 Sep 2021 22:47:09 +0200 Message-Id: <20210910204718.17765-3-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910204718.17765-1-marek.vasut+renesas@gmail.com> References: <20210910204718.17765-1-marek.vasut+renesas@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean The arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() implementations are all mostly the same, except for a couple of details. Implement a generic arch_lmb_reserve_generic() function which can be parametrized enough to cater for those differences between architectures. This can also be parametrized enough so it can handle cases where U-Boot is not relocated to the end of DRAM e.g. because there is some other reserved memory past U-Boot (e.g. unmovable firmware for coprocessor), it is not relocated at all, and other such use cases. Signed-off-by: Marek Vasut Cc: Alexey Brodkin Cc: Angelo Dureghello Cc: Daniel Schwierzeck Cc: Eugeniy Paltsev Cc: Hai Pham Cc: Michal Simek Cc: Simon Goldschmidt Cc: Tom Rini Cc: Wolfgang Denk --- V2: Reword code comment --- include/lmb.h | 1 + lib/lmb.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index 3c4afdf9f0..1984291132 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -122,6 +122,7 @@ lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); +void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align); /* Low level functions */ diff --git a/lib/lmb.c b/lib/lmb.c index 7bd1255f7a..793647724c 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -12,6 +12,10 @@ #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; + #define LMB_ALLOC_ANYWHERE 0 static void lmb_dump_region(struct lmb_region *rgn, char *name) @@ -113,6 +117,37 @@ void lmb_init(struct lmb *lmb) lmb->reserved.cnt = 0; } +void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align) +{ + ulong bank_end; + int bank; + + /* + * Reserve memory from aligned address below the bottom of U-Boot stack + * until end of U-Boot area using LMB to prevent U-Boot from overwriting + * that memory. + */ + debug("## Current stack ends at 0x%08lx ", sp); + + /* adjust sp by 4K to be safe */ + sp -= align; + for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { + if (!gd->bd->bi_dram[bank].size || + sp < gd->bd->bi_dram[bank].start) + continue; + /* Watch out for RAM at end of address space! */ + bank_end = gd->bd->bi_dram[bank].start + + gd->bd->bi_dram[bank].size - 1; + if (sp > bank_end) + continue; + if (bank_end > end) + bank_end = end - 1; + + lmb_reserve(lmb, sp, bank_end - sp + 1); + break; + } +} + static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob) { arch_lmb_reserve(lmb); -- 2.33.0