coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ipmi_ocp.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Place in devicetree.cb:
4  *
5  * chip drivers/ipmi/ocp # OCP specific IPMI porting
6  device pnp ca2.1 on end
7  * end
8  */
9 
10 #include <console/console.h>
11 #include <device/device.h>
12 #include <device/pnp.h>
13 #include <drivers/ipmi/ipmi_kcs.h>
15 #include <types.h>
16 
17 #include "ipmi_ocp.h"
18 
19 static enum cb_err ipmi_set_ppin(struct device *dev)
20 {
21  int ret;
22  struct ipmi_rsp rsp;
23  struct ppin_req req = {0};
24 
25  req.cpu0_lo = xeon_sp_ppin[0].lo;
26  req.cpu0_hi = xeon_sp_ppin[0].hi;
27  if (CONFIG_MAX_SOCKET > 1) {
28  req.cpu1_lo = xeon_sp_ppin[1].lo;
29  req.cpu1_hi = xeon_sp_ppin[1].hi;
30  }
32  (const unsigned char *) &req, sizeof(req), (unsigned char *) &rsp, sizeof(rsp));
33 
34  if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) {
35  printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
36  __func__, ret, rsp.completion_code);
37  return CB_ERR;
38  }
39  printk(BIOS_DEBUG, "IPMI: %s command success\n", __func__);
40  return CB_SUCCESS;
41 }
42 
43 static void ipmi_ocp_init(struct device *dev)
44 {
45  /* Add OCP specific IPMI command */
46 }
47 
48 static void ipmi_ocp_final(struct device *dev)
49 {
50  /* Add OCP specific IPMI command */
51 
52  if (CONFIG(OCP_DMI))
53  ipmi_set_ppin(dev);
54 }
55 
56 static void ipmi_set_resources(struct device *dev)
57 {
58  struct resource *res;
59 
60  for (res = dev->resource_list; res; res = res->next) {
61  if (!(res->flags & IORESOURCE_ASSIGNED))
62  continue;
63 
64  res->flags |= IORESOURCE_STORED;
65  report_resource_stored(dev, res, "");
66  }
67 }
68 
69 static void ipmi_read_resources(struct device *dev)
70 {
71  struct resource *res = new_resource(dev, 0);
72  res->base = dev->path.pnp.port;
73  res->size = 2;
75 }
76 
77 static struct device_operations ops = {
79  .set_resources = ipmi_set_resources,
80  .init = ipmi_ocp_init,
81  .final = ipmi_ocp_final,
82 };
83 
84 static void enable_dev(struct device *dev)
85 {
86  if (dev->path.type != DEVICE_PATH_PNP)
87  printk(BIOS_ERR, "%s: Unsupported device type\n",
88  dev_path(dev));
89  else if (dev->path.pnp.port & 1)
90  printk(BIOS_ERR, "%s: Base address needs to be aligned to 2\n",
91  dev_path(dev));
92  else
93  dev->ops = &ops;
94 }
95 
97  CHIP_NAME("IPMI OCP")
98  .enable_dev = enable_dev,
99 };
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
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
void report_resource_stored(struct device *dev, const struct resource *resource, const char *comment)
Print the resource that was just stored.
Definition: device_util.c:508
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
@ CONFIG
Definition: dsi_common.h:201
#define CHIP_NAME(X)
Definition: device.h:32
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
static void enable_dev(struct device *dev)
Definition: ipmi_ocp.c:84
static void ipmi_read_resources(struct device *dev)
Definition: ipmi_ocp.c:69
static struct device_operations ops
Definition: ipmi_ocp.c:77
static void ipmi_ocp_final(struct device *dev)
Definition: ipmi_ocp.c:48
static void ipmi_set_resources(struct device *dev)
Definition: ipmi_ocp.c:56
static enum cb_err ipmi_set_ppin(struct device *dev)
Definition: ipmi_ocp.c:19
static void ipmi_ocp_init(struct device *dev)
Definition: ipmi_ocp.c:43
struct chip_operations drivers_ipmi_ocp_ops
Definition: ipmi_ocp.c:96
#define IPMI_OEM_SET_PPIN
Definition: ipmi_ocp.h:9
#define IPMI_NETFN_OEM
Definition: ipmi_ocp.h:8
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
msr_t xeon_sp_ppin[]
Definition: smbios.c:22
@ DEVICE_PATH_PNP
Definition: path.h:10
#define IORESOURCE_STORED
Definition: resource.h:32
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
#define IORESOURCE_FIXED
Definition: resource.h:36
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pnp_path pnp
Definition: path.h:117
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST struct resource * resource_list
Definition: device.h:134
uint8_t completion_code
Definition: ipmi_kcs.h:41
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
unsigned int port
Definition: path.h:58
uint32_t cpu1_lo
Definition: ipmi_ocp.h:23
uint32_t cpu0_lo
Definition: ipmi_ocp.h:21
uint32_t cpu1_hi
Definition: ipmi_ocp.h:24
uint32_t cpu0_hi
Definition: ipmi_ocp.h:22
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
DEVTREE_CONST struct resource * next
Definition: resource.h:48