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