Initial code release
[external/syslinux.git] / com32 / modules / dmitest.c
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2006 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 /*
30  * dmitest.c
31  *
32  * DMI demo program using libcom32
33  */
34
35 #include <string.h>
36 #include <stdio.h>
37 #include <console.h>
38 #include "dmi/dmi.h"
39
40 char display_line;
41
42 void display_memory(s_dmi * dmi)
43 {
44     int i;
45     for (i = 0; i < dmi->memory_count; i++) {
46         moreprintf("Memory Bank %d\n", i);
47         moreprintf("\tForm Factor  : %s\n", dmi->memory[i].form_factor);
48         moreprintf("\tType         : %s\n", dmi->memory[i].type);
49         moreprintf("\tType Detail  : %s\n", dmi->memory[i].type_detail);
50         moreprintf("\tSpeed        : %s\n", dmi->memory[i].speed);
51         moreprintf("\tSize         : %s\n", dmi->memory[i].size);
52         moreprintf("\tDevice Set   : %s\n", dmi->memory[i].device_set);
53         moreprintf("\tDevice Loc.  : %s\n", dmi->memory[i].device_locator);
54         moreprintf("\tBank Locator : %s\n", dmi->memory[i].bank_locator);
55         moreprintf("\tTotal Width  : %s\n", dmi->memory[i].total_width);
56         moreprintf("\tData Width   : %s\n", dmi->memory[i].data_width);
57         moreprintf("\tError        : %s\n", dmi->memory[i].error);
58         moreprintf("\tVendor       : %s\n", dmi->memory[i].manufacturer);
59         moreprintf("\tSerial       : %s\n", dmi->memory[i].serial);
60         moreprintf("\tAsset Tag    : %s\n", dmi->memory[i].asset_tag);
61         moreprintf("\tPart Number  : %s\n", dmi->memory[i].part_number);
62     }
63 }
64
65 void display_battery(s_dmi * dmi)
66 {
67     moreprintf("Battery\n");
68     moreprintf("\tVendor              : %s\n", dmi->battery.manufacturer);
69     moreprintf("\tManufacture Date    : %s\n", dmi->battery.manufacture_date);
70     moreprintf("\tSerial              : %s\n", dmi->battery.serial);
71     moreprintf("\tName                : %s\n", dmi->battery.name);
72     moreprintf("\tChemistry           : %s\n", dmi->battery.chemistry);
73     moreprintf("\tDesign Capacity     : %s\n", dmi->battery.design_capacity);
74     moreprintf("\tDesign Voltage      : %s\n", dmi->battery.design_voltage);
75     moreprintf("\tSBDS                : %s\n", dmi->battery.sbds);
76     moreprintf("\tSBDS Manufact. Date : %s\n",
77                dmi->battery.sbds_manufacture_date);
78     moreprintf("\tSBDS Chemistry      : %s\n", dmi->battery.sbds_chemistry);
79     moreprintf("\tMaximum Error       : %s\n", dmi->battery.maximum_error);
80     moreprintf("\tOEM Info            : %s\n", dmi->battery.oem_info);
81 }
82
83 void display_bios(s_dmi * dmi)
84 {
85     moreprintf("BIOS\n");
86     moreprintf("\tVendor:   %s\n", dmi->bios.vendor);
87     moreprintf("\tVersion:  %s\n", dmi->bios.version);
88     moreprintf("\tRelease:  %s\n", dmi->bios.release_date);
89     moreprintf("\tBios Revision     %s\n", dmi->bios.bios_revision);
90     moreprintf("\tFirmware Revision %s\n", dmi->bios.firmware_revision);
91     moreprintf("\tAddress:  0x%04X0\n", dmi->bios.address);
92     moreprintf("\tRuntime address: %u %s\n", dmi->bios.runtime_size,
93                dmi->bios.runtime_size_unit);
94     moreprintf("\tRom size: %u %s\n", dmi->bios.rom_size,
95                dmi->bios.rom_size_unit);
96     display_bios_characteristics(dmi);
97 }
98
99 void display_system(s_dmi * dmi)
100 {
101     moreprintf("\nSystem\n");
102     moreprintf("\tManufacturer %s\n", dmi->system.manufacturer);
103     moreprintf("\tProduct Name %s\n", dmi->system.product_name);
104     moreprintf("\tVersion      %s\n", dmi->system.version);
105     moreprintf("\tSerial       %s\n", dmi->system.serial);
106     moreprintf("\tUUID         %s\n", dmi->system.uuid);
107     moreprintf("\tWakeup Type  %s\n", dmi->system.wakeup_type);
108     moreprintf("\tSKU Number   %s\n", dmi->system.sku_number);
109     moreprintf("\tFamily       %s\n", dmi->system.family);
110 }
111
112 void display_base_board(s_dmi * dmi)
113 {
114     moreprintf("Base board\n");
115     moreprintf("\tManufacturer %s\n", dmi->base_board.manufacturer);
116     moreprintf("\tProduct Name %s\n", dmi->base_board.product_name);
117     moreprintf("\tVersion      %s\n", dmi->base_board.version);
118     moreprintf("\tSerial       %s\n", dmi->base_board.serial);
119     moreprintf("\tAsset Tag    %s\n", dmi->base_board.asset_tag);
120     moreprintf("\tLocation     %s\n", dmi->base_board.location);
121     moreprintf("\tType         %s\n", dmi->base_board.type);
122     display_base_board_features(dmi);
123 }
124
125 void display_chassis(s_dmi * dmi)
126 {
127     moreprintf("\nChassis\n");
128     moreprintf("\tManufacturer %s\n", dmi->chassis.manufacturer);
129     moreprintf("\tType     %s\n", dmi->chassis.type);
130     moreprintf("\tLock     %s\n", dmi->chassis.lock);
131     moreprintf("\tVersion      %s\n", dmi->chassis.version);
132     moreprintf("\tSerial       %s\n", dmi->chassis.serial);
133     moreprintf("\tAsset Tag    %s\n", dmi->chassis.asset_tag);
134     moreprintf("\tBoot up state %s\n", dmi->chassis.boot_up_state);
135     moreprintf("\tPower supply state %s\n", dmi->chassis.power_supply_state);
136     moreprintf("\tThermal state %s\n", dmi->chassis.thermal_state);
137     moreprintf("\tSecurity Status    %s\n", dmi->chassis.security_status);
138     moreprintf("\tOEM Information    %s\n", dmi->chassis.oem_information);
139     moreprintf("\tHeight       %u\n", dmi->chassis.height);
140     moreprintf("\tNB Power Cords     %u\n", dmi->chassis.nb_power_cords);
141 }
142
143 void display_cpu(s_dmi * dmi)
144 {
145     moreprintf("\nCPU\n");
146     moreprintf("\tSocket Designation %s\n", dmi->processor.socket_designation);
147     moreprintf("\tType         %s\n", dmi->processor.type);
148     moreprintf("\tFamily       %s\n", dmi->processor.family);
149     moreprintf("\tManufacturer %s\n", dmi->processor.manufacturer);
150     moreprintf("\tVersion      %s\n", dmi->processor.version);
151     moreprintf("\tExternal Clock    %u\n", dmi->processor.external_clock);
152     moreprintf("\tMax Speed         %u\n", dmi->processor.max_speed);
153     moreprintf("\tCurrent Speed     %u\n", dmi->processor.current_speed);
154     moreprintf("\tCpu Type     %u\n", dmi->processor.signature.type);
155     moreprintf("\tCpu Family   %u\n", dmi->processor.signature.family);
156     moreprintf("\tCpu Model    %u\n", dmi->processor.signature.model);
157     moreprintf("\tCpu Stepping %u\n", dmi->processor.signature.stepping);
158     moreprintf("\tCpu Minor Stepping %u\n",
159                dmi->processor.signature.minor_stepping);
160     moreprintf("\tVoltage      %d mV\n", dmi->processor.voltage_mv);
161     moreprintf("\tStatus       %s\n", dmi->processor.status);
162     moreprintf("\tUpgrade      %s\n", dmi->processor.upgrade);
163     moreprintf("\tCache L1 Handle %s\n", dmi->processor.cache1);
164     moreprintf("\tCache L2 Handle %s\n", dmi->processor.cache2);
165     moreprintf("\tCache L3 Handle %s\n", dmi->processor.cache3);
166     moreprintf("\tSerial       %s\n", dmi->processor.serial);
167     moreprintf("\tPart Number  %s\n", dmi->processor.part_number);
168     if (dmi->processor.core_count != 0)
169         moreprintf("\tCores Count   %d\n", dmi->processor.core_count);
170     if (dmi->processor.core_enabled != 0)
171         moreprintf("\tCores Enabled %d\n", dmi->processor.core_enabled);
172     if (dmi->processor.thread_count != 0)
173         moreprintf("\tThreads Count %d\n", dmi->processor.thread_count);
174     moreprintf("\tID           %s\n", dmi->processor.id);
175     display_processor_flags(dmi);
176 }
177
178 int main(void)
179 {
180     char buffer[1024];
181     s_dmi dmi;
182     openconsole(&dev_stdcon_r, &dev_stdcon_w);
183
184     if (dmi_iterate(&dmi) == -ENODMITABLE) {
185         printf("No DMI Structure found\n");
186         return -1;
187     } else {
188         printf("DMI %u.%u present.\n", dmi.dmitable.major_version,
189                dmi.dmitable.minor_version);
190         printf("%d structures occupying %d bytes.\n", dmi.dmitable.num,
191                dmi.dmitable.len);
192         printf("DMI table at 0x%08X.\n", dmi.dmitable.base);
193     }
194
195     parse_dmitable(&dmi);
196
197     for (;;) {
198         printf
199             ("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n");
200         printf("dmi: ");
201         fgets(buffer, sizeof buffer, stdin);
202         if (!strncmp(buffer, "exit", 4))
203             break;
204         if (!strncmp(buffer, "system", 6))
205             display_system(&dmi);
206         if (!strncmp(buffer, "chassis", 6))
207             display_chassis(&dmi);
208         if (!strncmp(buffer, "base_board", 10))
209             display_base_board(&dmi);
210         if (!strncmp(buffer, "cpu", 3))
211             display_cpu(&dmi);
212         if (!strncmp(buffer, "bios", 4))
213             display_bios(&dmi);
214         if (!strncmp(buffer, "memory", 6))
215             display_memory(&dmi);
216         if (!strncmp(buffer, "battery", 7))
217             display_battery(&dmi);
218         if (!strncmp(buffer, "all", 3)) {
219             display_bios(&dmi);
220             display_system(&dmi);
221             display_chassis(&dmi);
222             display_base_board(&dmi);
223             display_cpu(&dmi);
224             display_memory(&dmi);
225             display_battery(&dmi);
226         }
227     }
228
229     return 0;
230 }