diff mbox series

[v4,1/9] CONFIG_NR_DRAM_BANKS: Remove unreferenced code as its always defined

Message ID 20200813054800.469284-2-sr@denx.de
State Superseded
Delegated to: Tom Rini
Headers show
Series Remove CONFIG_NR_DRAM_BANKS option and bi_memstart/memsize from bd_info | expand

Commit Message

Stefan Roese Aug. 13, 2020, 5:47 a.m. UTC
Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
It makes no sense to still carry code that is guarded with
"#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
all these unreferenced code paths.

Signed-off-by: Stefan Roese <sr@denx.de>

---

Changes in v4:
- Only remove dead code with CONFIG_NR_DRAM_BANKS always defined

 arch/x86/cpu/broadwell/cpu_from_spl.c |  2 --
 board/xilinx/zynqmp/zynqmp.c          |  2 --
 cmd/bdinfo.c                          |  2 --
 common/board_f.c                      |  7 +-----
 common/image.c                        |  3 +--
 common/init/handoff.c                 | 33 +++++++++++----------------
 drivers/pci/pci-uclass.c              | 17 +-------------
 include/asm-generic/u-boot.h          |  2 --
 include/handoff.h                     |  2 --
 lib/fdtdec.c                          |  5 ----
 lib/lmb.c                             |  9 ++------
 11 files changed, 18 insertions(+), 66 deletions(-)

Comments

Pali Rohár Aug. 13, 2020, 7:45 a.m. UTC | #1
On Thursday 13 August 2020 07:47:52 Stefan Roese wrote:
> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> It makes no sense to still carry code that is guarded with
> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
> all these unreferenced code paths.
> 
> Signed-off-by: Stefan Roese <sr@denx.de>

Looks good for me, you can add my:

Reviewed-by: Pali Rohár <pali@kernel.org>
Andy Shevchenko Aug. 13, 2020, 11:14 a.m. UTC | #2
On Thu, Aug 13, 2020 at 07:47:52AM +0200, Stefan Roese wrote:
> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> It makes no sense to still carry code that is guarded with
> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
> all these unreferenced code paths.

...

>  	int pci_addr_cells, addr_cells, size_cells;
> +	struct bd_info *bd = gd->bd;
>  	int cells_per_record;
>  	const u32 *prop;
>  	int len;

>  	/* Add a region for our local memory */

> -#ifdef CONFIG_NR_DRAM_BANKS
> -	struct bd_info *bd = gd->bd;
> -

Can we leave assignment here?

>  	if (!bd)
>  		return;
Andy Shevchenko Aug. 13, 2020, 11:15 a.m. UTC | #3
On Thu, Aug 13, 2020 at 07:47:52AM +0200, Stefan Roese wrote:
> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> It makes no sense to still carry code that is guarded with
> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
> all these unreferenced code paths.

