Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oem-ibm: PLDM Power down effecter and APR support #572

Open
wants to merge 1 commit into
base: 1110
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libpldmresponder/oem_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Handler : public CmdHandler
*
* @param[in] entityType - entity type corresponding to the sensor
* @param[in] entityInstance - entity instance number
* @param[in] entityContainerID - container id
* @param[in] stateSetId - state set id
* @param[in] compSensorCnt - composite sensor count
* @param[out] stateField - The state field data for each of the states,
Expand Down
3 changes: 2 additions & 1 deletion libpldmresponder/pdr_numeric_effecter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static const Json empty{};
template <class DBusInterface, class Handler>
void generateNumericEffecterPDR(const DBusInterface& dBusIntf, const Json& json,
Handler& handler,
pdr_utils::RepoInterface& repo)
pdr_utils::RepoInterface& repo,
pldm_entity_association_tree* /*bmcEntityTree*/)
{
static const std::vector<Json> emptyList{};
auto entries = json.value("entries", emptyList);
Expand Down
3 changes: 2 additions & 1 deletion libpldmresponder/pdr_state_effecter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static const Json empty{};
*/
template <class DBusInterface, class Handler>
void generateStateEffecterPDR(const DBusInterface& dBusIntf, const Json& json,
Handler& handler, pdr_utils::RepoInterface& repo)
Handler& handler, pdr_utils::RepoInterface& repo,
pldm_entity_association_tree* /*bmcEntityTree*/)
{
static const std::vector<Json> emptyList{};
auto entries = json.value("entries", emptyList);
Expand Down
66 changes: 65 additions & 1 deletion libpldmresponder/pdr_state_sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ using Json = nlohmann::json;

static const Json empty{};

constexpr uint32_t BMC_PDR_START_RANGE = 0x00000000;
constexpr uint32_t BMC_PDR_END_RANGE = 0x00FFFFFF;

/** @brief Parse PDR JSON file and generate state sensor PDR structure
*
* @param[in] json - the JSON Object with the state sensor PDR
Expand All @@ -27,7 +30,8 @@ static const Json empty{};
*/
template <class DBusInterface, class Handler>
void generateStateSensorPDR(const DBusInterface& dBusIntf, const Json& json,
Handler& handler, pdr_utils::RepoInterface& repo)
Handler& handler, pdr_utils::RepoInterface& repo,
pldm_entity_association_tree* bmcEntityTree)
{
static const std::vector<Json> emptyList{};
auto entries = json.value("entries", emptyList);
Expand Down Expand Up @@ -99,6 +103,66 @@ void generateStateSensorPDR(const DBusInterface& dBusIntf, const Json& json,
{
continue;
}
// now attach this entity to the container that was
// mentioned in the json, and add this entity to the
// parents entity assocation PDR

std::string parent_entity_path = e.value("parent_entity_path",
"");
if (parent_entity_path != "" &&
associatedEntityMap.contains(parent_entity_path))
{
// find the parent node in the tree
pldm_entity parent_entity =
associatedEntityMap.at(parent_entity_path);
pldm_entity child_entity = {pdr->entity_type,
pdr->entity_instance,
pdr->container_id};
auto parent_node =
pldm_entity_association_tree_find_with_locality(
bmcEntityTree, &parent_entity, false);
if (!parent_node)
{
// parent node not found in the entity association tree,
// this should not be possible
error(
"Parent Entity of type {P_ENTITY_TYP} not found in the BMC Entity Association tree",
"P_ENTITY_TYP",
static_cast<unsigned>(parent_entity.entity_type));
return;
}
pldm_entity_association_tree_add_entity(
bmcEntityTree, &child_entity, pdr->entity_instance,
parent_node, PLDM_ENTITY_ASSOCIAION_PHYSICAL, false,
false, 0xFFFF);
uint32_t bmc_record_handle = 0;
#ifdef OEM_IBM
auto lastLocalRecord = pldm_pdr_find_last_in_range(
repo.getPdr(), BMC_PDR_START_RANGE, BMC_PDR_END_RANGE);
bmc_record_handle = pldm_pdr_get_record_handle(
repo.getPdr(), lastLocalRecord);
#endif

[[maybe_unused]] uint8_t bmcEventDataOps;
uint32_t updatedRecordHdlBmc = 0;
bool found = false;
pldm_entity_association_find_parent_entity(
repo.getPdr(), &parent_entity, false,
&updatedRecordHdlBmc, &found);
if (found)
{
pldm_entity_association_pdr_add_contained_entity_to_remote_pdr(
repo.getPdr(), &child_entity, updatedRecordHdlBmc);
bmcEventDataOps = PLDM_RECORDS_MODIFIED;
}
else
{
pldm_entity_association_pdr_create_new(
repo.getPdr(), bmc_record_handle, &parent_entity,
&child_entity, &updatedRecordHdlBmc);
bmcEventDataOps = PLDM_RECORDS_ADDED;
}
}
}
}
catch (const std::exception&)
Expand Down
32 changes: 19 additions & 13 deletions libpldmresponder/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
}

