blob: f2a3d6b1400153c14b70a374d0f6757839423240 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang5db9e672017-06-23 16:11:05 +08002/*
3 * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
Kever Yang5db9e672017-06-23 16:11:05 +08004 */
5
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Kever Yang5db9e672017-06-23 16:11:05 +08007#include <dm.h>
Simon Glass6980b6b2019-11-14 12:57:45 -07008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Kever Yang5db9e672017-06-23 16:11:05 +080010#include <ram.h>
Quentin Schulz6ba06862024-04-25 12:46:24 +020011#include <asm/armv8/mmu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Kever Yang5db9e672017-06-23 16:11:05 +080013#include <asm/io.h>
Kever Yange47db832019-11-15 11:04:33 +080014#include <asm/arch-rockchip/sdram.h>
Kever Yang5db9e672017-06-23 16:11:05 +080015#include <dm/uclass-internal.h>
16
17DECLARE_GLOBAL_DATA_PTR;
Kever Yangdfc8a7d2019-07-22 20:02:02 +080018
19#define TRUST_PARAMETER_OFFSET (34 * 1024 * 1024)
20
21struct tos_parameter_t {
22 u32 version;
23 u32 checksum;
24 struct {
25 char name[8];
26 s64 phy_addr;
27 u32 size;
28 u32 flags;
29 } tee_mem;
30 struct {
31 char name[8];
32 s64 phy_addr;
33 u32 size;
34 u32 flags;
35 } drm_mem;
36 s64 reserve[8];
37};
38
Quentin Schulz6ba06862024-04-25 12:46:24 +020039#ifdef CONFIG_ARM64
40/* Tag size and offset */
41#define ATAGS_SIZE SZ_8K
42#define ATAGS_OFFSET (SZ_2M - ATAGS_SIZE)
43#define ATAGS_PHYS_BASE (CFG_SYS_SDRAM_BASE + ATAGS_OFFSET)
44#define ATAGS_PHYS_END (ATAGS_PHYS_BASE + ATAGS_SIZE)
45
46/* ATAGS memory structures */
47
48enum tag_magic {
49 ATAG_NONE,
50 ATAG_CORE = 0x54410001,
51 ATAG_SERIAL = 0x54410050,
52 ATAG_DDR_MEM = 0x54410052,
53 ATAG_MAX = 0x544100ff,
54};
55
56/*
57 * An ATAG contains the following data:
58 * - header
59 * u32 size // sizeof(header + tag data) / sizeof(u32)
60 * u32 magic
61 * - tag data
62 */
63
64struct tag_header {
65 u32 size;
66 u32 magic;
67} __packed;
68
69/*
70 * DDR_MEM tag bank is storing data this way:
71 * - address0
72 * - address1
73 * - [...]
74 * - addressX
75 * - size0
76 * - size1
77 * - [...]
78 * - sizeX
79 *
80 * with X being tag_ddr_mem.count - 1.
81 */
82struct tag_ddr_mem {
83 u32 count;
84 u32 version;
85 u64 bank[20];
86 u32 flags;
87 u32 data[2];
88 u32 hash;
89} __packed;
90
91static u32 js_hash(const void *buf, u32 len)
92{
93 u32 i, hash = 0x47C6A7E6;
94
95 if (!buf || !len)
96 return hash;
97
98 for (i = 0; i < len; i++)
99 hash ^= ((hash << 5) + ((const char *)buf)[i] + (hash >> 2));
100
101 return hash;
102}
103
104static int rockchip_dram_init_banksize(void)
105{
106 const struct tag_header *tag_h = NULL;
107 u32 *addr = (void *)ATAGS_PHYS_BASE;
108 struct tag_ddr_mem *ddr_info;
109 u32 calc_hash;
110 u8 i, j;
111
112 if (!IS_ENABLED(CONFIG_ROCKCHIP_RK3588) &&
113 !IS_ENABLED(CONFIG_ROCKCHIP_RK3568))
114 return -ENOTSUPP;
115
116 if (!IS_ENABLED(CONFIG_ROCKCHIP_EXTERNAL_TPL))
117 return -ENOTSUPP;
118
119 /* Find DDR_MEM tag */
120 while (addr < (u32 *)ATAGS_PHYS_END) {
121 tag_h = (const struct tag_header *)addr;
122
123 if (!tag_h->size) {
124 debug("End of ATAGS (0-size tag), no DDR_MEM found\n");
125 return -ENODATA;
126 }
127
128 if (tag_h->magic == ATAG_DDR_MEM)
129 break;
130
131 switch (tag_h->magic) {
132 case ATAG_NONE:
133 case ATAG_CORE:
134 case ATAG_SERIAL ... ATAG_MAX:
135 addr += tag_h->size;
136 continue;
137 default:
138 debug("Invalid magic (0x%08x) for ATAG at 0x%p\n",
139 tag_h->magic, addr);
140 return -EINVAL;
141 }
142 }
143
144 if (addr >= (u32 *)ATAGS_PHYS_END ||
145 (tag_h && (addr + tag_h->size > (u32 *)ATAGS_PHYS_END))) {
146 debug("End of ATAGS, no DDR_MEM found\n");
147 return -ENODATA;
148 }
149
150 /* Data is right after the magic member of the tag_header struct */
151 ddr_info = (struct tag_ddr_mem *)(&tag_h->magic + 1);
152 if (!ddr_info->count || ddr_info->count > CONFIG_NR_DRAM_BANKS) {
153 debug("Too many ATAG banks, got (%d) but max allowed (%d)\n",
154 ddr_info->count, CONFIG_NR_DRAM_BANKS);
155 return -ENOMEM;
156 }
157
158 if (!ddr_info->hash) {
159 debug("No hash for tag (0x%08x)\n", tag_h->magic);
160 } else {
161 calc_hash = js_hash(addr, sizeof(u32) * (tag_h->size - 1));
162
163 if (calc_hash != ddr_info->hash) {
164 debug("Incorrect hash for tag (0x%08x), got (0x%08x) expected (0x%08x)\n",
165 tag_h->magic, ddr_info->hash, calc_hash);
166 return -EINVAL;
167 }
168 }
169
170 /*
171 * Rockchip guaranteed DDR_MEM is ordered so no need to worry about
172 * bi_dram order.
173 */
174 for (i = 0, j = 0; i < ddr_info->count; i++, j++) {
175 phys_size_t size = ddr_info->bank[(i + ddr_info->count)];
176 phys_addr_t start_addr = ddr_info->bank[i];
177 struct mm_region *tmp_mem_map = mem_map;
178 phys_addr_t end_addr;
179
180 /*
181 * BL31 (TF-A) reserves the first 2MB but DDR_MEM tag may not
182 * have it, so force this space as reserved.
183 */
184 if (start_addr < SZ_2M) {
185 size -= SZ_2M - start_addr;
186 start_addr = SZ_2M;
187 }
188
189 /*
190 * Put holes for reserved memory areas from mem_map.
191 *
192 * Only check for at most one overlap with one reserved memory
193 * area.
194 */
195 while (tmp_mem_map->size) {
196 const phys_addr_t rsrv_start = tmp_mem_map->phys;
197 const phys_size_t rsrv_size = tmp_mem_map->size;
198 const phys_addr_t rsrv_end = rsrv_start + rsrv_size;
199
200 /*
201 * DRAM memories are expected by Arm to be marked as
202 * Normal Write-back cacheable, Inner shareable[1], so
203 * let's filter on that to put holes in non-DRAM areas.
204 *
205 * [1] https://developer.arm.com/documentation/102376/0200/Cacheability-and-shareability-attributes
206 */
207 const u64 dram_attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
208 PTE_BLOCK_INNER_SHARE;
209 /*
210 * (AttrIndx | SH) in Lower Attributes of Block
211 * Descriptor[2].
212 * [2] https://developer.arm.com/documentation/102376/0200/Describing-memory-in-AArch64
213 */
214 const u64 attrs_mask = PMD_ATTRINDX_MASK | GENMASK(9, 8);
215
216 if ((tmp_mem_map->attrs & attrs_mask) == dram_attrs) {
217 tmp_mem_map++;
218 continue;
219 }
220
221 /*
222 * If the start of the DDR_MEM tag is in a reserved
223 * memory area, move start address and resize.
224 */
225 if (start_addr >= rsrv_start && start_addr < rsrv_end) {
226 if (rsrv_end - start_addr > size) {
227 debug("Would be negative memory size\n");
228 return -EINVAL;
229 }
230
231 size -= rsrv_end - start_addr;
232 start_addr = rsrv_end;
233 break;
234 }
235
236 if (start_addr < rsrv_start) {
237 end_addr = start_addr + size;
238
239 if (end_addr <= rsrv_start) {
240 tmp_mem_map++;
241 continue;
242 }
243
244 /*
245 * If the memory area overlaps a reserved memory
246 * area with start address outside of reserved
247 * memory area and...
248 *
249 * ... ends in the middle of reserved memory
250 * area, resize.
251 */
252 if (end_addr <= rsrv_end) {
253 size = rsrv_start - start_addr;
254 break;
255 }
256
257 /*
258 * ... ends after the reserved memory area,
259 * split the region in two, one for before the
260 * reserved memory area and one for after.
261 */
262 gd->bd->bi_dram[j].start = start_addr;
263 gd->bd->bi_dram[j].size = rsrv_start - start_addr;
264
265 j++;
266
267 size = end_addr - rsrv_end;
268 start_addr = rsrv_end;
269
270 break;
271 }
272
273 tmp_mem_map++;
274 }
275
276 if (j > CONFIG_NR_DRAM_BANKS) {
277 debug("Too many banks, max allowed (%d)\n",
278 CONFIG_NR_DRAM_BANKS);
279 return -ENOMEM;
280 }
281
282 gd->bd->bi_dram[j].start = start_addr;
283 gd->bd->bi_dram[j].size = size;
284 }
285
286 return 0;
287}
288#endif
289
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800290int dram_init_banksize(void)
291{
Jonas Karlmandd4d16f2023-02-07 17:27:11 +0000292 size_t ram_top = (unsigned long)(gd->ram_size + CFG_SYS_SDRAM_BASE);
293 size_t top = min((unsigned long)ram_top, (unsigned long)(gd->ram_top));
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800294
295#ifdef CONFIG_ARM64
Quentin Schulz6ba06862024-04-25 12:46:24 +0200296 int ret = rockchip_dram_init_banksize();
297
298 if (!ret)
299 return ret;
300
301 debug("Couldn't use ATAG (%d) to detect DDR layout, falling back...\n",
302 ret);
303
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800304 /* Reserve 0x200000 for ATF bl31 */
305 gd->bd->bi_dram[0].start = 0x200000;
306 gd->bd->bi_dram[0].size = top - gd->bd->bi_dram[0].start;
Jonas Karlmandd4d16f2023-02-07 17:27:11 +0000307
308 /* Add usable memory beyond the blob of space for peripheral near 4GB */
309 if (ram_top > SZ_4G && top < SZ_4G) {
310 gd->bd->bi_dram[1].start = SZ_4G;
311 gd->bd->bi_dram[1].size = ram_top - gd->bd->bi_dram[1].start;
312 }
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800313#else
Patrick Delaunaya7ca4802021-09-02 11:56:16 +0200314#ifdef CONFIG_SPL_OPTEE_IMAGE
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800315 struct tos_parameter_t *tos_parameter;
316
Tom Rinibb4dd962022-11-16 13:10:37 -0500317 tos_parameter = (struct tos_parameter_t *)(CFG_SYS_SDRAM_BASE +
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800318 TRUST_PARAMETER_OFFSET);
319
320 if (tos_parameter->tee_mem.flags == 1) {
Tom Rinibb4dd962022-11-16 13:10:37 -0500321 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800322 gd->bd->bi_dram[0].size = tos_parameter->tee_mem.phy_addr
Tom Rinibb4dd962022-11-16 13:10:37 -0500323 - CFG_SYS_SDRAM_BASE;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800324 gd->bd->bi_dram[1].start = tos_parameter->tee_mem.phy_addr +
325 tos_parameter->tee_mem.size;
Alex Beee3a34942020-07-15 01:03:31 +0200326 gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800327 } else {
Tom Rinibb4dd962022-11-16 13:10:37 -0500328 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800329 gd->bd->bi_dram[0].size = 0x8400000;
330 /* Reserve 32M for OPTEE with TA */
Tom Rinibb4dd962022-11-16 13:10:37 -0500331 gd->bd->bi_dram[1].start = CFG_SYS_SDRAM_BASE
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800332 + gd->bd->bi_dram[0].size + 0x2000000;
Alex Beee3a34942020-07-15 01:03:31 +0200333 gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800334 }
335#else
Tom Rinibb4dd962022-11-16 13:10:37 -0500336 gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE;
Kever Yangdfc8a7d2019-07-22 20:02:02 +0800337 gd->bd->bi_dram[0].size = top - gd->bd->bi_dram[0].start;
338#endif
339#endif
340
341 return 0;
342}
343
Kever Yang5db9e672017-06-23 16:11:05 +0800344size_t rockchip_sdram_size(phys_addr_t reg)
345{
Kever Yang117585a2019-11-15 11:04:35 +0800346 u32 rank, cs0_col, bk, cs0_row, cs1_row, bw, row_3_4;
Kever Yang5db9e672017-06-23 16:11:05 +0800347 size_t chipsize_mb = 0;
348 size_t size_mb = 0;
349 u32 ch;
Kever Yang117585a2019-11-15 11:04:35 +0800350 u32 cs1_col = 0;
351 u32 bg = 0;
352 u32 dbw, dram_type;
Kever Yang4c0c6e42019-11-15 11:04:36 +0800353 u32 sys_reg2 = readl(reg);
Kever Yang117585a2019-11-15 11:04:35 +0800354 u32 sys_reg3 = readl(reg + 4);
Kever Yang4c0c6e42019-11-15 11:04:36 +0800355 u32 ch_num = 1 + ((sys_reg2 >> SYS_REG_NUM_CH_SHIFT)
Kever Yang5db9e672017-06-23 16:11:05 +0800356 & SYS_REG_NUM_CH_MASK);
Jonas Karlmanf570c252023-02-07 17:27:10 +0000357 u32 version = (sys_reg3 >> SYS_REG_VERSION_SHIFT) &
358 SYS_REG_VERSION_MASK;
Kever Yang5db9e672017-06-23 16:11:05 +0800359
Kever Yang4c0c6e42019-11-15 11:04:36 +0800360 dram_type = (sys_reg2 >> SYS_REG_DDRTYPE_SHIFT) & SYS_REG_DDRTYPE_MASK;
Jonas Karlmanf570c252023-02-07 17:27:10 +0000361 if (version >= 3)
362 dram_type |= ((sys_reg3 >> SYS_REG_EXTEND_DDRTYPE_SHIFT) &
363 SYS_REG_EXTEND_DDRTYPE_MASK) << 3;
Kever Yang4c0c6e42019-11-15 11:04:36 +0800364 debug("%s %x %x\n", __func__, (u32)reg, sys_reg2);
Jonas Karlmanf570c252023-02-07 17:27:10 +0000365 debug("%s %x %x\n", __func__, (u32)reg + 4, sys_reg3);
Kever Yang5db9e672017-06-23 16:11:05 +0800366 for (ch = 0; ch < ch_num; ch++) {
Kever Yang4c0c6e42019-11-15 11:04:36 +0800367 rank = 1 + (sys_reg2 >> SYS_REG_RANK_SHIFT(ch) &
Kever Yang5db9e672017-06-23 16:11:05 +0800368 SYS_REG_RANK_MASK);
Kever Yang4c0c6e42019-11-15 11:04:36 +0800369 cs0_col = 9 + (sys_reg2 >> SYS_REG_COL_SHIFT(ch) &
Kever Yang117585a2019-11-15 11:04:35 +0800370 SYS_REG_COL_MASK);
371 cs1_col = cs0_col;
YouMin Chen618bddb2023-12-12 15:56:41 +0800372 if (dram_type == LPDDR5)
373 /* LPDDR5: 0:8bank(bk=3), 1:16bank(bk=4) */
374 bk = 3 + ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) &
375 SYS_REG_BK_MASK);
376 else
377 /* Other: 0:8bank(bk=3), 1:4bank(bk=2) */
378 bk = 3 - ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) &
379 SYS_REG_BK_MASK);
Jonas Karlmanf570c252023-02-07 17:27:10 +0000380 if (version >= 2) {
Kever Yang117585a2019-11-15 11:04:35 +0800381 cs1_col = 9 + (sys_reg3 >> SYS_REG_CS1_COL_SHIFT(ch) &
382 SYS_REG_CS1_COL_MASK);
383 if (((sys_reg3 >> SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
Kever Yang4c0c6e42019-11-15 11:04:36 +0800384 SYS_REG_EXTEND_CS0_ROW_MASK) << 2) + (sys_reg2 >>
Kever Yang117585a2019-11-15 11:04:35 +0800385 SYS_REG_CS0_ROW_SHIFT(ch) &
386 SYS_REG_CS0_ROW_MASK) == 7)
387 cs0_row = 12;
388 else
Kever Yang4c0c6e42019-11-15 11:04:36 +0800389 cs0_row = 13 + (sys_reg2 >>
Kever Yang117585a2019-11-15 11:04:35 +0800390 SYS_REG_CS0_ROW_SHIFT(ch) &
391 SYS_REG_CS0_ROW_MASK) +
392 ((sys_reg3 >>
393 SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
394 SYS_REG_EXTEND_CS0_ROW_MASK) << 2);
395 if (((sys_reg3 >> SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
Kever Yang4c0c6e42019-11-15 11:04:36 +0800396 SYS_REG_EXTEND_CS1_ROW_MASK) << 2) + (sys_reg2 >>
Kever Yang117585a2019-11-15 11:04:35 +0800397 SYS_REG_CS1_ROW_SHIFT(ch) &
398 SYS_REG_CS1_ROW_MASK) == 7)
399 cs1_row = 12;
400 else
Kever Yang4c0c6e42019-11-15 11:04:36 +0800401 cs1_row = 13 + (sys_reg2 >>
Kever Yang117585a2019-11-15 11:04:35 +0800402 SYS_REG_CS1_ROW_SHIFT(ch) &
403 SYS_REG_CS1_ROW_MASK) +
404 ((sys_reg3 >>
405 SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
406 SYS_REG_EXTEND_CS1_ROW_MASK) << 2);
407 } else {
Kever Yang4c0c6e42019-11-15 11:04:36 +0800408 cs0_row = 13 + (sys_reg2 >> SYS_REG_CS0_ROW_SHIFT(ch) &
Kever Yang5db9e672017-06-23 16:11:05 +0800409 SYS_REG_CS0_ROW_MASK);
Kever Yang4c0c6e42019-11-15 11:04:36 +0800410 cs1_row = 13 + (sys_reg2 >> SYS_REG_CS1_ROW_SHIFT(ch) &
Kever Yang5db9e672017-06-23 16:11:05 +0800411 SYS_REG_CS1_ROW_MASK);
Kever Yang117585a2019-11-15 11:04:35 +0800412 }
Kever Yang4c0c6e42019-11-15 11:04:36 +0800413 bw = (2 >> ((sys_reg2 >> SYS_REG_BW_SHIFT(ch)) &
Kever Yang5db9e672017-06-23 16:11:05 +0800414 SYS_REG_BW_MASK));
Kever Yang4c0c6e42019-11-15 11:04:36 +0800415 row_3_4 = sys_reg2 >> SYS_REG_ROW_3_4_SHIFT(ch) &
Kever Yang5db9e672017-06-23 16:11:05 +0800416 SYS_REG_ROW_3_4_MASK;
Kever Yang117585a2019-11-15 11:04:35 +0800417 if (dram_type == DDR4) {
Kever Yang4c0c6e42019-11-15 11:04:36 +0800418 dbw = (sys_reg2 >> SYS_REG_DBW_SHIFT(ch)) &
Kever Yang117585a2019-11-15 11:04:35 +0800419 SYS_REG_DBW_MASK;
420 bg = (dbw == 2) ? 2 : 1;
421 }
422 chipsize_mb = (1 << (cs0_row + cs0_col + bk + bg + bw - 20));
Kever Yang5db9e672017-06-23 16:11:05 +0800423
424 if (rank > 1)
Kever Yang117585a2019-11-15 11:04:35 +0800425 chipsize_mb += chipsize_mb >> ((cs0_row - cs1_row) +
426 (cs0_col - cs1_col));
Kever Yang5db9e672017-06-23 16:11:05 +0800427 if (row_3_4)
428 chipsize_mb = chipsize_mb * 3 / 4;
429 size_mb += chipsize_mb;
Kever Yang117585a2019-11-15 11:04:35 +0800430 if (rank > 1)
431 debug("rank %d cs0_col %d cs1_col %d bk %d cs0_row %d\
432 cs1_row %d bw %d row_3_4 %d\n",
433 rank, cs0_col, cs1_col, bk, cs0_row,
434 cs1_row, bw, row_3_4);
435 else
436 debug("rank %d cs0_col %d bk %d cs0_row %d\
437 bw %d row_3_4 %d\n",
438 rank, cs0_col, bk, cs0_row,
439 bw, row_3_4);
Kever Yang5db9e672017-06-23 16:11:05 +0800440 }
441
Kever Yange10e9062018-12-28 09:56:48 +0800442 /*
443 * This is workaround for issue we can't get correct size for 4GB ram
444 * in 32bit system and available before we really need ram space
445 * out of 4GB, eg.enable ARM LAPE(rk3288 supports 8GB ram).
446 * The size of 4GB is '0x1 00000000', and this value will be truncated
447 * to 0 in 32bit system, and system can not get correct ram size.
448 * Rockchip SoCs reserve a blob of space for peripheral near 4GB,
449 * and we are now setting SDRAM_MAX_SIZE as max available space for
450 * ram in 4GB, so we can use this directly to workaround the issue.
451 * TODO:
452 * 1. update correct value for SDRAM_MAX_SIZE as what dram
453 * controller sees.
454 * 2. update board_get_usable_ram_top() and dram_init_banksize()
455 * to reserve memory for peripheral space after previous update.
456 */
Jonas Karlmandd4d16f2023-02-07 17:27:11 +0000457 if (!IS_ENABLED(CONFIG_ARM64) && size_mb > (SDRAM_MAX_SIZE >> 20))
Kever Yange10e9062018-12-28 09:56:48 +0800458 size_mb = (SDRAM_MAX_SIZE >> 20);
459
Kever Yang5db9e672017-06-23 16:11:05 +0800460 return (size_t)size_mb << 20;
461}
462
463int dram_init(void)
464{
465 struct ram_info ram;
466 struct udevice *dev;
467 int ret;
468
469 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
470 if (ret) {
471 debug("DRAM init failed: %d\n", ret);
472 return ret;
473 }
474 ret = ram_get_info(dev, &ram);
475 if (ret) {
476 debug("Cannot get DRAM size: %d\n", ret);
477 return ret;
478 }
479 gd->ram_size = ram.size;
480 debug("SDRAM base=%lx, size=%lx\n",
481 (unsigned long)ram.base, (unsigned long)ram.size);
482
483 return 0;
484}
485
Heinrich Schuchardt51a9aac2023-08-12 20:16:58 +0200486phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
Kever Yang5db9e672017-06-23 16:11:05 +0800487{
Tom Rinibb4dd962022-11-16 13:10:37 -0500488 unsigned long top = CFG_SYS_SDRAM_BASE + SDRAM_MAX_SIZE;
Kever Yang5db9e672017-06-23 16:11:05 +0800489
490 return (gd->ram_top > top) ? top : gd->ram_top;
491}