coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ipmi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <console/console.h>
7 #include <drivers/vpd/vpd.h>
8 
9 #include "ipmi.h"
10 #include "vpd.h"
11 
12 enum cb_err ipmi_get_pcie_config(uint8_t *pcie_config)
13 {
14  int ret;
15  struct ipmi_config_rsp {
16  struct ipmi_rsp resp;
18  } __packed;
19  struct ipmi_config_rsp rsp;
20 
21  ret = ipmi_kcs_message(CONFIG_BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0,
22  IPMI_OEM_GET_PCIE_CONFIG, NULL, 0, (unsigned char *) &rsp,
23  sizeof(rsp));
24 
25  if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
26  printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
27  __func__, ret, rsp.resp.completion_code);
28  return CB_ERR;
29  }
30  *pcie_config = rsp.config;
31 
32  return CB_SUCCESS;
33 }
34 
35 enum cb_err ipmi_get_slot_id(uint8_t *slot_id)
36 {
37  int ret;
38  struct ipmi_config_rsp {
39  struct ipmi_rsp resp;
41  uint8_t board_rev_id;
42  uint8_t slot_id;
43  uint8_t slot_config_id;
44  } __packed;
45  struct ipmi_config_rsp rsp;
46 
47  ret = ipmi_kcs_message(CONFIG_BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, IPMI_OEM_GET_BOARD_ID,
48  NULL, 0, (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 (ret=%d resp=0x%x)\n",
52  __func__, ret, rsp.resp.completion_code);
53  return CB_ERR;
54  }
55  *slot_id = rsp.slot_id;
56 
57  return CB_SUCCESS;
58 }
59 
60 void init_frb2_wdt(void)
61 {
62  uint8_t enable;
63  int action, countdown;
64 
65  if (vpd_get_bool(FRB2_TIMER, VPD_RW_THEN_RO, &enable)) {
66  printk(BIOS_DEBUG, "Got VPD %s value: %d\n", FRB2_TIMER, enable);
67  } else {
68  printk(BIOS_INFO, "Not able to get VPD %s, default set to %d\n", FRB2_TIMER,
70  enable = FRB2_TIMER_DEFAULT;
71  }
72 
73  if (enable) {
74  if (vpd_get_int(FRB2_COUNTDOWN, VPD_RW_THEN_RO, &countdown)) {
75  printk(BIOS_DEBUG, "FRB2 timer countdown set to: %d ms\n",
76  countdown * 100);
77  } else {
78  printk(BIOS_DEBUG, "FRB2 timer use default value: %d ms\n",
80  countdown = FRB2_COUNTDOWN_DEFAULT;
81  }
82 
83  if (vpd_get_int(FRB2_ACTION, VPD_RW_THEN_RO, &action)) {
84  printk(BIOS_DEBUG, "FRB2 timer action set to: %d\n", action);
85  } else {
86  printk(BIOS_DEBUG, "FRB2 timer action use default value: %d\n",
88  action = FRB2_ACTION_DEFAULT;
89  }
90  ipmi_init_and_start_bmc_wdt(CONFIG_BMC_KCS_BASE, (uint16_t)countdown,
91  (uint8_t)action);
92  } else {
93  printk(BIOS_DEBUG, "Disable FRB2 timer\n");
94  ipmi_stop_bmc_wdt(CONFIG_BMC_KCS_BASE);
95  }
96 }
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
void init_frb2_wdt(void)
Definition: ipmi.c:60
enum cb_err ipmi_get_pcie_config(uint8_t *pcie_config)
Definition: ipmi.c:12
enum cb_err ipmi_get_slot_id(uint8_t *slot_id)
Definition: ipmi.c:35
#define IPMI_OEM_GET_PCIE_CONFIG
Definition: ipmi.h:8
#define IPMI_OEM_GET_BOARD_ID
Definition: ipmi.h:9
@ VPD_RW_THEN_RO
Definition: vpd.h:14
static uint8_t board_sku_id(void)
Definition: mainboard.c:53
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_NETFN_OEM
Definition: ipmi_ocp.h:8
enum cb_err ipmi_init_and_start_bmc_wdt(const int port, uint16_t countdown, uint8_t action)
Definition: ipmi_ops.c:8
enum cb_err ipmi_stop_bmc_wdt(const int port)
Definition: ipmi_ops.c:51
#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
enum board_config config
Definition: memory.c:448
#define FRB2_COUNTDOWN
Definition: vpd.h:11
#define FRB2_TIMER_DEFAULT
Definition: vpd.h:8
#define FRB2_ACTION
Definition: vpd.h:17
#define FRB2_COUNTDOWN_DEFAULT
Definition: vpd.h:13
#define FRB2_TIMER
Definition: vpd.h:7
#define FRB2_ACTION_DEFAULT
Definition: vpd.h:18
#define NULL
Definition: stddef.h:19
unsigned short uint16_t
Definition: stdint.h:11
unsigned char uint8_t
Definition: stdint.h:8
bool vpd_get_int(const char *const key, const enum vpd_region region, int *const val)
Definition: vpd.c:284
bool vpd_get_bool(const char *key, enum vpd_region region, uint8_t *val)
Definition: vpd.c:252