Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 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 |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 18 | #include "smbios.hpp" |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 19 | |
| 20 | #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp> |
| 21 | #include <xyz/openbmc_project/Inventory/Item/Cpu/server.hpp> |
| 22 | #include <xyz/openbmc_project/Inventory/Item/server.hpp> |
| 23 | #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> |
| 24 | |
| 25 | namespace phosphor |
| 26 | { |
| 27 | |
| 28 | namespace smbios |
| 29 | { |
| 30 | |
| 31 | // Definition follow smbios spec DSP0134 3.0.0 |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 32 | static const std::map<uint8_t, const char*> processorTypeTable = { |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 33 | {0x1, "Other"}, {0x2, "Unknown"}, {0x3, "Central Processor"}, |
| 34 | {0x4, "Math Processor"}, {0x5, "DSP Processor"}, {0x6, "Video Processor"}, |
| 35 | }; |
| 36 | |
| 37 | // Definition follow smbios spec DSP0134 3.0.0 |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 38 | static const std::map<uint8_t, const char*> familyTable = { |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 39 | {0x1, "Other"}, |
| 40 | {0x2, "Unknown"}, |
| 41 | {0x10, "Pentium II Xeon processor"}, |
| 42 | {0xa1, "Quad-Core Intel Xeon processor 3200 Series"}, |
| 43 | {0xa2, "Dual-Core Intel Xeon processor 3000 Series"}, |
| 44 | {0xa3, "Quad-Core Intel Xeon processor 5300 Series"}, |
| 45 | {0xa4, "Dual-Core Intel Xeon processor 5100 Series"}, |
| 46 | {0xa5, "Dual-Core Intel Xeon processor 5000 Series"}, |
| 47 | {0xa6, "Dual-Core Intel Xeon processor LV"}, |
| 48 | {0xa7, "Dual-Core Intel Xeon processor ULV"}, |
| 49 | {0xa8, "Dual-Core Intel Xeon processor 7100 Series"}, |
| 50 | {0xa9, "Quad-Core Intel Xeon processor 5400 Series"}, |
| 51 | {0xaa, "Quad-Core Intel Xeon processor"}, |
| 52 | {0xab, "Dual-Core Intel Xeon processor 5200 Series"}, |
| 53 | {0xac, "Dual-Core Intel Xeon processor 7200 Series"}, |
| 54 | {0xad, "Quad-Core Intel Xeon processor 7300 Series"}, |
| 55 | {0xae, "Quad-Core Intel Xeon processor 7400 Series"}, |
| 56 | {0xaf, "Multi-Core Intel Xeon processor 7400 Series"}, |
| 57 | {0xb0, "Pentium III Xeon processor"}, |
| 58 | {0xb3, "Intel Xeon processor"}, |
| 59 | {0xb5, "Intel Xeon processor MP"}, |
| 60 | {0xd6, "Multi-Core Intel Xeon processor"}, |
| 61 | {0xd7, "Dual-Core Intel Xeon processor 3xxx Series"}, |
| 62 | {0xd8, "Quad-Core Intel Xeon processor 3xxx Series"}, |
| 63 | {0xd9, "VIA Nano Processor Family"}, |
| 64 | {0xda, "Dual-Core Intel Xeon processor 5xxx Series"}, |
| 65 | {0xdb, "Quad-Core Intel Xeon processor 5xxx Series"}, |
| 66 | {0xdd, "Dual-Core Intel Xeon processor 7xxx Series"}, |
| 67 | {0xde, "Quad-Core Intel Xeon processor 7xxx Series"}, |
| 68 | {0xdf, "Multi-Core Intel Xeon processor 7xxx Series"}, |
| 69 | {0xe0, "Multi-Core Intel Xeon processor 3400 Series"} |
| 70 | |
| 71 | }; |
| 72 | |
| 73 | // Definition follow smbios spec DSP0134 3.0.0 |
| 74 | static const std::array<std::string, 16> characteristicsTable{ |
| 75 | "Reserved", |
| 76 | "Unknown", |
| 77 | "64-bit Capable", |
| 78 | "Multi-Core", |
| 79 | "Hardware Thread", |
| 80 | "Execute Protection", |
| 81 | "Enhanced Virtualization", |
| 82 | "Power/Performance Control", |
| 83 | "Reserved", |
| 84 | "Reserved", |
| 85 | "Reserved", |
| 86 | "Reserved", |
| 87 | "Reserved", |
| 88 | "Reserved", |
| 89 | "Reserved", |
| 90 | "Reserved"}; |
| 91 | |
| 92 | class Cpu |
| 93 | : sdbusplus::server::object::object< |
| 94 | sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu>, |
| 95 | sdbusplus::server::object::object< |
| 96 | sdbusplus::xyz::openbmc_project::Inventory::server::Item>, |
| 97 | sdbusplus::server::object::object< |
| 98 | sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>, |
| 99 | sdbusplus::server::object::object< |
| 100 | sdbusplus::xyz::openbmc_project::State::Decorator::server:: |
| 101 | OperationalStatus> |
| 102 | { |
| 103 | public: |
| 104 | Cpu() = delete; |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 105 | Cpu(const Cpu&) = delete; |
| 106 | Cpu& operator=(const Cpu&) = delete; |
| 107 | Cpu(Cpu&&) = delete; |
| 108 | Cpu& operator=(Cpu&&) = delete; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 109 | ~Cpu() = default; |
| 110 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 111 | Cpu(sdbusplus::bus::bus& bus, const std::string& objPath, |
| 112 | const uint8_t& cpuId, uint8_t* smbiosTableStorage) : |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 113 | sdbusplus::server::object::object< |
| 114 | sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu>( |
| 115 | bus, objPath.c_str()), |
| 116 | sdbusplus::server::object::object< |
| 117 | sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: |
| 118 | Asset>(bus, objPath.c_str()), |
| 119 | sdbusplus::server::object::object< |
| 120 | sdbusplus::xyz::openbmc_project::Inventory::server::Item>( |
| 121 | bus, objPath.c_str()), |
| 122 | sdbusplus::server::object::object< |
| 123 | sdbusplus::xyz::openbmc_project::State::Decorator::server:: |
| 124 | OperationalStatus>(bus, objPath.c_str()), |
| 125 | cpuNum(cpuId), storage(smbiosTableStorage) |
| 126 | { |
| 127 | processorInfoUpdate(); |
| 128 | } |
| 129 | |
| 130 | void processorInfoUpdate(void); |
| 131 | |
| 132 | std::string processorSocket(std::string value) override; |
| 133 | std::string processorType(std::string value) override; |
| 134 | std::string processorFamily(std::string value) override; |
| 135 | std::string manufacturer(std::string value) override; |
| 136 | uint32_t processorId(uint32_t value) override; |
| 137 | std::string processorVersion(std::string value) override; |
| 138 | uint16_t processorMaxSpeed(uint16_t value) override; |
| 139 | std::string processorCharacteristics(std::string value) override; |
| 140 | uint16_t processorCoreCount(uint16_t value) override; |
| 141 | uint16_t processorThreadCount(uint16_t value) override; |
| 142 | bool present(bool value) override; |
| 143 | bool functional(bool value) override; |
| 144 | |
| 145 | private: |
| 146 | uint8_t cpuNum; |
| 147 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 148 | uint8_t* storage; |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 149 | |
| 150 | struct ProcessorInfo |
| 151 | { |
| 152 | uint8_t type; |
| 153 | uint8_t length; |
| 154 | uint16_t handle; |
| 155 | uint8_t socketDesignation; |
| 156 | uint8_t processorType; |
| 157 | uint8_t family; |
| 158 | uint8_t manufacturer; |
| 159 | uint64_t id; |
| 160 | uint8_t version; |
| 161 | uint8_t voltage; |
| 162 | uint16_t exClock; |
| 163 | uint16_t maxSpeed; |
| 164 | uint16_t currSpeed; |
| 165 | uint8_t status; |
| 166 | uint8_t upgrade; |
| 167 | uint16_t l1Handle; |
| 168 | uint16_t l2Handle; |
| 169 | uint16_t l3Handle; |
| 170 | uint8_t serialNum; |
| 171 | uint8_t assetTag; |
| 172 | uint8_t partNum; |
| 173 | uint8_t coreCount; |
| 174 | uint8_t coreEnable; |
| 175 | uint8_t threadCount; |
| 176 | uint16_t characteristics; |
| 177 | uint16_t family2; |
| 178 | uint16_t coreCount2; |
| 179 | uint16_t coreEnable2; |
| 180 | uint16_t threadCount2; |
| 181 | } __attribute__((packed)); |
| 182 | |
| 183 | void cpuSocket(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 184 | uint8_t* dataIn); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 185 | void cpuType(const uint8_t value); |
| 186 | void cpuFamily(const uint8_t value); |
| 187 | void cpuManufacturer(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 188 | uint8_t* dataIn); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 189 | void cpuVersion(const uint8_t positionNum, const uint8_t structLen, |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 190 | uint8_t* dataIn); |
Cheng C Yang | 43c6a1d | 2019-12-19 00:48:34 +0800 | [diff] [blame] | 191 | void cpuCharacteristics(const uint16_t value); |
| 192 | void cpuStatus(const uint8_t value); |
| 193 | }; |
| 194 | |
| 195 | } // namespace smbios |
| 196 | |
| 197 | } // namespace phosphor |