• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2009 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 "hdt-menu.h"
30 
31 /* Computing Summary menu */
compute_summarymenu(struct s_my_menu * menu,struct s_hardware * hardware)32 void compute_summarymenu(struct s_my_menu *menu, struct s_hardware *hardware)
33 {
34     char buffer[SUBMENULEN + 1];
35     char statbuffer[STATLEN + 1];
36 
37     snprintf(buffer, sizeof(buffer), " Summary (%d CPU) ", hardware->physical_cpu_count);
38     menu->menu = add_menu(buffer, -1);
39     menu->items_count = 0;
40 
41     set_menu_pos(SUBMENU_Y, SUBMENU_X);
42 
43     snprintf(buffer, sizeof buffer, "CPU Vendor    : %s", hardware->cpu.vendor);
44     snprintf(statbuffer, sizeof statbuffer, "CPU Vendor: %s",
45 	     hardware->cpu.vendor);
46     add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
47     menu->items_count++;
48 
49     snprintf(buffer, sizeof buffer, "CPU Model     : %s", hardware->cpu.model);
50     snprintf(statbuffer, sizeof statbuffer, "CPU Model: %s",
51 	     hardware->cpu.model);
52     add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
53     menu->items_count++;
54 
55     char features[255]={0};
56     if (hardware->dmi.processor.thread_count != 0)
57         sprintf(buffer, ", %d thread", hardware->dmi.processor.thread_count);
58     else
59         buffer[0] = 0x00;
60     sprintf(features, "%d core%s, %dK L2 Cache", hardware->cpu.num_cores,
61         buffer, hardware->cpu.l2_cache_size);
62     if (hardware->cpu.flags.lm)
63 	strcat(features, ", 64bit");
64     else
65 	strcat(features, ", 32bit");
66     if (hardware->cpu.flags.smp)
67 	strcat(features, ", SMP");
68     if (hardware->cpu.flags.vmx || hardware->cpu.flags.svm)
69 	strcat(features, ", HwVIRT");
70     snprintf(buffer, sizeof buffer, "%s", features);
71     snprintf(statbuffer, sizeof statbuffer, "Features : %s", features);
72     add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
73     menu->items_count++;
74 
75     add_item("", "", OPT_SEP, "", 0);
76     if (hardware->is_dmi_valid == true) {
77 
78 	snprintf(buffer, sizeof buffer, "System Vendor : %s",
79 		 hardware->dmi.system.manufacturer);
80 	snprintf(statbuffer, sizeof statbuffer, "System Vendor: %s",
81 		 hardware->dmi.system.manufacturer);
82 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
83 	menu->items_count++;
84 
85 	snprintf(buffer, sizeof buffer, "System Product: %s",
86 		 hardware->dmi.system.product_name);
87 	snprintf(statbuffer, sizeof statbuffer,
88 		 "System Product Name: %s", hardware->dmi.system.product_name);
89 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
90 	menu->items_count++;
91 
92 	snprintf(buffer, sizeof buffer, "System Serial : %s",
93 		 hardware->dmi.system.serial);
94 	snprintf(statbuffer, sizeof statbuffer,
95 		 "System Serial Number: %s", hardware->dmi.system.serial);
96 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
97 	menu->items_count++;
98 
99 	add_item("", "", OPT_SEP, "", 0);
100 
101 	snprintf(buffer, sizeof buffer, "Bios Version  : %s",
102 		 hardware->dmi.bios.version);
103 	snprintf(statbuffer, sizeof statbuffer, "Bios Version: %s",
104 		 hardware->dmi.bios.version);
105 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
106 	menu->items_count++;
107 
108 	snprintf(buffer, sizeof buffer, "Bios Release  : %s",
109 		 hardware->dmi.bios.release_date);
110 	snprintf(statbuffer, sizeof statbuffer, "Bios Release Date: %s",
111 		 hardware->dmi.bios.release_date);
112 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
113 	menu->items_count++;
114     }
115 
116     add_item("", "", OPT_SEP, "", 0);
117 
118     snprintf(buffer, sizeof buffer, "Memory Size   : %lu MiB (%lu KiB)",
119 	     (hardware->detected_memory_size + (1 << 9)) >> 10,
120 	     hardware->detected_memory_size);
121     snprintf(statbuffer, sizeof statbuffer,
122 	     "Detected Memory Size: %lu MiB (%lu KiB)",
123 	     (hardware->detected_memory_size + (1 << 9)) >> 10,
124 	     hardware->detected_memory_size);
125     add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
126     menu->items_count++;
127 
128     add_item("", "", OPT_SEP, "", 0);
129 
130     snprintf(buffer, sizeof buffer, "Nb PCI Devices: %d",
131 	     hardware->nb_pci_devices);
132     snprintf(statbuffer, sizeof statbuffer, "Number of PCI Devices: %d",
133 	     hardware->nb_pci_devices);
134     add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
135     menu->items_count++;
136 
137     if (hardware->is_pxe_valid == true) {
138 	add_item("", "", OPT_SEP, "", 0);
139 
140 	struct s_pxe *p = &hardware->pxe;
141 
142 	snprintf(buffer, sizeof buffer, "PXE MAC Address: %s", p->mac_addr);
143 	snprintf(statbuffer, sizeof statbuffer, "PXE MAC Address: %s",
144 		 p->mac_addr);
145 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
146 	menu->items_count++;
147 
148 	snprintf(buffer, sizeof buffer, "PXE IP Address : %d.%d.%d.%d",
149 		 p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]);
150 	snprintf(statbuffer, sizeof statbuffer,
151 		 "PXE IP Address: %d.%d.%d.%d", p->ip_addr[0],
152 		 p->ip_addr[1], p->ip_addr[2], p->ip_addr[3]);
153 	add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
154 	menu->items_count++;
155     }
156 
157     if (hardware->modules_pcimap_return_code != -ENOMODULESPCIMAP) {
158 	add_item("", "", OPT_SEP, "", 0);
159 
160 	struct pci_device *pci_device;
161 	char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
162 			    MAX_KERNEL_MODULES_PER_PCI_DEVICE];
163 
164 	/*
165 	 * For every detected pci device, grab its kernel module to compute
166 	 * this submenu
167 	 */
168 	for_each_pci_func(pci_device, hardware->pci_domain) {
169 	    memset(kernel_modules, 0, sizeof kernel_modules);
170 	    for (int i = 0;
171 		 i < pci_device->dev_info->linux_kernel_module_count; i++) {
172 		if (i > 0) {
173 		    strncat(kernel_modules, " | ", 3);
174 		}
175 		strncat(kernel_modules,
176 			pci_device->dev_info->linux_kernel_module[i],
177 			LINUX_KERNEL_MODULE_SIZE - 1);
178 	    }
179 	    /* No need to add unknown kernel modules */
180 	    if (strlen(kernel_modules) > 0) {
181 		snprintf(buffer, sizeof buffer, "%s (%s)",
182 			 kernel_modules, pci_device->dev_info->class_name);
183 		snprintf(statbuffer, sizeof statbuffer,
184 			 "%04x:%04x %s : %s",
185 			 pci_device->vendor,
186 			 pci_device->product,
187 			 pci_device->dev_info->vendor_name,
188 			 pci_device->dev_info->product_name);
189 
190 		add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
191 		menu->items_count++;
192 	    }
193 	}
194     }
195 
196     printf("MENU: Summary menu done (%d items)\n", menu->items_count);
197 }
198