blob: 5b1311d8b5b9b92ebe2a34b41a795af5327da607 [file] [log] [blame]
Aaron Williams0dc4ab92020-06-30 12:08:56 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
Stefan Roese590d48e2020-09-02 08:29:09 +02003 * Copyright (C) 2020 Stefan Roese <sr@denx.de>
Aaron Williams0dc4ab92020-06-30 12:08:56 +02004 */
5
Stefan Roese590d48e2020-09-02 08:29:09 +02006#include <config.h>
Aaron Williams0dc4ab92020-06-30 12:08:56 +02007#include <dm.h>
8#include <ram.h>
9#include <asm/global_data.h>
10#include <linux/compat.h>
Stefan Roese590d48e2020-09-02 08:29:09 +020011#include <display_options.h>
Aaron Williams0dc4ab92020-06-30 12:08:56 +020012
13DECLARE_GLOBAL_DATA_PTR;
14
Stefan Roese590d48e2020-09-02 08:29:09 +020015#define UBOOT_RAM_SIZE_MAX 0x10000000ULL
16
Aaron Williams0dc4ab92020-06-30 12:08:56 +020017int dram_init(void)
18{
Stefan Roese590d48e2020-09-02 08:29:09 +020019 if (IS_ENABLED(CONFIG_RAM_OCTEON)) {
20 struct ram_info ram;
21 struct udevice *dev;
22 int ret;
23
24 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
25 if (ret) {
26 debug("DRAM init failed: %d\n", ret);
27 return ret;
28 }
29
30 ret = ram_get_info(dev, &ram);
31 if (ret) {
32 debug("Cannot get DRAM size: %d\n", ret);
33 return ret;
34 }
35
Stefan Roese8bab2c82020-10-28 15:10:01 +010036 gd->ram_size = ram.size;
Stefan Roese590d48e2020-09-02 08:29:09 +020037 debug("SDRAM base=%lx, size=%lx\n",
38 (unsigned long)ram.base, (unsigned long)ram.size);
39 } else {
40 /*
41 * No DDR init yet -> run in L2 cache
42 */
43 gd->ram_size = (4 << 20);
44 gd->bd->bi_dram[0].size = gd->ram_size;
45 gd->bd->bi_dram[1].size = 0;
46 }
Aaron Williams0dc4ab92020-06-30 12:08:56 +020047
48 return 0;
49}
50
Stefan Roese590d48e2020-09-02 08:29:09 +020051void board_add_ram_info(int use_default)
52{
53 if (IS_ENABLED(CONFIG_RAM_OCTEON)) {
54 struct ram_info ram;
55 struct udevice *dev;
56 int ret;
57
58 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
59 if (ret) {
60 debug("DRAM init failed: %d\n", ret);
61 return;
62 }
63
64 ret = ram_get_info(dev, &ram);
65 if (ret) {
66 debug("Cannot get DRAM size: %d\n", ret);
67 return;
68 }
69
70 printf(" (");
71 print_size(ram.size, " total)");
72 }
73}
74
Stefan Roese8bab2c82020-10-28 15:10:01 +010075phys_size_t get_effective_memsize(void)
76{
77 return UBOOT_RAM_SIZE_MAX;
78}
79
Heinrich Schuchardtd768dd82023-08-12 20:16:58 +020080phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
Aaron Williams0dc4ab92020-06-30 12:08:56 +020081{
Stefan Roese590d48e2020-09-02 08:29:09 +020082 if (IS_ENABLED(CONFIG_RAM_OCTEON)) {
83 /* Map a maximum of 256MiB - return not size but address */
Tom Riniaa6e94d2022-11-16 13:10:37 -050084 return CFG_SYS_SDRAM_BASE + min(gd->ram_size,
Stefan Roese590d48e2020-09-02 08:29:09 +020085 UBOOT_RAM_SIZE_MAX);
86 } else {
87 return gd->ram_top;
88 }
Aaron Williams0dc4ab92020-06-30 12:08:56 +020089}