acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / ipmi / ipmi_if.c
blob4ff900474175b19e131aaa07f93d3214910311c1
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include "ipmi_if.h"
5 #include <console/console.h>
6 #include <delay.h>
8 #include "chip.h"
10 int ipmi_get_device_id(const struct device *dev, struct ipmi_devid_rsp *rsp)
12 int ret;
14 ret = ipmi_message(dev->path.pnp.port, IPMI_NETFN_APPLICATION, 0,
15 IPMI_BMC_GET_DEVICE_ID, NULL, 0, (u8 *)rsp,
16 sizeof(*rsp));
17 if (ret < sizeof(struct ipmi_rsp) || rsp->resp.completion_code) {
18 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
19 __func__, ret, rsp->resp.completion_code);
20 return 1;
22 if (ret != sizeof(*rsp)) {
23 printk(BIOS_ERR, "IPMI: %s response truncated\n", __func__);
24 return 1;
26 return 0;
29 static int ipmi_get_bmc_self_test_result(const struct device *dev,
30 struct ipmi_selftest_rsp *rsp)
32 int ret;
34 ret = ipmi_message(dev->path.pnp.port, IPMI_NETFN_APPLICATION, 0,
35 IPMI_BMC_GET_SELFTEST_RESULTS, NULL, 0, (u8 *)rsp,
36 sizeof(*rsp));
38 if (ret < sizeof(struct ipmi_rsp) || rsp->resp.completion_code) {
39 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
40 __func__, ret, rsp->resp.completion_code);
41 return 1;
43 if (ret != sizeof(*rsp)) {
44 printk(BIOS_ERR, "IPMI: %s response truncated\n", __func__);
45 return 1;
48 return 0;
51 int ipmi_process_self_test_result(const struct device *dev)
53 int failure = 0;
54 uint8_t retry_count = 0;
55 struct ipmi_selftest_rsp selftestrsp = {0};
57 const struct drivers_ipmi_config *conf = dev->chip_info;
58 uint8_t retry_limit = 0;
60 if (conf && conf->wait_for_bmc)
61 retry_limit = conf->bmc_boot_timeout;
63 if (retry_limit == 0)
64 /* Try to get self-test results at least once */
65 retry_limit = 1;
67 printk(BIOS_INFO, "Get BMC self test result...");
68 for (retry_count = 0; retry_count < retry_limit; retry_count++) {
69 if (!ipmi_get_bmc_self_test_result(dev, &selftestrsp))
70 break;
72 mdelay(1000);
75 switch (selftestrsp.result) {
76 case IPMI_APP_SELFTEST_NO_ERROR: /* 0x55 */
77 printk(BIOS_DEBUG, "No Error\n");
78 break;
79 case IPMI_APP_SELFTEST_NOT_IMPLEMENTED: /* 0x56 */
80 printk(BIOS_DEBUG, "Function Not Implemented\n");
81 break;
82 case IPMI_APP_SELFTEST_ERROR: /* 0x57 */
83 printk(BIOS_ERR, "BMC: Corrupted or inaccessible data or device\n");
84 failure = 1;
85 break;
86 case IPMI_APP_SELFTEST_FATAL_HW_ERROR: /* 0x58 */
87 printk(BIOS_ERR, "BMC: Fatal Hardware Error\n");
88 failure = 1;
89 break;
90 case IPMI_APP_SELFTEST_RESERVED: /* 0xFF */
91 printk(BIOS_DEBUG, "Reserved\n");
92 break;
94 default: /* Other Device Specific Hardware Error */
95 printk(BIOS_ERR, "BMC: Device Specific Error: 0x%02x\n", selftestrsp.result);
96 failure = 1;
97 break;
100 return failure;