Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * PowerNV OPAL high level interfaces |
| 3 | * |
| 4 | * Copyright 2011 IBM Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #undef DEBUG |
| 13 | |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/of.h> |
Rob Herring | 26a2056 | 2013-09-26 07:40:04 -0500 | [diff] [blame] | 16 | #include <linux/of_fdt.h> |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 19 | #include <linux/notifier.h> |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 20 | #include <linux/slab.h> |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 21 | #include <linux/kobject.h> |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 22 | #include <asm/opal.h> |
| 23 | #include <asm/firmware.h> |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 24 | #include <asm/mce.h> |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 25 | |
| 26 | #include "powernv.h" |
| 27 | |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 28 | /* /sys/firmware/opal */ |
| 29 | struct kobject *opal_kobj; |
| 30 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 31 | struct opal { |
| 32 | u64 base; |
| 33 | u64 entry; |
| 34 | } opal; |
| 35 | |
| 36 | static struct device_node *opal_node; |
| 37 | static DEFINE_SPINLOCK(opal_write_lock); |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 38 | extern u64 opal_mc_secondary_handler[]; |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 39 | static unsigned int *opal_irqs; |
| 40 | static unsigned int opal_irq_count; |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 41 | static ATOMIC_NOTIFIER_HEAD(opal_notifier_head); |
| 42 | static DEFINE_SPINLOCK(opal_notifier_lock); |
| 43 | static uint64_t last_notified_mask = 0x0ul; |
| 44 | static atomic_t opal_notifier_hold = ATOMIC_INIT(0); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 45 | |
| 46 | int __init early_init_dt_scan_opal(unsigned long node, |
| 47 | const char *uname, int depth, void *data) |
| 48 | { |
| 49 | const void *basep, *entryp; |
| 50 | unsigned long basesz, entrysz; |
| 51 | |
| 52 | if (depth != 1 || strcmp(uname, "ibm,opal") != 0) |
| 53 | return 0; |
| 54 | |
| 55 | basep = of_get_flat_dt_prop(node, "opal-base-address", &basesz); |
| 56 | entryp = of_get_flat_dt_prop(node, "opal-entry-address", &entrysz); |
| 57 | |
| 58 | if (!basep || !entryp) |
| 59 | return 1; |
| 60 | |
| 61 | opal.base = of_read_number(basep, basesz/4); |
| 62 | opal.entry = of_read_number(entryp, entrysz/4); |
| 63 | |
| 64 | pr_debug("OPAL Base = 0x%llx (basep=%p basesz=%ld)\n", |
| 65 | opal.base, basep, basesz); |
| 66 | pr_debug("OPAL Entry = 0x%llx (entryp=%p basesz=%ld)\n", |
| 67 | opal.entry, entryp, entrysz); |
| 68 | |
| 69 | powerpc_firmware_features |= FW_FEATURE_OPAL; |
Benjamin Herrenschmidt | 75b93da | 2013-05-14 15:10:02 +1000 | [diff] [blame] | 70 | if (of_flat_dt_is_compatible(node, "ibm,opal-v3")) { |
| 71 | powerpc_firmware_features |= FW_FEATURE_OPALv2; |
| 72 | powerpc_firmware_features |= FW_FEATURE_OPALv3; |
| 73 | printk("OPAL V3 detected !\n"); |
| 74 | } else if (of_flat_dt_is_compatible(node, "ibm,opal-v2")) { |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 75 | powerpc_firmware_features |= FW_FEATURE_OPALv2; |
| 76 | printk("OPAL V2 detected !\n"); |
| 77 | } else { |
| 78 | printk("OPAL V1 detected !\n"); |
| 79 | } |
| 80 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 81 | return 1; |
| 82 | } |
| 83 | |
| 84 | static int __init opal_register_exception_handlers(void) |
| 85 | { |
Benjamin Herrenschmidt | 2918609 | 2013-09-23 12:05:04 +1000 | [diff] [blame] | 86 | #ifdef __BIG_ENDIAN__ |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 87 | u64 glue; |
| 88 | |
| 89 | if (!(powerpc_firmware_features & FW_FEATURE_OPAL)) |
| 90 | return -ENODEV; |
| 91 | |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 92 | /* Hookup some exception handlers. We use the fwnmi area at 0x7000 |
| 93 | * to provide the glue space to OPAL |
| 94 | */ |
| 95 | glue = 0x7000; |
| 96 | opal_register_exception_handler(OPAL_MACHINE_CHECK_HANDLER, |
| 97 | __pa(opal_mc_secondary_handler[0]), |
| 98 | glue); |
| 99 | glue += 128; |
| 100 | opal_register_exception_handler(OPAL_HYPERVISOR_MAINTENANCE_HANDLER, |
| 101 | 0, glue); |
| 102 | glue += 128; |
| 103 | opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue); |
Benjamin Herrenschmidt | 2918609 | 2013-09-23 12:05:04 +1000 | [diff] [blame] | 104 | #endif |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 105 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 106 | return 0; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 109 | early_initcall(opal_register_exception_handlers); |
| 110 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 111 | int opal_notifier_register(struct notifier_block *nb) |
| 112 | { |
| 113 | if (!nb) { |
| 114 | pr_warning("%s: Invalid argument (%p)\n", |
| 115 | __func__, nb); |
| 116 | return -EINVAL; |
| 117 | } |
| 118 | |
| 119 | atomic_notifier_chain_register(&opal_notifier_head, nb); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static void opal_do_notifier(uint64_t events) |
| 124 | { |
| 125 | unsigned long flags; |
| 126 | uint64_t changed_mask; |
| 127 | |
| 128 | if (atomic_read(&opal_notifier_hold)) |
| 129 | return; |
| 130 | |
| 131 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 132 | changed_mask = last_notified_mask ^ events; |
| 133 | last_notified_mask = events; |
| 134 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 135 | |
| 136 | /* |
| 137 | * We feed with the event bits and changed bits for |
| 138 | * enough information to the callback. |
| 139 | */ |
| 140 | atomic_notifier_call_chain(&opal_notifier_head, |
| 141 | events, (void *)changed_mask); |
| 142 | } |
| 143 | |
| 144 | void opal_notifier_update_evt(uint64_t evt_mask, |
| 145 | uint64_t evt_val) |
| 146 | { |
| 147 | unsigned long flags; |
| 148 | |
| 149 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 150 | last_notified_mask &= ~evt_mask; |
| 151 | last_notified_mask |= evt_val; |
| 152 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 153 | } |
| 154 | |
| 155 | void opal_notifier_enable(void) |
| 156 | { |
| 157 | int64_t rc; |
| 158 | uint64_t evt = 0; |
| 159 | |
| 160 | atomic_set(&opal_notifier_hold, 0); |
| 161 | |
| 162 | /* Process pending events */ |
| 163 | rc = opal_poll_events(&evt); |
| 164 | if (rc == OPAL_SUCCESS && evt) |
| 165 | opal_do_notifier(evt); |
| 166 | } |
| 167 | |
| 168 | void opal_notifier_disable(void) |
| 169 | { |
| 170 | atomic_set(&opal_notifier_hold, 1); |
| 171 | } |
| 172 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 173 | int opal_get_chars(uint32_t vtermno, char *buf, int count) |
| 174 | { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 175 | s64 rc; |
| 176 | __be64 evt, len; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 177 | |
| 178 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 179 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 180 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 181 | if ((be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_INPUT) == 0) |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 182 | return 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 183 | len = cpu_to_be64(count); |
| 184 | rc = opal_console_read(vtermno, &len, buf); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 185 | if (rc == OPAL_SUCCESS) |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 186 | return be64_to_cpu(len); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | int opal_put_chars(uint32_t vtermno, const char *data, int total_len) |
| 191 | { |
| 192 | int written = 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 193 | __be64 olen; |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 194 | s64 len, rc; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 195 | unsigned long flags; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 196 | __be64 evt; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 197 | |
| 198 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 199 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 200 | |
| 201 | /* We want put_chars to be atomic to avoid mangling of hvsi |
| 202 | * packets. To do that, we first test for room and return |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 203 | * -EAGAIN if there isn't enough. |
| 204 | * |
| 205 | * Unfortunately, opal_console_write_buffer_space() doesn't |
| 206 | * appear to work on opal v1, so we just assume there is |
| 207 | * enough room and be done with it |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 208 | */ |
| 209 | spin_lock_irqsave(&opal_write_lock, flags); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 210 | if (firmware_has_feature(FW_FEATURE_OPALv2)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 211 | rc = opal_console_write_buffer_space(vtermno, &olen); |
| 212 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 213 | if (rc || len < total_len) { |
| 214 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 215 | /* Closed -> drop characters */ |
| 216 | if (rc) |
| 217 | return total_len; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 218 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 219 | return -EAGAIN; |
| 220 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* We still try to handle partial completions, though they |
| 224 | * should no longer happen. |
| 225 | */ |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 226 | rc = OPAL_BUSY; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 227 | while(total_len > 0 && (rc == OPAL_BUSY || |
| 228 | rc == OPAL_BUSY_EVENT || rc == OPAL_SUCCESS)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 229 | olen = cpu_to_be64(total_len); |
| 230 | rc = opal_console_write(vtermno, &olen, data); |
| 231 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | 1de1455 | 2013-05-08 14:14:26 +1000 | [diff] [blame] | 232 | |
| 233 | /* Closed or other error drop */ |
| 234 | if (rc != OPAL_SUCCESS && rc != OPAL_BUSY && |
| 235 | rc != OPAL_BUSY_EVENT) { |
| 236 | written = total_len; |
| 237 | break; |
| 238 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 239 | if (rc == OPAL_SUCCESS) { |
| 240 | total_len -= len; |
| 241 | data += len; |
| 242 | written += len; |
| 243 | } |
| 244 | /* This is a bit nasty but we need that for the console to |
| 245 | * flush when there aren't any interrupts. We will clean |
| 246 | * things a bit later to limit that to synchronous path |
| 247 | * such as the kernel console and xmon/udbg |
| 248 | */ |
| 249 | do |
| 250 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 251 | while(rc == OPAL_SUCCESS && |
| 252 | (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT)); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 253 | } |
| 254 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 255 | return written; |
| 256 | } |
| 257 | |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 258 | int opal_machine_check(struct pt_regs *regs) |
| 259 | { |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 260 | struct machine_check_event evt; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 261 | const char *level, *sevstr, *subtype; |
| 262 | static const char *opal_mc_ue_types[] = { |
| 263 | "Indeterminate", |
| 264 | "Instruction fetch", |
| 265 | "Page table walk ifetch", |
| 266 | "Load/Store", |
| 267 | "Page table walk Load/Store", |
| 268 | }; |
| 269 | static const char *opal_mc_slb_types[] = { |
| 270 | "Indeterminate", |
| 271 | "Parity", |
| 272 | "Multihit", |
| 273 | }; |
| 274 | static const char *opal_mc_erat_types[] = { |
| 275 | "Indeterminate", |
| 276 | "Parity", |
| 277 | "Multihit", |
| 278 | }; |
| 279 | static const char *opal_mc_tlb_types[] = { |
| 280 | "Indeterminate", |
| 281 | "Parity", |
| 282 | "Multihit", |
| 283 | }; |
| 284 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 285 | if (!get_mce_event(&evt, MCE_EVENT_RELEASE)) |
| 286 | return 0; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 287 | |
| 288 | /* Print things out */ |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 289 | if (evt.version != MCE_V1) { |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 290 | pr_err("Machine Check Exception, Unknown event version %d !\n", |
| 291 | evt.version); |
| 292 | return 0; |
| 293 | } |
| 294 | switch(evt.severity) { |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 295 | case MCE_SEV_NO_ERROR: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 296 | level = KERN_INFO; |
| 297 | sevstr = "Harmless"; |
| 298 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 299 | case MCE_SEV_WARNING: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 300 | level = KERN_WARNING; |
| 301 | sevstr = ""; |
| 302 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 303 | case MCE_SEV_ERROR_SYNC: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 304 | level = KERN_ERR; |
| 305 | sevstr = "Severe"; |
| 306 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 307 | case MCE_SEV_FATAL: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 308 | default: |
| 309 | level = KERN_ERR; |
| 310 | sevstr = "Fatal"; |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | printk("%s%s Machine check interrupt [%s]\n", level, sevstr, |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 315 | evt.disposition == MCE_DISPOSITION_RECOVERED ? |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 316 | "Recovered" : "[Not recovered"); |
| 317 | printk("%s Initiator: %s\n", level, |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 318 | evt.initiator == MCE_INITIATOR_CPU ? "CPU" : "Unknown"); |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 319 | switch(evt.error_type) { |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 320 | case MCE_ERROR_TYPE_UE: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 321 | subtype = evt.u.ue_error.ue_error_type < |
| 322 | ARRAY_SIZE(opal_mc_ue_types) ? |
| 323 | opal_mc_ue_types[evt.u.ue_error.ue_error_type] |
| 324 | : "Unknown"; |
| 325 | printk("%s Error type: UE [%s]\n", level, subtype); |
| 326 | if (evt.u.ue_error.effective_address_provided) |
| 327 | printk("%s Effective address: %016llx\n", |
| 328 | level, evt.u.ue_error.effective_address); |
| 329 | if (evt.u.ue_error.physical_address_provided) |
| 330 | printk("%s Physial address: %016llx\n", |
| 331 | level, evt.u.ue_error.physical_address); |
| 332 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 333 | case MCE_ERROR_TYPE_SLB: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 334 | subtype = evt.u.slb_error.slb_error_type < |
| 335 | ARRAY_SIZE(opal_mc_slb_types) ? |
| 336 | opal_mc_slb_types[evt.u.slb_error.slb_error_type] |
| 337 | : "Unknown"; |
| 338 | printk("%s Error type: SLB [%s]\n", level, subtype); |
| 339 | if (evt.u.slb_error.effective_address_provided) |
| 340 | printk("%s Effective address: %016llx\n", |
| 341 | level, evt.u.slb_error.effective_address); |
| 342 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 343 | case MCE_ERROR_TYPE_ERAT: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 344 | subtype = evt.u.erat_error.erat_error_type < |
| 345 | ARRAY_SIZE(opal_mc_erat_types) ? |
| 346 | opal_mc_erat_types[evt.u.erat_error.erat_error_type] |
| 347 | : "Unknown"; |
| 348 | printk("%s Error type: ERAT [%s]\n", level, subtype); |
| 349 | if (evt.u.erat_error.effective_address_provided) |
| 350 | printk("%s Effective address: %016llx\n", |
| 351 | level, evt.u.erat_error.effective_address); |
| 352 | break; |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 353 | case MCE_ERROR_TYPE_TLB: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 354 | subtype = evt.u.tlb_error.tlb_error_type < |
| 355 | ARRAY_SIZE(opal_mc_tlb_types) ? |
| 356 | opal_mc_tlb_types[evt.u.tlb_error.tlb_error_type] |
| 357 | : "Unknown"; |
| 358 | printk("%s Error type: TLB [%s]\n", level, subtype); |
| 359 | if (evt.u.tlb_error.effective_address_provided) |
| 360 | printk("%s Effective address: %016llx\n", |
| 361 | level, evt.u.tlb_error.effective_address); |
| 362 | break; |
| 363 | default: |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 364 | case MCE_ERROR_TYPE_UNKNOWN: |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 365 | printk("%s Error type: Unknown\n", level); |
| 366 | break; |
| 367 | } |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame^] | 368 | return evt.severity == MCE_SEV_FATAL ? 0 : 1; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 371 | static irqreturn_t opal_interrupt(int irq, void *data) |
| 372 | { |
Anton Blanchard | 5e4da53 | 2013-09-23 12:05:06 +1000 | [diff] [blame] | 373 | __be64 events; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 374 | |
| 375 | opal_handle_interrupt(virq_to_hw(irq), &events); |
| 376 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 377 | opal_do_notifier(events); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 378 | |
| 379 | return IRQ_HANDLED; |
| 380 | } |
| 381 | |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 382 | static int opal_sysfs_init(void) |
| 383 | { |
| 384 | opal_kobj = kobject_create_and_add("opal", firmware_kobj); |
| 385 | if (!opal_kobj) { |
| 386 | pr_warn("kobject_create_and_add opal failed\n"); |
| 387 | return -ENOMEM; |
| 388 | } |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 393 | static int __init opal_init(void) |
| 394 | { |
| 395 | struct device_node *np, *consoles; |
Alistair Popple | 1cc79bc | 2013-09-23 12:04:54 +1000 | [diff] [blame] | 396 | const __be32 *irqs; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 397 | int rc, i, irqlen; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 398 | |
| 399 | opal_node = of_find_node_by_path("/ibm,opal"); |
| 400 | if (!opal_node) { |
| 401 | pr_warn("opal: Node not found\n"); |
| 402 | return -ENODEV; |
| 403 | } |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 404 | |
| 405 | /* Register OPAL consoles if any ports */ |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 406 | if (firmware_has_feature(FW_FEATURE_OPALv2)) |
| 407 | consoles = of_find_node_by_path("/ibm,opal/consoles"); |
| 408 | else |
| 409 | consoles = of_node_get(opal_node); |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 410 | if (consoles) { |
| 411 | for_each_child_of_node(consoles, np) { |
| 412 | if (strcmp(np->name, "serial")) |
| 413 | continue; |
| 414 | of_platform_device_create(np, NULL, NULL); |
| 415 | } |
| 416 | of_node_put(consoles); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 417 | } |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 418 | |
| 419 | /* Find all OPAL interrupts and request them */ |
| 420 | irqs = of_get_property(opal_node, "opal-interrupts", &irqlen); |
| 421 | pr_debug("opal: Found %d interrupts reserved for OPAL\n", |
| 422 | irqs ? (irqlen / 4) : 0); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 423 | opal_irq_count = irqlen / 4; |
| 424 | opal_irqs = kzalloc(opal_irq_count * sizeof(unsigned int), GFP_KERNEL); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 425 | for (i = 0; irqs && i < (irqlen / 4); i++, irqs++) { |
| 426 | unsigned int hwirq = be32_to_cpup(irqs); |
| 427 | unsigned int irq = irq_create_mapping(NULL, hwirq); |
| 428 | if (irq == NO_IRQ) { |
| 429 | pr_warning("opal: Failed to map irq 0x%x\n", hwirq); |
| 430 | continue; |
| 431 | } |
| 432 | rc = request_irq(irq, opal_interrupt, 0, "opal", NULL); |
| 433 | if (rc) |
| 434 | pr_warning("opal: Error %d requesting irq %d" |
| 435 | " (0x%x)\n", rc, irq, hwirq); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 436 | opal_irqs[i] = irq; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 437 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 438 | |
| 439 | /* Create "opal" kobject under /sys/firmware */ |
| 440 | rc = opal_sysfs_init(); |
Vasant Hegde | 50bd615 | 2013-10-24 16:04:58 +0530 | [diff] [blame] | 441 | if (rc == 0) { |
| 442 | /* Setup code update interface */ |
| 443 | opal_flash_init(); |
| 444 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 445 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | subsys_initcall(opal_init); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 449 | |
| 450 | void opal_shutdown(void) |
| 451 | { |
| 452 | unsigned int i; |
| 453 | |
| 454 | for (i = 0; i < opal_irq_count; i++) { |
| 455 | if (opal_irqs[i]) |
Anton Blanchard | b0d436c | 2013-08-07 02:01:24 +1000 | [diff] [blame] | 456 | free_irq(opal_irqs[i], NULL); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 457 | opal_irqs[i] = 0; |
| 458 | } |
| 459 | } |