blob: a5f39ee490b34565b05b21af894ec2f01531d60f [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#include "cpu.hpp"
18
Zhikui Ren18a5ab92020-09-01 21:35:20 -070019#include <bitset>
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080020#include <map>
21
22namespace phosphor
23{
24namespace smbios
25{
26
Zhikui Ren18a5ab92020-09-01 21:35:20 -070027void Cpu::socket(const uint8_t positionNum, const uint8_t structLen,
28 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080029{
30 std::string result = positionToString(positionNum, structLen, dataIn);
31
Zhikui Ren18a5ab92020-09-01 21:35:20 -070032 processor::socket(result);
Jie Yang31720392021-07-22 21:45:45 -070033
34 location::locationCode(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080035}
36
Zhikui Ren18a5ab92020-09-01 21:35:20 -070037void Cpu::family(const uint8_t value)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080038{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080039 std::map<uint8_t, const char*>::const_iterator it = familyTable.find(value);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080040 if (it == familyTable.end())
41 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070042 processor::family("Unknown Processor Family");
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080043 }
44 else
45 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070046 processor::family(it->second);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080047 }
48}
49
Zhikui Ren18a5ab92020-09-01 21:35:20 -070050void Cpu::manufacturer(const uint8_t positionNum, const uint8_t structLen,
51 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080052{
53 std::string result = positionToString(positionNum, structLen, dataIn);
54
Zhikui Ren18a5ab92020-09-01 21:35:20 -070055 asset::manufacturer(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080056}
57
Charles Boyere6431692021-08-31 16:47:47 -050058void Cpu::partNumber(const uint8_t positionNum, const uint8_t structLen,
59 uint8_t* dataIn)
60{
61 std::string result = positionToString(positionNum, structLen, dataIn);
62
63 asset::partNumber(result);
64}
65
66void Cpu::serialNumber(const uint8_t positionNum, const uint8_t structLen,
67 uint8_t* dataIn)
68{
69 std::string result = positionToString(positionNum, structLen, dataIn);
70
71 asset::serialNumber(result);
72}
73
Zhikui Ren18a5ab92020-09-01 21:35:20 -070074void Cpu::version(const uint8_t positionNum, const uint8_t structLen,
75 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080076{
77 std::string result;
78
79 result = positionToString(positionNum, structLen, dataIn);
80
Zhikui Ren18a5ab92020-09-01 21:35:20 -070081 rev::version(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080082}
83
Zhikui Ren18a5ab92020-09-01 21:35:20 -070084void Cpu::characteristics(uint16_t value)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080085{
Zhikui Ren18a5ab92020-09-01 21:35:20 -070086 std::vector<processor::Capability> result;
87 std::optional<processor::Capability> cap;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080088
Zhikui Ren18a5ab92020-09-01 21:35:20 -070089 std::bitset<16> charBits = value;
90 for (uint8_t index = 0; index < charBits.size(); index++)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080091 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070092 if (charBits.test(index))
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080093 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070094 if (cap = characteristicsTable[index])
95 {
96 result.emplace_back(*cap);
97 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080098 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080099 }
100
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700101 processor::characteristics(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800102}
103
104static constexpr uint8_t maxOldVersionCount = 0xff;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700105void Cpu::infoUpdate(void)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800106{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800107 uint8_t* dataIn = storage;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800108
109 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
110 if (dataIn == nullptr)
111 {
112 return;
113 }
114
115 for (uint8_t index = 0; index < cpuNum; index++)
116 {
117 dataIn = smbiosNextPtr(dataIn);
118 if (dataIn == nullptr)
119 {
120 return;
121 }
122 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
123 if (dataIn == nullptr)
124 {
125 return;
126 }
127 }
128
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800129 auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800130
Jonathan Doman563570d2021-05-24 10:52:43 -0700131 socket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h
132
133 constexpr uint32_t socketPopulatedMask = 1 << 6;
134 if ((cpuInfo->status & socketPopulatedMask) == 0)
135 {
136 // Don't attempt to fill in any other details if the CPU is not present.
137 present(false);
138 return;
139 }
140 present(true);
141
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700142 // this class is for type CPU //offset 5h
143 family(cpuInfo->family); // offset 6h
144 manufacturer(cpuInfo->manufacturer, cpuInfo->length,
145 dataIn); // offset 7h
146 id(cpuInfo->id); // offset 8h
147 version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h
148 maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h
Charles Boyere6431692021-08-31 16:47:47 -0500149 serialNumber(cpuInfo->serialNum, cpuInfo->length,
150 dataIn); // offset 20h
151 partNumber(cpuInfo->partNum, cpuInfo->length,
152 dataIn); // offset 22h
153 if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800154 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700155 coreCount(cpuInfo->coreCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800156 }
157 else
158 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700159 coreCount(cpuInfo->coreCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800160 }
161
162 if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh)
163 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700164 threadCount(cpuInfo->threadCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800165 }
166 else
167 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700168 threadCount(cpuInfo->threadCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800169 }
170
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700171 characteristics(cpuInfo->characteristics); // offset 26h
Jie Yange7cf3192021-08-20 11:21:43 -0700172
173 if (!motherboardPath.empty())
174 {
175 std::vector<std::tuple<std::string, std::string, std::string>> assocs;
176 assocs.emplace_back("chassis", "processors", motherboardPath);
177 association::associations(assocs);
178 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800179}
180
181} // namespace smbios
182} // namespace phosphor