Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/libsaio/smbios_decode.c

1/*
2 * A very simple SMBIOS Table decoder, part of the Chameleon Boot Loader Project
3 *
4 * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.
5 *
6 */
7
8#include "libsaio.h"
9#include "smbios.h"
10
11#ifndef DEBUG_SMBIOS
12#define DEBUG_SMBIOS 0
13#endif
14
15#if DEBUG_SMBIOS
16#define DBG(x...)printf(x)
17#else
18#define DBG(x...)//msglog(x)
19#endif
20
21
22static SMBWord minorVersion;
23
24extern char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field);
25
26//-------------------------------------------------------------------------------------------------------------------------
27// BIOSInformation
28//-------------------------------------------------------------------------------------------------------------------------
29void decodeBIOSInformation(SMBBIOSInformation *structHeader)
30{
31DBG("BIOSInformation:\n");
32DBG("\tvendor: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor));
33DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
34DBG("\treleaseDate: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate));
35DBG("\n");
36}
37
38//-------------------------------------------------------------------------------------------------------------------------
39// SystemInformation
40//-------------------------------------------------------------------------------------------------------------------------
41void decodeSystemInformation(SMBSystemInformation *structHeader)
42{
43DBG("SystemInformation:\n");
44DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
45DBG("\tproductName: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->productName));
46DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
47DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
48
49if (minorVersion < 1 || structHeader->header.length < 25)
50return;
51//Azi: if debug?
52//uint8_t *uuid = structHeader->uuid;
53DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n",
54uuid[0], uuid[1], uuid[2], uuid[3],
55uuid[4], uuid[5],
56uuid[6], uuid[7],
57uuid[8], uuid[9],
58uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
59DBG("\twakeupReason: 0x%x\n", structHeader->wakeupReason);
60
61if (minorVersion < 4 || structHeader->header.length < 27)
62return;
63DBG("\tskuNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber));
64DBG("\tfamily: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->family));
65DBG("\n");
66}
67
68//-------------------------------------------------------------------------------------------------------------------------
69// BaseBoard
70//-------------------------------------------------------------------------------------------------------------------------
71void decodeBaseBoard(SMBBaseBoard *structHeader)
72{
73DBG("BaseBoard:\n");
74DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
75DBG("\tproduct: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->product));
76DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
77DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
78DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
79DBG("\tlocationInChassis: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis));
80DBG("\tboardType: 0x%X\n", structHeader->boardType);
81DBG("\n");
82}
83
84//-------------------------------------------------------------------------------------------------------------------------
85// SystemEnclosure
86//-------------------------------------------------------------------------------------------------------------------------
87void decodeSystemEnclosure(SMBSystemEnclosure *structHeader)
88{
89DBG("SystemEnclosure:\n");
90DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
91DBG("\ttype: %d\n", structHeader->type);
92DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version));
93DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
94DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber));
95DBG("\n");
96}
97
98//-------------------------------------------------------------------------------------------------------------------------
99// ProcessorInformation
100//-------------------------------------------------------------------------------------------------------------------------
101void decodeProcessorInformation(SMBProcessorInformation *structHeader)
102{
103DBG("ProcessorInformation:\n");
104DBG("\tsocketDesignation: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation));
105DBG("\tprocessorType: %d\n", structHeader->processorType);
106DBG("\tprocessorFamily: 0x%X\n", structHeader->processorFamily);
107DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
108DBG("\tprocessorID: 0x%llX\n", structHeader->processorID);
109DBG("\tprocessorVersion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion));
110DBG("\texternalClock: %dMHz\n", structHeader->externalClock);
111DBG("\tmaximumClock: %dMHz\n", structHeader->maximumClock);
112DBG("\tcurrentClock: %dMHz\n", structHeader->currentClock);
113
114if (minorVersion < 3 || structHeader->header.length < 35)
115return;
116DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
117DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
118DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
119DBG("\n");
120}
121
122//-------------------------------------------------------------------------------------------------------------------------
123// MemoryDevice
124//-------------------------------------------------------------------------------------------------------------------------
125void decodeMemoryDevice(SMBMemoryDevice *structHeader)
126{
127DBG("MemoryDevice:\n");
128DBG("\tdeviceLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator));
129DBG("\tbankLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator));
130DBG("\tmemoryType: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]);
131
132if (minorVersion < 3 || structHeader->header.length < 27)
133return;
134DBG("\tmemorySpeed: %dMHz\n", structHeader->memorySpeed);
135DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer));
136DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber));
137DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag));
138DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber));
139DBG("\n");
140}
141
142//-------------------------------------------------------------------------------------------------------------------------
143// Apple Specific
144//-------------------------------------------------------------------------------------------------------------------------
145void decodeOemProcessorType(SMBOemProcessorType *structHeader)
146{
147DBG("AppleProcessorType:\n");
148DBG("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
149DBG("\n");
150}
151
152void decodeOemProcessorBusSpeed(SMBOemProcessorBusSpeed *structHeader)
153{
154DBG("AppleProcessorBusSpeed:\n");
155DBG("\tProcessorBusSpeed (QPI): %d.%dGT/s\n",
156((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 1000,
157(((SMBOemProcessorBusSpeed *)structHeader)->ProcessorBusSpeed / 100) % 10);
158DBG("\n");
159}
160//-------------------------------------------------------------------------------------------------------------------------
161
162
163void decodeSMBIOSTable(SMBEntryPoint *eps)
164{
165uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
166SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
167
168minorVersion = eps->minorVersion;
169
170DBG("\n");
171for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
172{
173DBG("Type: %d, Length: %d, Handle: 0x%x\n",
174structHeader->type, structHeader->length, structHeader->handle);
175
176switch (structHeader->type)
177{
178case kSMBTypeBIOSInformation:
179decodeBIOSInformation((SMBBIOSInformation *)structHeader);
180break;
181
182case kSMBTypeSystemInformation:
183decodeSystemInformation((SMBSystemInformation *)structHeader);
184break;
185
186case kSMBTypeBaseBoard:
187decodeBaseBoard((SMBBaseBoard *)structHeader);
188break;
189
190case kSMBTypeSystemEnclosure:
191decodeSystemEnclosure((SMBSystemEnclosure *)structHeader);
192break;
193
194case kSMBTypeProcessorInformation:
195decodeProcessorInformation((SMBProcessorInformation *)structHeader);
196break;
197
198case kSMBTypeMemoryDevice:
199decodeMemoryDevice((SMBMemoryDevice *)structHeader);
200break;
201
202/* Skip all Apple Specific Structures */
203case kSMBTypeFirmwareVolume:
204case kSMBTypeMemorySPD:
205break;
206
207case kSMBTypeOemProcessorType:
208decodeOemProcessorType((SMBOemProcessorType *)structHeader);
209break;
210
211case kSMBTypeOemProcessorBusSpeed:
212decodeOemProcessorBusSpeed((SMBOemProcessorBusSpeed *)structHeader);
213break;
214
215case kSMBTypeEndOfTable:
216/* Skip, to be added at the end */
217break;
218
219default:
220break;
221}
222
223ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
224for (; ((uint16_t *)ptr)[0] != 0; ptr++);
225
226if (((uint16_t *)ptr)[0] == 0)
227ptr += 2;
228
229structHeader = (SMBStructHeader *)ptr;
230}
231DBG("\n");
232}
233
234

Archive Download this file

Revision: 840