Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | cddd600 | 2019-09-23 17:38:27 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 4 | * Place in devicetree.cb: |
| 5 | * |
| 6 | * chip drivers/ipmi |
| 7 | * device pnp ca2.0 on end # IPMI KCS |
| 8 | * end |
| 9 | */ |
| 10 | |
Elyes HAOUAS | 92f46aa | 2020-09-15 08:42:17 +0200 | [diff] [blame] | 11 | #include <arch/io.h> |
Michael Niewöhner | 548a3dc | 2020-11-24 12:45:07 +0100 | [diff] [blame] | 12 | #include <bootstate.h> |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 13 | #include <console/console.h> |
| 14 | #include <device/device.h> |
Michael Niewöhner | 31830d3 | 2020-11-23 13:24:40 +0100 | [diff] [blame] | 15 | #include <device/gpio.h> |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 16 | #include <device/pnp.h> |
| 17 | #if CONFIG(HAVE_ACPI_TABLES) |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 18 | #include <acpi/acpi.h> |
| 19 | #include <acpi/acpigen.h> |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 20 | #endif |
| 21 | #if CONFIG(GENERATE_SMBIOS_TABLES) |
| 22 | #include <smbios.h> |
| 23 | #endif |
| 24 | #include <version.h> |
| 25 | #include <delay.h> |
Patrick Rudolph | 3d41a13 | 2019-07-22 16:31:35 +0200 | [diff] [blame] | 26 | #include <timer.h> |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 27 | #include "ipmi_kcs.h" |
Patrick Rudolph | 09cdeba | 2019-12-30 14:40:04 +0100 | [diff] [blame] | 28 | #include "ipmi_supermicro_oem.h" |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 29 | #include "chip.h" |
| 30 | |
| 31 | /* 4 bit encoding */ |
| 32 | static u8 ipmi_revision_major = 0x1; |
| 33 | static u8 ipmi_revision_minor = 0x0; |
| 34 | |
Tim Chu | 278ad21 | 2020-10-06 01:40:53 -0700 | [diff] [blame] | 35 | static u8 bmc_revision_major = 0x0; |
| 36 | static u8 bmc_revision_minor = 0x0; |
| 37 | |
Michael Niewöhner | 548a3dc | 2020-11-24 12:45:07 +0100 | [diff] [blame] | 38 | static struct boot_state_callback bscb_post_complete; |
| 39 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 40 | static int ipmi_get_device_id(struct device *dev, struct ipmi_devid_rsp *rsp) |
| 41 | { |
| 42 | int ret; |
| 43 | |
| 44 | ret = ipmi_kcs_message(dev->path.pnp.port, IPMI_NETFN_APPLICATION, 0, |
| 45 | IPMI_BMC_GET_DEVICE_ID, NULL, 0, (u8 *)rsp, |
| 46 | sizeof(*rsp)); |
| 47 | if (ret < sizeof(struct ipmi_rsp) || rsp->resp.completion_code) { |
| 48 | printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", |
| 49 | __func__, ret, rsp->resp.completion_code); |
| 50 | return 1; |
| 51 | } |
| 52 | if (ret != sizeof(*rsp)) { |
| 53 | printk(BIOS_ERR, "IPMI: %s response truncated\n", __func__); |
| 54 | return 1; |
| 55 | } |
| 56 | return 0; |
| 57 | } |
| 58 | |
Morgan Jang | 5015502 | 2019-11-06 10:24:47 +0800 | [diff] [blame] | 59 | static int ipmi_get_bmc_self_test_result(struct device *dev, struct ipmi_selftest_rsp *rsp) |
| 60 | { |
| 61 | int ret; |
| 62 | |
| 63 | ret = ipmi_kcs_message(dev->path.pnp.port, IPMI_NETFN_APPLICATION, 0, |
| 64 | IPMI_BMC_GET_SELFTEST_RESULTS, NULL, 0, (u8 *)rsp, |
| 65 | sizeof(*rsp)); |
| 66 | |
| 67 | if (ret < sizeof(struct ipmi_rsp) || rsp->resp.completion_code) { |
| 68 | printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", |
| 69 | __func__, ret, rsp->resp.completion_code); |
| 70 | return 1; |
| 71 | } |
| 72 | if (ret != sizeof(*rsp)) { |
| 73 | printk(BIOS_ERR, "IPMI: %s response truncated\n", __func__); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Michael Niewöhner | 548a3dc | 2020-11-24 12:45:07 +0100 | [diff] [blame] | 80 | static void bmc_set_post_complete_gpio_callback(void *arg) |
| 81 | { |
| 82 | struct drivers_ipmi_config *conf = arg; |
| 83 | const struct gpio_operations *gpio_ops; |
| 84 | |
| 85 | if (!conf || !conf->post_complete_gpio) |
| 86 | return; |
| 87 | |
| 88 | gpio_ops = dev_get_gpio_ops(conf->gpio_dev); |
| 89 | if (!gpio_ops) { |
| 90 | printk(BIOS_WARNING, "IPMI: specified gpio device is missing gpio ops!\n"); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | /* Set POST Complete pin. The `invert` field controls the polarity. */ |
| 95 | gpio_ops->output(conf->post_complete_gpio, conf->post_complete_invert ^ 1); |
| 96 | |
| 97 | printk(BIOS_DEBUG, "BMC: POST complete gpio set\n"); |
| 98 | } |
| 99 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 100 | static void ipmi_kcs_init(struct device *dev) |
| 101 | { |
| 102 | struct ipmi_devid_rsp rsp; |
| 103 | uint32_t man_id = 0, prod_id = 0; |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 104 | struct drivers_ipmi_config *conf = dev->chip_info; |
Michael Niewöhner | 31830d3 | 2020-11-23 13:24:40 +0100 | [diff] [blame] | 105 | const struct gpio_operations *gpio_ops; |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 106 | struct ipmi_selftest_rsp selftestrsp = {0}; |
Morgan Jang | 5015502 | 2019-11-06 10:24:47 +0800 | [diff] [blame] | 107 | uint8_t retry_count; |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 108 | |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 109 | if (!conf) { |
| 110 | printk(BIOS_WARNING, "IPMI: chip_info is missing! Skip init.\n"); |
| 111 | return; |
| 112 | } |
Patrick Rudolph | 3d41a13 | 2019-07-22 16:31:35 +0200 | [diff] [blame] | 113 | |
Michael Niewöhner | 31830d3 | 2020-11-23 13:24:40 +0100 | [diff] [blame] | 114 | if (conf->bmc_jumper_gpio) { |
| 115 | gpio_ops = dev_get_gpio_ops(conf->gpio_dev); |
| 116 | if (!gpio_ops) { |
| 117 | printk(BIOS_WARNING, "IPMI: gpio device is missing gpio ops!\n"); |
| 118 | } else { |
| 119 | /* Get jumper value and set device state accordingly */ |
| 120 | dev->enabled = gpio_ops->get(conf->bmc_jumper_gpio); |
| 121 | if (!dev->enabled) |
| 122 | printk(BIOS_INFO, "IPMI: Disabled by jumper\n"); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (!dev->enabled) |
| 127 | return; |
| 128 | |
| 129 | printk(BIOS_DEBUG, "IPMI: PNP KCS 0x%x\n", dev->path.pnp.port); |
| 130 | |
Michael Niewöhner | 548a3dc | 2020-11-24 12:45:07 +0100 | [diff] [blame] | 131 | /* Set up boot state callback for POST_COMPLETE# */ |
| 132 | if (conf->post_complete_gpio) { |
| 133 | bscb_post_complete.callback = bmc_set_post_complete_gpio_callback; |
| 134 | bscb_post_complete.arg = conf; |
| 135 | boot_state_sched_on_entry(&bscb_post_complete, BS_PAYLOAD_BOOT); |
| 136 | } |
| 137 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 138 | /* Get IPMI version for ACPI and SMBIOS */ |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 139 | if (conf->wait_for_bmc && conf->bmc_boot_timeout) { |
Patrick Rudolph | 3d41a13 | 2019-07-22 16:31:35 +0200 | [diff] [blame] | 140 | struct stopwatch sw; |
| 141 | stopwatch_init_msecs_expire(&sw, conf->bmc_boot_timeout * 1000); |
Paul Menzel | 01c1815 | 2020-06-02 11:12:30 +0200 | [diff] [blame] | 142 | printk(BIOS_INFO, "IPMI: Waiting for BMC...\n"); |
Patrick Rudolph | 3d41a13 | 2019-07-22 16:31:35 +0200 | [diff] [blame] | 143 | |
| 144 | while (!stopwatch_expired(&sw)) { |
| 145 | if (inb(dev->path.pnp.port) != 0xff) |
| 146 | break; |
| 147 | mdelay(100); |
| 148 | } |
| 149 | if (stopwatch_expired(&sw)) { |
| 150 | printk(BIOS_INFO, "IPMI: Waiting for BMC timed out\n"); |
| 151 | /* Don't write tables if communication failed */ |
| 152 | dev->enabled = 0; |
| 153 | return; |
| 154 | } |
| 155 | } |
| 156 | |
Morgan Jang | 5015502 | 2019-11-06 10:24:47 +0800 | [diff] [blame] | 157 | printk(BIOS_INFO, "Get BMC self test result..."); |
| 158 | for (retry_count = 0; retry_count < conf->bmc_boot_timeout; retry_count++) { |
| 159 | if (!ipmi_get_bmc_self_test_result(dev, &selftestrsp)) |
| 160 | break; |
| 161 | |
| 162 | mdelay(1000); |
| 163 | } |
| 164 | |
| 165 | switch (selftestrsp.result) { |
| 166 | case IPMI_APP_SELFTEST_NO_ERROR: /* 0x55 */ |
| 167 | printk(BIOS_DEBUG, "No Error\n"); |
| 168 | break; |
| 169 | case IPMI_APP_SELFTEST_NOT_IMPLEMENTED: /* 0x56 */ |
| 170 | printk(BIOS_DEBUG, "Function Not Implemented\n"); |
| 171 | break; |
| 172 | case IPMI_APP_SELFTEST_ERROR: /* 0x57 */ |
| 173 | printk(BIOS_ERR, "BMC: Corrupted or inaccessible data or device\n"); |
| 174 | /* Don't write tables if communication failed */ |
| 175 | dev->enabled = 0; |
| 176 | break; |
| 177 | case IPMI_APP_SELFTEST_FATAL_HW_ERROR: /* 0x58 */ |
| 178 | printk(BIOS_ERR, "BMC: Fatal Hardware Error\n"); |
| 179 | /* Don't write tables if communication failed */ |
| 180 | dev->enabled = 0; |
| 181 | break; |
| 182 | case IPMI_APP_SELFTEST_RESERVED: /* 0xFF */ |
| 183 | printk(BIOS_DEBUG, "Reserved\n"); |
| 184 | break; |
| 185 | |
| 186 | default: /* Other Device Specific Hardware Error */ |
| 187 | printk(BIOS_ERR, "BMC: Device Specific Error\n"); |
| 188 | /* Don't write tables if communication failed */ |
| 189 | dev->enabled = 0; |
| 190 | break; |
| 191 | } |
| 192 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 193 | if (!ipmi_get_device_id(dev, &rsp)) { |
Patrick Rudolph | 3d41a13 | 2019-07-22 16:31:35 +0200 | [diff] [blame] | 194 | /* Queried the IPMI revision from BMC */ |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 195 | ipmi_revision_minor = IPMI_IPMI_VERSION_MINOR(rsp.ipmi_version); |
| 196 | ipmi_revision_major = IPMI_IPMI_VERSION_MAJOR(rsp.ipmi_version); |
| 197 | |
Tim Chu | 278ad21 | 2020-10-06 01:40:53 -0700 | [diff] [blame] | 198 | bmc_revision_major = rsp.fw_rev1; |
| 199 | bmc_revision_minor = rsp.fw_rev2; |
| 200 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 201 | memcpy(&man_id, rsp.manufacturer_id, |
| 202 | sizeof(rsp.manufacturer_id)); |
| 203 | |
| 204 | memcpy(&prod_id, rsp.product_id, sizeof(rsp.product_id)); |
| 205 | |
| 206 | printk(BIOS_INFO, "IPMI: Found man_id 0x%06x, prod_id 0x%04x\n", |
| 207 | man_id, prod_id); |
| 208 | |
| 209 | printk(BIOS_INFO, "IPMI: Version %01x.%01x\n", |
| 210 | ipmi_revision_major, ipmi_revision_minor); |
| 211 | } else { |
| 212 | /* Don't write tables if communication failed */ |
| 213 | dev->enabled = 0; |
| 214 | } |
Patrick Rudolph | 09cdeba | 2019-12-30 14:40:04 +0100 | [diff] [blame] | 215 | |
| 216 | if (!dev->enabled) |
| 217 | return; |
| 218 | |
| 219 | if (CONFIG(DRIVERS_IPMI_SUPERMICRO_OEM)) |
| 220 | supermicro_ipmi_oem(dev->path.pnp.port); |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | #if CONFIG(HAVE_ACPI_TABLES) |
| 224 | static uint32_t uid_cnt = 0; |
| 225 | |
| 226 | static unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 227 | ipmi_write_acpi_tables(const struct device *dev, unsigned long current, |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 228 | struct acpi_rsdp *rsdp) |
| 229 | { |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 230 | struct drivers_ipmi_config *conf = dev->chip_info; |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 231 | struct acpi_spmi *spmi; |
| 232 | s8 gpe_interrupt = -1; |
| 233 | u32 apic_interrupt = 0; |
| 234 | acpi_addr_t addr = { |
| 235 | .space_id = ACPI_ADDRESS_SPACE_IO, |
| 236 | .access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS, |
| 237 | .addrl = dev->path.pnp.port, |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 238 | .bit_width = 8, |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 241 | switch (CONFIG_IPMI_KCS_REGISTER_SPACING) { |
| 242 | case 4: |
| 243 | addr.bit_offset = 32; |
| 244 | break; |
| 245 | case 16: |
| 246 | addr.bit_offset = 128; |
| 247 | break; |
| 248 | default: |
| 249 | printk(BIOS_ERR, "IPMI: Unsupported register spacing for SPMI\n"); |
| 250 | /* fall through */ |
| 251 | case 1: |
| 252 | addr.bit_offset = 8; |
| 253 | break; |
| 254 | } |
| 255 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 256 | current = ALIGN_UP(current, 8); |
| 257 | printk(BIOS_DEBUG, "ACPI: * SPMI at %lx\n", current); |
| 258 | spmi = (struct acpi_spmi *)current; |
| 259 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 260 | if (conf) { |
| 261 | if (conf->have_gpe) |
| 262 | gpe_interrupt = conf->gpe_interrupt; |
| 263 | if (conf->have_apic) |
| 264 | apic_interrupt = conf->apic_interrupt; |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 265 | |
| 266 | /* Use command to get UID from ipmi_ssdt */ |
| 267 | acpi_create_ipmi(dev, spmi, (ipmi_revision_major << 8) | |
| 268 | (ipmi_revision_minor << 4), &addr, |
| 269 | IPMI_INTERFACE_KCS, gpe_interrupt, apic_interrupt, |
| 270 | conf->uid); |
| 271 | |
| 272 | acpi_add_table(rsdp, spmi); |
| 273 | |
| 274 | current += spmi->header.length; |
| 275 | } else { |
| 276 | printk(BIOS_WARNING, "IPMI: chip_info is missing!\n"); |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 279 | return current; |
| 280 | } |
| 281 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 282 | static void ipmi_ssdt(const struct device *dev) |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 283 | { |
| 284 | const char *scope = acpi_device_scope(dev); |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 285 | struct drivers_ipmi_config *conf = dev->chip_info; |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 286 | |
| 287 | if (!scope) { |
| 288 | printk(BIOS_ERR, "IPMI: Missing ACPI scope for %s\n", |
| 289 | dev_path(dev)); |
| 290 | return; |
| 291 | } |
| 292 | |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 293 | if (!conf) { |
| 294 | printk(BIOS_WARNING, "IPMI: chip_info is missing!\n"); |
| 295 | return; |
| 296 | } |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 297 | |
| 298 | /* Use command to pass UID to ipmi_write_acpi_tables */ |
Furquan Shaikh | 0f6e652 | 2020-04-24 21:35:23 -0700 | [diff] [blame] | 299 | conf->uid = uid_cnt++; |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 300 | |
| 301 | /* write SPMI device */ |
| 302 | acpigen_write_scope(scope); |
| 303 | acpigen_write_device("SPMI"); |
| 304 | acpigen_write_name_string("_HID", "IPI0001"); |
Patrick Rudolph | 389c827 | 2019-12-17 13:54:41 +0100 | [diff] [blame] | 305 | acpigen_write_name_unicode("_STR", "IPMI_KCS"); |
Furquan Shaikh | 0f6e652 | 2020-04-24 21:35:23 -0700 | [diff] [blame] | 306 | acpigen_write_name_byte("_UID", conf->uid); |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 307 | acpigen_write_STA(0xf); |
| 308 | acpigen_write_name("_CRS"); |
| 309 | acpigen_write_resourcetemplate_header(); |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 310 | acpigen_write_io16(dev->path.pnp.port, dev->path.pnp.port, 1, 1, 1); |
| 311 | acpigen_write_io16(dev->path.pnp.port + CONFIG_IPMI_KCS_REGISTER_SPACING, |
| 312 | dev->path.pnp.port + CONFIG_IPMI_KCS_REGISTER_SPACING, 1, 1, 1); |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 313 | |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 314 | // FIXME: is that correct? |
| 315 | if (conf->have_apic) |
| 316 | acpigen_write_irq(1 << conf->apic_interrupt); |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 317 | |
| 318 | acpigen_write_resourcetemplate_footer(); |
| 319 | |
| 320 | acpigen_write_method("_IFT", 0); |
| 321 | acpigen_write_return_byte(1); // KCS |
| 322 | acpigen_pop_len(); |
| 323 | |
| 324 | acpigen_write_method("_SRV", 0); |
| 325 | acpigen_write_return_integer((ipmi_revision_major << 8) | |
| 326 | (ipmi_revision_minor << 4)); |
| 327 | acpigen_pop_len(); |
| 328 | |
| 329 | acpigen_pop_len(); /* pop device */ |
| 330 | acpigen_pop_len(); /* pop scope */ |
| 331 | } |
| 332 | #endif |
| 333 | |
Tim Chu | 278ad21 | 2020-10-06 01:40:53 -0700 | [diff] [blame] | 334 | void ipmi_bmc_version(uint8_t *ipmi_bmc_major_revision, uint8_t *ipmi_bmc_minor_revision) |
| 335 | { |
| 336 | if (!bmc_revision_major || !bmc_revision_minor) { |
| 337 | printk(BIOS_ERR, "IPMI: BMC revision missing\n"); |
| 338 | *ipmi_bmc_major_revision = 0; |
| 339 | *ipmi_bmc_minor_revision = 0; |
| 340 | } else { |
| 341 | *ipmi_bmc_major_revision = bmc_revision_major; |
| 342 | *ipmi_bmc_minor_revision = bmc_revision_minor; |
| 343 | } |
| 344 | } |
| 345 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 346 | #if CONFIG(GENERATE_SMBIOS_TABLES) |
| 347 | static int ipmi_smbios_data(struct device *dev, int *handle, |
| 348 | unsigned long *current) |
| 349 | { |
Bill XIE | f880eb0 | 2020-11-10 15:20:24 +0800 | [diff] [blame] | 350 | struct drivers_ipmi_config *conf = dev->chip_info; |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 351 | u8 nv_storage = 0xff; |
| 352 | u8 i2c_address = 0; |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 353 | u8 register_spacing; |
| 354 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 355 | int len = 0; |
| 356 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 357 | if (conf) { |
| 358 | if (conf->have_nv_storage) |
| 359 | nv_storage = conf->nv_storage_device_address; |
| 360 | i2c_address = conf->bmc_i2c_address; |
| 361 | } |
| 362 | |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 363 | switch (CONFIG_IPMI_KCS_REGISTER_SPACING) { |
| 364 | case 4: |
| 365 | register_spacing = 1 << 6; |
| 366 | break; |
| 367 | case 16: |
| 368 | register_spacing = 2 << 6; |
| 369 | break; |
| 370 | default: |
| 371 | printk(BIOS_ERR, "IPMI: Unsupported register spacing for SMBIOS\n"); |
| 372 | /* fall through */ |
| 373 | case 1: |
| 374 | register_spacing = 0 << 6; |
| 375 | break; |
| 376 | } |
| 377 | |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 378 | // add IPMI Device Information |
| 379 | len += smbios_write_type38( |
| 380 | current, handle, |
| 381 | SMBIOS_BMC_INTERFACE_KCS, |
| 382 | ipmi_revision_minor | (ipmi_revision_major << 4), |
| 383 | i2c_address, // I2C address |
| 384 | nv_storage, // NV storage |
| 385 | dev->path.pnp.port | 1, // IO interface |
Patrick Rudolph | a96c4a1 | 2019-08-29 19:44:32 +0200 | [diff] [blame] | 386 | register_spacing, |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 387 | 0); // no IRQ |
| 388 | |
| 389 | return len; |
| 390 | } |
| 391 | #endif |
| 392 | |
| 393 | static void ipmi_set_resources(struct device *dev) |
| 394 | { |
| 395 | struct resource *res; |
| 396 | |
| 397 | for (res = dev->resource_list; res; res = res->next) { |
| 398 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
| 399 | continue; |
| 400 | |
| 401 | res->flags |= IORESOURCE_STORED; |
| 402 | report_resource_stored(dev, res, ""); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | static void ipmi_read_resources(struct device *dev) |
| 407 | { |
| 408 | struct resource *res = new_resource(dev, 0); |
| 409 | res->base = dev->path.pnp.port; |
| 410 | res->size = 2; |
| 411 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 412 | } |
| 413 | |
| 414 | static struct device_operations ops = { |
| 415 | .read_resources = ipmi_read_resources, |
| 416 | .set_resources = ipmi_set_resources, |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 417 | .init = ipmi_kcs_init, |
| 418 | #if CONFIG(HAVE_ACPI_TABLES) |
| 419 | .write_acpi_tables = ipmi_write_acpi_tables, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 420 | .acpi_fill_ssdt = ipmi_ssdt, |
Patrick Rudolph | ffbc3b5 | 2019-06-06 15:45:51 +0200 | [diff] [blame] | 421 | #endif |
| 422 | #if CONFIG(GENERATE_SMBIOS_TABLES) |
| 423 | .get_smbios_data = ipmi_smbios_data, |
| 424 | #endif |
| 425 | }; |
| 426 | |
| 427 | static void enable_dev(struct device *dev) |
| 428 | { |
| 429 | if (dev->path.type != DEVICE_PATH_PNP) |
| 430 | printk(BIOS_ERR, "%s: Unsupported device type\n", |
| 431 | dev_path(dev)); |
| 432 | else if (dev->path.pnp.port & 1) |
| 433 | printk(BIOS_ERR, "%s: Base address needs to be aligned to 2\n", |
| 434 | dev_path(dev)); |
| 435 | else |
| 436 | dev->ops = &ops; |
| 437 | } |
| 438 | |
| 439 | struct chip_operations drivers_ipmi_ops = { |
| 440 | CHIP_NAME("IPMI KCS") |
| 441 | .enable_dev = enable_dev, |
| 442 | }; |