Cheng C Yang | 3e3269a | 2019-12-02 15:11:30 +0800 | [diff] [blame^] | 1 | /* |
| 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 <sys/stat.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <unistd.h> |
| 22 | |
| 23 | #include <phosphor-logging/elog-errors.hpp> |
| 24 | #include <phosphor-logging/log.hpp> |
| 25 | #include <sdbusplus/server.hpp> |
| 26 | #include <sdbusplus/timer.hpp> |
| 27 | |
| 28 | static constexpr uint8_t mdr2Version = 2; |
| 29 | static constexpr uint32_t mdr2SMSize = 0x00100000; |
| 30 | static constexpr uint16_t mdrSMBIOSSize = 32 * 1024; |
| 31 | static constexpr uint32_t mdr2SMBaseAddress = 0x9FF00000; |
| 32 | static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2"; |
| 33 | |
| 34 | enum class MDR2SMBIOSStatusEnum |
| 35 | { |
| 36 | mdr2Init = 0, |
| 37 | mdr2Loaded = 1, |
| 38 | mdr2Updated = 2, |
| 39 | mdr2Updating = 3 |
| 40 | }; |
| 41 | |
| 42 | enum class MDR2DirLockEnum |
| 43 | { |
| 44 | mdr2DirUnlock = 0, |
| 45 | mdr2DirLock = 1 |
| 46 | }; |
| 47 | |
| 48 | typedef struct |
| 49 | { |
| 50 | uint8_t dataInfo[16]; |
| 51 | } DataIdStruct; |
| 52 | |
| 53 | typedef struct |
| 54 | { |
| 55 | DataIdStruct id; |
| 56 | uint32_t size; |
| 57 | uint32_t dataSetSize; |
| 58 | uint32_t dataVersion; |
| 59 | uint32_t timestamp; |
| 60 | } Mdr2DirEntry; |
| 61 | |
| 62 | typedef struct |
| 63 | { |
| 64 | Mdr2DirEntry common; |
| 65 | MDR2SMBIOSStatusEnum stage; |
| 66 | MDR2DirLockEnum lock; |
| 67 | uint16_t lockHandle; |
| 68 | uint32_t xferBuff; |
| 69 | uint32_t xferSize; |
| 70 | uint32_t maxDataSize; |
| 71 | uint8_t* dataStorage; |
| 72 | } Mdr2DirLocalStruct; |
| 73 | |
| 74 | typedef struct |
| 75 | { |
| 76 | uint8_t agentVersion; |
| 77 | uint8_t dirVersion; |
| 78 | uint8_t dirEntries; |
| 79 | uint8_t status; // valid / locked / etc |
| 80 | uint8_t remoteDirVersion; |
| 81 | uint16_t sessionHandle; |
| 82 | Mdr2DirLocalStruct dir[maxDirEntries]; |
| 83 | } Mdr2DirStruct; |
| 84 | |
| 85 | struct MDRSMBIOSHeader |
| 86 | { |
| 87 | uint8_t dirVer; |
| 88 | uint8_t mdrType; |
| 89 | uint32_t timestamp; |
| 90 | uint32_t dataSize; |
| 91 | } __attribute__((packed)); |
| 92 | |
| 93 | namespace phosphor |
| 94 | { |
| 95 | namespace smbios |
| 96 | { |
| 97 | |
| 98 | class MDR_V2 |
| 99 | { |
| 100 | public: |
| 101 | MDR_V2() = delete; |
| 102 | MDR_V2(const MDR_V2&) = delete; |
| 103 | MDR_V2& operator=(const MDR_V2&) = delete; |
| 104 | MDR_V2(MDR_V2&&) = delete; |
| 105 | MDR_V2& operator=(MDR_V2&&) = delete; |
| 106 | ~MDR_V2() = default; |
| 107 | |
| 108 | MDR_V2(sdbusplus::bus::bus& bus, const char* path, sd_event* event) : |
| 109 | bus(bus), timer(event, [&](void) { agentSynchronizeData(); }) |
| 110 | { |
| 111 | |
| 112 | smbiosDir.agentVersion = smbiosAgentVersion; |
| 113 | smbiosDir.dirVersion = 1; |
| 114 | smbiosDir.dirEntries = 1; |
| 115 | directoryEntries(smbiosDir.dirEntries); |
| 116 | smbiosDir.status = 1; |
| 117 | smbiosDir.remoteDirVersion = 0; |
| 118 | |
| 119 | std::copy(smbiosTableId.begin(), smbiosTableId.end(), |
| 120 | smbiosDir.dir[smbiosDirIndex].common.id.dataInfo); |
| 121 | |
| 122 | smbiosDir.dir[smbiosDirIndex].dataStorage = smbiosTableStorage; |
| 123 | |
| 124 | agentSynchronizeData(); |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | Timer timer; |
| 129 | |
| 130 | sdbusplus::bus::bus& bus; |
| 131 | |
| 132 | Mdr2DirStruct smbiosDir; |
| 133 | |
| 134 | const std::array<uint8_t, 16> smbiosTableId{ |
| 135 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0x42}; |
| 136 | uint8_t smbiosTableStorage[smbiosTableStorageSize]; |
| 137 | |
| 138 | bool smbiosIsUpdating(uint8_t index); |
| 139 | bool smbiosIsAvailForUpdate(uint8_t index); |
| 140 | inline uint8_t smbiosValidFlag(uint8_t index); |
| 141 | void systemInfoUpdate(void); |
| 142 | }; |
| 143 | |
| 144 | } // namespace smbios |
| 145 | } // namespace phosphor |