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> |
Mahesh Salgaonkar | b63a0ff | 2013-10-30 20:06:13 +0530 | [diff] [blame^] | 21 | #include <linux/sched.h> |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 22 | #include <linux/kobject.h> |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 23 | #include <asm/opal.h> |
| 24 | #include <asm/firmware.h> |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 25 | #include <asm/mce.h> |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 26 | |
| 27 | #include "powernv.h" |
| 28 | |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 29 | /* /sys/firmware/opal */ |
| 30 | struct kobject *opal_kobj; |
| 31 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 32 | struct opal { |
| 33 | u64 base; |
| 34 | u64 entry; |
| 35 | } opal; |
| 36 | |
| 37 | static struct device_node *opal_node; |
| 38 | static DEFINE_SPINLOCK(opal_write_lock); |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 39 | extern u64 opal_mc_secondary_handler[]; |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 40 | static unsigned int *opal_irqs; |
| 41 | static unsigned int opal_irq_count; |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 42 | static ATOMIC_NOTIFIER_HEAD(opal_notifier_head); |
| 43 | static DEFINE_SPINLOCK(opal_notifier_lock); |
| 44 | static uint64_t last_notified_mask = 0x0ul; |
| 45 | static atomic_t opal_notifier_hold = ATOMIC_INIT(0); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 46 | |
| 47 | int __init early_init_dt_scan_opal(unsigned long node, |
| 48 | const char *uname, int depth, void *data) |
| 49 | { |
| 50 | const void *basep, *entryp; |
| 51 | unsigned long basesz, entrysz; |
| 52 | |
| 53 | if (depth != 1 || strcmp(uname, "ibm,opal") != 0) |
| 54 | return 0; |
| 55 | |
| 56 | basep = of_get_flat_dt_prop(node, "opal-base-address", &basesz); |
| 57 | entryp = of_get_flat_dt_prop(node, "opal-entry-address", &entrysz); |
| 58 | |
| 59 | if (!basep || !entryp) |
| 60 | return 1; |
| 61 | |
| 62 | opal.base = of_read_number(basep, basesz/4); |
| 63 | opal.entry = of_read_number(entryp, entrysz/4); |
| 64 | |
| 65 | pr_debug("OPAL Base = 0x%llx (basep=%p basesz=%ld)\n", |
| 66 | opal.base, basep, basesz); |
| 67 | pr_debug("OPAL Entry = 0x%llx (entryp=%p basesz=%ld)\n", |
| 68 | opal.entry, entryp, entrysz); |
| 69 | |
| 70 | powerpc_firmware_features |= FW_FEATURE_OPAL; |
Benjamin Herrenschmidt | 75b93da | 2013-05-14 15:10:02 +1000 | [diff] [blame] | 71 | if (of_flat_dt_is_compatible(node, "ibm,opal-v3")) { |
| 72 | powerpc_firmware_features |= FW_FEATURE_OPALv2; |
| 73 | powerpc_firmware_features |= FW_FEATURE_OPALv3; |
| 74 | printk("OPAL V3 detected !\n"); |
| 75 | } else if (of_flat_dt_is_compatible(node, "ibm,opal-v2")) { |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 76 | powerpc_firmware_features |= FW_FEATURE_OPALv2; |
| 77 | printk("OPAL V2 detected !\n"); |
| 78 | } else { |
| 79 | printk("OPAL V1 detected !\n"); |
| 80 | } |
| 81 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 82 | return 1; |
| 83 | } |
| 84 | |
| 85 | static int __init opal_register_exception_handlers(void) |
| 86 | { |
Benjamin Herrenschmidt | 2918609 | 2013-09-23 12:05:04 +1000 | [diff] [blame] | 87 | #ifdef __BIG_ENDIAN__ |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 88 | u64 glue; |
| 89 | |
| 90 | if (!(powerpc_firmware_features & FW_FEATURE_OPAL)) |
| 91 | return -ENODEV; |
| 92 | |
Mahesh Salgaonkar | 28446de | 2013-10-30 20:05:58 +0530 | [diff] [blame] | 93 | /* Hookup some exception handlers except machine check. We use the |
| 94 | * fwnmi area at 0x7000 to provide the glue space to OPAL |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 95 | */ |
| 96 | glue = 0x7000; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 97 | opal_register_exception_handler(OPAL_HYPERVISOR_MAINTENANCE_HANDLER, |
| 98 | 0, glue); |
| 99 | glue += 128; |
| 100 | opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue); |
Benjamin Herrenschmidt | 2918609 | 2013-09-23 12:05:04 +1000 | [diff] [blame] | 101 | #endif |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 102 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 103 | return 0; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 106 | early_initcall(opal_register_exception_handlers); |
| 107 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 108 | int opal_notifier_register(struct notifier_block *nb) |
| 109 | { |
| 110 | if (!nb) { |
| 111 | pr_warning("%s: Invalid argument (%p)\n", |
| 112 | __func__, nb); |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | |
| 116 | atomic_notifier_chain_register(&opal_notifier_head, nb); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static void opal_do_notifier(uint64_t events) |
| 121 | { |
| 122 | unsigned long flags; |
| 123 | uint64_t changed_mask; |
| 124 | |
| 125 | if (atomic_read(&opal_notifier_hold)) |
| 126 | return; |
| 127 | |
| 128 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 129 | changed_mask = last_notified_mask ^ events; |
| 130 | last_notified_mask = events; |
| 131 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 132 | |
| 133 | /* |
| 134 | * We feed with the event bits and changed bits for |
| 135 | * enough information to the callback. |
| 136 | */ |
| 137 | atomic_notifier_call_chain(&opal_notifier_head, |
| 138 | events, (void *)changed_mask); |
| 139 | } |
| 140 | |
| 141 | void opal_notifier_update_evt(uint64_t evt_mask, |
| 142 | uint64_t evt_val) |
| 143 | { |
| 144 | unsigned long flags; |
| 145 | |
| 146 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 147 | last_notified_mask &= ~evt_mask; |
| 148 | last_notified_mask |= evt_val; |
| 149 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 150 | } |
| 151 | |
| 152 | void opal_notifier_enable(void) |
| 153 | { |
| 154 | int64_t rc; |
| 155 | uint64_t evt = 0; |
| 156 | |
| 157 | atomic_set(&opal_notifier_hold, 0); |
| 158 | |
| 159 | /* Process pending events */ |
| 160 | rc = opal_poll_events(&evt); |
| 161 | if (rc == OPAL_SUCCESS && evt) |
| 162 | opal_do_notifier(evt); |
| 163 | } |
| 164 | |
| 165 | void opal_notifier_disable(void) |
| 166 | { |
| 167 | atomic_set(&opal_notifier_hold, 1); |
| 168 | } |
| 169 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 170 | int opal_get_chars(uint32_t vtermno, char *buf, int count) |
| 171 | { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 172 | s64 rc; |
| 173 | __be64 evt, len; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 174 | |
| 175 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 176 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 177 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 178 | if ((be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_INPUT) == 0) |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 179 | return 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 180 | len = cpu_to_be64(count); |
| 181 | rc = opal_console_read(vtermno, &len, buf); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 182 | if (rc == OPAL_SUCCESS) |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 183 | return be64_to_cpu(len); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | int opal_put_chars(uint32_t vtermno, const char *data, int total_len) |
| 188 | { |
| 189 | int written = 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 190 | __be64 olen; |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 191 | s64 len, rc; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 192 | unsigned long flags; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 193 | __be64 evt; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 194 | |
| 195 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 196 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 197 | |
| 198 | /* We want put_chars to be atomic to avoid mangling of hvsi |
| 199 | * packets. To do that, we first test for room and return |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 200 | * -EAGAIN if there isn't enough. |
| 201 | * |
| 202 | * Unfortunately, opal_console_write_buffer_space() doesn't |
| 203 | * appear to work on opal v1, so we just assume there is |
| 204 | * enough room and be done with it |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 205 | */ |
| 206 | spin_lock_irqsave(&opal_write_lock, flags); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 207 | if (firmware_has_feature(FW_FEATURE_OPALv2)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 208 | rc = opal_console_write_buffer_space(vtermno, &olen); |
| 209 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 210 | if (rc || len < total_len) { |
| 211 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 212 | /* Closed -> drop characters */ |
| 213 | if (rc) |
| 214 | return total_len; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 215 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 216 | return -EAGAIN; |
| 217 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* We still try to handle partial completions, though they |
| 221 | * should no longer happen. |
| 222 | */ |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 223 | rc = OPAL_BUSY; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 224 | while(total_len > 0 && (rc == OPAL_BUSY || |
| 225 | rc == OPAL_BUSY_EVENT || rc == OPAL_SUCCESS)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 226 | olen = cpu_to_be64(total_len); |
| 227 | rc = opal_console_write(vtermno, &olen, data); |
| 228 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | 1de1455 | 2013-05-08 14:14:26 +1000 | [diff] [blame] | 229 | |
| 230 | /* Closed or other error drop */ |
| 231 | if (rc != OPAL_SUCCESS && rc != OPAL_BUSY && |
| 232 | rc != OPAL_BUSY_EVENT) { |
| 233 | written = total_len; |
| 234 | break; |
| 235 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 236 | if (rc == OPAL_SUCCESS) { |
| 237 | total_len -= len; |
| 238 | data += len; |
| 239 | written += len; |
| 240 | } |
| 241 | /* This is a bit nasty but we need that for the console to |
| 242 | * flush when there aren't any interrupts. We will clean |
| 243 | * things a bit later to limit that to synchronous path |
| 244 | * such as the kernel console and xmon/udbg |
| 245 | */ |
| 246 | do |
| 247 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 248 | while(rc == OPAL_SUCCESS && |
| 249 | (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT)); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 250 | } |
| 251 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 252 | return written; |
| 253 | } |
| 254 | |
Mahesh Salgaonkar | b63a0ff | 2013-10-30 20:06:13 +0530 | [diff] [blame^] | 255 | static int opal_recover_mce(struct pt_regs *regs, |
| 256 | struct machine_check_event *evt) |
| 257 | { |
| 258 | int recovered = 0; |
| 259 | uint64_t ea = get_mce_fault_addr(evt); |
| 260 | |
| 261 | if (!(regs->msr & MSR_RI)) { |
| 262 | /* If MSR_RI isn't set, we cannot recover */ |
| 263 | recovered = 0; |
| 264 | } else if (evt->disposition == MCE_DISPOSITION_RECOVERED) { |
| 265 | /* Platform corrected itself */ |
| 266 | recovered = 1; |
| 267 | } else if (ea && !is_kernel_addr(ea)) { |
| 268 | /* |
| 269 | * Faulting address is not in kernel text. We should be fine. |
| 270 | * We need to find which process uses this address. |
| 271 | * For now, kill the task if we have received exception when |
| 272 | * in userspace. |
| 273 | * |
| 274 | * TODO: Queue up this address for hwpoisioning later. |
| 275 | */ |
| 276 | if (user_mode(regs) && !is_global_init(current)) { |
| 277 | _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); |
| 278 | recovered = 1; |
| 279 | } else |
| 280 | recovered = 0; |
| 281 | } else if (user_mode(regs) && !is_global_init(current) && |
| 282 | evt->severity == MCE_SEV_ERROR_SYNC) { |
| 283 | /* |
| 284 | * If we have received a synchronous error when in userspace |
| 285 | * kill the task. |
| 286 | */ |
| 287 | _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip); |
| 288 | recovered = 1; |
| 289 | } |
| 290 | return recovered; |
| 291 | } |
| 292 | |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 293 | int opal_machine_check(struct pt_regs *regs) |
| 294 | { |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 295 | struct machine_check_event evt; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 296 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 297 | if (!get_mce_event(&evt, MCE_EVENT_RELEASE)) |
| 298 | return 0; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 299 | |
| 300 | /* Print things out */ |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 301 | if (evt.version != MCE_V1) { |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 302 | pr_err("Machine Check Exception, Unknown event version %d !\n", |
| 303 | evt.version); |
| 304 | return 0; |
| 305 | } |
Mahesh Salgaonkar | b5ff421 | 2013-10-30 20:05:49 +0530 | [diff] [blame] | 306 | machine_check_print_event_info(&evt); |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 307 | |
Mahesh Salgaonkar | b63a0ff | 2013-10-30 20:06:13 +0530 | [diff] [blame^] | 308 | if (opal_recover_mce(regs, &evt)) |
| 309 | return 1; |
| 310 | return 0; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 313 | static irqreturn_t opal_interrupt(int irq, void *data) |
| 314 | { |
Anton Blanchard | 5e4da53 | 2013-09-23 12:05:06 +1000 | [diff] [blame] | 315 | __be64 events; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 316 | |
| 317 | opal_handle_interrupt(virq_to_hw(irq), &events); |
| 318 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 319 | opal_do_notifier(events); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 320 | |
| 321 | return IRQ_HANDLED; |
| 322 | } |
| 323 | |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 324 | static int opal_sysfs_init(void) |
| 325 | { |
| 326 | opal_kobj = kobject_create_and_add("opal", firmware_kobj); |
| 327 | if (!opal_kobj) { |
| 328 | pr_warn("kobject_create_and_add opal failed\n"); |
| 329 | return -ENOMEM; |
| 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 335 | static int __init opal_init(void) |
| 336 | { |
| 337 | struct device_node *np, *consoles; |
Alistair Popple | 1cc79bc | 2013-09-23 12:04:54 +1000 | [diff] [blame] | 338 | const __be32 *irqs; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 339 | int rc, i, irqlen; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 340 | |
| 341 | opal_node = of_find_node_by_path("/ibm,opal"); |
| 342 | if (!opal_node) { |
| 343 | pr_warn("opal: Node not found\n"); |
| 344 | return -ENODEV; |
| 345 | } |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 346 | |
| 347 | /* Register OPAL consoles if any ports */ |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 348 | if (firmware_has_feature(FW_FEATURE_OPALv2)) |
| 349 | consoles = of_find_node_by_path("/ibm,opal/consoles"); |
| 350 | else |
| 351 | consoles = of_node_get(opal_node); |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 352 | if (consoles) { |
| 353 | for_each_child_of_node(consoles, np) { |
| 354 | if (strcmp(np->name, "serial")) |
| 355 | continue; |
| 356 | of_platform_device_create(np, NULL, NULL); |
| 357 | } |
| 358 | of_node_put(consoles); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 359 | } |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 360 | |
| 361 | /* Find all OPAL interrupts and request them */ |
| 362 | irqs = of_get_property(opal_node, "opal-interrupts", &irqlen); |
| 363 | pr_debug("opal: Found %d interrupts reserved for OPAL\n", |
| 364 | irqs ? (irqlen / 4) : 0); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 365 | opal_irq_count = irqlen / 4; |
| 366 | opal_irqs = kzalloc(opal_irq_count * sizeof(unsigned int), GFP_KERNEL); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 367 | for (i = 0; irqs && i < (irqlen / 4); i++, irqs++) { |
| 368 | unsigned int hwirq = be32_to_cpup(irqs); |
| 369 | unsigned int irq = irq_create_mapping(NULL, hwirq); |
| 370 | if (irq == NO_IRQ) { |
| 371 | pr_warning("opal: Failed to map irq 0x%x\n", hwirq); |
| 372 | continue; |
| 373 | } |
| 374 | rc = request_irq(irq, opal_interrupt, 0, "opal", NULL); |
| 375 | if (rc) |
| 376 | pr_warning("opal: Error %d requesting irq %d" |
| 377 | " (0x%x)\n", rc, irq, hwirq); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 378 | opal_irqs[i] = irq; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 379 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 380 | |
| 381 | /* Create "opal" kobject under /sys/firmware */ |
| 382 | rc = opal_sysfs_init(); |
Vasant Hegde | 50bd615 | 2013-10-24 16:04:58 +0530 | [diff] [blame] | 383 | if (rc == 0) { |
| 384 | /* Setup code update interface */ |
| 385 | opal_flash_init(); |
| 386 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 387 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | subsys_initcall(opal_init); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 391 | |
| 392 | void opal_shutdown(void) |
| 393 | { |
| 394 | unsigned int i; |
| 395 | |
| 396 | for (i = 0; i < opal_irq_count; i++) { |
| 397 | if (opal_irqs[i]) |
Anton Blanchard | b0d436c | 2013-08-07 02:01:24 +1000 | [diff] [blame] | 398 | free_irq(opal_irqs[i], NULL); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 399 | opal_irqs[i] = 0; |
| 400 | } |
| 401 | } |