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