• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2011 Erwan Velu - 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 #include "hdt-common.h"
31 #include "hdt-dump.h"
32 
dump_88(struct s_hardware * hardware,ZZJSON_CONFIG * config,ZZJSON ** item)33 void dump_88(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
34 
35 	(void) hardware;
36 	int mem_size = 0;
37 	CREATE_NEW_OBJECT;
38 	if (detect_memory_88(&mem_size)) {
39 		add_s("memory.error","8800h memory configuration is invalid");
40 		FLUSH_OBJECT
41 		return;
42 	}
43 
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);
47 	FLUSH_OBJECT;
48 }
49 
dump_e801(struct s_hardware * hardware,ZZJSON_CONFIG * config,ZZJSON ** item)50 void dump_e801(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
51 
52 	(void) hardware;
53 	int mem_low, mem_high = 0;
54 	CREATE_NEW_OBJECT;
55 	if (detect_memory_e801(&mem_low,&mem_high)) {
56 		add_s("memory.error","e801 memory configuration is invalid");
57 		FLUSH_OBJECT;
58 		return;
59 	}
60 
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);
68 	FLUSH_OBJECT;
69 
70 }
dump_e820(struct s_hardware * hardware,ZZJSON_CONFIG * config,ZZJSON ** item)71 void dump_e820(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
72 
73 	(void) hardware;
74 	struct e820entry map[E820MAX];
75 	struct e820entry nm[E820MAX];
76 	unsigned long memsize = 0;
77 	int count = 0;
78 	char type[14] = {0};
79 
80 	detect_memory_e820(map, E820MAX, &count);
81  	memsize = memsize_e820(map, count);
82 
83 	CREATE_NEW_OBJECT;
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);
87 	FLUSH_OBJECT;
88 
89 	for (int i = 0; i < count; i++) {
90 		get_type(map[i].type, type, sizeof(type));
91 		char begin[24]={0};
92 		char size[24]={0};
93 		char end[24]={0};
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);
97 		CREATE_NEW_OBJECT;
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));
102 		FLUSH_OBJECT;
103 	}
104 
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));
108 		char begin[24]={0};
109 		char size[24]={0};
110 		char end[24]={0};
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);
114 		CREATE_NEW_OBJECT;
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));
119 		FLUSH_OBJECT;
120 	}
121 }
122 
dump_memory(struct s_hardware * hardware,ZZJSON_CONFIG * config,ZZJSON ** item)123 void dump_memory(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
124 
125 	CREATE_NEW_OBJECT;
126 		add_s("Memory configuration","true");
127 	FLUSH_OBJECT;
128 
129 	dump_88(hardware,config,item);
130 	dump_e801(hardware,config,item);
131 	dump_e820(hardware,config,item);
132 	to_cpio("memory");
133 }
134