1 | /* ----------------------------------------------------------------------- * |
---|
2 | * |
---|
3 | * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved |
---|
4 | * |
---|
5 | * Permission is hereby granted, free of charge, to any person |
---|
6 | * obtaining a copy of this software and associated documentation |
---|
7 | * files (the "Software"), to deal in the Software without |
---|
8 | * restriction, including without limitation the rights to use, |
---|
9 | * copy, modify, merge, publish, distribute, sublicense, and/or |
---|
10 | * sell copies of the Software, and to permit persons to whom |
---|
11 | * the Software is furnished to do so, subject to the following |
---|
12 | * conditions: |
---|
13 | * |
---|
14 | * The above copyright notice and this permission notice shall |
---|
15 | * be included in all copies or substantial portions of the Software. |
---|
16 | * |
---|
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
---|
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
---|
19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
---|
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
---|
21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
---|
24 | * OTHER DEALINGS IN THE SOFTWARE. |
---|
25 | * |
---|
26 | * ----------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | |
---|
29 | #include <memory.h> |
---|
30 | |
---|
31 | #include "hdt-cli.h" |
---|
32 | #include "hdt-common.h" |
---|
33 | |
---|
34 | static void show_memory_e820(int argc __unused, char **argv __unused, |
---|
35 | struct s_hardware *hardware __unused) |
---|
36 | { |
---|
37 | struct e820entry map[E820MAX]; |
---|
38 | unsigned long memsize = 0; |
---|
39 | int count = 0; |
---|
40 | char type[14]; |
---|
41 | |
---|
42 | detect_memory_e820(map, E820MAX, &count); |
---|
43 | memsize = memsize_e820(map, count); |
---|
44 | reset_more_printf(); |
---|
45 | more_printf("Detected RAM : %lu MiB (%lu KiB)\n", |
---|
46 | (memsize + (1 << 9)) >> 10, memsize); |
---|
47 | more_printf("BIOS-provided physical RAM e820 map:\n"); |
---|
48 | for (int i = 0; i < count; i++) { |
---|
49 | get_type(map[i].type, type, 14); |
---|
50 | more_printf("%016llx - %016llx %016llx (%s)\n", |
---|
51 | map[i].addr, map[i].size, map[i].addr + map[i].size, |
---|
52 | remove_spaces(type)); |
---|
53 | } |
---|
54 | struct e820entry nm[E820MAX]; |
---|
55 | |
---|
56 | /* Clean up, adjust and copy the BIOS-supplied E820-map. */ |
---|
57 | int nr = sanitize_e820_map(map, nm, count); |
---|
58 | |
---|
59 | more_printf("\n"); |
---|
60 | more_printf("Sanitized e820 map:\n"); |
---|
61 | for (int i = 0; i < nr; i++) { |
---|
62 | get_type(nm[i].type, type, 14); |
---|
63 | more_printf("%016llx - %016llx %016llx (%s)\n", |
---|
64 | nm[i].addr, nm[i].size, nm[i].addr + nm[i].size, |
---|
65 | remove_spaces(type)); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | static void show_memory_e801(int argc __unused, char **argv __unused, |
---|
70 | struct s_hardware *hardware __unused) |
---|
71 | { |
---|
72 | int mem_low, mem_high = 0; |
---|
73 | |
---|
74 | reset_more_printf(); |
---|
75 | if (detect_memory_e801(&mem_low, &mem_high)) { |
---|
76 | more_printf("e801 bogus!\n"); |
---|
77 | } else { |
---|
78 | more_printf("Detected RAM : %d MiB(%d KiB)\n", |
---|
79 | (mem_low >> 10) + (mem_high >> 4), |
---|
80 | mem_low + (mem_high << 6)); |
---|
81 | more_printf("e801 details : %d Kb (%d MiB) - %d Kb (%d MiB)\n", mem_low, |
---|
82 | mem_low >> 10, mem_high << 6, mem_high >> 4); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | static void show_memory_88(int argc __unused, char **argv __unused, |
---|
87 | struct s_hardware *hardware __unused) |
---|
88 | { |
---|
89 | int mem_size = 0; |
---|
90 | |
---|
91 | reset_more_printf(); |
---|
92 | if (detect_memory_88(&mem_size)) { |
---|
93 | more_printf("8800h bogus!\n"); |
---|
94 | } else { |
---|
95 | more_printf("8800h memory size: %d Kb (%d MiB)\n", mem_size, |
---|
96 | mem_size >> 10); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | struct cli_callback_descr list_memory_show_modules[] = { |
---|
101 | { |
---|
102 | .name = "e820", |
---|
103 | .exec = show_memory_e820, |
---|
104 | .nomodule=false, |
---|
105 | }, |
---|
106 | { |
---|
107 | .name = "e801", |
---|
108 | .exec = show_memory_e801, |
---|
109 | .nomodule=false, |
---|
110 | }, |
---|
111 | { |
---|
112 | .name = "88", |
---|
113 | .exec = show_memory_88, |
---|
114 | .nomodule=false, |
---|
115 | }, |
---|
116 | { |
---|
117 | .name = CLI_DMI_MEMORY_BANK, |
---|
118 | .exec = show_dmi_memory_bank, |
---|
119 | .nomodule=false, |
---|
120 | }, |
---|
121 | { |
---|
122 | .name = NULL, |
---|
123 | .exec = NULL, |
---|
124 | .nomodule=false, |
---|
125 | }, |
---|
126 | }; |
---|
127 | |
---|
128 | struct cli_module_descr memory_show_modules = { |
---|
129 | .modules = list_memory_show_modules, |
---|
130 | .default_callback = show_dmi_memory_modules, |
---|
131 | }; |
---|
132 | |
---|
133 | struct cli_mode_descr memory_mode = { |
---|
134 | .mode = MEMORY_MODE, |
---|
135 | .name = CLI_MEMORY, |
---|
136 | .default_modules = NULL, |
---|
137 | .show_modules = &memory_show_modules, |
---|
138 | .set_modules = NULL, |
---|
139 | }; |
---|