Ben Pai | 44cee31 | 2020-03-16 15:24:46 +0800 | [diff] [blame^] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "wistronoem.hpp" |
| 4 | |
| 5 | #include "smbus.hpp" |
| 6 | |
| 7 | #include <endian.h> |
| 8 | #include <ipmid/api.h> |
| 9 | #include <stdio.h> |
| 10 | #include <string.h> |
| 11 | #include <systemd/sd-bus.h> |
| 12 | |
| 13 | #include <fstream> |
| 14 | #include <functional> |
| 15 | #include <iostream> |
| 16 | #include <ipmid-host/cmd.hpp> |
| 17 | #include <memory> |
| 18 | #include <sdbusplus/bus.hpp> |
| 19 | #include <sdbusplus/exception.hpp> |
| 20 | |
| 21 | #include "i2c.h" |
| 22 | |
| 23 | #define SWITCH_SLAVE_ADDRESS 112 /* Hexadecimal value:0x70 */ |
| 24 | #define RISERF_SLAVE_ADDRESS 16 /* Hexadecimal value:0x10 */ |
| 25 | |
| 26 | void register_detect_riserf() __attribute__((constructor)); |
| 27 | |
| 28 | ipmi_ret_t ipmi_wistron_detect_riserf(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 29 | ipmi_request_t request, |
| 30 | ipmi_response_t response, |
| 31 | ipmi_data_len_t data_len, |
| 32 | ipmi_context_t context) |
| 33 | { |
| 34 | phosphor::smbus::Smbus smbus; |
| 35 | |
| 36 | auto init_cp0 = smbus.smbusInit(9); |
| 37 | if (init_cp0 == initError) |
| 38 | { |
| 39 | std::cerr << "smbusInit fail!" |
| 40 | << "\n"; |
| 41 | return false; |
| 42 | } |
| 43 | smbus.SetSmbusCmdByte(9, SWITCH_SLAVE_ADDRESS, 0, 8); |
| 44 | auto res_cp0 = smbus.GetSmbusCmdByte(9, RISERF_SLAVE_ADDRESS, command); |
| 45 | |
| 46 | auto init_cp1 = smbus.smbusInit(10); |
| 47 | if (init_cp1 == initError) |
| 48 | { |
| 49 | std::cerr << "smbusInit fail!" |
| 50 | << "\n"; |
| 51 | return false; |
| 52 | } |
| 53 | smbus.SetSmbusCmdByte(10, SWITCH_SLAVE_ADDRESS, 0, 8); |
| 54 | auto res_cp1 = smbus.GetSmbusCmdByte(10, RISERF_SLAVE_ADDRESS, command); |
| 55 | |
| 56 | // CPU0 & CPU1 are not present. |
| 57 | if (res_cp0 < 0 && res_cp1 < 0) |
| 58 | { |
| 59 | *data_len = sizeof(a); |
| 60 | memcpy(response, &a, *data_len); |
| 61 | } |
| 62 | |
| 63 | // CPU0 isn't present but CPU1 is present. |
| 64 | if (res_cp0 < 0 && res_cp1 >= 0) |
| 65 | { |
| 66 | *data_len = sizeof(b); |
| 67 | memcpy(response, &b, *data_len); |
| 68 | } |
| 69 | |
| 70 | // CPU0 is present but CPU1 isn't present. |
| 71 | if (res_cp0 >= 0 && res_cp1 < 0) |
| 72 | { |
| 73 | *data_len = sizeof(c); |
| 74 | memcpy(response, &c, *data_len); |
| 75 | } |
| 76 | |
| 77 | // CPU0 & CPU1 are present. |
| 78 | if (res_cp0 >= 0 && res_cp1 >= 0) |
| 79 | { |
| 80 | *data_len = sizeof(d); |
| 81 | memcpy(response, &d, *data_len); |
| 82 | } |
| 83 | |
| 84 | smbus.smbusClose(9); |
| 85 | smbus.smbusClose(10); |
| 86 | |
| 87 | return IPMI_CC_OK; |
| 88 | } |
| 89 | |
| 90 | void register_detect_riserf() |
| 91 | { |
| 92 | ipmi_register_callback(NETFUN_OEM, IPMI_CMD_DETECT_RISERF, NULL, |
| 93 | ipmi_wistron_detect_riserf, SYSTEM_INTERFACE); |
| 94 | } |