blob: 6f88ae206938ea89b211b94ab6f796e139924e76 [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>
Cheng C Yang8c3fab62019-12-19 00:51:06 +080026
27namespace phosphor
28{
29
30namespace smbios
31{
32
33using DeviceType =
34 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm::DeviceType;
35
Zhikui Ren18a5ab92020-09-01 21:35:20 -070036class Dimm :
37 sdbusplus::server::object::object<
38 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>,
39 sdbusplus::server::object::object<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053040 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset>,
41 sdbusplus::server::object::object<
Jie Yang31720392021-07-22 21:45:45 -070042 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
43 LocationCode>,
44 sdbusplus::server::object::object<
Jie Yang41654fc2021-09-07 20:26:32 -070045 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot>,
46 sdbusplus::server::object::object<
Jie Yange7cf3192021-08-20 11:21:43 -070047 sdbusplus::xyz::openbmc_project::Inventory::server::Item>,
48 sdbusplus::server::object::object<
49 sdbusplus::xyz::openbmc_project::Association::server::Definitions>
50
Cheng C Yang8c3fab62019-12-19 00:51:06 +080051{
52 public:
53 Dimm() = delete;
54 ~Dimm() = default;
55 Dimm(const Dimm&) = delete;
56 Dimm& operator=(const Dimm&) = delete;
57 Dimm(Dimm&&) = default;
58 Dimm& operator=(Dimm&&) = default;
59
60 Dimm(sdbusplus::bus::bus& bus, const std::string& objPath,
Jie Yange7cf3192021-08-20 11:21:43 -070061 const uint8_t& dimmId, uint8_t* smbiosTableStorage,
62 const std::string& motherboard) :
Cheng C Yang8c3fab62019-12-19 00:51:06 +080063
64 sdbusplus::server::object::object<
65 sdbusplus::xyz::openbmc_project::Inventory::Item::server::Dimm>(
66 bus, objPath.c_str()),
67 sdbusplus::server::object::object<
68 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
69 Asset>(bus, objPath.c_str()),
Joshi-Mansi33c948a2021-03-20 00:58:50 +053070 sdbusplus::server::object::object<
Jie Yang31720392021-07-22 21:45:45 -070071 sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
72 LocationCode>(bus, objPath.c_str()),
73 sdbusplus::server::object::object<
Jie Yang41654fc2021-09-07 20:26:32 -070074 sdbusplus::xyz::openbmc_project::Inventory::Connector::server::
75 Slot>(bus, objPath.c_str()),
76 sdbusplus::server::object::object<
Joshi-Mansi33c948a2021-03-20 00:58:50 +053077 sdbusplus::xyz::openbmc_project::Inventory::server::Item>(
78 bus, objPath.c_str()),
Jie Yange7cf3192021-08-20 11:21:43 -070079 sdbusplus::server::object::object<
80 sdbusplus::xyz::openbmc_project::Association::server::Definitions>(
81 bus, objPath.c_str()),
82 dimmNum(dimmId), storage(smbiosTableStorage),
83 motherboardPath(motherboard)
Cheng C Yang8c3fab62019-12-19 00:51:06 +080084 {
85 memoryInfoUpdate();
86 }
87
88 void memoryInfoUpdate(void);
89
90 uint16_t memoryDataWidth(uint16_t value) override;
Jason M. Billse7770992021-05-14 13:24:33 -070091 size_t memorySizeInKB(size_t value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080092 std::string memoryDeviceLocator(std::string value) override;
93 DeviceType memoryType(DeviceType value) override;
94 std::string memoryTypeDetail(std::string value) override;
95 uint16_t maxMemorySpeedInMhz(uint16_t value) override;
96 std::string manufacturer(std::string value) override;
Joshi-Mansi33c948a2021-03-20 00:58:50 +053097 bool present(bool value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +080098 std::string serialNumber(std::string value) override;
99 std::string partNumber(std::string value) override;
Jie Yang31720392021-07-22 21:45:45 -0700100 std::string locationCode(std::string value) override;
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800101 uint8_t memoryAttributes(uint8_t value) override;
102 uint16_t memoryConfiguredSpeedInMhz(uint16_t value) override;
103
104 private:
105 uint8_t dimmNum;
106
107 uint8_t* storage;
108
Jie Yange7cf3192021-08-20 11:21:43 -0700109 std::string motherboardPath;
110
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800111 void dimmSize(const uint16_t size);
Jason M. Billse7770992021-05-14 13:24:33 -0700112 void dimmSizeExt(const size_t size);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800113 void dimmDeviceLocator(const uint8_t positionNum, const uint8_t structLen,
114 uint8_t* dataIn);
115 void dimmType(const uint8_t type);
116 void dimmTypeDetail(const uint16_t detail);
117 void dimmManufacturer(const uint8_t positionNum, const uint8_t structLen,
118 uint8_t* dataIn);
119 void dimmSerialNum(const uint8_t positionNum, const uint8_t structLen,
120 uint8_t* dataIn);
121 void dimmPartNum(const uint8_t positionNum, const uint8_t structLen,
122 uint8_t* dataIn);
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800123};
124
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700125struct MemoryInfo
126{
127 uint8_t type;
128 uint8_t length;
129 uint16_t handle;
130 uint16_t phyArrayHandle;
131 uint16_t errInfoHandle;
132 uint16_t totalWidth;
133 uint16_t dataWidth;
134 uint16_t size;
135 uint8_t formFactor;
136 uint8_t deviceSet;
137 uint8_t deviceLocator;
138 uint8_t bankLocator;
139 uint8_t memoryType;
140 uint16_t typeDetail;
141 uint16_t speed;
142 uint8_t manufacturer;
143 uint8_t serialNum;
144 uint8_t assetTag;
145 uint8_t partNum;
146 uint8_t attributes;
Jason M. Billse7770992021-05-14 13:24:33 -0700147 size_t extendedSize;
Zhikui Ren18a5ab92020-09-01 21:35:20 -0700148 uint16_t confClockSpeed;
149 uint16_t minimumVoltage;
150 uint16_t maximumVoltage;
151 uint16_t configuredVoltage;
152 uint8_t memoryTechnology;
153 uint16_t memoryOperatingModeCap;
154 uint8_t firwareVersion;
155 uint16_t modelManufId;
156 uint16_t modelProdId;
157 uint16_t memSubConManufId;
158 uint16_t memSubConProdId;
159 uint64_t nvSize;
160 uint64_t volatileSize;
161 uint64_t cacheSize;
162 uint64_t logicalSize;
163} __attribute__((packed));
164
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800165const std::map<uint8_t, DeviceType> dimmTypeTable = {
166 {0x1, DeviceType::Other}, {0x2, DeviceType::Unknown},
167 {0x3, DeviceType::DRAM}, {0x4, DeviceType::EDRAM},
168 {0x5, DeviceType::VRAM}, {0x6, DeviceType::SRAM},
169 {0x7, DeviceType::RAM}, {0x8, DeviceType::ROM},
170 {0x9, DeviceType::FLASH}, {0xa, DeviceType::EEPROM},
171 {0xb, DeviceType::FEPROM}, {0xc, DeviceType::EPROM},
172 {0xd, DeviceType::CDRAM}, {0xe, DeviceType::ThreeDRAM},
173 {0xf, DeviceType::SDRAM}, {0x10, DeviceType::DDR_SGRAM},
174 {0x11, DeviceType::RDRAM}, {0x12, DeviceType::DDR},
175 {0x13, DeviceType::DDR2}, {0x14, DeviceType::DDR2_SDRAM_FB_DIMM},
176 {0x18, DeviceType::DDR3}, {0x19, DeviceType::FBD2},
177 {0x1a, DeviceType::DDR4}, {0x1b, DeviceType::LPDDR_SDRAM},
178 {0x1c, DeviceType::LPDDR2_SDRAM}, {0x1d, DeviceType::LPDDR3_SDRAM},
179 {0x1e, DeviceType::LPDDR4_SDRAM}, {0x1f, DeviceType::Logical},
Mansi Joshi7ece93a2021-07-19 15:07:52 +0530180 {0x20, DeviceType::HBM}, {0x21, DeviceType::HBM2},
181 {0x22, DeviceType::DDR5}, {0x23, DeviceType::LPDDR5_SDRAM}};
Cheng C Yang8c3fab62019-12-19 00:51:06 +0800182
183const std::array<std::string, 16> detailTable{
184 "Reserved", "Other", "Unknown", "Fast-paged",
185 "Static column", "Pseudo-static", "RAMBUS", "Synchronous",
186 "CMOS", "EDO", "Window DRAM", "Cache DRAM",
187 "Non-volatile", "Registered", "Unbuffered", "LRDIMM"};
188
189} // namespace smbios
190
191} // namespace phosphor