I don't see any other patches, this one, after addressing
the assignment position,

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Stefan Roese <sr@denx.de>
> 
> ---
> 
> Changes in v4:
> - Only remove dead code with CONFIG_NR_DRAM_BANKS always defined
> 
>  arch/x86/cpu/broadwell/cpu_from_spl.c |  2 --
>  board/xilinx/zynqmp/zynqmp.c          |  2 --
>  cmd/bdinfo.c                          |  2 --
>  common/board_f.c                      |  7 +-----
>  common/image.c                        |  3 +--
>  common/init/handoff.c                 | 33 +++++++++++----------------
>  drivers/pci/pci-uclass.c              | 17 +-------------
>  include/asm-generic/u-boot.h          |  2 --
>  include/handoff.h                     |  2 --
>  lib/fdtdec.c                          |  5 ----
>  lib/lmb.c                             |  9 ++------
>  11 files changed, 18 insertions(+), 66 deletions(-)
> 
> diff --git a/arch/x86/cpu/broadwell/cpu_from_spl.c b/arch/x86/cpu/broadwell/cpu_from_spl.c
> index 6567d50653..4d4cdafa2b 100644
> --- a/arch/x86/cpu/broadwell/cpu_from_spl.c
> +++ b/arch/x86/cpu/broadwell/cpu_from_spl.c
> @@ -53,14 +53,12 @@ void board_debug_uart_init(void)
>  
>  int dram_init_banksize(void)
>  {
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	struct spl_handoff *ho;
>  
>  	ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(*ho));
>  	if (!ho)
>  		return log_msg_ret("Missing SPL hand-off info", -ENOENT);
>  	handoff_load_dram_banks(ho);
> -#endif
>  
>  	return 0;
>  }
> diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
> index ebb7172908..4cc5cb6fd7 100644
> --- a/board/xilinx/zynqmp/zynqmp.c
> +++ b/board/xilinx/zynqmp/zynqmp.c
> @@ -467,10 +467,8 @@ int dram_init(void)
>  #else
>  int dram_init_banksize(void)
>  {
> -#if defined(CONFIG_NR_DRAM_BANKS)
>  	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
>  	gd->bd->bi_dram[0].size = get_effective_memsize();
> -#endif
>  
>  	mem_map_fill();
>  
> diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
> index 9593b345a3..9e230f23cb 100644
> --- a/cmd/bdinfo.c
> +++ b/cmd/bdinfo.c
> @@ -49,7 +49,6 @@ void bdinfo_print_mhz(const char *name, unsigned long hz)
>  
>  static void print_bi_dram(const struct bd_info *bd)
>  {
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	int i;
>  
>  	for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
> @@ -59,7 +58,6 @@ static void print_bi_dram(const struct bd_info *bd)
>  			bdinfo_print_num("-> size",	bd->bi_dram[i].size);
>  		}
>  	}
> -#endif
>  }
>  
>  __weak void arch_print_bdinfo(void)
> diff --git a/common/board_f.c b/common/board_f.c
> index 79532f4365..dd9a5220e1 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -215,8 +215,6 @@ static int announce_dram_init(void)
>  static int show_dram_config(void)
>  {
>  	unsigned long long size;
> -
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	int i;
>  
>  	debug("\nRAM Configuration:\n");
> @@ -229,9 +227,6 @@ static int show_dram_config(void)
>  #endif
>  	}
>  	debug("\nDRAM:  ");
> -#else
> -	size = gd->ram_size;
> -#endif
>  
>  	print_size(size, "");
>  	board_add_ram_info(0);
> @@ -242,7 +237,7 @@ static int show_dram_config(void)
>  
>  __weak int dram_init_banksize(void)
>  {
> -#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
> +#if defined(CONFIG_SYS_SDRAM_BASE)
>  	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
>  	gd->bd->bi_dram[0].size = get_effective_memsize();
>  #endif
> diff --git a/common/image.c b/common/image.c
> index 9d7d5c17d1..2ed46f7685 100644
> --- a/common/image.c
> +++ b/common/image.c
> @@ -685,8 +685,7 @@ phys_size_t env_get_bootm_size(void)
>  		return tmp;
>  	}
>  
> -#if (defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)) && \
> -     defined(CONFIG_NR_DRAM_BANKS)
> +#if defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)
>  	start = gd->bd->bi_dram[0].start;
>  	size = gd->bd->bi_dram[0].size;
>  #else
> diff --git a/common/init/handoff.c b/common/init/handoff.c
> index e00b43e6a7..62071bd017 100644
> --- a/common/init/handoff.c
> +++ b/common/init/handoff.c
> @@ -12,18 +12,15 @@ DECLARE_GLOBAL_DATA_PTR;
>  
>  void handoff_save_dram(struct spl_handoff *ho)
>  {
> +	struct bd_info *bd = gd->bd;
> +	int i;
> +
>  	ho->ram_size = gd->ram_size;
> -#ifdef CONFIG_NR_DRAM_BANKS
> -	{
> -		struct bd_info *bd = gd->bd;
> -		int i;
> -
> -		for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> -			ho->ram_bank[i].start = bd->bi_dram[i].start;
> -			ho->ram_bank[i].size = bd->bi_dram[i].size;
> -		}
> +
> +	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> +		ho->ram_bank[i].start = bd->bi_dram[i].start;
> +		ho->ram_bank[i].size = bd->bi_dram[i].size;
>  	}
> -#endif
>  }
>  
>  void handoff_load_dram_size(struct spl_handoff *ho)
> @@ -33,15 +30,11 @@ void handoff_load_dram_size(struct spl_handoff *ho)
>  
>  void handoff_load_dram_banks(struct spl_handoff *ho)
>  {
> -#ifdef CONFIG_NR_DRAM_BANKS
> -	{
> -		struct bd_info *bd = gd->bd;
> -		int i;
> -
> -		for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> -			bd->bi_dram[i].start = ho->ram_bank[i].start;
> -			bd->bi_dram[i].size = ho->ram_bank[i].size;
> -		}
> +	struct bd_info *bd = gd->bd;
> +	int i;
> +
> +	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> +		bd->bi_dram[i].start = ho->ram_bank[i].start;
> +		bd->bi_dram[i].size = ho->ram_bank[i].size;
>  	}
> -#endif
>  }
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index 834526c5a4..69fb46d3f4 100644
> --- a/drivers/pci/pci-uclass.c
> +++ b/drivers/pci/pci-uclass.c
> @@ -871,6 +871,7 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node,
>  			   ofnode node)
>  {
>  	int pci_addr_cells, addr_cells, size_cells;
> +	struct bd_info *bd = gd->bd;
>  	int cells_per_record;
>  	const u32 *prop;
>  	int len;
> @@ -938,9 +939,6 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node,
>  	}
>  
>  	/* Add a region for our local memory */
> -#ifdef CONFIG_NR_DRAM_BANKS
> -	struct bd_info *bd = gd->bd;
> -
>  	if (!bd)
>  		return;
>  
> @@ -958,19 +956,6 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node,
>  				       PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
>  		}
>  	}
> -#else
> -	phys_addr_t base = 0, size;
> -
> -	size = gd->ram_size;
> -#ifdef CONFIG_SYS_SDRAM_BASE
> -	base = CONFIG_SYS_SDRAM_BASE;
> -#endif
> -	if (gd->pci_ram_top && gd->pci_ram_top < base + size)
> -		size = gd->pci_ram_top - base;
> -	if (size)
> -		pci_set_region(hose->regions + hose->region_count++, base,
> -			base, size, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
> -#endif
>  
>  	return;
>  }
> diff --git a/include/asm-generic/u-boot.h b/include/asm-generic/u-boot.h
> index 62e61d41cc..99d3fe33ad 100644
> --- a/include/asm-generic/u-boot.h
> +++ b/include/asm-generic/u-boot.h
> @@ -70,12 +70,10 @@ struct bd_info {
>  #endif
>  	ulong	        bi_arch_number;	/* unique id for this board */
>  	ulong	        bi_boot_params;	/* where this board expects params */
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	struct {			/* RAM configuration */
>  		phys_addr_t start;
>  		phys_size_t size;
>  	} bi_dram[CONFIG_NR_DRAM_BANKS];
> -#endif /* CONFIG_NR_DRAM_BANKS */
>  };
>  
>  #endif /* __ASSEMBLY__ */
> diff --git a/include/handoff.h b/include/handoff.h
> index 75d19b1f6e..070a79c1b9 100644
> --- a/include/handoff.h
> +++ b/include/handoff.h
> @@ -20,12 +20,10 @@
>  struct spl_handoff {
>  	struct arch_spl_handoff arch;
>  	u64 ram_size;
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	struct {
>  		u64 start;
>  		u64 size;
>  	} ram_bank[CONFIG_NR_DRAM_BANKS];
> -#endif
>  };
>  
>  void handoff_save_dram(struct spl_handoff *ho);
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 78576b530f..ecbf10121d 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -1055,8 +1055,6 @@ int fdtdec_setup_mem_size_base(void)
>  	return 0;
>  }
>  
> -#if defined(CONFIG_NR_DRAM_BANKS)
> -
>  static int get_next_memory_node(const void *blob, int mem)
>  {
>  	do {
> @@ -1106,7 +1104,6 @@ int fdtdec_setup_memory_banksize(void)
>  
>  	return 0;
>  }
> -#endif
>  
>  #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
>  # if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
> @@ -1569,7 +1566,6 @@ int fdtdec_resetup(int *rescan)
>  }
>  #endif
>  
> -#ifdef CONFIG_NR_DRAM_BANKS
>  int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
>  			   phys_addr_t *basep, phys_size_t *sizep,
>  			   struct bd_info *bd)
> @@ -1675,6 +1671,5 @@ int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
>  
>  	return 0;
>  }
> -#endif /* CONFIG_NR_DRAM_BANKS */
>  
>  #endif /* !USE_HOSTCC */
> diff --git a/lib/lmb.c b/lib/lmb.c
> index 75082f3559..d126f8dc04 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -117,22 +117,17 @@ static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
>  /* Initialize the struct, add memory and call arch/board reserve functions */
>  void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob)
>  {
> -#ifdef CONFIG_NR_DRAM_BANKS
>  	int i;
> -#endif
>  
>  	lmb_init(lmb);
> -#ifdef CONFIG_NR_DRAM_BANKS
> +
>  	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
>  		if (bd->bi_dram[i].size) {
>  			lmb_add(lmb, bd->bi_dram[i].start,
>  				bd->bi_dram[i].size);
>  		}
>  	}
> -#else
> -	if (bd->bi_memsize)
> -		lmb_add(lmb, bd->bi_memstart, bd->bi_memsize);
> -#endif
> +
>  	lmb_reserve_common(lmb, fdt_blob);
>  }
>  
> -- 
> 2.28.0
>
Stefan Roese Aug. 13, 2020, 11:28 a.m. UTC | #4
On 13.08.20 13:14, Andy Shevchenko wrote:
> On Thu, Aug 13, 2020 at 07:47:52AM +0200, Stefan Roese wrote:
>> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
>> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
>> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
>> It makes no sense to still carry code that is guarded with
>> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
>> all these unreferenced code paths.
> 
> ...
> 
>>   	int pci_addr_cells, addr_cells, size_cells;
>> +	struct bd_info *bd = gd->bd;
>>   	int cells_per_record;
>>   	const u32 *prop;
>>   	int len;
> 
>>   	/* Add a region for our local memory */
> 
>> -#ifdef CONFIG_NR_DRAM_BANKS
>> -	struct bd_info *bd = gd->bd;
>> -
> 
> Can we leave assignment here?

