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.8 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 E5DC8C4338F for ; Sun, 15 Aug 2021 18:17:59 +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 5D10561212 for ; Sun, 15 Aug 2021 18:17:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5D10561212 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 1D8FE82C91; Sun, 15 Aug 2021 20:17:33 +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="nwcObd38"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 83B7482E00; Sun, 15 Aug 2021 20:17:21 +0200 (CEST) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 64859829C3 for ; Sun, 15 Aug 2021 20:17:15 +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-wm1-x330.google.com with SMTP id a201-20020a1c7fd2000000b002e6d33447f9so2209438wmd.0 for ; Sun, 15 Aug 2021 11:17:15 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=86qru6t/XuYO3B1gRZoxJgLznvd6oh724KnWA+txkZE=; b=nwcObd38Du3x93An8izBl1F5uPRSiAqhAn7wYFCr6ofF/9JdRPTJ7OIZKtJAVYpafu c3f7X7sT8ry2ZmicB9ibf8qEGUjeLa/puEHOVfQB5eOBGuV3uLQr2RE4YF0Snbyob72Q qYDCiukamp/nrkha1tJgLiAxlDt6cO/abiRdT/9IqrjtqTMgxPFqhM74Ib06dJU+7aVn 2t29IVEe4YVWK4jgMCvVRZV8W9tqT/rjZon6r2GwRgNsLAc3MhVJxthy5HMeweb/drj1 PgnAk2e7GGwF9m1Sgs44tlLbFCi45WfthiU1bF1i4Pr8YVonXacIh4W98X0r7HRx4Hx4 VZZg== 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:mime-version:content-transfer-encoding; bh=86qru6t/XuYO3B1gRZoxJgLznvd6oh724KnWA+txkZE=; b=OClrUZn2CGj5/IoCRzLcmTlZqnAhXNxM2dXzMpc0R/0xMDD9940gpbCFIMuYEZFlHM Af6vLkceomaYO0Z3lsH7Gyhh8cTE2WiMaOxrdgEqoybKDvwD+W02waWKOUo1q7o5QQfP 7Gj8oh261IGNLqItVQSKzLikqjJ7h0kvigKBERy8WOj8iWuC+ByZv7hSkS/aowMc9x2j ihL4g8kfKRk5rgKIalNPl3lNGeUmEze7pk6kfuBCPL3DQxNbQ7SxXP/0oIXSu5Ew50Bi KdrLROijvtRbwOEGZdt9ww81Sfo0mRLriRVePto1qw8+5dBVlW/vFZctUEAjluh6zxid gadA== X-Gm-Message-State: AOAM532/JODfnme+Ye9rF+SaBgSwzniJO2zPibFvYfJXCqXFNzrfOPjJ uyB5N2951GfnxZRppoH0JSvaxoZ3ocfpRw== X-Google-Smtp-Source: ABdhPJwSrObtUOkSbhVLVNQrflEgr4hLYHvolmcCEVucQPG9oe500C8wLdYvCzMKn55jdnNAHuBelw== X-Received: by 2002:a05:600c:4f0f:: with SMTP id l15mr12002291wmq.106.1629051434970; Sun, 15 Aug 2021 11:17:14 -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 i8sm5920343wrv.70.2021.08.15.11.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 11:17:14 -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 05/14] lmb: Add generic arch_lmb_reserve_generic() Date: Sun, 15 Aug 2021 20:13:05 +0200 Message-Id: <20210815181314.132330-5-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210815181314.132330-1-marek.vasut+renesas@gmail.com> References: <20210815181314.132330-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 --- include/lmb.h | 1 + lib/lmb.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index fa1474a360..deca551ee7 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..fed3c341a7 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,41 @@ 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; + + /* + * Booting a (Linux) kernel image + * + * Allocate space for command line and board info - the + * address should be as high as possible within the reach of + * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused + * memory, which means far enough below the current stack + * pointer. + */ + 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.30.2