Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #include "oem_ibm_handler.hpp" |
| 2 | |
| 3 | #include "libpldm/entity.h" |
| 4 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame^] | 5 | #include "libpldmresponder/pdr_utils.hpp" |
| 6 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 7 | namespace pldm |
| 8 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 9 | namespace responder |
| 10 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 11 | namespace oem_ibm_platform |
| 12 | { |
| 13 | |
| 14 | int pldm::responder::oem_ibm_platform::Handler:: |
| 15 | getOemStateSensorReadingsHandler( |
| 16 | EntityType entityType, EntityInstance entityInstance, |
| 17 | StateSetId stateSetId, CompositeCount compSensorCnt, |
| 18 | std::vector<get_sensor_state_field>& stateField) |
| 19 | { |
| 20 | int rc = PLDM_SUCCESS; |
| 21 | stateField.clear(); |
| 22 | |
| 23 | for (size_t i = 0; i < compSensorCnt; i++) |
| 24 | { |
| 25 | uint8_t sensorOpState{}; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame^] | 26 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 27 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 28 | { |
| 29 | sensorOpState = fetchBootSide(entityInstance, codeUpdate); |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | rc = PLDM_PLATFORM_INVALID_STATE_VALUE; |
| 34 | break; |
| 35 | } |
| 36 | stateField.push_back({PLDM_SENSOR_ENABLED, PLDM_SENSOR_UNKNOWN, |
| 37 | PLDM_SENSOR_UNKNOWN, sensorOpState}); |
| 38 | } |
| 39 | return rc; |
| 40 | } |
| 41 | |
| 42 | int pldm::responder::oem_ibm_platform::Handler:: |
| 43 | oemSetStateEffecterStatesHandler( |
| 44 | EntityType entityType, EntityInstance entityInstance, |
| 45 | StateSetId stateSetId, CompositeCount compEffecterCnt, |
| 46 | const std::vector<set_effecter_state_field>& stateField) |
| 47 | { |
| 48 | int rc = PLDM_SUCCESS; |
| 49 | |
| 50 | for (uint8_t currState = 0; currState < compEffecterCnt; ++currState) |
| 51 | { |
| 52 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 53 | { |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame^] | 54 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 55 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 56 | { |
| 57 | rc = setBootSide(entityInstance, currState, stateField, |
| 58 | codeUpdate); |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
| 63 | } |
| 64 | } |
| 65 | if (rc != PLDM_SUCCESS) |
| 66 | { |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | return rc; |
| 71 | } |
| 72 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame^] | 73 | void buildAllCodeUpdateEffecterPDR(platform::Handler* platformHandler, |
| 74 | uint16_t entityInstance, uint16_t stateSetID, |
| 75 | pdr_utils::Repo& repo) |
| 76 | { |
| 77 | size_t pdrSize = 0; |
| 78 | pdrSize = sizeof(pldm_state_effecter_pdr) + |
| 79 | sizeof(state_effecter_possible_states); |
| 80 | std::vector<uint8_t> entry{}; |
| 81 | entry.resize(pdrSize); |
| 82 | pldm_state_effecter_pdr* pdr = |
| 83 | reinterpret_cast<pldm_state_effecter_pdr*>(entry.data()); |
| 84 | if (!pdr) |
| 85 | { |
| 86 | std::cerr << "Failed to get record by PDR type, ERROR:" |
| 87 | << PLDM_PLATFORM_INVALID_EFFECTER_ID << std::endl; |
| 88 | } |
| 89 | pdr->hdr.record_handle = 0; |
| 90 | pdr->hdr.version = 1; |
| 91 | pdr->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 92 | pdr->hdr.record_change_num = 0; |
| 93 | pdr->hdr.length = sizeof(pldm_state_effecter_pdr) - sizeof(pldm_pdr_hdr); |
| 94 | pdr->terminus_handle = pdr::BmcPldmTerminusHandle; |
| 95 | pdr->effecter_id = platformHandler->getNextEffecterId(); |
| 96 | pdr->entity_type = PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE; |
| 97 | pdr->entity_instance = entityInstance; |
| 98 | pdr->container_id = 0; |
| 99 | pdr->effecter_semantic_id = 0; |
| 100 | pdr->effecter_init = PLDM_NO_INIT; |
| 101 | pdr->has_description_pdr = false; |
| 102 | pdr->composite_effecter_count = 1; |
| 103 | |
| 104 | auto* possibleStatesPtr = pdr->possible_states; |
| 105 | auto possibleStates = |
| 106 | reinterpret_cast<state_effecter_possible_states*>(possibleStatesPtr); |
| 107 | possibleStates->state_set_id = stateSetID; |
| 108 | possibleStates->possible_states_size = 2; |
| 109 | auto state = |
| 110 | reinterpret_cast<state_effecter_possible_states*>(possibleStates); |
| 111 | if (stateSetID == PLDM_OEM_IBM_BOOT_STATE) |
| 112 | state->states[0].byte = 6; |
| 113 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 114 | state->states[0].byte = 126; |
| 115 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 116 | pdrEntry.data = entry.data(); |
| 117 | pdrEntry.size = pdrSize; |
| 118 | repo.addRecord(pdrEntry); |
| 119 | } |
| 120 | |
| 121 | void buildAllCodeUpdateSensorPDR(platform::Handler* platformHandler, |
| 122 | uint16_t entityInstance, uint16_t stateSetID, |
| 123 | pdr_utils::Repo& repo) |
| 124 | { |
| 125 | size_t pdrSize = 0; |
| 126 | pdrSize = |
| 127 | sizeof(pldm_state_sensor_pdr) + sizeof(state_sensor_possible_states); |
| 128 | std::vector<uint8_t> entry{}; |
| 129 | entry.resize(pdrSize); |
| 130 | pldm_state_sensor_pdr* pdr = |
| 131 | reinterpret_cast<pldm_state_sensor_pdr*>(entry.data()); |
| 132 | if (!pdr) |
| 133 | { |
| 134 | std::cerr << "Failed to get record by PDR type, ERROR:" |
| 135 | << PLDM_PLATFORM_INVALID_SENSOR_ID << std::endl; |
| 136 | } |
| 137 | pdr->hdr.record_handle = 0; |
| 138 | pdr->hdr.version = 1; |
| 139 | pdr->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 140 | pdr->hdr.record_change_num = 0; |
| 141 | pdr->hdr.length = sizeof(pldm_state_sensor_pdr) - sizeof(pldm_pdr_hdr); |
| 142 | pdr->terminus_handle = pdr::BmcPldmTerminusHandle; |
| 143 | pdr->sensor_id = platformHandler->getNextSensorId(); |
| 144 | pdr->entity_type = PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER; |
| 145 | pdr->entity_instance = entityInstance; |
| 146 | pdr->container_id = 0; |
| 147 | pdr->sensor_init = PLDM_NO_INIT; |
| 148 | pdr->sensor_auxiliary_names_pdr = false; |
| 149 | pdr->composite_sensor_count = 1; |
| 150 | |
| 151 | auto* possibleStatesPtr = pdr->possible_states; |
| 152 | auto possibleStates = |
| 153 | reinterpret_cast<state_sensor_possible_states*>(possibleStatesPtr); |
| 154 | possibleStates->state_set_id = stateSetID; |
| 155 | possibleStates->possible_states_size = 2; |
| 156 | auto state = |
| 157 | reinterpret_cast<state_sensor_possible_states*>(possibleStates); |
| 158 | if (stateSetID == PLDM_OEM_IBM_BOOT_STATE) |
| 159 | state->states[0].byte = 6; |
| 160 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 161 | state->states[0].byte = 126; |
| 162 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 163 | pdrEntry.data = entry.data(); |
| 164 | pdrEntry.size = pdrSize; |
| 165 | repo.addRecord(pdrEntry); |
| 166 | } |
| 167 | |
| 168 | void pldm::responder::oem_ibm_platform::Handler::buildOEMPDR( |
| 169 | pdr_utils::Repo& repo) |
| 170 | { |
| 171 | buildAllCodeUpdateEffecterPDR(platformHandler, ENTITY_INSTANCE_0, |
| 172 | PLDM_OEM_IBM_BOOT_STATE, repo); |
| 173 | buildAllCodeUpdateEffecterPDR(platformHandler, ENTITY_INSTANCE_1, |
| 174 | PLDM_OEM_IBM_BOOT_STATE, repo); |
| 175 | buildAllCodeUpdateEffecterPDR(platformHandler, ENTITY_INSTANCE_0, |
| 176 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 177 | |
| 178 | buildAllCodeUpdateSensorPDR(platformHandler, ENTITY_INSTANCE_0, |
| 179 | PLDM_OEM_IBM_BOOT_STATE, repo); |
| 180 | buildAllCodeUpdateSensorPDR(platformHandler, ENTITY_INSTANCE_1, |
| 181 | PLDM_OEM_IBM_BOOT_STATE, repo); |
| 182 | buildAllCodeUpdateSensorPDR(platformHandler, ENTITY_INSTANCE_0, |
| 183 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 184 | } |
| 185 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 186 | void pldm::responder::oem_ibm_platform::Handler::setPlatformHandler( |
| 187 | pldm::responder::platform::Handler* handler) |
| 188 | { |
| 189 | platformHandler = handler; |
| 190 | } |
| 191 | |
| 192 | } // namespace oem_ibm_platform |
| 193 | |
| 194 | } // namespace responder |
| 195 | |
| 196 | } // namespace pldm |