blob: c7497f05ee67f2d8bd3085254561935fffa3b076 [file] [log] [blame]
Tom Josephbe5eaa12017-07-12 19:54:44 +05301#include "dcmihandler.hpp"
Patrick Williams37af7332016-09-02 21:21:42 -05002#include "host-ipmid/ipmid-api.h"
Tom Josephbe5eaa12017-07-12 19:54:44 +05303#include <phosphor-logging/elog-errors.hpp>
Chris Austen1810bec2015-10-13 12:12:39 -05004#include <stdio.h>
5#include <string.h>
6#include <stdint.h>
Tom Josephbe5eaa12017-07-12 19:54:44 +05307#include "utils.hpp"
8#include "xyz/openbmc_project/Common/error.hpp"
9
10using namespace phosphor::logging;
11using InternalFailure =
12 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Chris Austen1810bec2015-10-13 12:12:39 -050013
14void register_netfn_dcmi_functions() __attribute__((constructor));
15
16
17ipmi_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 Josephbe5eaa12017-07-12 19:54:44 +053040namespace dcmi
41{
42
43void 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
78std::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 Austen1810bec2015-10-13 12:12:39 -0500109
110void register_netfn_dcmi_functions()
111{
Tom05732372016-09-06 17:21:23 +0530112 // <Get Power Limit>
Chris Austen1810bec2015-10-13 12:12:39 -0500113 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_GRPEXT, IPMI_CMD_DCMI_GET_POWER);
Tom05732372016-09-06 17:21:23 +0530114 ipmi_register_callback(NETFUN_GRPEXT, IPMI_CMD_DCMI_GET_POWER, NULL, ipmi_dcmi_get_power_limit,
115 PRIVILEGE_USER);
Chris Austen1810bec2015-10-13 12:12:39 -0500116 return;
117}
Tom05732372016-09-06 17:21:23 +0530118// 956379