blob: 66de5bbda706c7eed36d72c23371c22ddf77e1cc [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 :
38 sdbusplus::server::object::object<
39 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
40 sdbusplus::server::object::object<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053041 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
42 sdbusplus::server::object::object<
Jie Yang31720392021-07-22 21:45:45 -070043 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
44 LocationCode>,
45 sdbusplus::server::object::object<
Jie Yang41654fc2021-09-07 20:26:32 -070046 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot>,
47 sdbusplus::server::object::object<
Jie Yange7cf3192021-08-20 11:21:43 -070048 sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
49 sdbusplus::server::object::object<
Tim Leedc469c72021-07-20 10:55:58 +080050 sdbusplus::xyz::openbmc_project::Association::server::Definitions>,
51 sdbusplus::server::object::object<sdbusplus::xyz::openbmc_project::State::
52 Decorator::server::OperationalStatus>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080053{
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,
Jie Yange7cf3192021-08-20 11:21:43 -070063 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
64 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080065
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()),
Joshi-Mansi33c948a2021-03-20 00:58:50 +053072 sdbusplus::server::object::object<
Jie Yang31720392021-07-22 21:45:45 -070073 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
74 LocationCode>(bus, objPath.c_str()),
75 sdbusplus::server::object::object<
Jie Yang41654fc2021-09-07 20:26:32 -070076 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::
77 Slot>(bus, objPath.c_str()),
78 sdbusplus::server::object::object<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053079 sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
80 bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -070081 sdbusplus::server::object::object<
82 sdbusplus::xyz::openbmc_project::Association::server::Definitions>(
83 bus, objPath.c_str()),
Tim Leedc469c72021-07-20 10:55:58 +080084 sdbusplus::server::object::object<
85 sdbusplus::xyz::openbmc_project::State::Decorator::server::
86 OperationalStatus>(bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -070087 dimmNum(dimmId), storage(smbiosTableStorage),
88 motherboardPath(motherboard)
Cheng C Yang8c3fab62019-12-19 00:51:06 +080089 {
90 memoryInfoUpdate();
91 }
92
93 void memoryInfoUpdate(void);
94
95 uint16_t memoryDataWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -070096 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080097 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;
Joshi-Mansi33c948a2021-03-20 00:58:50 +0530102 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800103 std::string serialNumber(std::string value) override;
104 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700105 std::string locationCode(std::string value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800106 uint8_t memoryAttributes(uint8_t value) override;
107 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
Tim Leedc469c72021-07-20 10:55:58 +0800108 bool functional(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800109
110 private:
111 uint8_t dimmNum;
112
113 uint8_t* storage;
114
Jie Yange7cf3192021-08-20 11:21:43 -0700115 std::string motherboardPath;
116
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800117 void dimmSize(const uint16_t size);
Jason M. Billse7770992021-05-14 13:24:33 -0700118 void dimmSizeExt(const size_t size);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800119 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);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800129};
130
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700131struct 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;
Jason M. Billse7770992021-05-14 13:24:33 -0700153 size_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700154 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
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800171const 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},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530186 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
187 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800188
189const 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