Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame^] | 1 | #include "dcmihandler.hpp" |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 2 | #include "host-ipmid/ipmid-api.h" |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame^] | 3 | #include <phosphor-logging/elog-errors.hpp> |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <stdint.h> |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame^] | 7 | #include "utils.hpp" |
| 8 | #include "xyz/openbmc_project/Common/error.hpp" |
| 9 | |
| 10 | using namespace phosphor::logging; |
| 11 | using InternalFailure = |
| 12 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 13 | |
| 14 | void register_netfn_dcmi_functions() __attribute__((constructor)); |
| 15 | |
| 16 | |
| 17 | ipmi_ret_t ipmi_dcmi_get_power_limit(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 18 | ipmi_request_t request, ipmi_response_t response, |
| 19 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 20 | { |
| 21 | ipmi_ret_t rc = IPMI_DCMI_CC_NO_ACTIVE_POWER_LIMIT; |
| 22 | |
| 23 | // dcmi-v1-5-rev-spec.pdf 6.6.2. |
| 24 | // This is good enough for OpenBMC support for OpenPOWER based systems |
| 25 | // TODO research if more is needed |
| 26 | uint8_t data_response[] = { 0xDC, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 28 | 0x00, 0x01}; |
| 29 | |
| 30 | |
| 31 | |
| 32 | printf("IPMI DCMI_GET_POWER_LEVEL\n"); |
| 33 | |
| 34 | memcpy(response, data_response, sizeof(data_response)); |
| 35 | *data_len = sizeof(data_response); |
| 36 | |
| 37 | return rc; |
| 38 | } |
| 39 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame^] | 40 | namespace dcmi |
| 41 | { |
| 42 | |
| 43 | void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree) |
| 44 | { |
| 45 | static constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; |
| 46 | static constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; |
| 47 | static constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper"; |
| 48 | static constexpr auto inventoryRoot = "/xyz/openbmc_project/inventory/"; |
| 49 | |
| 50 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 51 | auto depth = 0; |
| 52 | |
| 53 | auto mapperCall = bus.new_method_call(mapperBusName, |
| 54 | mapperObjPath, |
| 55 | mapperIface, |
| 56 | "GetSubTree"); |
| 57 | |
| 58 | mapperCall.append(inventoryRoot); |
| 59 | mapperCall.append(depth); |
| 60 | mapperCall.append(std::vector<std::string>({dcmi::assetTagIntf})); |
| 61 | |
| 62 | auto mapperReply = bus.call(mapperCall); |
| 63 | if (mapperReply.is_method_error()) |
| 64 | { |
| 65 | log<level::ERR>("Error in mapper call"); |
| 66 | elog<InternalFailure>(); |
| 67 | } |
| 68 | |
| 69 | mapperReply.read(objectTree); |
| 70 | |
| 71 | if (objectTree.empty()) |
| 72 | { |
| 73 | log<level::ERR>("AssetTag property is not populated"); |
| 74 | elog<InternalFailure>(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | std::string readAssetTag() |
| 79 | { |
| 80 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 81 | dcmi::assettag::ObjectTree objectTree; |
| 82 | |
| 83 | // Read the object tree with the inventory root to figure out the object |
| 84 | // that has implemented the Asset tag interface. |
| 85 | readAssetTagObjectTree(objectTree); |
| 86 | |
| 87 | auto method = bus.new_method_call( |
| 88 | (objectTree.begin()->second.begin()->first).c_str(), |
| 89 | (objectTree.begin()->first).c_str(), |
| 90 | dcmi::propIntf, |
| 91 | "Get"); |
| 92 | method.append(dcmi::assetTagIntf); |
| 93 | method.append(dcmi::assetTagProp); |
| 94 | |
| 95 | auto reply = bus.call(method); |
| 96 | if (reply.is_method_error()) |
| 97 | { |
| 98 | log<level::ERR>("Error in reading asset tag"); |
| 99 | elog<InternalFailure>(); |
| 100 | } |
| 101 | |
| 102 | sdbusplus::message::variant<std::string> assetTag; |
| 103 | reply.read(assetTag); |
| 104 | |
| 105 | return assetTag.get<std::string>(); |
| 106 | } |
| 107 | |
| 108 | } // namespace dcmi |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 109 | |
| 110 | void register_netfn_dcmi_functions() |
| 111 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 112 | // <Get Power Limit> |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 113 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_GRPEXT, IPMI_CMD_DCMI_GET_POWER); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 114 | ipmi_register_callback(NETFUN_GRPEXT, IPMI_CMD_DCMI_GET_POWER, NULL, ipmi_dcmi_get_power_limit, |
| 115 | PRIVILEGE_USER); |
Chris Austen | 1810bec | 2015-10-13 12:12:39 -0500 | [diff] [blame] | 116 | return; |
| 117 | } |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 118 | // 956379 |