void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
const std::vector<fs::path>& dir, Repo& repo)
const std::vector<fs::path>& dir, Repo& repo,
pldm_entity_association_tree* bmcEntityTree)
{
for (const auto& directory : dir)
{
Expand All @@ -86,22 +87,27 @@ void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
const std::map<Type, generatePDR> generateHandlers = {
{PLDM_STATE_EFFECTER_PDR,
[this](const DBusHandler& dBusIntf, const auto& json,
RepoInterface& repo) {
RepoInterface& repo,
pldm_entity_association_tree* bmcEntityTree) {
pdr_state_effecter::generateStateEffecterPDR<pldm::utils::DBusHandler,
Handler>(dBusIntf, json,
*this, repo);
Handler>(
dBusIntf, json, *this, repo, bmcEntityTree);
}},
{PLDM_NUMERIC_EFFECTER_PDR,
[this](const DBusHandler& dBusIntf, const auto& json,
RepoInterface& repo) {
RepoInterface& repo,
pldm_entity_association_tree* bmcEntityTree) {
pdr_numeric_effecter::generateNumericEffecterPDR<
pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, repo);
pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, repo,
bmcEntityTree);
}},
{PLDM_STATE_SENSOR_PDR, [this](const DBusHandler& dBusIntf,
const auto& json, RepoInterface& repo) {
{PLDM_STATE_SENSOR_PDR,
[this](const DBusHandler& dBusIntf, const auto& json,
RepoInterface& repo,
pldm_entity_association_tree* bmcEntityTree) {
pdr_state_sensor::generateStateSensorPDR<pldm::utils::DBusHandler,
Handler>(dBusIntf, json, *this,
repo);
repo, bmcEntityTree);
}}};

Type pdrType{};
Expand All @@ -121,15 +127,15 @@ void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
{
pdrType = effecter.value("pdrType", 0);
generateHandlers.at(pdrType)(dBusIntf, effecter,
repo);
repo, bmcEntityTree);
}

auto sensorPDRs = json.value("sensorPDRs", empty);
for (const auto& sensor : sensorPDRs)
{
pdrType = sensor.value("pdrType", 0);
generateHandlers.at(pdrType)(dBusIntf, sensor,
repo);
generateHandlers.at(pdrType)(dBusIntf, sensor, repo,
bmcEntityTree);
}
}
}
Expand Down Expand Up @@ -199,7 +205,7 @@ Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
{
oemPlatformHandler->buildOEMPDR(pdrRepo);
}
generate(*dBusIntf, pdrJsonsDir, pdrRepo);
generate(*dBusIntf, pdrJsonsDir, pdrRepo, bmcEntityTree);

pdrCreated = true;

