1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 Erwan Velu - All Rights Reserved
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
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
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.
26 * -----------------------------------------------------------------------
30 #include "hdt-common.h"
33 void dump_88(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
38 if (detect_memory_88(&mem_size
)) {
39 add_s("memory.error","8800h memory configuration is invalid");
44 add_s("dmi.item","memory via 88");
45 add_i("memory.size (KiB)", mem_size
);
46 add_i("memory.size (MiB)", mem_size
>> 10);
50 void dump_e801(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
53 int mem_low
, mem_high
= 0;
55 if (detect_memory_e801(&mem_low
,&mem_high
)) {
56 add_s("memory.error","e801 memory configuration is invalid");
61 add_s("dmi.item","memory via e801");
62 add_i("memory.total.size (KiB)", mem_low
+ (mem_high
<< 6));
63 add_i("memory.total.size (MiB)", (mem_low
>> 10) + (mem_high
>> 4));
64 add_i("memory.low.size (KiB)", mem_low
);
65 add_i("memory.low.size (MiB)", mem_low
>> 10);
66 add_i("memory.high.size (KiB)", mem_high
<< 6);
67 add_i("memory.high.size (MiB)", mem_high
>> 4);
71 void dump_e820(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
74 struct e820entry map
[E820MAX
];
75 struct e820entry nm
[E820MAX
];
76 unsigned long memsize
= 0;
80 detect_memory_e820(map
, E820MAX
, &count
);
81 memsize
= memsize_e820(map
, count
);
84 add_s("dmi.item","memory via e820");
85 add_i("memory.total.size (KiB)", memsize
);
86 add_i("memory.total.size (MiB)", (memsize
+ (1 << 9)) >> 10);
89 for (int i
= 0; i
< count
; i
++) {
90 get_type(map
[i
].type
, type
, sizeof(type
));
94 snprintf(begin
,sizeof(begin
),"0x%016llx",map
[i
].addr
);
95 snprintf(size
,sizeof(size
),"0x%016llx",map
[i
].size
);
96 snprintf(end
,sizeof(end
),"0x%016llx",map
[i
].addr
+map
[i
].size
);
98 add_s("memory.segment.start",begin
);
99 add_s("memory.segment.size ",size
);
100 add_s("memory.segment.end ",end
);
101 add_s("memory.segment.type ",remove_spaces(type
));
105 int nr
= sanitize_e820_map(map
, nm
, count
);
106 for (int i
= 0; i
< nr
; i
++) {
107 get_type(nm
[i
].type
, type
, sizeof(type
));
111 snprintf(begin
,sizeof(begin
),"0x%016llx",nm
[i
].addr
);
112 snprintf(size
,sizeof(size
),"0x%016llx",nm
[i
].size
);
113 snprintf(end
,sizeof(end
),"0x%016llx",nm
[i
].addr
+nm
[i
].size
);
115 add_s("sanitized_memory.segment.start",begin
);
116 add_s("sanitized_memory.segment.size ",size
);
117 add_s("sanitized_memory.segment.end ",end
);
118 add_s("sanitized_memory.segment.type ",remove_spaces(type
));
123 void dump_memory(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
126 add_s("Memory configuration","true");
129 dump_88(hardware
,config
,item
);
130 dump_e801(hardware
,config
,item
);
131 dump_e820(hardware
,config
,item
);