blob: 20ff0cf3ec1138872bf935a54b5a16caf5fee55a [file] [log] [blame]
Cheng C Yang43c6a1d2019-12-19 00:48:34 +08001/*
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
Zhikui Ren18a5ab92020-09-01 21:35:20 -070018#include "smbios_mdrv2.hpp"
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080019
Jie Yange7cf3192021-08-20 11:21:43 -070020#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Jie Yang41654fc2021-09-07 20:26:32 -070021#include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080022#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
Jie Yang31720392021-07-22 21:45:45 -070023#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
Zhikui Ren18a5ab92020-09-01 21:35:20 -070024#include <xyz/openbmc_project/Inventory/Decorator/Revision/server.hpp>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080025#include <xyz/openbmc_project/Inventory/Item/Cpu/server.hpp>
Jonathan Doman563570d2021-05-24 10:52:43 -070026#include <xyz/openbmc_project/Inventory/Item/server.hpp>
David Wange05a5422023-08-23 17:15:32 +080027#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080028
29namespace phosphor
30{
31
32namespace smbios
33{
34
Zhikui Ren18a5ab92020-09-01 21:35:20 -070035using rev =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070036 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Revision;
Zhikui Ren18a5ab92020-09-01 21:35:20 -070037using asset =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070038 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset;
Jie Yang31720392021-07-22 21:45:45 -070039using location =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070040 sdbusplus::server::xyz::openbmc_project::inventory::decorator::LocationCode;
Jie Yang41654fc2021-09-07 20:26:32 -070041using connector =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070042 sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot;
43using processor = sdbusplus::server::xyz::openbmc_project::inventory::item::Cpu;
44using Item = sdbusplus::server::xyz::openbmc_project::inventory::Item;
Jie Yange7cf3192021-08-20 11:21:43 -070045using association =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070046 sdbusplus::server::xyz::openbmc_project::association::Definitions;
David Wange05a5422023-08-23 17:15:32 +080047using operationalStatus = sdbusplus::xyz::openbmc_project::State::Decorator::
48 server::OperationalStatus;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080049
Josh Lehan6076d2c2023-09-19 21:05:12 -070050// This table is up to date as of SMBIOS spec DSP0134 3.7.0
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080051static const std::map<uint8_t, const char*> familyTable = {
Josh Lehan6076d2c2023-09-19 21:05:12 -070052 {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"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080067 {0x10, "Pentium II Xeon processor"},
Josh Lehan6076d2c2023-09-19 21:05:12 -070068 {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"},
Jayaprakash Mutyala79a7f6c2023-04-04 05:58:44 +000093 {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"},
Josh Lehan6076d2c2023-09-19 21:05:12 -070098 {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"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800178 {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"},
Josh Lehan6076d2c2023-09-19 21:05:12 -0700194 {0xb1, "Pentium III Processor with Intel SpeedStep Technology"},
195 {0xb2, "Pentium 4 Processor"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800196 {0xb3, "Intel Xeon processor"},
Josh Lehan6076d2c2023-09-19 21:05:12 -0700197 {0xb4, "AS400 Family"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800198 {0xb5, "Intel Xeon processor MP"},
Josh Lehan6076d2c2023-09-19 21:05:12 -0700199 {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"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800228 {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"},
Charles Boyer800bb702021-08-31 17:09:19 -0500237 {0xe0, "Multi-Core Intel Xeon processor 3400 Series"},
Josh Lehan6076d2c2023-09-19 21:05:12 -0700238 {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"}};
Charles Boyer800bb702021-08-31 17:09:19 -0500253
Josh Lehan6076d2c2023-09-19 21:05:12 -0700254// This table is up to date as of SMBIOS spec DSP0134 3.7.0
Charles Boyer800bb702021-08-31 17:09:19 -0500255static const std::map<uint16_t, const char*> family2Table = {
Josh Lehan6076d2c2023-09-19 21:05:12 -0700256 {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"}};
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800289
290// Definition follow smbios spec DSP0134 3.0.0
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700291static 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};
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800308
Jie Yang41654fc2021-09-07 20:26:32 -0700309class Cpu :
310 sdbusplus::server::object_t<processor, asset, location, connector, rev,
David Wange05a5422023-08-23 17:15:32 +0800311 Item, association, operationalStatus>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800312{
313 public:
314 Cpu() = delete;
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800315 Cpu(const Cpu&) = delete;
316 Cpu& operator=(const Cpu&) = delete;
317 Cpu(Cpu&&) = delete;
318 Cpu& operator=(Cpu&&) = delete;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800319 ~Cpu() = default;
320
Patrick Williams77b9c472022-07-22 19:26:57 -0500321 Cpu(sdbusplus::bus_t& bus, const std::string& objPath, const uint8_t& cpuId,
322 uint8_t* smbiosTableStorage, const std::string& motherboard) :
Jie Yang41654fc2021-09-07 20:26:32 -0700323 sdbusplus::server::object_t<processor, asset, location, connector, rev,
David Wange05a5422023-08-23 17:15:32 +0800324 Item, association, operationalStatus>(
325 bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -0700326 cpuNum(cpuId), storage(smbiosTableStorage), motherboardPath(motherboard)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800327 {
Brandon Kim5a122a62023-05-04 04:25:03 +0000328 infoUpdate(smbiosTableStorage, motherboard);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800329 }
330
Brandon Kim5a122a62023-05-04 04:25:03 +0000331 void infoUpdate(uint8_t* smbiosTableStorage,
332 const std::string& motherboard);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800333
334 private:
335 uint8_t cpuNum;
336
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800337 uint8_t* storage;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800338
Jie Yange7cf3192021-08-20 11:21:43 -0700339 std::string motherboardPath;
340
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800341 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
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700374 void socket(const uint8_t positionNum, const uint8_t structLen,
375 uint8_t* dataIn);
Charles Boyer800bb702021-08-31 17:09:19 -0500376 void family(const uint8_t family, const uint16_t family2);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700377 void manufacturer(const uint8_t positionNum, const uint8_t structLen,
378 uint8_t* dataIn);
Charles Boyere6431692021-08-31 16:47:47 -0500379 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);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700383 void version(const uint8_t positionNum, const uint8_t structLen,
384 uint8_t* dataIn);
385 void characteristics(const uint16_t value);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800386};
387
388} // namespace smbios
389
390} // namespace phosphor