Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 1 | #include "libpldm/base.h" |
| 2 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 3 | #include "libpldm/bios.h" |
| 4 | #include "libpldm/fru.h" |
| 5 | #include "libpldm/platform.h" |
| 6 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 7 | #include "base.hpp" |
| 8 | |
| 9 | #include <array> |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 10 | #include <cstring> |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 11 | #include <map> |
| 12 | #include <stdexcept> |
| 13 | #include <vector> |
| 14 | |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 15 | #ifdef OEM_IBM |
| 16 | #include "libpldm/file_io.h" |
| 17 | #include "libpldm/host.h" |
| 18 | #endif |
| 19 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 20 | namespace pldm |
| 21 | { |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 22 | |
| 23 | using Type = uint8_t; |
| 24 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 25 | namespace responder |
| 26 | { |
| 27 | |
| 28 | using Cmd = std::vector<uint8_t>; |
| 29 | |
| 30 | static const std::map<Type, Cmd> capabilities{ |
Zahed Hossain | 5e4e383 | 2019-07-05 03:43:18 -0500 | [diff] [blame] | 31 | {PLDM_BASE, |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 32 | {PLDM_GET_TID, PLDM_GET_PLDM_VERSION, PLDM_GET_PLDM_TYPES, |
| 33 | PLDM_GET_PLDM_COMMANDS}}, |
Sridevi Ramesh | f58d9a5 | 2020-02-14 00:30:58 -0600 | [diff] [blame] | 34 | {PLDM_PLATFORM, {PLDM_GET_PDR, PLDM_SET_STATE_EFFECTER_STATES}}, |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 35 | {PLDM_BIOS, |
Sridevi Ramesh | f58d9a5 | 2020-02-14 00:30:58 -0600 | [diff] [blame] | 36 | {PLDM_GET_DATE_TIME, PLDM_SET_DATE_TIME, PLDM_GET_BIOS_TABLE, |
Xiaochao Ma | d3cf57e | 2019-12-31 14:22:38 +0800 | [diff] [blame] | 37 | PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE, |
| 38 | PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE}}, |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 39 | {PLDM_FRU, {PLDM_GET_FRU_RECORD_TABLE_METADATA, PLDM_GET_FRU_RECORD_TABLE}}, |
| 40 | #ifdef OEM_IBM |
| 41 | {PLDM_OEM, |
| 42 | {PLDM_HOST_GET_ALERT_STATUS, PLDM_GET_FILE_TABLE, PLDM_READ_FILE, |
| 43 | PLDM_WRITE_FILE, PLDM_READ_FILE_INTO_MEMORY, PLDM_WRITE_FILE_FROM_MEMORY, |
| 44 | PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY, |
| 45 | PLDM_NEW_FILE_AVAILABLE, PLDM_READ_FILE_BY_TYPE, PLDM_WRITE_FILE_BY_TYPE, |
| 46 | PLDM_FILE_ACK}}, |
| 47 | #endif |
| 48 | }; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 49 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 50 | static const std::map<Type, ver32_t> versions{ |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 51 | {PLDM_BASE, {0xF1, 0xF0, 0xF0, 0x00}}, |
Tom Joseph | 0bead97 | 2020-01-28 10:54:03 +0530 | [diff] [blame] | 52 | {PLDM_PLATFORM, {0xF1, 0xF2, 0xF0, 0x00}}, |
Zahed Hossain | 74c1c1e | 2019-06-18 02:13:48 -0500 | [diff] [blame] | 53 | {PLDM_BIOS, {0xF1, 0xF0, 0xF0, 0x00}}, |
Deepak Kodihalli | ec48297 | 2019-11-26 07:57:10 -0600 | [diff] [blame] | 54 | {PLDM_FRU, {0xF1, 0xF0, 0xF0, 0x00}}, |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 55 | #ifdef OEM_IBM |
| 56 | {PLDM_OEM, {0xF1, 0xF0, 0xF0, 0x00}}, |
| 57 | #endif |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 58 | }; |
| 59 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 60 | namespace base |
| 61 | { |
| 62 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 63 | Response Handler::getPLDMTypes(const pldm_msg* request, |
| 64 | size_t /*payloadLength*/) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 65 | { |
| 66 | // DSP0240 has this as a bitfield8[N], where N = 0 to 7 |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 67 | std::array<bitfield8_t, 8> types{}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 68 | for (const auto& type : capabilities) |
| 69 | { |
| 70 | auto index = type.first / 8; |
| 71 | // <Type Number> = <Array Index> * 8 + <bit position> |
| 72 | auto bit = type.first - (index * 8); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 73 | types[index].byte |= 1 << bit; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 74 | } |
| 75 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 76 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES, 0); |
| 77 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 78 | auto rc = encode_get_types_resp(request->hdr.instance_id, PLDM_SUCCESS, |
| 79 | types.data(), responsePtr); |
| 80 | if (rc != PLDM_SUCCESS) |
| 81 | { |
| 82 | return CmdHandler::ccOnlyResponse(request, rc); |
| 83 | } |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 84 | |
| 85 | return response; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 86 | } |
| 87 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 88 | Response Handler::getPLDMCommands(const pldm_msg* request, size_t payloadLength) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 89 | { |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 90 | ver32_t version{}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 91 | Type type; |
| 92 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 93 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_RESP_BYTES, 0); |
| 94 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 95 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 96 | auto rc = decode_get_commands_req(request, payloadLength, &type, &version); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 97 | |
| 98 | if (rc != PLDM_SUCCESS) |
| 99 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 100 | return CmdHandler::ccOnlyResponse(request, rc); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 101 | } |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 102 | |
| 103 | // DSP0240 has this as a bitfield8[N], where N = 0 to 31 |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 104 | std::array<bitfield8_t, 32> cmds{}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 105 | if (capabilities.find(type) == capabilities.end()) |
| 106 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 107 | return CmdHandler::ccOnlyResponse(request, |
| 108 | PLDM_ERROR_INVALID_PLDM_TYPE); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | for (const auto& cmd : capabilities.at(type)) |
| 112 | { |
| 113 | auto index = cmd / 8; |
| 114 | // <Type Number> = <Array Index> * 8 + <bit position> |
| 115 | auto bit = cmd - (index * 8); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 116 | cmds[index].byte |= 1 << bit; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 117 | } |
| 118 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 119 | rc = encode_get_commands_resp(request->hdr.instance_id, PLDM_SUCCESS, |
| 120 | cmds.data(), responsePtr); |
| 121 | if (rc != PLDM_SUCCESS) |
| 122 | { |
| 123 | return ccOnlyResponse(request, rc); |
| 124 | } |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 125 | |
| 126 | return response; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 127 | } |
| 128 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 129 | Response Handler::getPLDMVersion(const pldm_msg* request, size_t payloadLength) |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 130 | { |
| 131 | uint32_t transferHandle; |
| 132 | Type type; |
| 133 | uint8_t transferFlag; |
| 134 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 135 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_RESP_BYTES, 0); |
| 136 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 137 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 138 | uint8_t rc = decode_get_version_req(request, payloadLength, &transferHandle, |
| 139 | &transferFlag, &type); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 140 | |
| 141 | if (rc != PLDM_SUCCESS) |
| 142 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 143 | return CmdHandler::ccOnlyResponse(request, rc); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 144 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 145 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 146 | ver32_t version{}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 147 | auto search = versions.find(type); |
| 148 | |
| 149 | if (search == versions.end()) |
| 150 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 151 | return CmdHandler::ccOnlyResponse(request, |
| 152 | PLDM_ERROR_INVALID_PLDM_TYPE); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | memcpy(&version, &(search->second), sizeof(version)); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 156 | rc = encode_get_version_resp(request->hdr.instance_id, PLDM_SUCCESS, 0, |
| 157 | PLDM_START_AND_END, &version, |
| 158 | sizeof(pldm_version), responsePtr); |
| 159 | if (rc != PLDM_SUCCESS) |
| 160 | { |
| 161 | return ccOnlyResponse(request, rc); |
| 162 | } |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 163 | |
| 164 | return response; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 165 | } |
| 166 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 167 | Response Handler::getTID(const pldm_msg* request, size_t /*payloadLength*/) |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 168 | { |
| 169 | // assigned 1 to the bmc as the PLDM terminus |
| 170 | uint8_t tid = 1; |
| 171 | |
| 172 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TID_RESP_BYTES, 0); |
| 173 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 174 | auto rc = encode_get_tid_resp(request->hdr.instance_id, PLDM_SUCCESS, tid, |
| 175 | responsePtr); |
| 176 | if (rc != PLDM_SUCCESS) |
| 177 | { |
| 178 | return ccOnlyResponse(request, rc); |
| 179 | } |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 180 | |
| 181 | return response; |
| 182 | } |
| 183 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 184 | } // namespace base |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 185 | } // namespace responder |
| 186 | } // namespace pldm |