Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2024 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 7 | #include <bloblist.h> |
| 8 | #include <bootstage.h> |
Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 9 | #include <command.h> |
| 10 | #include <display_options.h> |
Simon Glass | 9b259c5 | 2024-10-21 10:19:32 +0200 | [diff] [blame] | 11 | #include <lmb.h> |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 12 | #include <malloc.h> |
| 13 | #include <mapmem.h> |
Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 14 | #include <asm/global_data.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 18 | static 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 Glass | 9b259c5 | 2024-10-21 10:19:32 +0200 | [diff] [blame] | 29 | static 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 Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 50 | static int do_meminfo(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 51 | char *const argv[]) |
Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 52 | { |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 53 | ulong upto, stk_bot; |
| 54 | |
Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 55 | puts("DRAM: "); |
| 56 | print_size(gd->ram_size, "\n"); |
| 57 | |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 58 | 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 Glass | 9b259c5 | 2024-10-21 10:19:32 +0200 | [diff] [blame] | 88 | if (IS_ENABLED(CONFIG_LMB)) |
| 89 | show_lmb(lmb_get(), &upto); |
| 90 | print_region("free", gd->ram_base, upto, &upto); |
Simon Glass | 84015e5 | 2024-10-21 10:19:30 +0200 | [diff] [blame] | 91 | |
Simon Glass | 8f9b052 | 2024-10-21 10:19:29 +0200 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | U_BOOT_CMD( |
| 96 | meminfo, 1, 1, do_meminfo, |
| 97 | "display memory information", |
| 98 | "" |
| 99 | ); |