]> Git Repo - J-u-boot.git/blame - arch/arm/mach-stm32mp/dram_init.c
arm: stm32mp: Implement support for TZC 400 controller
[J-u-boot.git] / arch / arm / mach-stm32mp / dram_init.c
CommitLineData
4549e789 1// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2514c2d0
PD
2/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
2514c2d0
PD
4 */
5
eb653acd
PD
6#define LOG_CATEGORY LOGC_ARCH
7
2514c2d0
PD
8#include <common.h>
9#include <dm.h>
4d72caa5
SG
10#include <image.h>
11#include <init.h>
4a1b975d 12#include <lmb.h>
f7ae49fc 13#include <log.h>
2514c2d0 14#include <ram.h>
401d1c4f 15#include <asm/global_data.h>
1419e5b5 16#include <asm/system.h>
2514c2d0
PD
17
18DECLARE_GLOBAL_DATA_PTR;
19
20int dram_init(void)
21{
22 struct ram_info ram;
23 struct udevice *dev;
24 int ret;
25
26 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
27 if (ret) {
eb653acd 28 log_debug("RAM init failed: %d\n", ret);
2514c2d0
PD
29 return ret;
30 }
31 ret = ram_get_info(dev, &ram);
32 if (ret) {
eb653acd 33 log_debug("Cannot get RAM size: %d\n", ret);
2514c2d0
PD
34 return ret;
35 }
eb653acd 36 log_debug("RAM init base=%lx, size=%x\n", ram.base, ram.size);
2514c2d0
PD
37
38 gd->ram_size = ram.size;
39
40 return 0;
41}
4a1b975d
PD
42
43ulong board_get_usable_ram_top(ulong total_size)
44{
1419e5b5 45 phys_size_t size;
4a1b975d
PD
46 phys_addr_t reg;
47 struct lmb lmb;
48
49 /* found enough not-reserved memory to relocated U-Boot */
50 lmb_init(&lmb);
51 lmb_add(&lmb, gd->ram_base, gd->ram_size);
52 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
7dc6068f
PD
53 /* add 8M for reserved memory for display, fdt, gd,... */
54 size = ALIGN(SZ_8M + CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE),
1419e5b5 55 reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
4a1b975d 56
1419e5b5
PD
57 if (!reg)
58 reg = gd->ram_top - size;
4a1b975d 59
7dc6068f
PD
60 /* before relocation, mark the U-Boot memory as cacheable by default */
61 if (!(gd->flags & GD_FLG_RELOC))
62 mmu_set_region_dcache_behaviour(reg, size, DCACHE_DEFAULT_OPTION);
1419e5b5
PD
63
64 return reg + size;
4a1b975d 65}
This page took 0.144803 seconds and 4 git commands to generate.