xref: /openbmc/smbios-mdr/include/pcieslot.hpp (revision 5a122a6e1b620e79c5c6807e83f1cd75fe872fb6)
108e4a6dfSJie Yang #pragma once
208e4a6dfSJie Yang #include "smbios_mdrv2.hpp"
308e4a6dfSJie Yang 
4e7cf3195SJie Yang #include <xyz/openbmc_project/Association/Definitions/server.hpp>
508e4a6dfSJie Yang #include <xyz/openbmc_project/Inventory/Connector/Embedded/server.hpp>
608e4a6dfSJie Yang #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
708e4a6dfSJie Yang #include <xyz/openbmc_project/Inventory/Item/PCIeSlot/server.hpp>
808e4a6dfSJie Yang #include <xyz/openbmc_project/Inventory/Item/server.hpp>
908e4a6dfSJie Yang 
1008e4a6dfSJie Yang #include <cstdint>
1108e4a6dfSJie Yang #include <map>
1208e4a6dfSJie Yang #include <unordered_set>
1308e4a6dfSJie Yang 
1408e4a6dfSJie Yang namespace phosphor
1508e4a6dfSJie Yang {
1608e4a6dfSJie Yang 
1708e4a6dfSJie Yang namespace smbios
1808e4a6dfSJie Yang {
1908e4a6dfSJie Yang 
2008e4a6dfSJie Yang using PCIeSlot =
2133ae81feSJason M. Bills     sdbusplus::server::xyz::openbmc_project::inventory::item::PCIeSlot;
2233ae81feSJason M. Bills using PCIeGeneration = sdbusplus::server::xyz::openbmc_project::inventory::
2333ae81feSJason M. Bills     item::PCIeSlot::Generations;
2433ae81feSJason M. Bills using PCIeType = sdbusplus::server::xyz::openbmc_project::inventory::item::
2508e4a6dfSJie Yang     PCIeSlot::SlotTypes;
2608e4a6dfSJie Yang using embedded =
2733ae81feSJason M. Bills     sdbusplus::server::xyz::openbmc_project::inventory::connector::Embedded;
2808e4a6dfSJie Yang using location =
2933ae81feSJason M. Bills     sdbusplus::server::xyz::openbmc_project::inventory::decorator::LocationCode;
3033ae81feSJason M. Bills using item = sdbusplus::server::xyz::openbmc_project::inventory::Item;
31e7cf3195SJie Yang using association =
3233ae81feSJason M. Bills     sdbusplus::server::xyz::openbmc_project::association::Definitions;
3308e4a6dfSJie Yang 
34e7cf3195SJie Yang class Pcie :
35e7cf3195SJie Yang     sdbusplus::server::object_t<PCIeSlot, location, embedded, item, association>
3608e4a6dfSJie Yang {
3708e4a6dfSJie Yang   public:
3808e4a6dfSJie Yang     Pcie() = delete;
3908e4a6dfSJie Yang     Pcie(const Pcie&) = delete;
4008e4a6dfSJie Yang     Pcie& operator=(const Pcie&) = delete;
4108e4a6dfSJie Yang     Pcie(Pcie&&) = delete;
4208e4a6dfSJie Yang     Pcie& operator=(Pcie&&) = delete;
4308e4a6dfSJie Yang     ~Pcie() = default;
4408e4a6dfSJie Yang 
Pcie(sdbusplus::bus_t & bus,const std::string & objPath,const uint8_t & pcieId,uint8_t * smbiosTableStorage,const std::string & motherboard)4577b9c478SPatrick Williams     Pcie(sdbusplus::bus_t& bus, const std::string& objPath,
46e7cf3195SJie Yang          const uint8_t& pcieId, uint8_t* smbiosTableStorage,
47e7cf3195SJie Yang          const std::string& motherboard) :
48e7cf3195SJie Yang         sdbusplus::server::object_t<PCIeSlot, location, embedded, item,
49e7cf3195SJie Yang                                     association>(bus, objPath.c_str()),
50*5a122a6eSBrandon Kim         pcieNum(pcieId)
5108e4a6dfSJie Yang     {
52*5a122a6eSBrandon Kim         pcieInfoUpdate(smbiosTableStorage, motherboard);
5308e4a6dfSJie Yang     }
5408e4a6dfSJie Yang 
55*5a122a6eSBrandon Kim     void pcieInfoUpdate(uint8_t* smbiosTableStorage,
56*5a122a6eSBrandon Kim                         const std::string& motherboard);
5708e4a6dfSJie Yang 
5808e4a6dfSJie Yang   private:
5908e4a6dfSJie Yang     uint8_t pcieNum;
6008e4a6dfSJie Yang     uint8_t* storage;
61e7cf3195SJie Yang     std::string motherboardPath;
6208e4a6dfSJie Yang 
6308e4a6dfSJie Yang     struct SystemSlotInfo
6408e4a6dfSJie Yang     {
6508e4a6dfSJie Yang         uint8_t type;
6608e4a6dfSJie Yang         uint8_t length;
6708e4a6dfSJie Yang         uint16_t handle;
6808e4a6dfSJie Yang         uint8_t slotDesignation;
6908e4a6dfSJie Yang         uint8_t slotType;
7008e4a6dfSJie Yang         uint8_t slotDataBusWidth;
7108e4a6dfSJie Yang         uint8_t currUsage;
7208e4a6dfSJie Yang         uint8_t slotLength;
7308e4a6dfSJie Yang         uint16_t slotID;
7408e4a6dfSJie Yang         uint8_t characteristics1;
7508e4a6dfSJie Yang         uint8_t characteristics2;
7608e4a6dfSJie Yang         uint16_t segGroupNum;
7708e4a6dfSJie Yang         uint8_t busNum;
7808e4a6dfSJie Yang         uint8_t deviceNum;
7908e4a6dfSJie Yang     } __attribute__((packed));
8008e4a6dfSJie Yang 
8108e4a6dfSJie Yang     void pcieGeneration(const uint8_t type);
8208e4a6dfSJie Yang     void pcieType(const uint8_t type);
8308e4a6dfSJie Yang     void pcieLaneSize(const uint8_t width);
8408e4a6dfSJie Yang     void pcieIsHotPluggable(const uint8_t characteristics);
8508e4a6dfSJie Yang     void pcieLocation(const uint8_t slotDesignation, const uint8_t structLen,
8608e4a6dfSJie Yang                       uint8_t* dataIn);
8708e4a6dfSJie Yang };
8808e4a6dfSJie Yang 
8908e4a6dfSJie Yang static const std::unordered_set<uint8_t> pcieSmbiosType = {
9008e4a6dfSJie Yang     0x09, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1c,
9108e4a6dfSJie Yang     0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0xa5,
9208e4a6dfSJie Yang     0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1,
9308e4a6dfSJie Yang     0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd,
9408e4a6dfSJie Yang     0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6};
9508e4a6dfSJie Yang 
9608e4a6dfSJie Yang // Definition follow smbios spec DSP0134 3.4.0
9708e4a6dfSJie Yang static const std::map<uint8_t, PCIeGeneration> pcieGenerationTable = {
9808e4a6dfSJie Yang     {0x09, PCIeGeneration::Unknown}, {0x14, PCIeGeneration::Gen3},
9908e4a6dfSJie Yang     {0x15, PCIeGeneration::Gen3},    {0x16, PCIeGeneration::Gen3},
10008e4a6dfSJie Yang     {0x17, PCIeGeneration::Gen3},    {0x18, PCIeGeneration::Gen1},
10108e4a6dfSJie Yang     {0x19, PCIeGeneration::Gen1},    {0x1a, PCIeGeneration::Gen1},
10208e4a6dfSJie Yang     {0x1b, PCIeGeneration::Gen1},    {0x1c, PCIeGeneration::Gen1},
10308e4a6dfSJie Yang     {0x1d, PCIeGeneration::Gen3},    {0x1e, PCIeGeneration::Gen3},
10408e4a6dfSJie Yang     {0x1f, PCIeGeneration::Gen2},    {0x20, PCIeGeneration::Gen3},
10508e4a6dfSJie Yang     {0x21, PCIeGeneration::Gen1},    {0x22, PCIeGeneration::Gen1},
10608e4a6dfSJie Yang     {0x23, PCIeGeneration::Gen1},    {0x24, PCIeGeneration::Gen4},
10708e4a6dfSJie Yang     {0x25, PCIeGeneration::Gen5},    {0x26, PCIeGeneration::Unknown},
10808e4a6dfSJie Yang     {0x27, PCIeGeneration::Unknown}, {0x28, PCIeGeneration::Unknown},
10908e4a6dfSJie Yang     {0x29, PCIeGeneration::Unknown}, {0xa5, PCIeGeneration::Gen1},
11008e4a6dfSJie Yang     {0xa6, PCIeGeneration::Gen1},    {0xa7, PCIeGeneration::Gen1},
11108e4a6dfSJie Yang     {0xa8, PCIeGeneration::Gen1},    {0xa9, PCIeGeneration::Gen1},
11208e4a6dfSJie Yang     {0xaa, PCIeGeneration::Gen1},    {0xab, PCIeGeneration::Gen2},
11308e4a6dfSJie Yang     {0xac, PCIeGeneration::Gen2},    {0xad, PCIeGeneration::Gen2},
11408e4a6dfSJie Yang     {0xae, PCIeGeneration::Gen2},    {0xaf, PCIeGeneration::Gen2},
11508e4a6dfSJie Yang     {0xb0, PCIeGeneration::Gen2},    {0xb1, PCIeGeneration::Gen3},
11608e4a6dfSJie Yang     {0xb2, PCIeGeneration::Gen3},    {0xb3, PCIeGeneration::Gen3},
11708e4a6dfSJie Yang     {0xb4, PCIeGeneration::Gen3},    {0xb5, PCIeGeneration::Gen3},
11808e4a6dfSJie Yang     {0xb6, PCIeGeneration::Gen3},    {0xb8, PCIeGeneration::Gen4},
11908e4a6dfSJie Yang     {0xb9, PCIeGeneration::Gen4},    {0xba, PCIeGeneration::Gen4},
12008e4a6dfSJie Yang     {0xbb, PCIeGeneration::Gen4},    {0xbc, PCIeGeneration::Gen4},
12108e4a6dfSJie Yang     {0xbd, PCIeGeneration::Gen4},    {0xbe, PCIeGeneration::Gen5},
12208e4a6dfSJie Yang     {0xbf, PCIeGeneration::Gen5},    {0xc0, PCIeGeneration::Gen5},
12308e4a6dfSJie Yang     {0xc1, PCIeGeneration::Gen5},    {0xc2, PCIeGeneration::Gen5},
12408e4a6dfSJie Yang     {0xc3, PCIeGeneration::Gen5},    {0xc4, PCIeGeneration::Unknown},
12508e4a6dfSJie Yang     {0xc5, PCIeGeneration::Unknown}, {0xc6, PCIeGeneration::Unknown}};
12608e4a6dfSJie Yang 
12708e4a6dfSJie Yang static const std::map<uint8_t, PCIeType> pcieTypeTable = {
12808e4a6dfSJie Yang     {0x09, PCIeType::OEM},       {0x14, PCIeType::M_2},
12908e4a6dfSJie Yang     {0x15, PCIeType::M_2},       {0x16, PCIeType::M_2},
13008e4a6dfSJie Yang     {0x17, PCIeType::M_2},       {0x18, PCIeType::Unknown},
13108e4a6dfSJie Yang     {0x19, PCIeType::Unknown},   {0x1a, PCIeType::Unknown},
13208e4a6dfSJie Yang     {0x1b, PCIeType::Unknown},   {0x1c, PCIeType::Unknown},
13308e4a6dfSJie Yang     {0x1d, PCIeType::Unknown},   {0x1e, PCIeType::Unknown},
13408e4a6dfSJie Yang     {0xa8, PCIeType::Unknown},   {0xa9, PCIeType::Unknown},
13508e4a6dfSJie Yang     {0x1F, PCIeType::U_2},       {0x20, PCIeType::U_2},
13608e4a6dfSJie Yang     {0x21, PCIeType::Mini},      {0x22, PCIeType::Mini},
13708e4a6dfSJie Yang     {0x23, PCIeType::Mini},      {0x24, PCIeType::U_2},
13808e4a6dfSJie Yang     {0x25, PCIeType::U_2},       {0x26, PCIeType::OCP3Small},
13908e4a6dfSJie Yang     {0x27, PCIeType::OCP3Large}, {0x28, PCIeType::Unknown},
14008e4a6dfSJie Yang     {0x29, PCIeType::Unknown},   {0xa5, PCIeType::Unknown},
14108e4a6dfSJie Yang     {0xa6, PCIeType::Unknown},   {0xa7, PCIeType::Unknown},
14208e4a6dfSJie Yang     {0xa8, PCIeType::Unknown},   {0xa9, PCIeType::Unknown},
14308e4a6dfSJie Yang     {0xaa, PCIeType::Unknown},   {0xab, PCIeType::Unknown},
14408e4a6dfSJie Yang     {0xac, PCIeType::Unknown},   {0xad, PCIeType::Unknown},
14508e4a6dfSJie Yang     {0xae, PCIeType::Unknown},   {0xaf, PCIeType::Unknown},
14608e4a6dfSJie Yang     {0xb0, PCIeType::Unknown},   {0xb1, PCIeType::Unknown},
14708e4a6dfSJie Yang     {0xb2, PCIeType::Unknown},   {0xb3, PCIeType::Unknown},
14808e4a6dfSJie Yang     {0xb4, PCIeType::Unknown},   {0xb5, PCIeType::Unknown},
14908e4a6dfSJie Yang     {0xb6, PCIeType::Unknown},   {0xb8, PCIeType::Unknown},
15008e4a6dfSJie Yang     {0xb9, PCIeType::Unknown},   {0xba, PCIeType::Unknown},
15108e4a6dfSJie Yang     {0xbb, PCIeType::Unknown},   {0xbc, PCIeType::Unknown},
15208e4a6dfSJie Yang     {0xbd, PCIeType::Unknown},   {0xbe, PCIeType::Unknown},
15308e4a6dfSJie Yang     {0xbf, PCIeType::Unknown},   {0xc0, PCIeType::Unknown},
15408e4a6dfSJie Yang     {0xc1, PCIeType::Unknown},   {0xc2, PCIeType::Unknown},
15508e4a6dfSJie Yang     {0xc3, PCIeType::Unknown},   {0xc4, PCIeType::Unknown},
15608e4a6dfSJie Yang     {0xc5, PCIeType::Unknown},   {0xc6, PCIeType::Unknown}};
15708e4a6dfSJie Yang 
15808e4a6dfSJie Yang const std::map<uint8_t, size_t> pcieLanesTable = {
15908e4a6dfSJie Yang     {0x08, 1}, {0x09, 2}, {0xa, 4}, {0xb, 8}, {0xc, 12}, {0xd, 16}, {0xe, 32}};
16008e4a6dfSJie Yang 
16108e4a6dfSJie Yang }; // namespace smbios
16208e4a6dfSJie Yang 
16308e4a6dfSJie Yang }; // namespace phosphor
164