blob: 1d1fc18d9e3eb2556e1b0b56430ad9aa66fd6760 [file] [log] [blame]
Cheng C Yang8c3fab62019-12-19 00:51:06 +08001/*
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
Zhikui Ren18a5ab92020-09-01 21:35:20 -070018#include "smbios_mdrv2.hpp"
Cheng C Yang8c3fab62019-12-19 00:51:06 +080019
Jie Yange7cf3192021-08-20 11:21:43 -070020#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Jie Yang41654fc2021-09-07 20:26:32 -070021#include <xyz/openbmc_project/Inventory/Connector/Slot/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080022#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
Jie Yang31720392021-07-22 21:45:45 -070023#include <xyz/openbmc_project/Inventory/Decorator/LocationCode/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080024#include <xyz/openbmc_project/Inventory/Item/Dimm/server.hpp>
Joshi-Mansi33c948a2021-03-20 00:58:50 +053025#include <xyz/openbmc_project/Inventory/Item/server.hpp>
Tim Leedc469c72021-07-20 10:55:58 +080026#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080027
28namespace phosphor
29{
30
31namespace smbios
32{
33
34using DeviceType =
35 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::DeviceType;
36
Zhikui Ren18a5ab92020-09-01 21:35:20 -070037class Dimm :
Patrick Williams77b9c472022-07-22 19:26:57 -050038 sdbusplus::server::object_t<
Zhikui Ren18a5ab92020-09-01 21:35:20 -070039 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
Patrick Williams77b9c472022-07-22 19:26:57 -050040 sdbusplus::server::object_t<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053041 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
Patrick Williams77b9c472022-07-22 19:26:57 -050042 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
43 Decorator::server::LocationCode>,
44 sdbusplus::server::object_t<
Jie Yang41654fc2021-09-07 20:26:32 -070045 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot>,
Patrick Williams77b9c472022-07-22 19:26:57 -050046 sdbusplus::server::object_t<
Jie Yange7cf3192021-08-20 11:21:43 -070047 sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
Patrick Williams77b9c472022-07-22 19:26:57 -050048 sdbusplus::server::object_t<
Tim Leedc469c72021-07-20 10:55:58 +080049 sdbusplus::xyz::openbmc_project::Association::server::Definitions>,
Patrick Williams77b9c472022-07-22 19:26:57 -050050 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
51 Decorator::server::OperationalStatus>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080052{
53 public:
54 Dimm() = delete;
55 ~Dimm() = default;
56 Dimm(const Dimm&) = delete;
57 Dimm& operator=(const Dimm&) = delete;
58 Dimm(Dimm&&) = default;
59 Dimm& operator=(Dimm&&) = default;
60
Patrick Williams77b9c472022-07-22 19:26:57 -050061 Dimm(sdbusplus::bus_t& bus, const std::string& objPath,
Jie Yange7cf3192021-08-20 11:21:43 -070062 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
63 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080064
Patrick Williams77b9c472022-07-22 19:26:57 -050065 sdbusplus::server::object_t<
Cheng C Yang8c3fab62019-12-19 00:51:06 +080066 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>(
67 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050068 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
69 Decorator::server::Asset>(
70 bus, objPath.c_str()),
71 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
72 Decorator::server::LocationCode>(
73 bus, objPath.c_str()),
74 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Inventory::
75 Connector::server::Slot>(
76 bus, objPath.c_str()),
77 sdbusplus::server::object_t<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053078 sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
79 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050080 sdbusplus::server::object_t<
Jie Yange7cf3192021-08-20 11:21:43 -070081 sdbusplus::xyz::openbmc_project::Association::server::Definitions>(
82 bus, objPath.c_str()),
Patrick Williams77b9c472022-07-22 19:26:57 -050083 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
84 Decorator::server::OperationalStatus>(
85 bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -070086 dimmNum(dimmId), storage(smbiosTableStorage),
87 motherboardPath(motherboard)
Cheng C Yang8c3fab62019-12-19 00:51:06 +080088 {
89 memoryInfoUpdate();
90 }
91
92 void memoryInfoUpdate(void);
93
94 uint16_t memoryDataWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -070095 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080096 std::string memoryDeviceLocator(std::string value) override;
97 DeviceType memoryType(DeviceType value) override;
98 std::string memoryTypeDetail(std::string value) override;
99 uint16_t maxMemorySpeedInMhz(uint16_t value) override;
100 std::string manufacturer(std::string value) override;
Joshi-Mansi33c948a2021-03-20 00:58:50 +0530101 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800102 std::string serialNumber(std::string value) override;
103 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700104 std::string locationCode(std::string value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800105 uint8_t memoryAttributes(uint8_t value) override;
106 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
Tim Leedc469c72021-07-20 10:55:58 +0800107 bool functional(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800108
109 private:
110 uint8_t dimmNum;
111
112 uint8_t* storage;
113
Jie Yange7cf3192021-08-20 11:21:43 -0700114 std::string motherboardPath;
115
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800116 void dimmSize(const uint16_t size);
Jason M. Billse7770992021-05-14 13:24:33 -0700117 void dimmSizeExt(const size_t size);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800118 void dimmDeviceLocator(const uint8_t positionNum, const uint8_t structLen,
119 uint8_t* dataIn);
120 void dimmType(const uint8_t type);
121 void dimmTypeDetail(const uint16_t detail);
122 void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
123 uint8_t* dataIn);
124 void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
125 uint8_t* dataIn);
126 void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
127 uint8_t* dataIn);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800128};
129
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700130struct MemoryInfo
131{
132 uint8_t type;
133 uint8_t length;
134 uint16_t handle;
135 uint16_t phyArrayHandle;
136 uint16_t errInfoHandle;
137 uint16_t totalWidth;
138 uint16_t dataWidth;
139 uint16_t size;
140 uint8_t formFactor;
141 uint8_t deviceSet;
142 uint8_t deviceLocator;
143 uint8_t bankLocator;
144 uint8_t memoryType;
145 uint16_t typeDetail;
146 uint16_t speed;
147 uint8_t manufacturer;
148 uint8_t serialNum;
149 uint8_t assetTag;
150 uint8_t partNum;
151 uint8_t attributes;
Jason M. Billse7770992021-05-14 13:24:33 -0700152 size_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700153 uint16_t confClockSpeed;
154 uint16_t minimumVoltage;
155 uint16_t maximumVoltage;
156 uint16_t configuredVoltage;
157 uint8_t memoryTechnology;
158 uint16_t memoryOperatingModeCap;
159 uint8_t firwareVersion;
160 uint16_t modelManufId;
161 uint16_t modelProdId;
162 uint16_t memSubConManufId;
163 uint16_t memSubConProdId;
164 uint64_t nvSize;
165 uint64_t volatileSize;
166 uint64_t cacheSize;
167 uint64_t logicalSize;
168} __attribute__((packed));
169
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800170const std::map<uint8_t, DeviceType> dimmTypeTable = {
171 {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
172 {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
173 {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM},
174 {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM},
175 {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM},
176 {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM},
177 {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM},
178 {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM},
179 {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR},
180 {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
181 {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2},
182 {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM},
183 {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
184 {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530185 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
186 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800187
188const std::array<std::string, 16> detailTable{
189 "Reserved", "Other", "Unknown", "Fast-paged",
190 "Static column", "Pseudo-static", "RAMBUS", "Synchronous",
191 "CMOS", "EDO", "Window DRAM", "Cache DRAM",
192 "Non-volatile", "Registered", "Unbuffered", "LRDIMM"};
193
194} // namespace smbios
195
196} // namespace phosphor