blob: d16d75ec71a177fbddbc725f622dcc1c2d938021 [file] [log] [blame]
Jie Yang08e4a6d2021-08-23 13:07:41 -07001#pragma once
2#include "smbios_mdrv2.hpp"
3
4#include <xyz/openbmc_project/Inventory/Connector/Embedded/server.hpp>
5#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
6#include <xyz/openbmc_project/Inventory/Item/PCIeSlot/server.hpp>
7#include <xyz/openbmc_project/Inventory/Item/server.hpp>
8
9#include <cstdint>
10#include <map>
11#include <unordered_set>
12
13namespace phosphor
14{
15
16namespace smbios
17{
18
19using PCIeSlot =
20 sdbusplus::xyz::openbmc_project::Inventory::Item::server::PCIeSlot;
21using PCIeGeneration = sdbusplus::xyz::openbmc_project::Inventory::Item::
22 server::PCIeSlot::Generations;
23using PCIeType = sdbusplus::xyz::openbmc_project::Inventory::Item::server::
24 PCIeSlot::SlotTypes;
25using embedded =
26 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Embedded;
27using location =
28 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::LocationCode;
29using item = sdbusplus::xyz::openbmc_project::Inventory::server::Item;
30
31class Pcie : sdbusplus::server::object_t<PCIeSlot, location, embedded, item>
32{
33 public:
34 Pcie() = delete;
35 Pcie(const Pcie&) = delete;
36 Pcie& operator=(const Pcie&) = delete;
37 Pcie(Pcie&&) = delete;
38 Pcie& operator=(Pcie&&) = delete;
39 ~Pcie() = default;
40
41 Pcie(sdbusplus::bus::bus& bus, const std::string& objPath,
42 const uint8_t& pcieId, uint8_t* smbiosTableStorage) :
43 sdbusplus::server::object_t<PCIeSlot, location, embedded, item>(
44 bus, objPath.c_str()),
45 pcieNum(pcieId), storage(smbiosTableStorage)
46 {
47 pcieInfoUpdate();
48 }
49
50 void pcieInfoUpdate();
51
52 private:
53 uint8_t pcieNum;
54 uint8_t* storage;
55
56 struct SystemSlotInfo
57 {
58 uint8_t type;
59 uint8_t length;
60 uint16_t handle;
61 uint8_t slotDesignation;
62 uint8_t slotType;
63 uint8_t slotDataBusWidth;
64 uint8_t currUsage;
65 uint8_t slotLength;
66 uint16_t slotID;
67 uint8_t characteristics1;
68 uint8_t characteristics2;
69 uint16_t segGroupNum;
70 uint8_t busNum;
71 uint8_t deviceNum;
72 } __attribute__((packed));
73
74 void pcieGeneration(const uint8_t type);
75 void pcieType(const uint8_t type);
76 void pcieLaneSize(const uint8_t width);
77 void pcieIsHotPluggable(const uint8_t characteristics);
78 void pcieLocation(const uint8_t slotDesignation, const uint8_t structLen,
79 uint8_t* dataIn);
80};
81
82static const std::unordered_set<uint8_t> pcieSmbiosType = {
83 0x09, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1c,
84 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0xa5,
85 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1,
86 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd,
87 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6};
88
89// Definition follow smbios spec DSP0134 3.4.0
90static const std::map<uint8_t, PCIeGeneration> pcieGenerationTable = {
91 {0x09, PCIeGeneration::Unknown}, {0x14, PCIeGeneration::Gen3},
92 {0x15, PCIeGeneration::Gen3}, {0x16, PCIeGeneration::Gen3},
93 {0x17, PCIeGeneration::Gen3}, {0x18, PCIeGeneration::Gen1},
94 {0x19, PCIeGeneration::Gen1}, {0x1a, PCIeGeneration::Gen1},
95 {0x1b, PCIeGeneration::Gen1}, {0x1c, PCIeGeneration::Gen1},
96 {0x1d, PCIeGeneration::Gen3}, {0x1e, PCIeGeneration::Gen3},
97 {0x1f, PCIeGeneration::Gen2}, {0x20, PCIeGeneration::Gen3},
98 {0x21, PCIeGeneration::Gen1}, {0x22, PCIeGeneration::Gen1},
99 {0x23, PCIeGeneration::Gen1}, {0x24, PCIeGeneration::Gen4},
100 {0x25, PCIeGeneration::Gen5}, {0x26, PCIeGeneration::Unknown},
101 {0x27, PCIeGeneration::Unknown}, {0x28, PCIeGeneration::Unknown},
102 {0x29, PCIeGeneration::Unknown}, {0xa5, PCIeGeneration::Gen1},
103 {0xa6, PCIeGeneration::Gen1}, {0xa7, PCIeGeneration::Gen1},
104 {0xa8, PCIeGeneration::Gen1}, {0xa9, PCIeGeneration::Gen1},
105 {0xaa, PCIeGeneration::Gen1}, {0xab, PCIeGeneration::Gen2},
106 {0xac, PCIeGeneration::Gen2}, {0xad, PCIeGeneration::Gen2},
107 {0xae, PCIeGeneration::Gen2}, {0xaf, PCIeGeneration::Gen2},
108 {0xb0, PCIeGeneration::Gen2}, {0xb1, PCIeGeneration::Gen3},
109 {0xb2, PCIeGeneration::Gen3}, {0xb3, PCIeGeneration::Gen3},
110 {0xb4, PCIeGeneration::Gen3}, {0xb5, PCIeGeneration::Gen3},
111 {0xb6, PCIeGeneration::Gen3}, {0xb8, PCIeGeneration::Gen4},
112 {0xb9, PCIeGeneration::Gen4}, {0xba, PCIeGeneration::Gen4},
113 {0xbb, PCIeGeneration::Gen4}, {0xbc, PCIeGeneration::Gen4},
114 {0xbd, PCIeGeneration::Gen4}, {0xbe, PCIeGeneration::Gen5},
115 {0xbf, PCIeGeneration::Gen5}, {0xc0, PCIeGeneration::Gen5},
116 {0xc1, PCIeGeneration::Gen5}, {0xc2, PCIeGeneration::Gen5},
117 {0xc3, PCIeGeneration::Gen5}, {0xc4, PCIeGeneration::Unknown},
118 {0xc5, PCIeGeneration::Unknown}, {0xc6, PCIeGeneration::Unknown}};
119
120static const std::map<uint8_t, PCIeType> pcieTypeTable = {
121 {0x09, PCIeType::OEM}, {0x14, PCIeType::M_2},
122 {0x15, PCIeType::M_2}, {0x16, PCIeType::M_2},
123 {0x17, PCIeType::M_2}, {0x18, PCIeType::Unknown},
124 {0x19, PCIeType::Unknown}, {0x1a, PCIeType::Unknown},
125 {0x1b, PCIeType::Unknown}, {0x1c, PCIeType::Unknown},
126 {0x1d, PCIeType::Unknown}, {0x1e, PCIeType::Unknown},
127 {0xa8, PCIeType::Unknown}, {0xa9, PCIeType::Unknown},
128 {0x1F, PCIeType::U_2}, {0x20, PCIeType::U_2},
129 {0x21, PCIeType::Mini}, {0x22, PCIeType::Mini},
130 {0x23, PCIeType::Mini}, {0x24, PCIeType::U_2},
131 {0x25, PCIeType::U_2}, {0x26, PCIeType::OCP3Small},
132 {0x27, PCIeType::OCP3Large}, {0x28, PCIeType::Unknown},
133 {0x29, PCIeType::Unknown}, {0xa5, PCIeType::Unknown},
134 {0xa6, PCIeType::Unknown}, {0xa7, PCIeType::Unknown},
135 {0xa8, PCIeType::Unknown}, {0xa9, PCIeType::Unknown},
136 {0xaa, PCIeType::Unknown}, {0xab, PCIeType::Unknown},
137 {0xac, PCIeType::Unknown}, {0xad, PCIeType::Unknown},
138 {0xae, PCIeType::Unknown}, {0xaf, PCIeType::Unknown},
139 {0xb0, PCIeType::Unknown}, {0xb1, PCIeType::Unknown},
140 {0xb2, PCIeType::Unknown}, {0xb3, PCIeType::Unknown},
141 {0xb4, PCIeType::Unknown}, {0xb5, PCIeType::Unknown},
142 {0xb6, PCIeType::Unknown}, {0xb8, PCIeType::Unknown},
143 {0xb9, PCIeType::Unknown}, {0xba, PCIeType::Unknown},
144 {0xbb, PCIeType::Unknown}, {0xbc, PCIeType::Unknown},
145 {0xbd, PCIeType::Unknown}, {0xbe, PCIeType::Unknown},
146 {0xbf, PCIeType::Unknown}, {0xc0, PCIeType::Unknown},
147 {0xc1, PCIeType::Unknown}, {0xc2, PCIeType::Unknown},
148 {0xc3, PCIeType::Unknown}, {0xc4, PCIeType::Unknown},
149 {0xc5, PCIeType::Unknown}, {0xc6, PCIeType::Unknown}};
150
151const std::map<uint8_t, size_t> pcieLanesTable = {
152 {0x08, 1}, {0x09, 2}, {0xa, 4}, {0xb, 8}, {0xc, 12}, {0xd, 16}, {0xe, 32}};
153
154}; // namespace smbios
155
156}; // namespace phosphor