Expand Down
21 changes: 14 additions & 7 deletions libpldmresponder/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ namespace responder
{
namespace platform
{
using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf,
const pldm::utils::Json& json,
pdr_utils::RepoInterface& repo)>;
using generatePDR = std::function<void(
const pldm::utils::DBusHandler& dBusIntf, const pldm::utils::Json& json,
pdr_utils::RepoInterface& repo,
pldm_entity_association_tree* bmcEntityTree)>;

using EffecterId = uint16_t;
using DbusObjMaps =
Expand All @@ -54,6 +55,7 @@ class Handler : public CmdHandler
pldm_pdr* repo, HostPDRHandler* hostPDRHandler,
pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler,
fru::Handler* fruHandler,
pldm_entity_association_tree* bmcEntityTree,
pldm::responder::oem_platform::Handler* oemPlatformHandler,
pldm::responder::platform_config::Handler* platformConfigHandler,
pldm::requester::Handler<pldm::requester::Request>* handler,
Expand All @@ -63,15 +65,16 @@ class Handler : public CmdHandler
instanceIdDb(instanceIdDb), pdrRepo(repo),
hostPDRHandler(hostPDRHandler),
dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler),
bmcEntityTree(bmcEntityTree), dBusIntf(dBusIntf),
oemPlatformHandler(oemPlatformHandler),
platformConfigHandler(platformConfigHandler), handler(handler),
event(event), pdrJsonDir(pdrJsonDir), pdrCreated(false),
pdrJsonsDir({pdrJsonDir})
{
if (!buildPDRLazily)
{
generateTerminusLocatorPDR(pdrRepo);
generate(*dBusIntf, pdrJsonsDir, pdrRepo);
generate(*dBusIntf, pdrJsonsDir, pdrRepo, bmcEntityTree);
pdrCreated = true;
}

Expand Down Expand Up @@ -196,15 +199,17 @@ class Handler : public CmdHandler
*/
void generate(const pldm::utils::DBusHandler& dBusIntf,
const std::vector<fs::path>& dir,
pldm::responder::pdr_utils::Repo& repo);
pldm::responder::pdr_utils::Repo& repo,
pldm_entity_association_tree* bmcEntityTree);

/** @brief Parse PDR JSONs and build state effecter PDR repository
*
* @param[in] json - platform specific PDR JSON files
* @param[in] repo - instance of state effecter implementation of Repo
*/
void generateStateEffecterRepo(const pldm::utils::Json& json,
pldm::responder::pdr_utils::Repo& repo);
pldm::responder::pdr_utils::Repo& repo,
pldm_entity_association_tree* bmcEntityTree);

/** @brief map of PLDM event type to EventHandlers
*
Expand Down Expand Up @@ -499,6 +504,7 @@ class Handler : public CmdHandler
HostPDRHandler* hostPDRHandler;
pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
fru::Handler* fruHandler;
pldm_entity_association_tree* bmcEntityTree;
const pldm::utils::DBusHandler* dBusIntf;
pldm::responder::oem_platform::Handler* oemPlatformHandler;
pldm::responder::platform_config::Handler* platformConfigHandler;
Expand All @@ -521,6 +527,7 @@ class Handler : public CmdHandler
* @param[out] entityType - entity type
* @param[out] entityInstance - entity instance number
* @param[out] stateSetId - state set id
* @param[out] containerId - container id
*
* @return true if the sensor is OEM. All out parameters are invalid
* for a non OEM sensor
Expand Down
8 changes: 4 additions & 4 deletions libpldmresponder/test/libpldmresponder_pdr_effecter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(GeneratePDRByStateEffecter, testGoodJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_effecter/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);

Expand Down Expand Up @@ -133,7 +133,7 @@ TEST(GeneratePDRByNumericEffecter, testGoodJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_effecter/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_NUMERIC_EFFECTER_PDR);

Expand Down Expand Up @@ -181,7 +181,7 @@ TEST(GeneratePDR, testMalformedJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_effecter/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR);

Expand All @@ -204,7 +204,7 @@ TEST(findStateEffecterId, goodJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_effecter/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
uint16_t entityType = 33;
uint16_t entityInstance = 0;
uint16_t containerId = 0;
Expand Down
4 changes: 2 additions & 2 deletions libpldmresponder/test/libpldmresponder_pdr_sensor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(GeneratePDRByStateSensor, testGoodJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_sensor/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
Expand Down Expand Up @@ -88,7 +88,7 @@ TEST(GeneratePDR, testMalformedJson)
auto event = sdeventplus::Event::get_default();
Handler handler(&mockedUtils, 0, nullptr, "./pdr_jsons/state_sensor/good",
inPDRRepo, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, event);
nullptr, nullptr, event);
handler.getPDR(req, requestPayloadLength);
Repo inRepo(inPDRRepo);
getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR);
Expand Down
Loading