blob: 8a87e4a8e035133bbea72b39c540eff8d81a137b [file] [log] [blame]
Marek Behúne577cc32020-04-08 19:25:18 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
4 */
5
Tom Rini676ea8b2024-04-30 07:35:44 -06006#include <config.h>
Marek Behúne577cc32020-04-08 19:25:18 +02007#include <asm/arch/cpu.h>
8#include <asm/arch/soc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Tom Rini676ea8b2024-04-30 07:35:44 -060010#include <asm/u-boot.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060011#include <asm/ptrace.h>
Marek Behúne577cc32020-04-08 19:25:18 +020012#include <asm/system.h>
13#include <linux/sizes.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17#define MV_SIP_DRAM_SIZE 0x82000010
18
19u64 a8k_dram_scan_ap_sz(void)
20{
21 struct pt_regs pregs;
22
23 pregs.regs[0] = MV_SIP_DRAM_SIZE;
24 pregs.regs[1] = SOC_REGS_PHY_BASE;
25 smc_call(&pregs);
26
27 return pregs.regs[0];
28}
29
30int a8k_dram_init_banksize(void)
31{
32 /*
33 * The firmware (ATF) leaves a 1G whole above the 3G mark for IO
34 * devices. Higher RAM is mapped at 4G.
35 *
36 * Config 2 DRAM banks:
37 * Bank 0 - max size 4G - 1G
38 * Bank 1 - ram size - 4G + 1G
39 */
40 phys_size_t max_bank0_size = SZ_4G - SZ_1G;
41
Tom Rinibb4dd962022-11-16 13:10:37 -050042 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
Marek Behúne577cc32020-04-08 19:25:18 +020043 if (gd->ram_size <= max_bank0_size) {
44 gd->bd->bi_dram[0].size = gd->ram_size;
45 return 0;
46 }
47
48 gd->bd->bi_dram[0].size = max_bank0_size;
49 if (CONFIG_NR_DRAM_BANKS > 1) {
50 gd->bd->bi_dram[1].start = SZ_4G;
51 gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
52 }
53
54 return 0;
55}