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