blob: 0ea7a8b647342f1e3d7b53a4e2149a0b233f7f88 [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);
Jie Yange7cf3192021-08-20 11:21:43 -070051
52 if (!motherboardPath.empty())
53 {
54 std::vector<std::tuple<std::string, std::string, std::string>> assocs;
55 assocs.emplace_back("chassis", "pcie_slots", motherboardPath);
56 association::associations(assocs);
57 }
Jie Yang08e4a6d2021-08-23 13:07:41 -070058}
59
60void Pcie::pcieGeneration(const uint8_t type)
61{
62 std::map<uint8_t, PCIeGeneration>::const_iterator it =
63 pcieGenerationTable.find(type);
64 if (it == pcieGenerationTable.end())
65 {
66 PCIeSlot::generation(PCIeGeneration::Unknown);
67 }
68 else
69 {
70 PCIeSlot::generation(it->second);
71 }
72}
73
74void Pcie::pcieType(const uint8_t type)
75{
76 std::map<uint8_t, PCIeType>::const_iterator it = pcieTypeTable.find(type);
77 if (it == pcieTypeTable.end())
78 {
79 PCIeSlot::slotType(PCIeType::Unknown);
80 }
81 else
82 {
83 PCIeSlot::slotType(it->second);
84 }
85}
86
87void Pcie::pcieLaneSize(const uint8_t width)
88{
89 std::map<uint8_t, size_t>::const_iterator it = pcieLanesTable.find(width);
90 if (it == pcieLanesTable.end())
91 {
92 PCIeSlot::lanes(0);
93 }
94 else
95 {
96 PCIeSlot::lanes(it->second);
97 }
98}
99
100void Pcie::pcieIsHotPluggable(const uint8_t characteristics)
101{
102 /* Bit 1 of slot characteristics 2 indicates if slot supports hot-plug
103 * devices
104 */
105 PCIeSlot::hotPluggable(characteristics & 0x2);
106}
107
108void Pcie::pcieLocation(const uint8_t slotDesignation, const uint8_t structLen,
109 uint8_t* dataIn)
110{
111 location::locationCode(
112 positionToString(slotDesignation, structLen, dataIn));
113}
114
115} // namespace smbios
116} // namespace phosphor