blob: 90c1191c26ab4e656f50cf976252e4ffa7d87ce9 [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
Zhikui Ren18a5ab92020-09-01 21:35:20 -070056void Cpu::version(const uint8_t positionNum, const uint8_t structLen,
57 uint8_t* dataIn)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080058{
59 std::string result;
60
61 result = positionToString(positionNum, structLen, dataIn);
62
Zhikui Ren18a5ab92020-09-01 21:35:20 -070063 rev::version(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080064}
65
Zhikui Ren18a5ab92020-09-01 21:35:20 -070066void Cpu::characteristics(uint16_t value)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080067{
Zhikui Ren18a5ab92020-09-01 21:35:20 -070068 std::vector<processor::Capability> result;
69 std::optional<processor::Capability> cap;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080070
Zhikui Ren18a5ab92020-09-01 21:35:20 -070071 std::bitset<16> charBits = value;
72 for (uint8_t index = 0; index < charBits.size(); index++)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080073 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070074 if (charBits.test(index))
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080075 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -070076 if (cap = characteristicsTable[index])
77 {
78 result.emplace_back(*cap);
79 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080080 }
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080081 }
82
Zhikui Ren18a5ab92020-09-01 21:35:20 -070083 processor::characteristics(result);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080084}
85
86static constexpr uint8_t maxOldVersionCount = 0xff;
Zhikui Ren18a5ab92020-09-01 21:35:20 -070087void Cpu::infoUpdate(void)
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080088{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080089 uint8_t* dataIn = storage;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080090
91 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
92 if (dataIn == nullptr)
93 {
94 return;
95 }
96
97 for (uint8_t index = 0; index < cpuNum; index++)
98 {
99 dataIn = smbiosNextPtr(dataIn);
100 if (dataIn == nullptr)
101 {
102 return;
103 }
104 dataIn = getSMBIOSTypePtr(dataIn, processorsType);
105 if (dataIn == nullptr)
106 {
107 return;
108 }
109 }
110
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800111 auto cpuInfo = reinterpret_cast<struct ProcessorInfo*>(dataIn);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800112
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700113 socket(cpuInfo->socketDesignation, cpuInfo->length,
114 dataIn); // offset 4h
115 // this class is for type CPU //offset 5h
116 family(cpuInfo->family); // offset 6h
117 manufacturer(cpuInfo->manufacturer, cpuInfo->length,
118 dataIn); // offset 7h
119 id(cpuInfo->id); // offset 8h
120 version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h
121 maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h
122 if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800123 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700124 coreCount(cpuInfo->coreCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800125 }
126 else
127 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700128 coreCount(cpuInfo->coreCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800129 }
130
131 if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh)
132 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700133 threadCount(cpuInfo->threadCount);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800134 }
135 else
136 {
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700137 threadCount(cpuInfo->threadCount2);
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800138 }
139
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700140 characteristics(cpuInfo->characteristics); // offset 26h
Cheng C Yang43c6a1d2019-12-19 00:48:34 +0800141}
142
143} // namespace smbios
144} // namespace phosphor