blob: 1b464071bf32f4158aa3cd30ac7a7d38c0aa6bbf [file] [log] [blame]
Jie Yang08e4a6d2021-08-23 13:07:41 -07001#include "pcieslot.hpp"
2
3#include <cstdint>
4#include <map>
5
6namespace phosphor
7{
8namespace smbios
9{
10
11void Pcie::pcieInfoUpdate()
12{
13 uint8_t* dataIn = getSMBIOSTypePtr(storage, systemSlots);
14
15 if (dataIn == nullptr)
16 {
17 return;
18 }
19
20 /* offset 5 points to the slot type */
21 for (uint8_t index = 0;
22 index < pcieNum ||
23 pcieSmbiosType.find(*(dataIn + 5)) == pcieSmbiosType.end();)
24 {
25 dataIn = smbiosNextPtr(dataIn);
26 if (dataIn == nullptr)
27 {
28 return;
29 }
30 dataIn = getSMBIOSTypePtr(dataIn, systemSlots);
31 if (dataIn == nullptr)
32 {
33 return;
34 }
35 if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end())
36 {
37 index++;
38 }
39 }
40
41 auto pcieInfo = reinterpret_cast<struct SystemSlotInfo*>(dataIn);
42
43 pcieGeneration(pcieInfo->slotType);
44 pcieType(pcieInfo->slotType);
45 pcieLaneSize(pcieInfo->slotDataBusWidth);
46 pcieIsHotPluggable(pcieInfo->characteristics2);
47 pcieLocation(pcieInfo->slotDesignation, pcieInfo->length, dataIn);
48
49 /* Pcie slot is embedded on the board. Always be true */
50 Item::present(true);
51}
52
53void Pcie::pcieGeneration(const uint8_t type)
54{
55 std::map<uint8_t, PCIeGeneration>::const_iterator it =
56 pcieGenerationTable.find(type);
57 if (it == pcieGenerationTable.end())
58 {
59 PCIeSlot::generation(PCIeGeneration::Unknown);
60 }
61 else
62 {
63 PCIeSlot::generation(it->second);
64 }
65}
66
67void Pcie::pcieType(const uint8_t type)
68{
69 std::map<uint8_t, PCIeType>::const_iterator it = pcieTypeTable.find(type);
70 if (it == pcieTypeTable.end())
71 {
72 PCIeSlot::slotType(PCIeType::Unknown);
73 }
74 else
75 {
76 PCIeSlot::slotType(it->second);
77 }
78}
79
80void Pcie::pcieLaneSize(const uint8_t width)
81{
82 std::map<uint8_t, size_t>::const_iterator it = pcieLanesTable.find(width);
83 if (it == pcieLanesTable.end())
84 {
85 PCIeSlot::lanes(0);
86 }
87 else
88 {
89 PCIeSlot::lanes(it->second);
90 }
91}
92
93void Pcie::pcieIsHotPluggable(const uint8_t characteristics)
94{
95 /* Bit 1 of slot characteristics 2 indicates if slot supports hot-plug
96 * devices
97 */
98 PCIeSlot::hotPluggable(characteristics & 0x2);
99}
100
101void Pcie::pcieLocation(const uint8_t slotDesignation, const uint8_t structLen,
102 uint8_t* dataIn)
103{
104 location::locationCode(
105 positionToString(slotDesignation, structLen, dataIn));
106}
107
108} // namespace smbios
109} // namespace phosphor