Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 3 | * Copyright (C) 2020 Stefan Roese <sr@denx.de> |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 6 | #include <config.h> |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <ram.h> |
| 9 | #include <asm/global_data.h> |
| 10 | #include <linux/compat.h> |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 11 | #include <display_options.h> |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 15 | #define UBOOT_RAM_SIZE_MAX 0x10000000ULL |
| 16 | |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 17 | int dram_init(void) |
| 18 | { |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 19 | 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 Roese | 380a97c | 2020-10-28 15:10:01 +0100 | [diff] [blame] | 36 | gd->ram_size = ram.size; |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 37 | 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 Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 51 | void 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 Roese | 380a97c | 2020-10-28 15:10:01 +0100 | [diff] [blame] | 75 | phys_size_t get_effective_memsize(void) |
| 76 | { |
| 77 | return UBOOT_RAM_SIZE_MAX; |
| 78 | } |
| 79 | |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 80 | ulong board_get_usable_ram_top(ulong total_size) |
| 81 | { |
Stefan Roese | 7113ee3 | 2020-09-02 08:29:09 +0200 | [diff] [blame] | 82 | if (IS_ENABLED(CONFIG_RAM_OCTEON)) { |
| 83 | /* Map a maximum of 256MiB - return not size but address */ |
| 84 | return CONFIG_SYS_SDRAM_BASE + min(gd->ram_size, |
| 85 | UBOOT_RAM_SIZE_MAX); |
| 86 | } else { |
| 87 | return gd->ram_top; |
| 88 | } |
Aaron Williams | b2ea818 | 2020-06-30 12:08:56 +0200 | [diff] [blame] | 89 | } |