Sure. Just curious why? Is it recommended not to make the assignment
with the declaration?

Thanks,
Stefan
Andy Shevchenko Aug. 13, 2020, 1:10 p.m. UTC | #5
On Thu, Aug 13, 2020 at 01:28:29PM +0200, Stefan Roese wrote:
> On 13.08.20 13:14, Andy Shevchenko wrote:
> > On Thu, Aug 13, 2020 at 07:47:52AM +0200, Stefan Roese wrote:
> > > Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> > > commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> > > CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> > > It makes no sense to still carry code that is guarded with
> > > "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
> > > all these unreferenced code paths.
> > 
> > ...
> > 
> > >   	int pci_addr_cells, addr_cells, size_cells;
> > > +	struct bd_info *bd = gd->bd;
> > >   	int cells_per_record;
> > >   	const u32 *prop;
> > >   	int len;
> > 
> > >   	/* Add a region for our local memory */
> > 
> > > -#ifdef CONFIG_NR_DRAM_BANKS
> > > -	struct bd_info *bd = gd->bd;
> > > -
> > 
> > Can we leave assignment here?
> 
> Sure. Just curious why? Is it recommended not to make the assignment
> with the declaration?

Slightly easier to read and understand the code. I find it's hard when you need
to spend additional 1,2...10 seconds to go around and see where this value
comes from. Easy question to ask when you see such code: is this parameter
evaluation (defensive programming) or some assignment happened earlier to
check?
Wolfgang Denk Aug. 18, 2020, 10:31 a.m. UTC | #6
Dear Stefan Roese,

