blob: e75edca6593aa8210e932fbb335df8eb73df8ccf [file] [log] [blame]
Tim Chu1343bc32020-07-28 04:27:35 -07001/* 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>
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030013#include <drivers/ipmi/ipmi_if.h>
Johnny Lin3acea5c2021-01-08 15:24:25 +080014#include <drivers/ocp/dmi/ocp_dmi.h>
Marc Jones882a5682020-10-02 20:31:23 -060015#include <types.h>
16
Tim Chu1343bc32020-07-28 04:27:35 -070017#include "ipmi_ocp.h"
18
Johnny Lin3acea5c2021-01-08 15:24:25 +080019static 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 }
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030031 ret = ipmi_message(dev->path.pnp.port, IPMI_NETFN_OEM, 0x0, IPMI_OEM_SET_PPIN,
Elyes Haouas1ef547e2022-11-18 15:05:39 +010032 (const unsigned char *)&req, sizeof(req),
33 (unsigned char *)&rsp, sizeof(rsp));
Johnny Lin3acea5c2021-01-08 15:24:25 +080034
35 if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) {
36 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
37 __func__, ret, rsp.completion_code);
38 return CB_ERR;
39 }
40 printk(BIOS_DEBUG, "IPMI: %s command success\n", __func__);
41 return CB_SUCCESS;
42}
43
Tim Chu1343bc32020-07-28 04:27:35 -070044static void ipmi_ocp_init(struct device *dev)
45{
46 /* Add OCP specific IPMI command */
47}
48
49static void ipmi_ocp_final(struct device *dev)
50{
51 /* Add OCP specific IPMI command */
Tim Chu6b297c02020-06-08 22:52:58 -070052
Johnny Lin3acea5c2021-01-08 15:24:25 +080053 if (CONFIG(OCP_DMI))
54 ipmi_set_ppin(dev);
Tim Chu1343bc32020-07-28 04:27:35 -070055}
56
57static void ipmi_set_resources(struct device *dev)
58{
59 struct resource *res;
60
61 for (res = dev->resource_list; res; res = res->next) {
62 if (!(res->flags & IORESOURCE_ASSIGNED))
63 continue;
64
65 res->flags |= IORESOURCE_STORED;
66 report_resource_stored(dev, res, "");
67 }
68}
69
70static void ipmi_read_resources(struct device *dev)
71{
72 struct resource *res = new_resource(dev, 0);
73 res->base = dev->path.pnp.port;
74 res->size = 2;
75 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
76}
77
78static struct device_operations ops = {
79 .read_resources = ipmi_read_resources,
80 .set_resources = ipmi_set_resources,
81 .init = ipmi_ocp_init,
82 .final = ipmi_ocp_final,
83};
84
85static void enable_dev(struct device *dev)
86{
87 if (dev->path.type != DEVICE_PATH_PNP)
88 printk(BIOS_ERR, "%s: Unsupported device type\n",
89 dev_path(dev));
90 else if (dev->path.pnp.port & 1)
91 printk(BIOS_ERR, "%s: Base address needs to be aligned to 2\n",
92 dev_path(dev));
93 else
94 dev->ops = &ops;
95}
96
97struct chip_operations drivers_ipmi_ocp_ops = {
98 CHIP_NAME("IPMI OCP")
99 .enable_dev = enable_dev,
100};