xref: /openbmc/smbios-mdr/include/cpu.hpp (revision e05a5423)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include "smbios_mdrv2.hpp"
19 
20 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
21 #include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
22 #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
23 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
24 #include <xyz/openbmc_project/Inventory/Decorator/Revision/server.hpp>
25 #include <xyz/openbmc_project/Inventory/Item/Cpu/server.hpp>
26 #include <xyz/openbmc_project/Inventory/Item/server.hpp>
27 #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
28 
29 namespace phosphor
30 {
31 
32 namespace smbios
33 {
34 
35 using rev =
36     sdbusplus::server::xyz::openbmc_project::inventory::decorator::Revision;
37 using asset =
38     sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset;
39 using location =
40     sdbusplus::server::xyz::openbmc_project::inventory::decorator::LocationCode;
41 using connector =
42     sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot;
43 using processor = sdbusplus::server::xyz::openbmc_project::inventory::item::Cpu;
44 using Item = sdbusplus::server::xyz::openbmc_project::inventory::Item;
45 using association =
46     sdbusplus::server::xyz::openbmc_project::association::Definitions;
47 using operationalStatus = sdbusplus::xyz::openbmc_project::State::Decorator::
48     server::OperationalStatus;
49 
50 // This table is up to date as of SMBIOS spec DSP0134 3.7.0
51 static const std::map<uint8_t, const char*> familyTable = {
52     {0x01, "Other"},
53     {0x02, "Unknown"},
54     {0x03, "8086"},
55     {0x04, "80286"},
56     {0x05, "Intel 386 processor"},
57     {0x06, "Intel 486 processor"},
58     {0x07, "8087"},
59     {0x08, "80287"},
60     {0x09, "80387"},
61     {0x0a, "80487"},
62     {0x0b, "Intel Pentium processor"},
63     {0x0c, "Pentium Pro processor"},
64     {0x0d, "Pentium II processor"},
65     {0x0e, "Pentium processor with MMX technology"},
66     {0x0f, "Intel Celeron processor"},
67     {0x10, "Pentium II Xeon processor"},
68     {0x11, "Pentium III processor"},
69     {0x12, "M1 Family"},
70     {0x13, "M2 Family"},
71     {0x14, "Intel Celeron M processor"},
72     {0x15, "Intel Pentium 4 HT processor"},
73     {0x16, "Intel Processor"},
74     {0x18, "AMD Duron Processor Family"},
75     {0x19, "K5 Family"},
76     {0x1a, "K6 Family"},
77     {0x1b, "K6-2"},
78     {0x1c, "K6-3"},
79     {0x1d, "AMD Athlon Processor Family"},
80     {0x1e, "AMD29000 Family"},
81     {0x1f, "K6-2+"},
82     {0x20, "Power PC Family"},
83     {0x21, "Power PC 601"},
84     {0x22, "Power PC 603"},
85     {0x23, "Power PC 603+"},
86     {0x24, "Power PC 604"},
87     {0x25, "Power PC 620"},
88     {0x26, "Power PC x704"},
89     {0x27, "Power PC 750"},
90     {0x28, "Intel Core Duo processor"},
91     {0x29, "Intel Core Duo mobile processor"},
92     {0x2a, "Intel Core Solo mobile processor"},
93     {0x2b, "Intel Atom processor"},
94     {0x2c, "Intel Core M processor"},
95     {0x2d, "Intel Core m3 processor"},
96     {0x2e, "Intel Core m5 processor"},
97     {0x2f, "Intel Core m7 processor"},
98     {0x30, "Alpha Family"},
99     {0x31, "Alpha 21064"},
100     {0x32, "Alpha 21066"},
101     {0x33, "Alpha 21164"},
102     {0x34, "Alpha 21164PC"},
103     {0x35, "Alpha 21164a"},
104     {0x36, "Alpha 21264"},
105     {0x37, "Alpha 21364"},
106     {0x38, "AMD Turion II Ultra Dual-Core Mobile M Processor Family"},
107     {0x39, "AMD Turion II Dual-Core Mobile M Processor Family"},
108     {0x3a, "AMD Athlon II Dual-Core M Processor Family"},
109     {0x3b, "AMD Opteron 6100 Series Processor"},
110     {0x3c, "AMD Opteron 4100 Series Processor"},
111     {0x3d, "AMD Opteron 6200 Series Processor"},
112     {0x3e, "AMD Opteron 4200 Series Processor"},
113     {0x3f, "AMD FX Series Processor"},
114     {0x40, "MIPS Family"},
115     {0x41, "MIPS R4000"},
116     {0x42, "MIPS R4200"},
117     {0x43, "MIPS R4400"},
118     {0x44, "MIPS R4600"},
119     {0x45, "MIPS R10000"},
120     {0x46, "AMD C-Series Processor"},
121     {0x47, "AMD E-Series Processor"},
122     {0x48, "AMD A-Series Processor"},
123     {0x49, "AMD G-Series Processor"},
124     {0x4a, "AMD Z-Series Processor"},
125     {0x4b, "AMD R-Series Processor"},
126     {0x4c, "AMD Opteron 4300 Series Processor"},
127     {0x4d, "AMD Opteron 6300 Series Processor"},
128     {0x4e, "AMD Opteron 3300 Series Processor"},
129     {0x4f, "AMD FirePro Series Processor"},
130     {0x50, "SPARC Family"},
131     {0x51, "SuperSPARC"},
132     {0x52, "microSPARC II"},
133     {0x53, "microSPARC IIep"},
134     {0x54, "UltraSPARC"},
135     {0x55, "UltraSPARC II"},
136     {0x56, "UltraSPARC Iii"},
137     {0x57, "UltraSPARC III"},
138     {0x58, "UltraSPARC IIIi"},
139     {0x60, "68040 Family"},
140     {0x61, "68xxx"},
141     {0x62, "68000"},
142     {0x63, "68010"},
143     {0x64, "68020"},
144     {0x65, "68030"},
145     {0x66, "AMD Athlon X4 Quad-Core Processor Family"},
146     {0x67, "AMD Opteron X1000 Series Processor"},
147     {0x68, "AMD Opteron X2000 Series APU"},
148     {0x69, "AMD Opteron A-Series Processor"},
149     {0x6a, "AMD Opteron X3000 Series APU"},
150     {0x6b, "AMD Zen Processor Family"},
151     {0x70, "Hobbit Family"},
152     {0x78, "Crusoe TM5000 Family"},
153     {0x79, "Crusoe TM3000 Family"},
154     {0x7a, "Efficeon TM8000 Family"},
155     {0x80, "Weitek"},
156     {0x82, "Itanium processor"},
157     {0x83, "AMD Athlon 64 Processor Family"},
158     {0x84, "AMD Opteron Processor Family"},
159     {0x85, "AMD Sempron Processor Family"},
160     {0x86, "AMD Turion 64 Mobile Technology"},
161     {0x87, "Dual-Core AMD Opteron Processor Family"},
162     {0x88, "AMD Athlon 64 X2 Dual-Core Processor Family"},
163     {0x89, "AMD Turion 64 X2 Mobile Technology"},
164     {0x8a, "Quad-Core AMD Opteron Processor Family"},
165     {0x8b, "Third-Generation AMD Opteron Processor Family"},
166     {0x8c, "AMD Phenom FX Quad-Core Processor Family"},
167     {0x8d, "AMD Phenom X4 Quad-Core Processor Family"},
168     {0x8e, "AMD Phenom X2 Dual-Core Processor Family"},
169     {0x8f, "AMD Athlon X2 Dual-Core Processor Family"},
170     {0x90, "PA-RISC Family"},
171     {0x91, "PA-RISC 8500"},
172     {0x92, "PA-RISC 8000"},
173     {0x93, "PA-RISC 7300LC"},
174     {0x94, "PA-RISC 7200"},
175     {0x95, "PA-RISC 7100LC"},
176     {0x96, "PA-RISC 7100"},
177     {0xa0, "V30 Family"},
178     {0xa1, "Quad-Core Intel Xeon processor 3200 Series"},
179     {0xa2, "Dual-Core Intel Xeon processor 3000 Series"},
180     {0xa3, "Quad-Core Intel Xeon processor 5300 Series"},
181     {0xa4, "Dual-Core Intel Xeon processor 5100 Series"},
182     {0xa5, "Dual-Core Intel Xeon processor 5000 Series"},
183     {0xa6, "Dual-Core Intel Xeon processor LV"},
184     {0xa7, "Dual-Core Intel Xeon processor ULV"},
185     {0xa8, "Dual-Core Intel Xeon processor 7100 Series"},
186     {0xa9, "Quad-Core Intel Xeon processor 5400 Series"},
187     {0xaa, "Quad-Core Intel Xeon processor"},
188     {0xab, "Dual-Core Intel Xeon processor 5200 Series"},
189     {0xac, "Dual-Core Intel Xeon processor 7200 Series"},
190     {0xad, "Quad-Core Intel Xeon processor 7300 Series"},
191     {0xae, "Quad-Core Intel Xeon processor 7400 Series"},
192     {0xaf, "Multi-Core Intel Xeon processor 7400 Series"},
193     {0xb0, "Pentium III Xeon processor"},
194     {0xb1, "Pentium III Processor with Intel SpeedStep Technology"},
195     {0xb2, "Pentium 4 Processor"},
196     {0xb3, "Intel Xeon processor"},
197     {0xb4, "AS400 Family"},
198     {0xb5, "Intel Xeon processor MP"},
199     {0xb6, "AMD Athlon XP Processor Family"},
200     {0xb7, "AMD Athlon MP Processor Family"},
201     {0xb8, "Intel Itanium 2 processor"},
202     {0xb9, "Intel Pentium M processor"},
203     {0xba, "Intel Celeron D processor"},
204     {0xbb, "Intel Pentium D processor"},
205     {0xbc, "Intel Pentium Processor Extreme Edition"},
206     {0xbd, "Intel Core Solo Processor"},
207     {0xbf, "Intel Core 2 Duo Processor"},
208     {0xc0, "Intel Core 2 Solo processor"},
209     {0xc1, "Intel Core 2 Extreme processor"},
210     {0xc2, "Intel Core 2 Quad processor"},
211     {0xc3, "Intel Core 2 Extreme mobile processor"},
212     {0xc4, "Intel Core 2 Duo mobile processor"},
213     {0xc5, "Intel Core 2 Solo mobile processor"},
214     {0xc6, "Intel Core i7 processor"},
215     {0xc7, "Dual-Core Intel Celeron processor"},
216     {0xc8, "IBM390 Family"},
217     {0xc9, "G4"},
218     {0xca, "G5"},
219     {0xcb, "ESA/390 G6"},
220     {0xcc, "z/Architecture base"},
221     {0xcd, "Intel Core i5 processor"},
222     {0xce, "Intel Core i3 processor"},
223     {0xcf, "Intel Core i9 processor"},
224     {0xd2, "VIA C7-M Processor Family"},
225     {0xd3, "VIA C7-D Processor Family"},
226     {0xd4, "VIA C7 Processor Family"},
227     {0xd5, "VIA Eden Processor Family"},
228     {0xd6, "Multi-Core Intel Xeon processor"},
229     {0xd7, "Dual-Core Intel Xeon processor 3xxx Series"},
230     {0xd8, "Quad-Core Intel Xeon processor 3xxx Series"},
231     {0xd9, "VIA Nano Processor Family"},
232     {0xda, "Dual-Core Intel Xeon processor 5xxx Series"},
233     {0xdb, "Quad-Core Intel Xeon processor 5xxx Series"},
234     {0xdd, "Dual-Core Intel Xeon processor 7xxx Series"},
235     {0xde, "Quad-Core Intel Xeon processor 7xxx Series"},
236     {0xdf, "Multi-Core Intel Xeon processor 7xxx Series"},
237     {0xe0, "Multi-Core Intel Xeon processor 3400 Series"},
238     {0xe4, "AMD Opteron 3000 Series Processor"},
239     {0xe5, "AMD Sempron II Processor"},
240     {0xe6, "Embedded AMD Opteron Quad-Core Processor Family"},
241     {0xe7, "AMD Phenom Triple-Core Processor Family"},
242     {0xe8, "AMD Turion Ultra Dual-Core Mobile Processor Family"},
243     {0xe9, "AMD Turion Dual-Core Mobile Processor Family"},
244     {0xea, "AMD Athlon Dual-Core Processor Family"},
245     {0xeb, "AMD Sempron SI Processor Family"},
246     {0xec, "AMD Phenom II Processor Family"},
247     {0xed, "AMD Athlon II Processor Family"},
248     {0xee, "Six-core AMD Opteron Processor Family"},
249     {0xef, "AMD Sempron M Processor Family"},
250     {0xfa, "i860"},
251     {0xfb, "i960"},
252     {0xfe, "Processor Family 2 Indicator"}};
253 
254 // This table is up to date as of SMBIOS spec DSP0134 3.7.0
255 static const std::map<uint16_t, const char*> family2Table = {
256     {0x100, "ARMv7"},
257     {0x101, "ARMv8"},
258     {0x102, "ARMv9"},
259     {0x104, "SH-3"},
260     {0x105, "SH-4"},
261     {0x118, "ARM"},
262     {0x119, "StrongARM"},
263     {0x12c, "6x86"},
264     {0x12d, "MediaGX"},
265     {0x12e, "MII"},
266     {0x140, "WinChip"},
267     {0x15e, "DSP"},
268     {0x1f4, "Video Processor"},
269     {0x200, "RISC-V RV32"},
270     {0x201, "RISC-V RV64"},
271     {0x202, "RISC-V RV128"},
272     {0x258, "LoongArch"},
273     {0x259, "Loongson 1 Processor Family"},
274     {0x25a, "Loongson 2 Processor Family"},
275     {0x25b, "Loongson 3 Processor Family"},
276     {0x25c, "Loongson 2K Processor Family"},
277     {0x25d, "Loongson 3A Processor Family"},
278     {0x25e, "Loongson 3B Processor Family"},
279     {0x25f, "Loongson 3C Processor Family"},
280     {0x260, "Loongson 3D Processor Family"},
281     {0x261, "Loongson 3E Processor Family"},
282     {0x262, "Dual-Core Loongson 2K Processor 2xxx Series"},
283     {0x26c, "Quad-Core Loongson 3A Processor 5xxx Series"},
284     {0x26d, "Multi-Core Loongson 3A Processor 5xxx Series"},
285     {0x26e, "Quad-Core Loongson 3B Processor 5xxx Series"},
286     {0x26f, "Multi-Core Loongson 3B Processor 5xxx Series"},
287     {0x270, "Multi-Core Loongson 3C Processor 5xxx Series"},
288     {0x271, "Multi-Core Loongson 3D Processor 5xxx Series"}};
289 
290 // Definition follow smbios spec DSP0134 3.0.0
291 static const std::array<std::optional<processor::Capability>, 16>
292     characteristicsTable{std::nullopt,
293                          std::nullopt,
294                          processor::Capability::Capable64bit,
295                          processor::Capability::MultiCore,
296                          processor::Capability::HardwareThread,
297                          processor::Capability::ExecuteProtection,
298                          processor::Capability::EnhancedVirtualization,
299                          processor::Capability::PowerPerformanceControl,
300                          std::nullopt,
301                          std::nullopt,
302                          std::nullopt,
303                          std::nullopt,
304                          std::nullopt,
305                          std::nullopt,
306                          std::nullopt,
307                          std::nullopt};
308 
309 class Cpu :
310     sdbusplus::server::object_t<processor, asset, location, connector, rev,
311                                 Item, association, operationalStatus>
312 {
313   public:
314     Cpu() = delete;
315     Cpu(const Cpu&) = delete;
316     Cpu& operator=(const Cpu&) = delete;
317     Cpu(Cpu&&) = delete;
318     Cpu& operator=(Cpu&&) = delete;
319     ~Cpu() = default;
320 
Cpu(sdbusplus::bus_t & bus,const std::string & objPath,const uint8_t & cpuId,uint8_t * smbiosTableStorage,const std::string & motherboard)321     Cpu(sdbusplus::bus_t& bus, const std::string& objPath, const uint8_t& cpuId,
322         uint8_t* smbiosTableStorage, const std::string& motherboard) :
323         sdbusplus::server::object_t<processor, asset, location, connector, rev,
324                                     Item, association, operationalStatus>(
325             bus, objPath.c_str()),
326         cpuNum(cpuId), storage(smbiosTableStorage), motherboardPath(motherboard)
327     {
328         infoUpdate(smbiosTableStorage, motherboard);
329     }
330 
331     void infoUpdate(uint8_t* smbiosTableStorage,
332                     const std::string& motherboard);
333 
334   private:
335     uint8_t cpuNum;
336 
337     uint8_t* storage;
338 
339     std::string motherboardPath;
340 
341     struct ProcessorInfo
342     {
343         uint8_t type;
344         uint8_t length;
345         uint16_t handle;
346         uint8_t socketDesignation;
347         uint8_t processorType;
348         uint8_t family;
349         uint8_t manufacturer;
350         uint64_t id;
351         uint8_t version;
352         uint8_t voltage;
353         uint16_t exClock;
354         uint16_t maxSpeed;
355         uint16_t currSpeed;
356         uint8_t status;
357         uint8_t upgrade;
358         uint16_t l1Handle;
359         uint16_t l2Handle;
360         uint16_t l3Handle;
361         uint8_t serialNum;
362         uint8_t assetTag;
363         uint8_t partNum;
364         uint8_t coreCount;
365         uint8_t coreEnable;
366         uint8_t threadCount;
367         uint16_t characteristics;
368         uint16_t family2;
369         uint16_t coreCount2;
370         uint16_t coreEnable2;
371         uint16_t threadCount2;
372     } __attribute__((packed));
373 
374     void socket(const uint8_t positionNum, const uint8_t structLen,
375                 uint8_t* dataIn);
376     void family(const uint8_t family, const uint16_t family2);
377     void manufacturer(const uint8_t positionNum, const uint8_t structLen,
378                       uint8_t* dataIn);
379     void serialNumber(const uint8_t positionNum, const uint8_t structLen,
380                       uint8_t* dataIn);
381     void partNumber(const uint8_t positionNum, const uint8_t structLen,
382                     uint8_t* dataIn);
383     void version(const uint8_t positionNum, const uint8_t structLen,
384                  uint8_t* dataIn);
385     void characteristics(const uint16_t value);
386 };
387 
388 } // namespace smbios
389 
390 } // namespace phosphor
391