xref: /openbmc/smbios-mdr/include/dimm.hpp (revision dc469c74cfb58cc8f4d7646c94f53f1f327d4817)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 #include "smbios_mdrv2.hpp"
19 
20 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
21 #include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
22 #include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
23 #include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
24 #include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
25 #include <xyz/openbmc_project/Inventory/Item/server.hpp>
26 #include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
27 
28 namespace phosphor
29 {
30 
31 namespace smbios
32 {
33 
34 using DeviceType =
35     sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::DeviceType;
36 
37 class Dimm :
38     sdbusplus::server::object::object<
39         sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
40     sdbusplus::server::object::object<
41         sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
42     sdbusplus::server::object::object<
43         sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
44             LocationCode>,
45     sdbusplus::server::object::object<
46         sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot>,
47     sdbusplus::server::object::object<
48         sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
49     sdbusplus::server::object::object<
50         sdbusplus::xyz::openbmc_project::Association::server::Definitions>,
51     sdbusplus::server::object::object<sdbusplus::xyz::openbmc_project::State::
52                                           Decorator::server::OperationalStatus>
53 {
54   public:
55     Dimm() = delete;
56     ~Dimm() = default;
57     Dimm(const Dimm&) = delete;
58     Dimm& operator=(const Dimm&) = delete;
59     Dimm(Dimm&&) = default;
60     Dimm& operator=(Dimm&&) = default;
61 
62     Dimm(sdbusplus::bus::bus& bus, const std::string& objPath,
63          const uint8_t& dimmId, uint8_t* smbiosTableStorage,
64          const std::string& motherboard) :
65 
66         sdbusplus::server::object::object<
67             sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>(
68             bus, objPath.c_str()),
69         sdbusplus::server::object::object<
70             sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
71                 Asset>(bus, objPath.c_str()),
72         sdbusplus::server::object::object<
73             sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
74                 LocationCode>(bus, objPath.c_str()),
75         sdbusplus::server::object::object<
76             sdbusplus::xyz::openbmc_project::Inventory::Connector::server::
77                 Slot>(bus, objPath.c_str()),
78         sdbusplus::server::object::object<
79             sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
80             bus, objPath.c_str()),
81         sdbusplus::server::object::object<
82             sdbusplus::xyz::openbmc_project::Association::server::Definitions>(
83             bus, objPath.c_str()),
84         sdbusplus::server::object::object<
85             sdbusplus::xyz::openbmc_project::State::Decorator::server::
86                 OperationalStatus>(bus, objPath.c_str()),
87         dimmNum(dimmId), storage(smbiosTableStorage),
88         motherboardPath(motherboard)
89     {
90         memoryInfoUpdate();
91     }
92 
93     void memoryInfoUpdate(void);
94 
95     uint16_t memoryDataWidth(uint16_t value) override;
96     size_t memorySizeInKB(size_t value) override;
97     std::string memoryDeviceLocator(std::string value) override;
98     DeviceType memoryType(DeviceType value) override;
99     std::string memoryTypeDetail(std::string value) override;
100     uint16_t maxMemorySpeedInMhz(uint16_t value) override;
101     std::string manufacturer(std::string value) override;
102     bool present(bool value) override;
103     std::string serialNumber(std::string value) override;
104     std::string partNumber(std::string value) override;
105     std::string locationCode(std::string value) override;
106     uint8_t memoryAttributes(uint8_t value) override;
107     uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
108     bool functional(bool value) override;
109 
110   private:
111     uint8_t dimmNum;
112 
113     uint8_t* storage;
114 
115     std::string motherboardPath;
116 
117     void dimmSize(const uint16_t size);
118     void dimmSizeExt(const size_t size);
119     void dimmDeviceLocator(const uint8_t positionNum, const uint8_t structLen,
120                            uint8_t* dataIn);
121     void dimmType(const uint8_t type);
122     void dimmTypeDetail(const uint16_t detail);
123     void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
124                           uint8_t* dataIn);
125     void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
126                        uint8_t* dataIn);
127     void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
128                      uint8_t* dataIn);
129 };
130 
131 struct MemoryInfo
132 {
133     uint8_t type;
134     uint8_t length;
135     uint16_t handle;
136     uint16_t phyArrayHandle;
137     uint16_t errInfoHandle;
138     uint16_t totalWidth;
139     uint16_t dataWidth;
140     uint16_t size;
141     uint8_t formFactor;
142     uint8_t deviceSet;
143     uint8_t deviceLocator;
144     uint8_t bankLocator;
145     uint8_t memoryType;
146     uint16_t typeDetail;
147     uint16_t speed;
148     uint8_t manufacturer;
149     uint8_t serialNum;
150     uint8_t assetTag;
151     uint8_t partNum;
152     uint8_t attributes;
153     size_t extendedSize;
154     uint16_t confClockSpeed;
155     uint16_t minimumVoltage;
156     uint16_t maximumVoltage;
157     uint16_t configuredVoltage;
158     uint8_t memoryTechnology;
159     uint16_t memoryOperatingModeCap;
160     uint8_t firwareVersion;
161     uint16_t modelManufId;
162     uint16_t modelProdId;
163     uint16_t memSubConManufId;
164     uint16_t memSubConProdId;
165     uint64_t nvSize;
166     uint64_t volatileSize;
167     uint64_t cacheSize;
168     uint64_t logicalSize;
169 } __attribute__((packed));
170 
171 const std::map<uint8_t, DeviceType> dimmTypeTable = {
172     {0x1, DeviceType::Other},         {0x2, DeviceType::Unknown},
173     {0x3, DeviceType::DRAM},          {0x4, DeviceType::EDRAM},
174     {0x5, DeviceType::VRAM},          {0x6, DeviceType::SRAM},
175     {0x7, DeviceType::RAM},           {0x8, DeviceType::ROM},
176     {0x9, DeviceType::FLASH},         {0xa, DeviceType::EEPROM},
177     {0xb, DeviceType::FEPROM},        {0xc, DeviceType::EPROM},
178     {0xd, DeviceType::CDRAM},         {0xe, DeviceType::ThreeDRAM},
179     {0xf, DeviceType::SDRAM},         {0x10, DeviceType::DDR_SGRAM},
180     {0x11, DeviceType::RDRAM},        {0x12, DeviceType::DDR},
181     {0x13, DeviceType::DDR2},         {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
182     {0x18, DeviceType::DDR3},         {0x19, DeviceType::FBD2},
183     {0x1a, DeviceType::DDR4},         {0x1b, DeviceType::LPDDR_SDRAM},
184     {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
185     {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
186     {0x20, DeviceType::HBM},          {0x21, DeviceType::HBM2},
187     {0x22, DeviceType::DDR5},         {0x23, DeviceType::LPDDR5_SDRAM}};
188 
189 const std::array<std::string, 16> detailTable{
190     "Reserved",      "Other",         "Unknown",     "Fast-paged",
191     "Static column", "Pseudo-static", "RAMBUS",      "Synchronous",
192     "CMOS",          "EDO",           "Window DRAM", "Cache DRAM",
193     "Non-volatile",  "Registered",    "Unbuffered",  "LRDIMM"};
194 
195 } // namespace smbios
196 
197 } // namespace phosphor
198