2018-05-06 22:27:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
2018-03-12 09:46:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, STMicroelectronics - All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:29 +00:00
|
|
|
#define LOG_CATEGORY LOGC_ARCH
|
|
|
|
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
|
|
|
#include <init.h>
|
2020-03-18 08:22:48 +00:00
|
|
|
#include <lmb.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
#include <ram.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2021-02-05 12:53:32 +00:00
|
|
|
#include <asm/system.h>
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
struct ram_info ram;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device(UCLASS_RAM, 0, &dev);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("RAM init failed: %d\n", ret);
|
2018-03-12 09:46:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = ram_get_info(dev, &ram);
|
|
|
|
if (ret) {
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("Cannot get RAM size: %d\n", ret);
|
2018-03-12 09:46:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2020-11-06 18:01:29 +00:00
|
|
|
log_debug("RAM init base=%lx, size=%x\n", ram.base, ram.size);
|
2018-03-12 09:46:10 +00:00
|
|
|
|
|
|
|
gd->ram_size = ram.size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-18 08:22:48 +00:00
|
|
|
|
|
|
|
ulong board_get_usable_ram_top(ulong total_size)
|
|
|
|
{
|
2021-02-05 12:53:32 +00:00
|
|
|
phys_size_t size;
|
2020-03-18 08:22:48 +00:00
|
|
|
phys_addr_t reg;
|
|
|
|
struct lmb lmb;
|
|
|
|
|
|
|
|
/* found enough not-reserved memory to relocated U-Boot */
|
|
|
|
lmb_init(&lmb);
|
|
|
|
lmb_add(&lmb, gd->ram_base, gd->ram_size);
|
|
|
|
boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
|
2021-05-07 12:50:34 +00:00
|
|
|
/* add 8M for reserved memory for display, fdt, gd,... */
|
|
|
|
size = ALIGN(SZ_8M + CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE),
|
2021-02-05 12:53:32 +00:00
|
|
|
reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
|
2020-03-18 08:22:48 +00:00
|
|
|
|
2021-02-05 12:53:32 +00:00
|
|
|
if (!reg)
|
|
|
|
reg = gd->ram_top - size;
|
2020-03-18 08:22:48 +00:00
|
|
|
|
2021-05-07 12:50:34 +00:00
|
|
|
/* before relocation, mark the U-Boot memory as cacheable by default */
|
|
|
|
if (!(gd->flags & GD_FLG_RELOC))
|
|
|
|
mmu_set_region_dcache_behaviour(reg, size, DCACHE_DEFAULT_OPTION);
|
2021-02-05 12:53:32 +00:00
|
|
|
|
|
|
|
return reg + size;
|
2020-03-18 08:22:48 +00:00
|
|
|
}
|