blob: bae8dc08c1d461fbf75f87e7ce2648ea931c67b7 [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>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080027
28namespace phosphor
29{
30
31namespace smbios
32{
33
Zhikui Ren18a5ab92020-09-01 21:35:20 -070034using rev =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070035 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Revision;
Zhikui Ren18a5ab92020-09-01 21:35:20 -070036using asset =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070037 sdbusplus::server::xyz::openbmc_project::inventory::decorator::Asset;
Jie Yang31720392021-07-22 21:45:45 -070038using location =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070039 sdbusplus::server::xyz::openbmc_project::inventory::decorator::LocationCode;
Jie Yang41654fc2021-09-07 20:26:32 -070040using connector =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070041 sdbusplus::server::xyz::openbmc_project::inventory::connector::Slot;
42using processor = sdbusplus::server::xyz::openbmc_project::inventory::item::Cpu;
43using Item = sdbusplus::server::xyz::openbmc_project::inventory::Item;
Jie Yange7cf3192021-08-20 11:21:43 -070044using association =
Jason M. Bills33ae81f2023-04-26 09:06:08 -070045 sdbusplus::server::xyz::openbmc_project::association::Definitions;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080046
47// Definition follow smbios spec DSP0134 3.0.0
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080048static const std::map<uint8_t, const char*> familyTable = {
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080049 {0x1, "Other"},
50 {0x2, "Unknown"},
51 {0x10, "Pentium II Xeon processor"},
Jayaprakash Mutyala79a7f6c2023-04-04 05:58:44 +000052 {0x2b, "Intel Atom processor"},
53 {0x2c, "Intel Core M processor"},
54 {0x2d, "Intel Core m3 processor"},
55 {0x2e, "Intel Core m5 processor"},
56 {0x2f, "Intel Core m7 processor"},
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080057 {0xa1, "Quad-Core Intel Xeon processor 3200 Series"},
58 {0xa2, "Dual-Core Intel Xeon processor 3000 Series"},
59 {0xa3, "Quad-Core Intel Xeon processor 5300 Series"},
60 {0xa4, "Dual-Core Intel Xeon processor 5100 Series"},
61 {0xa5, "Dual-Core Intel Xeon processor 5000 Series"},
62 {0xa6, "Dual-Core Intel Xeon processor LV"},
63 {0xa7, "Dual-Core Intel Xeon processor ULV"},
64 {0xa8, "Dual-Core Intel Xeon processor 7100 Series"},
65 {0xa9, "Quad-Core Intel Xeon processor 5400 Series"},
66 {0xaa, "Quad-Core Intel Xeon processor"},
67 {0xab, "Dual-Core Intel Xeon processor 5200 Series"},
68 {0xac, "Dual-Core Intel Xeon processor 7200 Series"},
69 {0xad, "Quad-Core Intel Xeon processor 7300 Series"},
70 {0xae, "Quad-Core Intel Xeon processor 7400 Series"},
71 {0xaf, "Multi-Core Intel Xeon processor 7400 Series"},
72 {0xb0, "Pentium III Xeon processor"},
73 {0xb3, "Intel Xeon processor"},
74 {0xb5, "Intel Xeon processor MP"},
75 {0xd6, "Multi-Core Intel Xeon processor"},
76 {0xd7, "Dual-Core Intel Xeon processor 3xxx Series"},
77 {0xd8, "Quad-Core Intel Xeon processor 3xxx Series"},
78 {0xd9, "VIA Nano Processor Family"},
79 {0xda, "Dual-Core Intel Xeon processor 5xxx Series"},
80 {0xdb, "Quad-Core Intel Xeon processor 5xxx Series"},
81 {0xdd, "Dual-Core Intel Xeon processor 7xxx Series"},
82 {0xde, "Quad-Core Intel Xeon processor 7xxx Series"},
83 {0xdf, "Multi-Core Intel Xeon processor 7xxx Series"},
Charles Boyer800bb702021-08-31 17:09:19 -050084 {0xe0, "Multi-Core Intel Xeon processor 3400 Series"},
85 {0xfe, "Processor Family 2 Indicator"}
86
87};
88
89// Definition follow smbios spec DSP0134 3.1.1
90static const std::map<uint16_t, const char*> family2Table = {
91 {0x100, "ARMv7"}, {0x101, "ARMv8"}, {0x118, "ARM"}, {0x119, "StrongARM"}
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080092
93};
94
95// Definition follow smbios spec DSP0134 3.0.0
Zhikui Ren18a5ab92020-09-01 21:35:20 -070096static const std::array<std::optional<processor::Capability>, 16>
97 characteristicsTable{std::nullopt,
98 std::nullopt,
99 processor::Capability::Capable64bit,
100 processor::Capability::MultiCore,
101 processor::Capability::HardwareThread,
102 processor::Capability::ExecuteProtection,
103 processor::Capability::EnhancedVirtualization,
104 processor::Capability::PowerPerformanceControl,
105 std::nullopt,
106 std::nullopt,
107 std::nullopt,
108 std::nullopt,
109 std::nullopt,
110 std::nullopt,
111 std::nullopt,
112 std::nullopt};
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800113
Jie Yang41654fc2021-09-07 20:26:32 -0700114class Cpu :
115 sdbusplus::server::object_t<processor, asset, location, connector, rev,
Jie Yange7cf3192021-08-20 11:21:43 -0700116 Item, association>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800117{
118 public:
119 Cpu() = delete;
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800120 Cpu(const Cpu&) = delete;
121 Cpu& operator=(const Cpu&) = delete;
122 Cpu(Cpu&&) = delete;
123 Cpu& operator=(Cpu&&) = delete;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800124 ~Cpu() = default;
125
Patrick Williams77b9c472022-07-22 19:26:57 -0500126 Cpu(sdbusplus::bus_t& bus, const std::string& objPath, const uint8_t& cpuId,
127 uint8_t* smbiosTableStorage, const std::string& motherboard) :
Jie Yang41654fc2021-09-07 20:26:32 -0700128 sdbusplus::server::object_t<processor, asset, location, connector, rev,
Jie Yange7cf3192021-08-20 11:21:43 -0700129 Item, association>(bus, objPath.c_str()),
130 cpuNum(cpuId), storage(smbiosTableStorage), motherboardPath(motherboard)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800131 {
Brandon Kim5a122a62023-05-04 04:25:03 +0000132 infoUpdate(smbiosTableStorage, motherboard);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800133 }
134
Brandon Kim5a122a62023-05-04 04:25:03 +0000135 void infoUpdate(uint8_t* smbiosTableStorage,
136 const std::string& motherboard);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800137
138 private:
139 uint8_t cpuNum;
140
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800141 uint8_t* storage;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800142
Jie Yange7cf3192021-08-20 11:21:43 -0700143 std::string motherboardPath;
144
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800145 struct ProcessorInfo
146 {
147 uint8_t type;
148 uint8_t length;
149 uint16_t handle;
150 uint8_t socketDesignation;
151 uint8_t processorType;
152 uint8_t family;
153 uint8_t manufacturer;
154 uint64_t id;
155 uint8_t version;
156 uint8_t voltage;
157 uint16_t exClock;
158 uint16_t maxSpeed;
159 uint16_t currSpeed;
160 uint8_t status;
161 uint8_t upgrade;
162 uint16_t l1Handle;
163 uint16_t l2Handle;
164 uint16_t l3Handle;
165 uint8_t serialNum;
166 uint8_t assetTag;
167 uint8_t partNum;
168 uint8_t coreCount;
169 uint8_t coreEnable;
170 uint8_t threadCount;
171 uint16_t characteristics;
172 uint16_t family2;
173 uint16_t coreCount2;
174 uint16_t coreEnable2;
175 uint16_t threadCount2;
176 } __attribute__((packed));
177
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700178 void socket(const uint8_t positionNum, const uint8_t structLen,
179 uint8_t* dataIn);
Charles Boyer800bb702021-08-31 17:09:19 -0500180 void family(const uint8_t family, const uint16_t family2);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700181 void manufacturer(const uint8_t positionNum, const uint8_t structLen,
182 uint8_t* dataIn);
Charles Boyere6431692021-08-31 16:47:47 -0500183 void serialNumber(const uint8_t positionNum, const uint8_t structLen,
184 uint8_t* dataIn);
185 void partNumber(const uint8_t positionNum, const uint8_t structLen,
186 uint8_t* dataIn);
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700187 void version(const uint8_t positionNum, const uint8_t structLen,
188 uint8_t* dataIn);
189 void characteristics(const uint16_t value);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800190};
191
192} // namespace smbios
193
194} // namespace phosphor