u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>, u-boot@lists.denx.de
Cc: Alexey Brodkin <alexey.brodkin@synopsys.com>,
	Angelo Dureghello <angelo@sysam.it>,
	Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
	Hai Pham <hai.pham.ud@renesas.com>,
	Michal Simek <monstr@monstr.eu>,
	Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>,
	Tom Rini <trini@konsulko.com>, Wolfgang Denk <wd@denx.de>
Subject: Re: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic()
Date: Mon, 13 Sep 2021 04:08:09 +0200	[thread overview]
Message-ID: <cd024d92-7f32-7eee-e413-2fe55191dd8d@denx.de> (raw)
In-Reply-To: <4d503594c9da872302e9afc79f070f7037ff2316.camel@gmail.com>

On 9/12/21 9:27 PM, Daniel Schwierzeck wrote:

[...]

>> 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 <log.h>
>>   #include <malloc.h>
>>   
>> +#include <asm/global_data.h>
>> +
>> +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 */
> 
> nit: comment doesn't fit anymore
> 
>> +	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;
> 
> isn't that all already taken care of when initializing gd->ram_top as
> well as gd->relocaddr and gd->start_addr_sp (based on gd->ram_top)? So
> gd->ram_top is already guaranteed to be less or equal some DRAM bank
> end address. AFAIK arch_lmb_reserve() should just protect the U-Boot
> area from gd->start_addr_sp up to gd->ram_top as well as the stack area
> from the current stack pointer up to the initial stack pointer in gd-
>> start_addr_sp. Also you changed all callers to always pass gd->ram_top
> in "ulong end". Thus I think arch_lmb_reserve_generic() could omit
> those redundant checks and could be simplified to:
> 
>      sp -= align;
>      lmb_reserve(lmb, sp, gd->ram_top - sp);
> Or am I overlooking something? Is that a valid use case to have U-Boot
This would not allow reserving space at the end of DRAM bank for e.g. 
DSP firmware which just has to be at the end of DRAM bank. That's why 
there is this passing of gd->ram_top into this function and it's not 
part of the function, to prepare for this use case.

> area and stack area in different memory banks? If yes, shouldn't then
> lmb_reserve() be called twice by arch_lmb_reserve() to protect stack
> area AND U-Boot area?

The U-Boot stack is below relocated U-Boot, and there is other stuff 
between those two, so that's why this isn't called twice for stack and 
U-Boot.

  reply	other threads:[~2021-09-13  2:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 20:47 [PATCH 01/12] lmb: Always compile arch_lmb_reserve() into U-Boot on arm Marek Vasut
2021-09-10 20:47 ` [PATCH 02/12] lmb: Always compile arch_lmb_reserve() into U-Boot on arc Marek Vasut
2021-09-24  2:41   ` Tom Rini
2021-09-10 20:47 ` [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic() Marek Vasut
2021-09-10 21:10   ` Tom Rini
2021-09-12 19:27   ` Daniel Schwierzeck
2021-09-13  2:08     ` Marek Vasut [this message]
2021-09-24  2:41   ` Tom Rini
2021-09-10 20:47 ` [PATCH 04/12] lmb: Switch to " Marek Vasut
2021-09-24  2:41   ` Tom Rini
2021-09-10 20:47 ` [PATCH 05/12] lmb: arm: Increase LMB alignment to 16k in arch_lmb_reserve_generic() Marek Vasut
2021-09-10 21:10   ` Tom Rini
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 06/12] lmb: Remove imx board_lmb_reserve() Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 07/12] lmb: nios2: Add arch_lmb_reserve() Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 08/12] lmb: nds32: " Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 09/12] lmb: riscv: " Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 10/12] lmb: sh: " Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 11/12] lmb: xtensa: " Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-10 20:47 ` [PATCH 12/12] lmb: x86: " Marek Vasut
2021-09-24  2:42   ` Tom Rini
2021-09-24  2:41 ` [PATCH 01/12] lmb: Always compile arch_lmb_reserve() into U-Boot on arm Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd024d92-7f32-7eee-e413-2fe55191dd8d@denx.de \
    --to=marex@denx.de \
    --cc=Eugeniy.Paltsev@synopsys.com \
    --cc=alexey.brodkin@synopsys.com \
    --cc=angelo@sysam.it \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=hai.pham.ud@renesas.com \
    --cc=monstr@monstr.eu \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=wd@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).