In message <20200813054800.469284-2-sr@denx.de> you wrote:
> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).

Has there been any evaluation about the impact this change had on
both text and data sizes of the resulting U-Boot image?
Especially the default value of 4 makes no sense to me - whiy is
this not 1?

> It makes no sense to still carry code that is guarded with
> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
> all these unreferenced code paths.

...thus futher hiding where we just lost another lof of memory, for
no advantage.

Sic...

Best regards,

Wolfgang Denk
Stefan Roese Aug. 18, 2020, 11:33 a.m. UTC | #7
Hi Wolfgang,

(added Ramon to Cc)

On 18.08.20 12:31, Wolfgang Denk wrote:
> In message <20200813054800.469284-2-sr@denx.de> you wrote:
>> Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
>> commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
>> CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> 
> Has there been any evaluation about the impact this change had on
> both text and data sizes of the resulting U-Boot image?

Not sure. Ramon and / or Tom might comment on this. Even though the
git history shows that these Kconfig migration patches have been
committed ~2 years ago, so their memory might be foggy ;)

commit 86cf1c82850f7c226f23684e19616e526ffaf10f
Author: Tom Rini <trini@konsulko.com>
Date:   Thu Aug 16 08:16:24 2018 -0400

     configs: Migrate CONFIG_NR_DRAM_BANKS

     We have the following cases:
     - CONFIG_NR_DRAM_BANKS was defined, migrate normally
     - CONFIG_NR_DRAM_BANKS_MAX was defined and then used for
       CONFIG_NR_DRAM_BANKS after a check, just migrate it over now.
     - CONFIG_NR_DRAM_BANKS was very oddly defined on p2771-0000-* (to 
1024 +
       2), set this to 8.

     Signed-off-by: Tom Rini <trini@konsulko.com>

