Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 1 | #include "pcieslot.hpp" |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <map> |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace smbios |
| 9 | { |
| 10 | |
| 11 | void 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 Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 51 | |
| 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 Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void 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 | |
| 74 | void 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 | |
| 87 | void 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 | |
| 100 | void 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 | |
| 108 | void 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 |