Skip to content

Commit

Permalink
rockchip: ram: support extend ram top
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Chen <[email protected]>
Change-Id: I1d8a5e9440071194a1c438345c08e7e2c4d0d3dc
  • Loading branch information
JosephChen2017 committed Feb 24, 2022
1 parent bdb740d commit d8e6f8d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
6 changes: 5 additions & 1 deletion arch/arm/include/asm/arch-rockchip/rk_atags.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
*/
#define B1P2_BOOT_CPU_MASK 0x00000fff

/* tag_ddr_mem.flags */
#define DDR_MEM_FLG_EXT_TOP 1

struct tag_serial {
u32 version;
u32 enable;
Expand All @@ -98,7 +101,8 @@ struct tag_ddr_mem {
u32 count;
u32 version;
u64 bank[20];
u32 reserved[3];
u32 flags;
u32 data[2];
u32 hash;
} __packed;

Expand Down
5 changes: 5 additions & 0 deletions arch/arm/mach-rockchip/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ struct memblock *param_parse_ddr_mem(int *out_count)

t = atags_get_tag(ATAG_DDR_MEM);
if (t && t->u.ddr_mem.count) {
/* extend top ram size */
if (t->u.ddr_mem.flags & DDR_MEM_FLG_EXT_TOP)
gd->ram_top_ext_size = t->u.ddr_mem.data[0];

/* normal ram size */
count = t->u.ddr_mem.count;
mem = calloc(count + MEM_RESV_COUNT, sizeof(*mem));
if (!mem) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/atags.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ static void atags_print_tag(struct tag *t)
printf(" version = 0x%x\n", t->u.ddr_mem.version);
for (i = 0; i < ARRAY_SIZE(t->u.ddr_mem.bank); i++)
printf(" bank[%d] = 0x%llx\n", i, t->u.ddr_mem.bank[i]);
for (i = 0; i < ARRAY_SIZE(t->u.ddr_mem.reserved); i++)
printf(" res[%d] = 0x%x\n", i, t->u.ddr_mem.reserved[i]);
printf(" flags = 0x%x\n", t->u.ddr_mem.flags);
for (i = 0; i < ARRAY_SIZE(t->u.ddr_mem.data); i++)
printf(" data[%d] = 0x%x\n", i, t->u.ddr_mem.data[i]);
printf(" hash = 0x%x\n", t->u.ddr_mem.hash);
break;
case ATAG_RAM_PARTITION:
Expand Down
1 change: 1 addition & 0 deletions include/asm-generic/global_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct global_data {
unsigned long env_valid; /* Environment valid? enum env_valid */

unsigned long ram_top; /* Top address of RAM used by U-Boot */
unsigned long ram_top_ext_size; /* Extend size of RAM top */
unsigned long relocaddr; /* Start address of U-Boot in RAM */
phys_size_t ram_size; /* RAM size */
unsigned long mon_len; /* monitor len */
Expand Down
26 changes: 23 additions & 3 deletions lib/bidram.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <malloc.h>
#include <sysmem.h>
#include <asm/io.h>
#include <asm/arch/rk_atags.h>

DECLARE_GLOBAL_DATA_PTR;

Expand Down Expand Up @@ -140,8 +141,9 @@ void bidram_gen_gd_bi_dram(void)
* Here handle that: there is the only one dram bank available.
*/
if (rsv_cnt == 1 && !res_rgn[0].base && !res_rgn[0].size) {
gd->bd->bi_dram[0].start = mem_rgn[0].base;
gd->bd->bi_dram[0].size = mem_rgn[0].size;
gd->bd->bi_dram[idx].start = mem_rgn[0].base;
gd->bd->bi_dram[idx].size = mem_rgn[0].size;
idx++;
goto done;
}

Expand Down Expand Up @@ -169,8 +171,23 @@ void bidram_gen_gd_bi_dram(void)
gd->bd->bi_dram[idx].start;
}
done:
/* Append 4GB+ memory blocks */
/* Append 4GB+ memory blocks and extend ram top */
if (bidram->fixup) {
/* extend ram top */
if (gd->ram_top_ext_size) {
int pos = idx - 1;
ulong top;

if (gd->bd->bi_dram[pos].start +
gd->bd->bi_dram[pos].size == gd->ram_top) {
top = gd->bd->bi_dram[pos].start + gd->bd->bi_dram[pos].size;
gd->bd->bi_dram[pos].size += gd->ram_top_ext_size;
printf("Extend top: 0x%08lx -> 0x%08lx\n",
top, top + (ulong)gd->ram_top_ext_size);
}
}

/* append 4GB+ */
for (i = 0; i < MEM_RESV_COUNT; i++) {
if (!bidram->size_u64[i])
continue;
Expand Down Expand Up @@ -210,6 +227,9 @@ u64 bidram_append_size(void)
for (i = 0; i < MEM_RESV_COUNT; i++)
size += bidram->size_u64[i];

if (gd->ram_top_ext_size)
size += gd->ram_top_ext_size;

return size;
}

Expand Down

0 comments on commit d8e6f8d

Please sign in to comment.