blob: e6dc743446c87864aceaac9d707a64058a2b6bfa [file] [log] [blame]
Cheng C Yang3e3269a2019-12-02 15:11:30 +08001/*
2// Copyright (c) 2019 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
19#include <array>
20
21static constexpr uint16_t smbiosAgentId = 0x0101;
22static constexpr int smbiosDirIndex = 0;
23static constexpr int firstAgentIndex = 1;
24static constexpr uint8_t maxDirEntries = 4;
25static constexpr uint32_t pageMask = 0xf000;
26static constexpr uint8_t smbiosAgentVersion = 1;
27static constexpr uint32_t defaultTimeout = 20000;
28static constexpr uint32_t smbiosTableVersion = 15;
29static constexpr uint32_t smbiosSMMemoryOffset = 0;
30static constexpr uint32_t smbiosSMMemorySize = 1024 * 1024;
31static constexpr uint32_t smbiosTableTimestamp = 0x45464748;
32static constexpr uint32_t smbiosTableStorageSize = 64 * 1024;
33static constexpr const char* smbiosPath = "/var/lib/smbios";
Cheng C Yangeecaf822019-12-19 00:34:23 +080034static constexpr uint16_t mdrSMBIOSSize = 32 * 1024;
Cheng C Yang3e3269a2019-12-02 15:11:30 +080035
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080036static constexpr const char* cpuPath =
37 "/xyz/openbmc_project/inventory/system/chassis/motherboard/cpu";
38
39static constexpr const char* dimmPath =
40 "/xyz/openbmc_project/inventory/system/chassis/motherboard/dimm";
41
42static constexpr const char* systemPath =
43 "/xyz/openbmc_project/inventory/system/chassis/motherboard/bios";
44
Cheng C Yang3e3269a2019-12-02 15:11:30 +080045enum class DirDataRequestEnum
46{
47 dirDataNotRequested = 0x00,
48 dirDataRequested = 0x01
49};
50
51enum class FlagStatus
52{
53 flagIsInvalid = 0,
54 flagIsValid = 1,
55 flagIsLocked = 2
56};
57
58typedef enum
59{
60 biosType = 0,
61 systemType = 1,
62 baseboardType = 2,
63 chassisType = 3,
64 processorsType = 4,
65 memoryControllerType = 5,
66 memoryModuleInformationType = 6,
67 cacheType = 7,
68 portConnectorType = 8,
69 systemSlots = 9,
70 onBoardDevicesType = 10,
71 oemStringsType = 11,
72 systemCconfigurationOptionsType = 12,
73 biosLanguageType = 13,
74 groupAssociatonsType = 14,
75 systemEventLogType = 15,
76 physicalMemoryArrayType = 16,
77 memoryDeviceType = 17,
78} SmbiosType;
Cheng C Yang43c6a1d2019-12-19 00:48:34 +080079
80static constexpr uint8_t separateLen = 2;
81
82static inline uint8_t* smbiosNextPtr(uint8_t* smbiosDataIn)
83{
84 if (smbiosDataIn == nullptr)
85 {
86 return nullptr;
87 }
88 uint8_t* smbiosData = smbiosDataIn + *(smbiosDataIn + 1);
89 int len = 0;
90 while ((*smbiosData | *(smbiosData + 1)) != 0)
91 {
92 smbiosData++;
93 len++;
94 if (len >= mdrSMBIOSSize) // To avoid endless loop
95 {
96 return nullptr;
97 }
98 }
99 return smbiosData + separateLen;
100}
101
102// When first time run getSMBIOSTypePtr, need to send the RegionS[].regionData
103// to smbiosDataIn
104static inline uint8_t* getSMBIOSTypePtr(uint8_t* smbiosDataIn, uint8_t typeId)
105{
106 if (smbiosDataIn == nullptr)
107 {
108 return nullptr;
109 }
110 char* smbiosData = reinterpret_cast<char*>(smbiosDataIn);
111 while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
112 {
113 if (*smbiosData != typeId)
114 {
115 uint32_t len = *(smbiosData + 1);
116 smbiosData += len;
117 while ((*smbiosData != '\0') || (*(smbiosData + 1) != '\0'))
118 {
119 smbiosData++;
120 len++;
121 if (len >= mdrSMBIOSSize) // To avoid endless loop
122 {
123 return nullptr;
124 }
125 }
126 smbiosData += separateLen;
127 continue;
128 }
129 return reinterpret_cast<uint8_t*>(smbiosData);
130 }
131 return nullptr;
132}
133
134static inline std::string positionToString(uint8_t positionNum,
135 uint8_t structLen, uint8_t* dataIn)
136{
137 if (dataIn == nullptr)
138 {
139 return "";
140 }
141 uint16_t limit = mdrSMBIOSSize; // set a limit to avoid endless loop
142
143 char* target = reinterpret_cast<char*>(dataIn + structLen);
144 for (uint8_t index = 1; index < positionNum; index++)
145 {
146 for (; *target != '\0'; target++)
147 {
148 limit--;
149 if (limit < 1)
150 {
151 return "";
152 }
153 }
154 target++;
155 if (*target == '\0')
156 {
157 return ""; // 0x00 0x00 means end of the entry.
158 }
159 }
160
161 std::string result = target;
162 return result;
163}