blob: 5e83d61c2dd3d10e4c6e2446a7c1bd6e32c31191 [file] [log] [blame]
Simon Glass8f9b0522024-10-21 10:19:29 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2024 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glass84015e52024-10-21 10:19:30 +02007#include <bloblist.h>
8#include <bootstage.h>
Simon Glass8f9b0522024-10-21 10:19:29 +02009#include <command.h>
10#include <display_options.h>
Simon Glass9b259c52024-10-21 10:19:32 +020011#include <lmb.h>
Simon Glass84015e52024-10-21 10:19:30 +020012#include <malloc.h>
13#include <mapmem.h>
Simon Glass8f9b0522024-10-21 10:19:29 +020014#include <asm/global_data.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Simon Glass84015e52024-10-21 10:19:30 +020018static void print_region(const char *name, ulong base, ulong size, ulong *uptop)
19{
20 ulong end = base + size;
21
22 printf("%-12s %8lx %8lx %8lx", name, base, size, end);
23 if (*uptop)
24 printf(" %8lx", *uptop - end);
25 putc('\n');
26 *uptop = base;
27}
28
Simon Glass9b259c52024-10-21 10:19:32 +020029static void show_lmb(const struct lmb *lmb, ulong *uptop)
30{
31 int i;
32
33 for (i = lmb->used_mem.count - 1; i >= 0; i--) {
34 const struct lmb_region *rgn = alist_get(&lmb->used_mem, i,
35 struct lmb_region);
36
37 /*
38 * Assume that the top lmb region is the U-Boot region, so just
39 * take account of the memory not already reported
40 */
41 if (lmb->used_mem.count - 1)
42 print_region("lmb", rgn->base, *uptop - rgn->base,
43 uptop);
44 else
45 print_region("lmb", rgn->base, rgn->size, uptop);
46 *uptop = rgn->base;
47 }
48}
49
Simon Glass8f9b0522024-10-21 10:19:29 +020050static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass84015e52024-10-21 10:19:30 +020051 char *const argv[])
Simon Glass8f9b0522024-10-21 10:19:29 +020052{
Simon Glass84015e52024-10-21 10:19:30 +020053 ulong upto, stk_bot;
54
Simon Glass8f9b0522024-10-21 10:19:29 +020055 puts("DRAM: ");
56 print_size(gd->ram_size, "\n");
57
Simon Glass84015e52024-10-21 10:19:30 +020058 if (!IS_ENABLED(CONFIG_CMD_MEMINFO_MAP))
59 return 0;
60
61 printf("\n%-12s %8s %8s %8s %8s\n", "Region", "Base", "Size", "End",
62 "Gap");
63 printf("------------------------------------------------\n");
64 upto = 0;
65 if (IS_ENABLED(CONFIG_VIDEO))
66 print_region("video", gd_video_bottom(),
67 gd_video_size(), &upto);
68 if (IS_ENABLED(CONFIG_TRACE))
69 print_region("trace", map_to_sysmem(gd_trace_buff()),
70 gd_trace_size(), &upto);
71 print_region("code", gd->relocaddr, gd->mon_len, &upto);
72 print_region("malloc", map_to_sysmem((void *)mem_malloc_start),
73 mem_malloc_end - mem_malloc_start, &upto);
74 print_region("board_info", map_to_sysmem(gd->bd),
75 sizeof(struct bd_info), &upto);
76 print_region("global_data", map_to_sysmem((void *)gd),
77 sizeof(struct global_data), &upto);
78 print_region("devicetree", map_to_sysmem(gd->fdt_blob),
79 fdt_totalsize(gd->fdt_blob), &upto);
80 if (IS_ENABLED(CONFIG_BOOTSTAGE))
81 print_region("bootstage", map_to_sysmem(gd_bootstage()),
82 bootstage_get_size(false), &upto);
83 if (IS_ENABLED(CONFIG_BLOBLIST))
84 print_region("bloblist", map_to_sysmem(gd_bloblist()),
85 bloblist_get_total_size(), &upto);
86 stk_bot = gd->start_addr_sp - CONFIG_STACK_SIZE;
87 print_region("stack", stk_bot, CONFIG_STACK_SIZE, &upto);
Simon Glass9b259c52024-10-21 10:19:32 +020088 if (IS_ENABLED(CONFIG_LMB))
89 show_lmb(lmb_get(), &upto);
90 print_region("free", gd->ram_base, upto, &upto);
Simon Glass84015e52024-10-21 10:19:30 +020091
Simon Glass8f9b0522024-10-21 10:19:29 +020092 return 0;
93}
94
95U_BOOT_CMD(
96 meminfo, 1, 1, do_meminfo,
97 "display memory information",
98 ""
99);