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