coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ipmi_ocp_romstage.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <console/console.h>
5 
6 #include "ipmi_ocp.h"
7 
8 enum cb_err ipmi_set_post_start(const int port)
9 {
10  int ret;
11  struct ipmi_rsp rsp;
12 
14  IPMI_BMC_SET_POST_START, NULL, 0, (u8 *) &rsp,
15  sizeof(rsp));
16 
17  if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) {
18  printk(BIOS_ERR, "IPMI: %s command failed (ret=%d rsp=0x%x)\n",
19  __func__, ret, rsp.completion_code);
20  return CB_ERR;
21  }
22  if (ret != sizeof(rsp)) {
23  printk(BIOS_ERR, "IPMI: %s response truncated\n", __func__);
24  return CB_ERR;
25  }
26 
27  printk(BIOS_DEBUG, "IPMI BMC POST is started\n");
28  return CB_SUCCESS;
29 }
30 
31 enum cb_err ipmi_set_cmos_clear(void)
32 {
33  int ret;
34 
35  struct ipmi_oem_rsp {
36  struct ipmi_rsp resp;
37  struct boot_order data;
38  } __packed;
39 
40  struct ipmi_oem_rsp rsp;
41  struct boot_order req;
42 
43  /* IPMI OEM get bios boot order command to check if the valid bit and
44  the CMOS clear bit are both set from the response BootMode byte. */
45  ret = ipmi_kcs_message(CONFIG_BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0,
47  NULL, 0,
48  (unsigned char *) &rsp, sizeof(rsp));
49 
50  if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
51  printk(BIOS_ERR, "IPMI: %s command failed (read ret=%d resp=0x%x)\n",
52  __func__, ret, rsp.resp.completion_code);
53  return CB_ERR;
54  }
55 
56  if (!IS_CMOS_AND_VALID_BIT(rsp.data.boot_mode)) {
57  req = rsp.data;
58  SET_CMOS_AND_VALID_BIT(req.boot_mode);
59  ret = ipmi_kcs_message(CONFIG_BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0,
61  (const unsigned char *) &req, sizeof(req),
62  (unsigned char *) &rsp, sizeof(rsp));
63 
64  if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
65  printk(BIOS_ERR, "IPMI: %s command failed (sent ret=%d resp=0x%x)\n",
66  __func__, ret, rsp.resp.completion_code);
67  return CB_ERR;
68  }
69 
70  printk(BIOS_INFO, "IPMI CMOS clear requested because CMOS data is invalid.\n");
71 
72  return CB_SUCCESS;
73  }
74 
75  return CB_SUCCESS;
76 }
cb_err
coreboot error codes
Definition: cb_err.h:15
@ CB_ERR
Generic error code.
Definition: cb_err.h:17
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
#define printk(level,...)
Definition: stdlib.h:16
#define __packed
Definition: compiler.h:10
port
Definition: i915.h:29
int ipmi_kcs_message(int port, int netfn, int lun, int cmd, const unsigned char *inmsg, int inlen, unsigned char *outmsg, int outlen)
Definition: ipmi_kcs.c:222
#define IPMI_BMC_SET_POST_START
Definition: ipmi_ocp.h:10
#define IPMI_OEM_SET_BIOS_BOOT_ORDER
Definition: ipmi_ocp.h:11
#define IS_CMOS_AND_VALID_BIT(x)
Definition: ipmi_ocp.h:18
#define SET_CMOS_AND_VALID_BIT(x)
Definition: ipmi_ocp.h:17
#define IPMI_OEM_GET_BIOS_BOOT_ORDER
Definition: ipmi_ocp.h:12
#define IPMI_NETFN_OEM
Definition: ipmi_ocp.h:8
enum cb_err ipmi_set_post_start(const int port)
enum cb_err ipmi_set_cmos_clear(void)
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define NULL
Definition: stddef.h:19
uint8_t u8
Definition: stdint.h:45
uint8_t completion_code
Definition: ipmi_kcs.h:41