Tim Chu | 1343bc3 | 2020-07-28 04:27:35 -0700 | [diff] [blame] | 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> |
Sergii Dmytruk | ef7dd5d | 2021-10-22 01:02:32 +0300 | [diff] [blame] | 13 | #include <drivers/ipmi/ipmi_if.h> |
Johnny Lin | 3acea5c | 2021-01-08 15:24:25 +0800 | [diff] [blame] | 14 | #include <drivers/ocp/dmi/ocp_dmi.h> |
Marc Jones | 882a568 | 2020-10-02 20:31:23 -0600 | [diff] [blame] | 15 | #include <types.h> |
| 16 | |
Tim Chu | 1343bc3 | 2020-07-28 04:27:35 -0700 | [diff] [blame] | 17 | #include "ipmi_ocp.h" |
| 18 | |
Johnny Lin | 3acea5c | 2021-01-08 15:24:25 +0800 | [diff] [blame] | 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 | } |
Sergii Dmytruk | ef7dd5d | 2021-10-22 01:02:32 +0300 | [diff] [blame] | 31 | ret = ipmi_message(dev->path.pnp.port, IPMI_NETFN_OEM, 0x0, IPMI_OEM_SET_PPIN, |
Elyes Haouas | 1ef547e | 2022-11-18 15:05:39 +0100 | [diff] [blame^] | 32 | (const unsigned char *)&req, sizeof(req), |
| 33 | (unsigned char *)&rsp, sizeof(rsp)); |
Johnny Lin | 3acea5c | 2021-01-08 15:24:25 +0800 | [diff] [blame] | 34 | |
| 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 Chu | 1343bc3 | 2020-07-28 04:27:35 -0700 | [diff] [blame] | 44 | static void ipmi_ocp_init(struct device *dev) |
| 45 | { |
| 46 | /* Add OCP specific IPMI command */ |
| 47 | } |
| 48 | |
| 49 | static void ipmi_ocp_final(struct device *dev) |
| 50 | { |
| 51 | /* Add OCP specific IPMI command */ |
Tim Chu | 6b297c0 | 2020-06-08 22:52:58 -0700 | [diff] [blame] | 52 | |
Johnny Lin | 3acea5c | 2021-01-08 15:24:25 +0800 | [diff] [blame] | 53 | if (CONFIG(OCP_DMI)) |
| 54 | ipmi_set_ppin(dev); |
Tim Chu | 1343bc3 | 2020-07-28 04:27:35 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static 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 | |
| 70 | static 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 | |
| 78 | static 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 | |
| 85 | static 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 | |
| 97 | struct chip_operations drivers_ipmi_ocp_ops = { |
| 98 | CHIP_NAME("IPMI OCP") |
| 99 | .enable_dev = enable_dev, |
| 100 | }; |