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 | |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 11 | void Pcie::pcieInfoUpdate(uint8_t* smbiosTableStorage, |
| 12 | const std::string& motherboard) |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 13 | { |
Brandon Kim | 5a122a6 | 2023-05-04 04:25:03 +0000 | [diff] [blame] | 14 | storage = smbiosTableStorage; |
| 15 | motherboardPath = motherboard; |
| 16 | |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 17 | uint8_t* dataIn = getSMBIOSTypePtr(storage, systemSlots); |
| 18 | |
| 19 | if (dataIn == nullptr) |
| 20 | { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | /* offset 5 points to the slot type */ |
| 25 | for (uint8_t index = 0; |
| 26 | index < pcieNum || |
| 27 | pcieSmbiosType.find(*(dataIn + 5)) == pcieSmbiosType.end();) |
| 28 | { |
| 29 | dataIn = smbiosNextPtr(dataIn); |
| 30 | if (dataIn == nullptr) |
| 31 | { |
| 32 | return; |
| 33 | } |
| 34 | dataIn = getSMBIOSTypePtr(dataIn, systemSlots); |
| 35 | if (dataIn == nullptr) |
| 36 | { |
| 37 | return; |
| 38 | } |
| 39 | if (pcieSmbiosType.find(*(dataIn + 5)) != pcieSmbiosType.end()) |
| 40 | { |
| 41 | index++; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | auto pcieInfo = reinterpret_cast<struct SystemSlotInfo*>(dataIn); |
| 46 | |
| 47 | pcieGeneration(pcieInfo->slotType); |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 48 | pcieType(pcieInfo->slotType, pcieInfo->slotLength); |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 49 | pcieLaneSize(pcieInfo->slotDataBusWidth); |
| 50 | pcieIsHotPluggable(pcieInfo->characteristics2); |
| 51 | pcieLocation(pcieInfo->slotDesignation, pcieInfo->length, dataIn); |
| 52 | |
Manojkiran Eda | ce89a37 | 2025-02-05 23:09:04 +0530 | [diff] [blame] | 53 | #ifdef SLOT_DRIVE_PRESENCE |
| 54 | /* Set PCIeSlot presence based on its current Usage */ |
| 55 | Item::present(pcieInfo->currUsage == |
| 56 | static_cast<uint8_t>(Availability::InUse)); |
| 57 | #else |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 58 | /* Pcie slot is embedded on the board. Always be true */ |
| 59 | Item::present(true); |
Manojkiran Eda | ce89a37 | 2025-02-05 23:09:04 +0530 | [diff] [blame] | 60 | #endif |
Jie Yang | e7cf319 | 2021-08-20 11:21:43 -0700 | [diff] [blame] | 61 | |
| 62 | if (!motherboardPath.empty()) |
| 63 | { |
| 64 | std::vector<std::tuple<std::string, std::string, std::string>> assocs; |
| 65 | assocs.emplace_back("chassis", "pcie_slots", motherboardPath); |
| 66 | association::associations(assocs); |
| 67 | } |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void Pcie::pcieGeneration(const uint8_t type) |
| 71 | { |
| 72 | std::map<uint8_t, PCIeGeneration>::const_iterator it = |
| 73 | pcieGenerationTable.find(type); |
| 74 | if (it == pcieGenerationTable.end()) |
| 75 | { |
| 76 | PCIeSlot::generation(PCIeGeneration::Unknown); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | PCIeSlot::generation(it->second); |
| 81 | } |
| 82 | } |
| 83 | |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 84 | void Pcie::pcieType(const uint8_t type, const uint8_t slotLength) |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 85 | { |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 86 | // Try to find PCIeType in the main table |
| 87 | auto it = pcieTypeTable.find(type); |
| 88 | PCIeType pcieSlotType = PCIeType::Unknown; |
| 89 | |
| 90 | if (it != pcieTypeTable.end()) |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 91 | { |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 92 | pcieSlotType = it->second; |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 96 | // If not found in `pcieTypeTable`, check `PCIeTypeByLength` |
| 97 | auto slotIt = PCIeTypeByLength.find(slotLength); |
| 98 | if (slotIt != PCIeTypeByLength.end()) |
| 99 | { |
| 100 | pcieSlotType = slotIt->second; |
| 101 | } |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 102 | } |
Manojkiran Eda | f3b25e5 | 2025-02-07 14:30:06 +0530 | [diff] [blame] | 103 | |
| 104 | // Set the slot type |
| 105 | PCIeSlot::slotType(pcieSlotType); |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void Pcie::pcieLaneSize(const uint8_t width) |
| 109 | { |
| 110 | std::map<uint8_t, size_t>::const_iterator it = pcieLanesTable.find(width); |
| 111 | if (it == pcieLanesTable.end()) |
| 112 | { |
| 113 | PCIeSlot::lanes(0); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | PCIeSlot::lanes(it->second); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void Pcie::pcieIsHotPluggable(const uint8_t characteristics) |
| 122 | { |
| 123 | /* Bit 1 of slot characteristics 2 indicates if slot supports hot-plug |
| 124 | * devices |
| 125 | */ |
| 126 | PCIeSlot::hotPluggable(characteristics & 0x2); |
| 127 | } |
| 128 | |
| 129 | void Pcie::pcieLocation(const uint8_t slotDesignation, const uint8_t structLen, |
| 130 | uint8_t* dataIn) |
| 131 | { |
| 132 | location::locationCode( |
| 133 | positionToString(slotDesignation, structLen, dataIn)); |
| 134 | } |
| 135 | |
| 136 | } // namespace smbios |
| 137 | } // namespace phosphor |