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