1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Memory Map commands File: ui_memcmds.c
6 * Memory Manager user interface
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
50 #include "lib_types.h"
51 #include "lib_string.h"
52 #include "lib_queue.h"
53 #include "lib_malloc.h"
54 #include "lib_printf.h"
55 #include "lib_arena.h"
57 #include "ui_command.h"
64 const static char * const cfe_arenatypes
[] = {
67 "Memory Controller (unused)",
68 "DRAM (in use by firmware)",
76 extern arena_t cfe_arena
;
80 int ui_init_memcmds(void);
82 static int ui_cmd_physmap(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
83 static int ui_cmd_heapstats(ui_cmdline_t
*cmd
,int argc
,char *argv
[]);
86 int ui_init_memcmds(void)
88 cmd_addcmd("show memory",
91 "Display the system physical memory map.",
92 "show memory [-a]\n\n"
93 "This command displays the arena, or system physical memory map\n"
94 "You can use this command to determine the areas of RAM that will\n"
95 "be made available to operating systems.\n",
96 "-a;Display all entries in the map, not just the blocks\n"
97 "of available memory.");
99 cmd_addcmd("show heap",
102 "Display information about CFE's heap",
104 "This is a debugging command that can be used to determine the health\n"
105 "of CFE's internal memory manager.",
111 static int ui_cmd_heapstats(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
116 res
= KMEMSTATS(&stats
);
119 xprintf("Total bytes: %d\n",stats
.mem_totalbytes
);
120 xprintf("Free bytes: %d\n",stats
.mem_freebytes
);
121 xprintf("Free nodes: %d\n",stats
.mem_freenodes
);
122 xprintf("Allocated bytes: %d\n",stats
.mem_allocbytes
);
123 xprintf("Allocated nodes: %d\n",stats
.mem_allocnodes
);
124 xprintf("Largest free node: %d\n",stats
.mem_largest
);
125 xprintf("Heap status: %s\n",(res
== 0) ? "CONSISTENT" : "CORRUPT!");
132 #define PHYSMAP_FLG_ALL 1
133 #define PHYSMAP_FLG_AVAIL 2
135 static int ui_cmd_physmap(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
139 arena_t
*arena
= &cfe_arena
;
142 if (cmd_sw_isset(cmd
,"-a")) {
143 flags
|= PHYSMAP_FLG_ALL
;
146 flags
= PHYSMAP_FLG_AVAIL
;
150 xprintf("Range Start Range End Range Size Description\n");
151 xprintf("------------ ------------ -------------- --------------------\n");
153 for (qb
= (arena
->arena_list
.q_next
); qb
!= &(arena
->arena_list
);
155 node
= (arena_node_t
*) qb
;
157 if ((flags
& PHYSMAP_FLG_ALL
) ||
158 ((flags
& PHYSMAP_FLG_AVAIL
) && (node
->an_type
== MEMTYPE_DRAM_AVAILABLE
))) {
160 xprintf("%012llX-%012llX (%012llX) %s\n",
162 node
->an_address
+node
->an_length
-1,
164 cfe_arenatypes
[node
->an_type
]);