commit 999a772d9f24bf9b8d0726e1359c9d8c3bdad72e
Author: Ramon Fried <ramon.fried@gmail.com>
Date:   Tue Aug 14 01:00:04 2018 +0300

     Kconfig: Migrate CONFIG_NR_DRAM_BANKS

     Move CONFIG_NR_DRAM_BANKS from headers to Kconfig.

     Signed-off-by: Ramon Fried <ramon.fried@gmail.com>

> Especially the default value of 4 makes no sense to me - whiy is
> this not 1?

I can't really tell. I can only assume, that it originates from this
patch:

commit 6b6f216f9234c33881af05116057c902cb411a62
Author: Ramon Fried <ramon.fried@gmail.com>
Date:   Tue Aug 14 00:35:42 2018 +0300

     fdt_support: Use CONFIG_NR_DRAM_BANKS if necessary

     If CONFIG_NR_DRAM_BANKS is bigger than the default
     value (4) define MEMORY_BANKS_MAX as CONFIG_NR_DRAM_BANKS.

     Fixes: 2a1f4f1758b5 ("Revert "fdt_support: Use CONFIG_NR_DRAM_BANKS 
if defined"")
     Signed-off-by: Ramon Fried <ramon.fried@gmail.com>

>> It makes no sense to still carry code that is guarded with
>> "#ifndef CONFIG_NR_DRAM_BANKS" (and similar). This patch removes
>> all these unreferenced code paths.
> 
> ...thus futher hiding where we just lost another lof of memory, for
> no advantage.
> 
> Sic...

I'm not sure, what you mean with "lost lot of memory"? We carried
referenced code for ~2 years, which this patch series now tries to
solve.

Thanks,
Stefan
Wolfgang Denk Aug. 18, 2020, 12:19 p.m. UTC | #8
Dear Stefan,

