blob: 24389d5cf1e32c042cd838d4cdccd9aa20ab0408 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay85b53972018-03-12 10:46:10 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay85b53972018-03-12 10:46:10 +01004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
9#include <init.h>
Patrick Delaunayd1633b32020-03-18 09:22:48 +010010#include <lmb.h>
Patrick Delaunay85b53972018-03-12 10:46:10 +010011#include <ram.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15int dram_init(void)
16{
17 struct ram_info ram;
18 struct udevice *dev;
19 int ret;
20
21 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
22 if (ret) {
23 debug("RAM init failed: %d\n", ret);
24 return ret;
25 }
26 ret = ram_get_info(dev, &ram);
27 if (ret) {
28 debug("Cannot get RAM size: %d\n", ret);
29 return ret;
30 }
31 debug("RAM init base=%lx, size=%x\n", ram.base, ram.size);
32
33 gd->ram_size = ram.size;
34
35 return 0;
36}
Patrick Delaunayd1633b32020-03-18 09:22:48 +010037
38ulong board_get_usable_ram_top(ulong total_size)
39{
40 phys_addr_t reg;
41 struct lmb lmb;
42
43 /* found enough not-reserved memory to relocated U-Boot */
44 lmb_init(&lmb);
45 lmb_add(&lmb, gd->ram_base, gd->ram_size);
46 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
47 reg = lmb_alloc(&lmb, CONFIG_SYS_MALLOC_LEN + total_size, SZ_4K);
48
49 if (reg)
50 return ALIGN(reg + CONFIG_SYS_MALLOC_LEN + total_size, SZ_4K);
51
52 return gd->ram_top;
53}