smbios.cc (5612:1bd333953e49) smbios.cc (5615:1c4b9b1aa500)
1/*
2 * Copyright (c) 2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 74 unchanged lines hidden (view full) ---

83 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 *
85 * Authors: Gabe Black
86 */
87
88#include "arch/x86/bios/smbios.hh"
89#include "arch/x86/isa_traits.hh"
90#include "mem/port.hh"
1/*
2 * Copyright (c) 2008 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 74 unchanged lines hidden (view full) ---

83 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 *
85 * Authors: Gabe Black
86 */
87
88#include "arch/x86/bios/smbios.hh"
89#include "arch/x86/isa_traits.hh"
90#include "mem/port.hh"
91#include "params/X86SMBiosBiosInformation.hh"
92#include "params/X86SMBiosSMBiosStructure.hh"
93#include "params/X86SMBiosSMBiosTable.hh"
91#include "sim/byteswap.hh"
92#include "sim/host.hh"
93
94#include "sim/byteswap.hh"
95#include "sim/host.hh"
96
97using namespace std;
98
94const char X86ISA::SMBios::SMBiosTable::SMBiosHeader::anchorString[] = "_SM_";
95const uint8_t X86ISA::SMBios::SMBiosTable::
96 SMBiosHeader::formattedArea[] = {0,0,0,0,0};
97const uint8_t X86ISA::SMBios::SMBiosTable::
98 SMBiosHeader::entryPointLength = 0x1F;
99const uint8_t X86ISA::SMBios::SMBiosTable::
100 SMBiosHeader::entryPointRevision = 0;
101const char X86ISA::SMBios::SMBiosTable::
102 SMBiosHeader::IntermediateHeader::anchorString[] = "_DMI_";
103
99const char X86ISA::SMBios::SMBiosTable::SMBiosHeader::anchorString[] = "_SM_";
100const uint8_t X86ISA::SMBios::SMBiosTable::
101 SMBiosHeader::formattedArea[] = {0,0,0,0,0};
102const uint8_t X86ISA::SMBios::SMBiosTable::
103 SMBiosHeader::entryPointLength = 0x1F;
104const uint8_t X86ISA::SMBios::SMBiosTable::
105 SMBiosHeader::entryPointRevision = 0;
106const char X86ISA::SMBios::SMBiosTable::
107 SMBiosHeader::IntermediateHeader::anchorString[] = "_DMI_";
108
109template <class T>
110uint64_t
111composeBitVector(T vec)
112{
113 uint64_t val = 0;
114 typename T::iterator vecIt;
115 for (vecIt = vec.begin(); vecIt != vec.end(); vecIt++) {
116 val |= (1 << (*vecIt));
117 }
118 return val;
119}
120
104uint16_t
121uint16_t
122X86ISA::SMBios::SMBiosStructure::writeOut(FunctionalPort * port, Addr addr)
123{
124 port->writeBlob(addr, (uint8_t *)(&type), 1);
125
126 uint8_t length = getLength();
127 port->writeBlob(addr + 1, (uint8_t *)(&length), 1);
128
129 uint16_t handleGuest = X86ISA::htog(handle);
130 port->writeBlob(addr + 2, (uint8_t *)(&handleGuest), 2);
131
132 return length + getStringLength();
133}
134
135X86ISA::SMBios::SMBiosStructure::SMBiosStructure(Params * p, uint8_t _type) :
136 SimObject(p), type(_type), handle(0), stringFields(false)
137{}
138
139void
140X86ISA::SMBios::SMBiosStructure::writeOutStrings(
141 FunctionalPort * port, Addr addr)
142{
143 std::vector<std::string>::iterator it;
144 Addr offset = 0;
145
146 const uint8_t nullTerminator = 0;
147
148 // If there are string fields but none of them are used, that's a
149 // special case which is handled by this if.
150 if (strings.size() == 0 && stringFields) {
151 port->writeBlob(addr + offset, (uint8_t *)(&nullTerminator), 1);
152 offset++;
153 } else {
154 for (it = strings.begin(); it != strings.end(); it++) {
155 port->writeBlob(addr + offset,
156 (uint8_t *)it->c_str(), it->length() + 1);
157 offset += it->length() + 1;
158 }
159 }
160 port->writeBlob(addr + offset, (uint8_t *)(&nullTerminator), 1);
161}
162
163int
164X86ISA::SMBios::SMBiosStructure::getStringLength()
165{
166 int size = 0;
167 std::vector<std::string>::iterator it;
168
169 for (it = strings.begin(); it != strings.end(); it++) {
170 size += it->length() + 1;
171 }
172
173 return size + 1;
174}
175
176int
177X86ISA::SMBios::SMBiosStructure::addString(string & newString)
178{
179 stringFields = true;
180 // If a string is empty, treat it as not existing. The index for empty
181 // strings is 0.
182 if (newString.length() == 0)
183 return 0;
184 strings.push_back(newString);
185 return strings.size();
186}
187
188string
189X86ISA::SMBios::SMBiosStructure::readString(int n)
190{
191 assert(n > 0 && n <= strings.size());
192 return strings[n - 1];
193}
194
195void
196X86ISA::SMBios::SMBiosStructure::setString(int n, std::string & newString)
197{
198 assert(n > 0 && n <= strings.size());
199 strings[n - 1] = newString;
200}
201
202X86ISA::SMBios::BiosInformation::BiosInformation(Params * p) :
203 SMBiosStructure(p, Type),
204 startingAddrSegment(p->starting_addr_segment),
205 romSize(p->rom_size),
206 majorVer(p->major), minorVer(p->minor),
207 embContFirmwareMajor(p->emb_cont_firmware_major),
208 embContFirmwareMinor(p->emb_cont_firmware_minor)
209 {
210 vendor = addString(p->vendor);
211 version = addString(p->version);
212 releaseDate = addString(p->release_date);
213
214 characteristics = composeBitVector(p->characteristics);
215 characteristicExtBytes =
216 composeBitVector(p->characteristic_ext_bytes);
217 }
218
219uint16_t
105X86ISA::SMBios::BiosInformation::writeOut(FunctionalPort * port, Addr addr)
106{
107 uint8_t size = SMBiosStructure::writeOut(port, addr);
108
109 port->writeBlob(addr + 0x4, (uint8_t *)(&vendor), 1);
110 port->writeBlob(addr + 0x5, (uint8_t *)(&version), 1);
111
112 uint16_t startingAddrSegmentGuest = X86ISA::htog(startingAddrSegment);

--- 4 unchanged lines hidden (view full) ---

117
118 uint64_t characteristicsGuest = X86ISA::htog(characteristics);
119 port->writeBlob(addr + 0xA, (uint8_t *)(&characteristicsGuest), 8);
120
121 uint16_t characteristicExtBytesGuest =
122 X86ISA::htog(characteristicExtBytes);
123 port->writeBlob(addr + 0x12, (uint8_t *)(&characteristicExtBytesGuest), 2);
124
220X86ISA::SMBios::BiosInformation::writeOut(FunctionalPort * port, Addr addr)
221{
222 uint8_t size = SMBiosStructure::writeOut(port, addr);
223
224 port->writeBlob(addr + 0x4, (uint8_t *)(&vendor), 1);
225 port->writeBlob(addr + 0x5, (uint8_t *)(&version), 1);
226
227 uint16_t startingAddrSegmentGuest = X86ISA::htog(startingAddrSegment);

--- 4 unchanged lines hidden (view full) ---

232
233 uint64_t characteristicsGuest = X86ISA::htog(characteristics);
234 port->writeBlob(addr + 0xA, (uint8_t *)(&characteristicsGuest), 8);
235
236 uint16_t characteristicExtBytesGuest =
237 X86ISA::htog(characteristicExtBytes);
238 port->writeBlob(addr + 0x12, (uint8_t *)(&characteristicExtBytesGuest), 2);
239
125 port->writeBlob(addr + 0x14, (uint8_t *)(&major), 1);
126 port->writeBlob(addr + 0x15, (uint8_t *)(&minor), 1);
240 port->writeBlob(addr + 0x14, (uint8_t *)(&majorVer), 1);
241 port->writeBlob(addr + 0x15, (uint8_t *)(&minorVer), 1);
127 port->writeBlob(addr + 0x16, (uint8_t *)(&embContFirmwareMajor), 1);
128 port->writeBlob(addr + 0x17, (uint8_t *)(&embContFirmwareMinor), 1);
129
130 writeOutStrings(port, addr + getLength());
131
132 return size;
133}
134
242 port->writeBlob(addr + 0x16, (uint8_t *)(&embContFirmwareMajor), 1);
243 port->writeBlob(addr + 0x17, (uint8_t *)(&embContFirmwareMinor), 1);
244
245 writeOutStrings(port, addr + getLength());
246
247 return size;
248}
249
250X86ISA::SMBios::SMBiosTable::SMBiosTable(Params * p) :
251 SimObject(p), structures(p->structures)
252{
253 smbiosHeader.majorVersion = p->major_version;
254 smbiosHeader.minorVersion = p->minor_version;
255 assert(p->major_version <= 9);
256 assert(p->minor_version <= 9);
257 smbiosHeader.intermediateHeader.smbiosBCDRevision =
258 (p->major_version << 4) | p->minor_version;
259}
260
135void
261void
136X86ISA::SMBios::SMBiosTable::writeOut(FunctionalPort * port, Addr addr)
262X86ISA::SMBios::SMBiosTable::writeOut(FunctionalPort * port, Addr addr,
263 Addr &headerSize, Addr &structSize)
137{
264{
265 headerSize = 0x1F;
138
139 /*
140 * The main header
141 */
142 uint8_t mainChecksum = 0;
143
144 port->writeBlob(addr, (uint8_t *)smbiosHeader.anchorString, 4);
145 for (int i = 0; i < 4; i++)

--- 54 unchanged lines hidden (view full) ---

200
201 /*
202 * Structure table
203 */
204
205 Addr base = smbiosHeader.intermediateHeader.tableAddr;
206 Addr offset = 0;
207 uint16_t maxSize = 0;
266
267 /*
268 * The main header
269 */
270 uint8_t mainChecksum = 0;
271
272 port->writeBlob(addr, (uint8_t *)smbiosHeader.anchorString, 4);
273 for (int i = 0; i < 4; i++)

--- 54 unchanged lines hidden (view full) ---

328
329 /*
330 * Structure table
331 */
332
333 Addr base = smbiosHeader.intermediateHeader.tableAddr;
334 Addr offset = 0;
335 uint16_t maxSize = 0;
208 std::vector::iterator it;
336 std::vector<SMBiosStructure *>::iterator it;
209 for (it = structures.begin(); it != structures.end(); it++) {
337 for (it = structures.begin(); it != structures.end(); it++) {
210 uint16_t size = it->writeOut(port, base + offset);
338 uint16_t size = (*it)->writeOut(port, base + offset);
211 if (size > maxSize)
212 maxSize = size;
213 offset += size;
214 }
215
339 if (size > maxSize)
340 maxSize = size;
341 offset += size;
342 }
343
344 structSize = offset;
345
216 /*
217 * Header
218 */
219
220 maxSize = X86ISA::htog(maxSize);
221 port->writeBlob(addr + 0x8, (uint8_t *)(&maxSize), 2);
222 for (int i = 0; i < 2; i++) {
223 mainChecksum += maxSize;

--- 14 unchanged lines hidden (view full) ---

238 for (int i = 0; i < 2; i++) {
239 intChecksum += tableSize;
240 tableSize >>= 8;
241 }
242
243 intChecksum = -intChecksum;
244 port->writeBlob(addr + 0x15, (uint8_t *)(&intChecksum), 1);
245}
346 /*
347 * Header
348 */
349
350 maxSize = X86ISA::htog(maxSize);
351 port->writeBlob(addr + 0x8, (uint8_t *)(&maxSize), 2);
352 for (int i = 0; i < 2; i++) {
353 mainChecksum += maxSize;

--- 14 unchanged lines hidden (view full) ---

368 for (int i = 0; i < 2; i++) {
369 intChecksum += tableSize;
370 tableSize >>= 8;
371 }
372
373 intChecksum = -intChecksum;
374 port->writeBlob(addr + 0x15, (uint8_t *)(&intChecksum), 1);
375}
376
377X86ISA::SMBios::BiosInformation *
378X86SMBiosBiosInformationParams::create()
379{
380 return new X86ISA::SMBios::BiosInformation(this);
381}
382
383X86ISA::SMBios::SMBiosTable *
384X86SMBiosSMBiosTableParams::create()
385{
386 return new X86ISA::SMBios::SMBiosTable(this);
387}