In message <8ddb672c-956c-68d2-ceb4-d77f96cdf4e4@denx.de> you wrote:
>
> > Especially the default value of 4 makes no sense to me - whiy is
> > this not 1?
>
> I can't really tell. I can only assume, that it originates from this
> patch:

Yes, probably.

I think the issue here resutlsfromt he fact that those who worked on
the patches came primarily from architectures where this array of
banks has been used; for Power Architecture systems this has (for a
long, long time) not been the case - there we would map several
memory banks (after determining their respecitve sizes) into one
contiguous area of memory starting at address 0.

So on all such system the definition of this array meand code and
data overhead, as it is not needed.

> > ...thus futher hiding where we just lost another lof of memory, for
> > no advantage.
> > 
> > Sic...
>
> I'm not sure, what you mean with "lost lot of memory"? We carried
> referenced code for ~2 years, which this patch series now tries to
> solve.

See above. On most PPC systems this array of sizes and addresses is
not needed at all, and _if_ code is changed to use such an array, it
should not waste even more memory be defining room for 4 banks where
there usually will be only one.

Sorry, I know that you are not to blame for that...

Best regards,

Wolfgang Denk
Tom Rini Aug. 18, 2020, 1:06 p.m. UTC | #9
On Tue, Aug 18, 2020 at 12:31:32PM +0200, Wolfgang Denk wrote:
> Dear Stefan Roese,
> 
> In message <20200813054800.469284-2-sr@denx.de> you wrote:
> > Since commit 86cf1c82850f ("configs: Migrate CONFIG_NR_DRAM_BANKS") &
> > commit 999a772d9f24 ("Kconfig: Migrate CONFIG_NR_DRAM_BANKS"),
> > CONFIG_NR_DRAM_BANKS is always defined with a value (4 is default).
> 
> Has there been any evaluation about the impact this change had on
> both text and data sizes of the resulting U-Boot image?
> Especially the default value of 4 makes no sense to me - whiy is
> this not 1?

The default value is 4 because that was the most commonly used value.
Annoyingly enough, I don't have those logs around (either I did them on
Google Compute, or it was on a build box we reinstalled and I didn't
save the logs off of) but I'm fairly sure there wasn't a size change,
that's one of my tests for these migrations (that does sometimes fail to
catch things, I need to play with getting the data out of buildman in
something I can filter more easily).
diff mbox series

Patch

diff --git a/arch/x86/cpu/broadwell/cpu_from_spl.c b/arch/x86/cpu/broadwell/cpu_from_spl.c
index 6567d50653..4d4cdafa2b 100644
--- a/arch/x86/cpu/broadwell/cpu_from_spl.c
+++ b/arch/x86/cpu/broadwell/cpu_from_spl.c
@@ -53,14 +53,12 @@  void board_debug_uart_init(void)
 
 int dram_init_banksize(void)
 {
-#ifdef CONFIG_NR_DRAM_BANKS
 	struct spl_handoff *ho;
 
 	ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(*ho));
 	if (!ho)
 		return log_msg_ret("Missing SPL hand-off info", -ENOENT);
 	handoff_load_dram_banks(ho);
-#endif
 
 	return 0;
 }
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index ebb7172908..4cc5cb6fd7 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -467,10 +467,8 @@  int dram_init(void)
 #else
 int dram_init_banksize(void)
 {
-#if defined(CONFIG_NR_DRAM_BANKS)
 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
 	gd->bd->bi_dram[0].size = get_effective_memsize();
-#endif
 
 	mem_map_fill();
 
diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 9593b345a3..9e230f23cb 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -49,7 +49,6 @@  void bdinfo_print_mhz(const char *name, unsigned long hz)
 
 static void print_bi_dram(const struct bd_info *bd)
 {
-#ifdef CONFIG_NR_DRAM_BANKS
 	int i;
 
 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
@@ -59,7 +58,6 @@  static void print_bi_dram(const struct bd_info *bd)
 			bdinfo_print_num("-> size",	bd->bi_dram[i].size);
 		}
 	}
