2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <fdt_support.h>
10 #include <asm/arch/tegra.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 extern unsigned long nvtboot_boot_x0;
17 * A parsed version of /memory/reg from the DTB that is passed to U-Boot in x0.
19 * We assume bank 0 is RAM completely below 4G mostly ignore other banks;
20 * assuming they contain RAM above 4G. This is all a fairly safe assumption,
21 * since the L4T kernel makes the same assumption, so the bootloader is
24 * This is written to before relocation, and hence cannot be in .bss, since
25 * .bss overlaps the DTB that's appended to the U-Boot binary. The initializer
26 * forces this into .data and avoids this issue. This also has the nice side-
27 * effect of the content being valid after relocation.
32 } ram_banks[CONFIG_NR_DRAM_BANKS] = {{1}};
37 const void *nvtboot_blob = (void *)nvtboot_boot_x0;
41 memset(ram_banks, 0, sizeof(ram_banks));
43 na = fdtdec_get_uint(nvtboot_blob, 0, "#address-cells", 2);
44 ns = fdtdec_get_uint(nvtboot_blob, 0, "#size-cells", 2);
46 node = fdt_path_offset(nvtboot_blob, "/memory");
48 pr_err("Can't find /memory node in nvtboot DTB");
51 prop = fdt_getprop(nvtboot_blob, node, "reg", &len);
53 pr_err("Can't find /memory/reg property in nvtboot DTB");
57 /* Calculate the true # of base/size pairs to read */
58 len /= 4; /* Convert bytes to number of cells */
59 len /= (na + ns); /* Convert cells to number of banks */
60 if (len > ARRAY_SIZE(ram_banks))
61 len = ARRAY_SIZE(ram_banks);
64 for (i = 0; i < len; i++) {
65 ram_banks[i].start = fdt_read_number(prop, na);
67 ram_banks[i].size = fdt_read_number(prop, ns);
69 gd->ram_size += ram_banks[i].size;
75 extern unsigned long nvtboot_boot_x0;
77 int dram_init_banksize(void)
81 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
82 gd->bd->bi_dram[i].start = ram_banks[i].start;
83 gd->bd->bi_dram[i].size = ram_banks[i].size;
87 gd->pci_ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
93 ulong board_get_usable_ram_top(ulong total_size)
95 return ram_banks[0].start + ram_banks[0].size;