1/*
2 * Copyright (c) 2008 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2008 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Gabe Black
41 */
42
43#ifndef __ARCH_X86_BIOS_SMBIOS_HH__
44#define __ARCH_X86_BIOS_SMBIOS_HH__
45
46#include <string>
47#include <vector>
48
49#include "base/types.hh"
50#include "enums/Characteristic.hh"
51#include "enums/ExtCharacteristic.hh"
52#include "sim/sim_object.hh"
53
54class PortProxy;
55struct X86SMBiosBiosInformationParams;
56struct X86SMBiosSMBiosStructureParams;
57struct X86SMBiosSMBiosTableParams;
58
59namespace X86ISA
60{
61
62namespace SMBios
63{
64
65class SMBiosStructure : public SimObject
66{
67  protected:
68    typedef X86SMBiosSMBiosStructureParams Params;
69
70  public:
71
72    virtual
73    ~SMBiosStructure()
74    {}
75
76    // Offset 00h, 1 byte
77    uint8_t type;
78
79    // Offset 01h, 1 byte
80    //Length: computed when written to memory.
81
82    // Offset 02h, 2 bytes
83    uint16_t handle;
84
85    virtual uint8_t
86    getLength()
87    {
88        // This is the size of a structure with nothing but the header
89        return 4;
90    }
91
92    virtual uint16_t writeOut(PortProxy& proxy, Addr addr);
93
94  protected:
95    bool stringFields;
96
97    SMBiosStructure(Params * p, uint8_t _type);
98
99    std::vector<std::string> strings;
100
101    void writeOutStrings(PortProxy& proxy, Addr addr);
102
103    int getStringLength();
104
105  public:
106
107    int addString(std::string & newString);
108    std::string readString(int n);
109    void setString(int n, std::string & newString);
110};
111
112class BiosInformation : public SMBiosStructure
113{
114  protected:
115    const static uint8_t Type = 0;
116
117    typedef X86SMBiosBiosInformationParams Params;
118
119  public:
120    // Offset 04h, 1 byte
121    uint8_t vendor;
122    // Offset 05h, 1 byte
123    uint8_t version;
124    // Offset 06h, 2 bytes
125    uint16_t startingAddrSegment;
126    // Offset 08h, 1 byte
127    uint8_t releaseDate;
128    // Offset 09h, 1 byte
129    uint8_t romSize;
130    // Offset 0Ah, 8 bytes
131    //See tables in 3.3.1 in the SMBios 2.5 spec from the DMTF for
132    //bit definitions.
133    uint64_t characteristics;
134    // Offset 12h, 2 bytes
135    uint16_t characteristicExtBytes;
136    // Offset 14h, 1 byte
137    uint8_t majorVer;
138    // Offset 15h, 1 byte
139    uint8_t minorVer;
140    // Offset 16h, 1 byte
141    uint8_t embContFirmwareMajor;
142    // Offset 17h, 1 byte
143    uint8_t embContFirmwareMinor;
144
145    BiosInformation(Params * p);
146
147    uint8_t getLength() { return 0x18; }
148    uint16_t writeOut(PortProxy& proxy, Addr addr);
149};
150
151class SMBiosTable : public SimObject
152{
153  protected:
154    typedef X86SMBiosSMBiosTableParams Params;
155
156    struct SMBiosHeader
157    {
158        SMBiosHeader()
159        {}
160
161        // Offset 00h, 4 bytes
162        static const char anchorString[];
163
164        // Offset 04h, 1 byte
165        //Checksum: computed when written to memory.
166
167        // Offset 05h, 1 byte
168        static const uint8_t entryPointLength;
169
170        // Offset 06h, 1 byte
171        uint8_t majorVersion;
172
173        // Offset 07h, 1 byte
174        uint8_t minorVersion;
175
176        // Offset 08h, 2 bytes
177        //Maximum structure size: computed when written to memory.
178
179        // Offset 0Ah, 1 byte
180        static const uint8_t entryPointRevision;
181
182        // Offset 0Bh, 5 bytes
183        static const uint8_t formattedArea[5];
184
185        // Offset 10h, 15 bytes
186        struct IntermediateHeader
187        {
188            IntermediateHeader() : tableAddr(0)
189            {}
190            // Offset 10h, 5 bytes
191            static const char anchorString[];
192
193            // Offset 15h, 1 byte
194            //Checksum: computed when written to memory.
195
196            // Offset 16h, 2 bytes
197            //Length of the structure table in bytes: computed when
198            //written to memory.
199
200            // Offset 18h, 4 bytes
201            uint32_t tableAddr;
202
203            // Offset 1Ch, 2 bytes
204            //Number of structures: computed when written to memory
205
206            // Offset 1Eh, 1 byte
207            uint8_t smbiosBCDRevision;
208        } intermediateHeader;
209    } smbiosHeader;
210
211    std::vector<SMBiosStructure *> structures;
212
213  public:
214    SMBiosTable(Params * p);
215
216    Addr getTableAddr()
217    {
218        return smbiosHeader.intermediateHeader.tableAddr;
219    }
220
221    void setTableAddr(Addr addr)
222    {
223        smbiosHeader.intermediateHeader.tableAddr = addr;
224    }
225
226    void writeOut(PortProxy& proxy, Addr addr,
227            Addr &headerSize, Addr &structSize);
228};
229
230} //SMBios
231} //X86ISA
232
233#endif
234