1
/* lsefimemmap.c - Display memory map. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2008 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
#include <grub/types.h>
21
#include <grub/misc.h>
22
#include <grub/efi/api.h>
23
#include <grub/efi/efi.h>
24
#include <grub/command.h>
26
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
27
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
30
grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
31
int argc __attribute__ ((unused)),
32
char **args __attribute__ ((unused)))
34
grub_efi_uintn_t map_size;
35
grub_efi_memory_descriptor_t *memory_map;
36
grub_efi_memory_descriptor_t *memory_map_end;
37
grub_efi_memory_descriptor_t *desc;
38
grub_efi_uintn_t desc_size;
41
if (grub_efi_get_memory_map (&map_size, NULL, NULL, &desc_size, 0) < 0)
44
memory_map = grub_malloc (map_size);
45
if (memory_map == NULL)
47
if (grub_efi_get_memory_map (&map_size, memory_map, NULL, &desc_size, 0) <= 0)
51
("Type Physical start - end #Pages "
52
" Size Attributes\n");
53
memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size);
54
for (desc = memory_map;
55
desc < memory_map_end;
56
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
58
grub_efi_uint64_t size;
59
grub_efi_uint64_t attr;
60
static const char types_str[][9] =
77
if (desc->type < ARRAY_SIZE (types_str))
78
grub_printf ("%s ", types_str[desc->type]);
80
grub_printf ("Unk %02x ", desc->type);
82
grub_printf (" %016" PRIxGRUB_UINT64_T "-%016" PRIxGRUB_UINT64_T
83
" %08" PRIxGRUB_UINT64_T,
85
desc->physical_start + (desc->num_pages << 12) - 1,
88
size = desc->num_pages;
91
grub_printf (" %4" PRIuGRUB_UINT64_T "KB", size);
96
grub_printf (" %4" PRIuGRUB_UINT64_T "MB", size);
100
grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size);
104
attr = desc->attribute;
105
if (attr & GRUB_EFI_MEMORY_RUNTIME)
107
if (attr & GRUB_EFI_MEMORY_UC)
109
if (attr & GRUB_EFI_MEMORY_WC)
111
if (attr & GRUB_EFI_MEMORY_WT)
113
if (attr & GRUB_EFI_MEMORY_WB)
115
if (attr & GRUB_EFI_MEMORY_UCE)
116
grub_printf (" UCE");
117
if (attr & GRUB_EFI_MEMORY_WP)
119
if (attr & GRUB_EFI_MEMORY_RP)
121
if (attr & GRUB_EFI_MEMORY_XP)
128
grub_free (memory_map);
132
static grub_command_t cmd;
134
GRUB_MOD_INIT(lsefimmap)
136
cmd = grub_register_command ("lsefimmap", grub_cmd_lsefimmap,
137
"", "Display EFI memory map.");
140
GRUB_MOD_FINI(lsefimmap)
142
grub_unregister_command (cmd);