blob: 1010b5838f26c246dd359327c8ec0ffa367024a9 [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);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080033}
34
Zhikui Ren18a5ab92020-09-01 21:35:20 -070035void Cpu::family(const uint8_t value)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080036{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080037 std::map<uint8_t, const char*>::const_iterator it = familyTable.find(value);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080038 if (it == familyTable.end())
39 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070040 processor::family("Unknown Processor Family");
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080041 }
42 else
43 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070044 processor::family(it->second);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080045 }
46}
47
Zhikui Ren18a5ab92020-09-01 21:35:20 -070048void Cpu::manufacturer(const uint8_t positionNum, const uint8_t structLen,
49 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080050{
51 std::string result = positionToString(positionNum, structLen, dataIn);
52
Zhikui Ren18a5ab92020-09-01 21:35:20 -070053 asset::manufacturer(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080054}
55
Charles Boyere6431692021-08-31 16:47:47 -050056void Cpu::partNumber(const uint8_t positionNum, const uint8_t structLen,
57 uint8_t* dataIn)
58{
59 std::string result = positionToString(positionNum, structLen, dataIn);
60
61 asset::partNumber(result);
62}
63
64void Cpu::serialNumber(const uint8_t positionNum, const uint8_t structLen,
65 uint8_t* dataIn)
66{
67 std::string result = positionToString(positionNum, structLen, dataIn);
68
69 asset::serialNumber(result);
70}
71
Zhikui Ren18a5ab92020-09-01 21:35:20 -070072void Cpu::version(const uint8_t positionNum, const uint8_t structLen,
73 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080074{
75 std::string result;
76
77 result = positionToString(positionNum, structLen, dataIn);
78
Zhikui Ren18a5ab92020-09-01 21:35:20 -070079 rev::version(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080080}
81
Zhikui Ren18a5ab92020-09-01 21:35:20 -070082void Cpu::characteristics(uint16_t value)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080083{
Zhikui Ren18a5ab92020-09-01 21:35:20 -070084 std::vector<processor::Capability> result;
85 std::optional<processor::Capability> cap;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080086
Zhikui Ren18a5ab92020-09-01 21:35:20 -070087 std::bitset<16> charBits = value;
88 for (uint8_t index = 0; index < charBits.size(); index++)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080089 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070090 if (charBits.test(index))
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080091 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070092 if (cap = characteristicsTable[index])
93 {
94 result.emplace_back(*cap);
95 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080096 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080097 }
98
Zhikui Ren18a5ab92020-09-01 21:35:20 -070099 processor::characteristics(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800100}
101
102static constexpr uint8_t maxOldVersionCount = 0xff;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700103void Cpu::infoUpdate(void)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800104{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800105 uint8_t* dataIn = storage;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800106
107 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
108 if (dataIn == nullptr)
109 {
110 return;
111 }
112
113 for (uint8_t index = 0; index < cpuNum; index++)
114 {
115 dataIn = smbiosNextPtr(dataIn);
116 if (dataIn == nullptr)
117 {
118 return;
119 }
120 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
121 if (dataIn == nullptr)
122 {
123 return;
124 }
125 }
126
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800127 auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800128
Jonathan Doman563570d2021-05-24 10:52:43 -0700129 socket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h
130
131 constexpr uint32_t socketPopulatedMask = 1 << 6;
132 if ((cpuInfo->status & socketPopulatedMask) == 0)
133 {
134 // Don't attempt to fill in any other details if the CPU is not present.
135 present(false);
136 return;
137 }
138 present(true);
139
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700140 // this class is for type CPU //offset 5h
141 family(cpuInfo->family); // offset 6h
142 manufacturer(cpuInfo->manufacturer, cpuInfo->length,
143 dataIn); // offset 7h
144 id(cpuInfo->id); // offset 8h
145 version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h
146 maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h
Charles Boyere6431692021-08-31 16:47:47 -0500147 serialNumber(cpuInfo->serialNum, cpuInfo->length,
148 dataIn); // offset 20h
149 partNumber(cpuInfo->partNum, cpuInfo->length,
150 dataIn); // offset 22h
151 if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800152 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700153 coreCount(cpuInfo->coreCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800154 }
155 else
156 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700157 coreCount(cpuInfo->coreCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800158 }
159
160 if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh)
161 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700162 threadCount(cpuInfo->threadCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800163 }
164 else
165 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700166 threadCount(cpuInfo->threadCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800167 }
168
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700169 characteristics(cpuInfo->characteristics); // offset 26h
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800170}
171
172} // namespace smbios
173} // namespace phosphor