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