-#endif
 }
 
 __weak void arch_print_bdinfo(void)
diff --git a/common/board_f.c b/common/board_f.c
index 79532f4365..dd9a5220e1 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -215,8 +215,6 @@  static int announce_dram_init(void)
 static int show_dram_config(void)
 {
 	unsigned long long size;
-
-#ifdef CONFIG_NR_DRAM_BANKS
 	int i;
 
 	debug("\nRAM Configuration:\n");
@@ -229,9 +227,6 @@  static int show_dram_config(void)
 #endif
 	}
 	debug("\nDRAM:  ");
-#else
-	size = gd->ram_size;
-#endif
 
 	print_size(size, "");
 	board_add_ram_info(0);
@@ -242,7 +237,7 @@  static int show_dram_config(void)
 
 __weak int dram_init_banksize(void)
 {
-#if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
+#if defined(CONFIG_SYS_SDRAM_BASE)
 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
 	gd->bd->bi_dram[0].size = get_effective_memsize();
 #endif
diff --git a/common/image.c b/common/image.c
index 9d7d5c17d1..2ed46f7685 100644
--- a/common/image.c
+++ b/common/image.c
@@ -685,8 +685,7 @@  phys_size_t env_get_bootm_size(void)
 		return tmp;
 	}
 
-#if (defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)) && \
-     defined(CONFIG_NR_DRAM_BANKS)
+#if defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)
 	start = gd->bd->bi_dram[0].start;
 	size = gd->bd->bi_dram[0].size;
 #else
diff --git a/common/init/handoff.c b/common/init/handoff.c
index e00b43e6a7..62071bd017 100644
--- a/common/init/handoff.c
+++ b/common/init/handoff.c
@@ -12,18 +12,15 @@  DECLARE_GLOBAL_DATA_PTR;
 
 void handoff_save_dram(struct spl_handoff *ho)
 {
+	struct bd_info *bd = gd->bd;
+	int i;
+
 	ho->ram_size = gd->ram_size;
-#ifdef CONFIG_NR_DRAM_BANKS
-	{
-		struct bd_info *bd = gd->bd;
-		int i;
-
-		for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
-			ho->ram_bank[i].start = bd->bi_dram[i].start;
-			ho->ram_bank[i].size = bd->bi_dram[i].size;
-		}
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+		ho->ram_bank[i].start = bd->bi_dram[i].start;
+		ho->ram_bank[i].size = bd->bi_dram[i].size;
 	}
-#endif
 }
 
 void handoff_load_dram_size(struct spl_handoff *ho)
@@ -33,15 +30,11 @@  void handoff_load_dram_size(struct spl_handoff *ho)
 
 void handoff_load_dram_banks(struct spl_handoff *ho)
 {
-#ifdef CONFIG_NR_DRAM_BANKS
-	{
-		struct bd_info *bd = gd->bd;
-		int i;
-
-		for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
-			bd->bi_dram[i].start = ho->ram_bank[i].start;
-			bd->bi_dram[i].size = ho->ram_bank[i].size;
-		}
+	struct bd_info *bd = gd->bd;
+	int i;
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+		bd->bi_dram[i].start = ho->ram_bank[i].start;
+		bd->bi_dram[i].size = ho->ram_bank[i].size;
 	}
-#endif
 }
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 834526c5a4..69fb46d3f4 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -871,6 +871,7 @@  static void decode_regions(struct pci_controller *hose, ofnode parent_node,
 			   ofnode node)
 {
 	int pci_addr_cells, addr_cells, size_cells;
+	struct bd_info *bd = gd->bd;
 	int cells_per_record;
 	const u32 *prop;
 	int len;
@@ -938,9 +939,6 @@  static void decode_regions(struct pci_controller *hose, ofnode parent_node,
 	}
 
 	/* Add a region for our local memory */
-#ifdef CONFIG_NR_DRAM_BANKS
-	struct bd_info *bd = gd->bd;
-
 	if (!bd)
 		return;
 
@@ -958,19 +956,6 @@  static void decode_regions(struct pci_controller *hose, ofnode parent_node,
 				       PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
 		}
 	}
-#else
-	phys_addr_t base = 0, size;
-
-	size = gd->ram_size;
-#ifdef CONFIG_SYS_SDRAM_BASE
-	base = CONFIG_SYS_SDRAM_BASE;
-#endif
-	if (gd->pci_ram_top && gd->pci_ram_top < base + size)
-		size = gd->pci_ram_top - base;
-	if (size)
-		pci_set_region(hose->regions + hose->region_count++, base,
-			base, size, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
-#endif
 
 	return;
 }
diff --git a/include/asm-generic/u-boot.h b/include/asm-generic/u-boot.h
index 62e61d41cc..99d3fe33ad 100644
--- a/include/asm-generic/u-boot.h
+++ b/include/asm-generic/u-boot.h
@@ -70,12 +70,10 @@  struct bd_info {
 #endif
 	ulong	        bi_arch_number;	/* unique id for this board */
 	ulong	        bi_boot_params;	/* where this board expects params */
-#ifdef CONFIG_NR_DRAM_BANKS
 	struct {			/* RAM configuration */
 		phys_addr_t start;
 		phys_size_t size;
 	} bi_dram[CONFIG_NR_DRAM_BANKS];
-#endif /* CONFIG_NR_DRAM_BANKS */
 };
 
 #endif /* __ASSEMBLY__ */
diff --git a/include/handoff.h b/include/handoff.h
index 75d19b1f6e..070a79c1b9 100644
--- a/include/handoff.h
+++ b/include/handoff.h
@@ -20,12 +20,10 @@ 
 struct spl_handoff {
 	struct arch_spl_handoff arch;
 	u64 ram_size;
-#ifdef CONFIG_NR_DRAM_BANKS
 	struct {
 		u64 start;
 		u64 size;
 	} ram_bank[CONFIG_NR_DRAM_BANKS];
-#endif
 };
 
 void handoff_save_dram(struct spl_handoff *ho);
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 78576b530f..ecbf10121d 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1055,8 +1055,6 @@  int fdtdec_setup_mem_size_base(void)
 	return 0;
 }
 
-#if defined(CONFIG_NR_DRAM_BANKS)
-
 static int get_next_memory_node(const void *blob, int mem)
 {
 	do {
@@ -1106,7 +1104,6 @@  int fdtdec_setup_memory_banksize(void)
 
 	return 0;
 }
-#endif
 
 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
 # if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
@@ -1569,7 +1566,6 @@  int fdtdec_resetup(int *rescan)
 }
 #endif
 
-#ifdef CONFIG_NR_DRAM_BANKS
 int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
 			   phys_addr_t *basep, phys_size_t *sizep,
 			   struct bd_info *bd)
@@ -1675,6 +1671,5 @@  int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
 
 	return 0;
 }
-#endif /* CONFIG_NR_DRAM_BANKS */
 
 #endif /* !USE_HOSTCC */
diff --git a/lib/lmb.c b/lib/lmb.c
index 75082f3559..d126f8dc04 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -117,22 +117,17 @@  static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
 /* Initialize the struct, add memory and call arch/board reserve functions */
 void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob)
 {
-#ifdef CONFIG_NR_DRAM_BANKS
 	int i;
-#endif
 
 	lmb_init(lmb);
-#ifdef CONFIG_NR_DRAM_BANKS
+
 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
 		if (bd->bi_dram[i].size) {
 			lmb_add(lmb, bd->bi_dram[i].start,
 				bd->bi_dram[i].size);
 		}
 	}
-#else
-	if (bd->bi_memsize)
-		lmb_add(lmb, bd->bi_memstart, bd->bi_memsize);
-#endif
+
 	lmb_reserve_common(lmb, fdt_blob);
 }