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 | |
Mahesh Salgaonkar | 28446de | 2013-10-30 20:05:58 +0530 | [diff] [blame^] | 92 | /* Hookup some exception handlers except machine check. We use the |
| 93 | * fwnmi area at 0x7000 to provide the glue space to OPAL |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 94 | */ |
| 95 | glue = 0x7000; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 96 | opal_register_exception_handler(OPAL_HYPERVISOR_MAINTENANCE_HANDLER, |
| 97 | 0, glue); |
| 98 | glue += 128; |
| 99 | opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue); |
Benjamin Herrenschmidt | 2918609 | 2013-09-23 12:05:04 +1000 | [diff] [blame] | 100 | #endif |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 101 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 102 | return 0; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Jeremy Kerr | c4463b3 | 2013-05-01 22:31:50 +0000 | [diff] [blame] | 105 | early_initcall(opal_register_exception_handlers); |
| 106 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 107 | int opal_notifier_register(struct notifier_block *nb) |
| 108 | { |
| 109 | if (!nb) { |
| 110 | pr_warning("%s: Invalid argument (%p)\n", |
| 111 | __func__, nb); |
| 112 | return -EINVAL; |
| 113 | } |
| 114 | |
| 115 | atomic_notifier_chain_register(&opal_notifier_head, nb); |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void opal_do_notifier(uint64_t events) |
| 120 | { |
| 121 | unsigned long flags; |
| 122 | uint64_t changed_mask; |
| 123 | |
| 124 | if (atomic_read(&opal_notifier_hold)) |
| 125 | return; |
| 126 | |
| 127 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 128 | changed_mask = last_notified_mask ^ events; |
| 129 | last_notified_mask = events; |
| 130 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 131 | |
| 132 | /* |
| 133 | * We feed with the event bits and changed bits for |
| 134 | * enough information to the callback. |
| 135 | */ |
| 136 | atomic_notifier_call_chain(&opal_notifier_head, |
| 137 | events, (void *)changed_mask); |
| 138 | } |
| 139 | |
| 140 | void opal_notifier_update_evt(uint64_t evt_mask, |
| 141 | uint64_t evt_val) |
| 142 | { |
| 143 | unsigned long flags; |
| 144 | |
| 145 | spin_lock_irqsave(&opal_notifier_lock, flags); |
| 146 | last_notified_mask &= ~evt_mask; |
| 147 | last_notified_mask |= evt_val; |
| 148 | spin_unlock_irqrestore(&opal_notifier_lock, flags); |
| 149 | } |
| 150 | |
| 151 | void opal_notifier_enable(void) |
| 152 | { |
| 153 | int64_t rc; |
| 154 | uint64_t evt = 0; |
| 155 | |
| 156 | atomic_set(&opal_notifier_hold, 0); |
| 157 | |
| 158 | /* Process pending events */ |
| 159 | rc = opal_poll_events(&evt); |
| 160 | if (rc == OPAL_SUCCESS && evt) |
| 161 | opal_do_notifier(evt); |
| 162 | } |
| 163 | |
| 164 | void opal_notifier_disable(void) |
| 165 | { |
| 166 | atomic_set(&opal_notifier_hold, 1); |
| 167 | } |
| 168 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 169 | int opal_get_chars(uint32_t vtermno, char *buf, int count) |
| 170 | { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 171 | s64 rc; |
| 172 | __be64 evt, len; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 173 | |
| 174 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 175 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 176 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 177 | if ((be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_INPUT) == 0) |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 178 | return 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 179 | len = cpu_to_be64(count); |
| 180 | rc = opal_console_read(vtermno, &len, buf); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 181 | if (rc == OPAL_SUCCESS) |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 182 | return be64_to_cpu(len); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | int opal_put_chars(uint32_t vtermno, const char *data, int total_len) |
| 187 | { |
| 188 | int written = 0; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 189 | __be64 olen; |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 190 | s64 len, rc; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 191 | unsigned long flags; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 192 | __be64 evt; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 193 | |
| 194 | if (!opal.entry) |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 195 | return -ENODEV; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 196 | |
| 197 | /* We want put_chars to be atomic to avoid mangling of hvsi |
| 198 | * packets. To do that, we first test for room and return |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 199 | * -EAGAIN if there isn't enough. |
| 200 | * |
| 201 | * Unfortunately, opal_console_write_buffer_space() doesn't |
| 202 | * appear to work on opal v1, so we just assume there is |
| 203 | * enough room and be done with it |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 204 | */ |
| 205 | spin_lock_irqsave(&opal_write_lock, flags); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 206 | if (firmware_has_feature(FW_FEATURE_OPALv2)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 207 | rc = opal_console_write_buffer_space(vtermno, &olen); |
| 208 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 209 | if (rc || len < total_len) { |
| 210 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 211 | /* Closed -> drop characters */ |
| 212 | if (rc) |
| 213 | return total_len; |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 214 | opal_poll_events(NULL); |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 215 | return -EAGAIN; |
| 216 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /* We still try to handle partial completions, though they |
| 220 | * should no longer happen. |
| 221 | */ |
Benjamin Herrenschmidt | daea117 | 2011-09-19 17:44:59 +0000 | [diff] [blame] | 222 | rc = OPAL_BUSY; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 223 | while(total_len > 0 && (rc == OPAL_BUSY || |
| 224 | rc == OPAL_BUSY_EVENT || rc == OPAL_SUCCESS)) { |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 225 | olen = cpu_to_be64(total_len); |
| 226 | rc = opal_console_write(vtermno, &olen, data); |
| 227 | len = be64_to_cpu(olen); |
Benjamin Herrenschmidt | 1de1455 | 2013-05-08 14:14:26 +1000 | [diff] [blame] | 228 | |
| 229 | /* Closed or other error drop */ |
| 230 | if (rc != OPAL_SUCCESS && rc != OPAL_BUSY && |
| 231 | rc != OPAL_BUSY_EVENT) { |
| 232 | written = total_len; |
| 233 | break; |
| 234 | } |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 235 | if (rc == OPAL_SUCCESS) { |
| 236 | total_len -= len; |
| 237 | data += len; |
| 238 | written += len; |
| 239 | } |
| 240 | /* This is a bit nasty but we need that for the console to |
| 241 | * flush when there aren't any interrupts. We will clean |
| 242 | * things a bit later to limit that to synchronous path |
| 243 | * such as the kernel console and xmon/udbg |
| 244 | */ |
| 245 | do |
| 246 | opal_poll_events(&evt); |
Benjamin Herrenschmidt | 4f89363 | 2013-09-23 12:05:02 +1000 | [diff] [blame] | 247 | while(rc == OPAL_SUCCESS && |
| 248 | (be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT)); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 249 | } |
| 250 | spin_unlock_irqrestore(&opal_write_lock, flags); |
| 251 | return written; |
| 252 | } |
| 253 | |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 254 | int opal_machine_check(struct pt_regs *regs) |
| 255 | { |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 256 | struct machine_check_event evt; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 257 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 258 | if (!get_mce_event(&evt, MCE_EVENT_RELEASE)) |
| 259 | return 0; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 260 | |
| 261 | /* Print things out */ |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 262 | if (evt.version != MCE_V1) { |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 263 | pr_err("Machine Check Exception, Unknown event version %d !\n", |
| 264 | evt.version); |
| 265 | return 0; |
| 266 | } |
Mahesh Salgaonkar | b5ff421 | 2013-10-30 20:05:49 +0530 | [diff] [blame] | 267 | machine_check_print_event_info(&evt); |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 268 | |
Mahesh Salgaonkar | 36df96f | 2013-10-30 20:05:40 +0530 | [diff] [blame] | 269 | return evt.severity == MCE_SEV_FATAL ? 0 : 1; |
Benjamin Herrenschmidt | ed79ba9 | 2011-09-19 17:45:04 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 272 | static irqreturn_t opal_interrupt(int irq, void *data) |
| 273 | { |
Anton Blanchard | 5e4da53 | 2013-09-23 12:05:06 +1000 | [diff] [blame] | 274 | __be64 events; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 275 | |
| 276 | opal_handle_interrupt(virq_to_hw(irq), &events); |
| 277 | |
Gavin Shan | 1bc98de | 2013-06-20 18:13:22 +0800 | [diff] [blame] | 278 | opal_do_notifier(events); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 279 | |
| 280 | return IRQ_HANDLED; |
| 281 | } |
| 282 | |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 283 | static int opal_sysfs_init(void) |
| 284 | { |
| 285 | opal_kobj = kobject_create_and_add("opal", firmware_kobj); |
| 286 | if (!opal_kobj) { |
| 287 | pr_warn("kobject_create_and_add opal failed\n"); |
| 288 | return -ENOMEM; |
| 289 | } |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 294 | static int __init opal_init(void) |
| 295 | { |
| 296 | struct device_node *np, *consoles; |
Alistair Popple | 1cc79bc | 2013-09-23 12:04:54 +1000 | [diff] [blame] | 297 | const __be32 *irqs; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 298 | int rc, i, irqlen; |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 299 | |
| 300 | opal_node = of_find_node_by_path("/ibm,opal"); |
| 301 | if (!opal_node) { |
| 302 | pr_warn("opal: Node not found\n"); |
| 303 | return -ENODEV; |
| 304 | } |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 305 | |
| 306 | /* Register OPAL consoles if any ports */ |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 307 | if (firmware_has_feature(FW_FEATURE_OPALv2)) |
| 308 | consoles = of_find_node_by_path("/ibm,opal/consoles"); |
| 309 | else |
| 310 | consoles = of_node_get(opal_node); |
Benjamin Herrenschmidt | 2db29d2 | 2013-07-15 13:03:14 +1000 | [diff] [blame] | 311 | if (consoles) { |
| 312 | for_each_child_of_node(consoles, np) { |
| 313 | if (strcmp(np->name, "serial")) |
| 314 | continue; |
| 315 | of_platform_device_create(np, NULL, NULL); |
| 316 | } |
| 317 | of_node_put(consoles); |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 318 | } |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 319 | |
| 320 | /* Find all OPAL interrupts and request them */ |
| 321 | irqs = of_get_property(opal_node, "opal-interrupts", &irqlen); |
| 322 | pr_debug("opal: Found %d interrupts reserved for OPAL\n", |
| 323 | irqs ? (irqlen / 4) : 0); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 324 | opal_irq_count = irqlen / 4; |
| 325 | opal_irqs = kzalloc(opal_irq_count * sizeof(unsigned int), GFP_KERNEL); |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 326 | for (i = 0; irqs && i < (irqlen / 4); i++, irqs++) { |
| 327 | unsigned int hwirq = be32_to_cpup(irqs); |
| 328 | unsigned int irq = irq_create_mapping(NULL, hwirq); |
| 329 | if (irq == NO_IRQ) { |
| 330 | pr_warning("opal: Failed to map irq 0x%x\n", hwirq); |
| 331 | continue; |
| 332 | } |
| 333 | rc = request_irq(irq, opal_interrupt, 0, "opal", NULL); |
| 334 | if (rc) |
| 335 | pr_warning("opal: Error %d requesting irq %d" |
| 336 | " (0x%x)\n", rc, irq, hwirq); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 337 | opal_irqs[i] = irq; |
Benjamin Herrenschmidt | a125e09 | 2011-09-19 17:45:03 +0000 | [diff] [blame] | 338 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 339 | |
| 340 | /* Create "opal" kobject under /sys/firmware */ |
| 341 | rc = opal_sysfs_init(); |
Vasant Hegde | 50bd615 | 2013-10-24 16:04:58 +0530 | [diff] [blame] | 342 | if (rc == 0) { |
| 343 | /* Setup code update interface */ |
| 344 | opal_flash_init(); |
| 345 | } |
Vasant Hegde | 6f68b5e | 2013-08-27 15:09:52 +0530 | [diff] [blame] | 346 | |
Benjamin Herrenschmidt | 14a43e6 | 2011-09-19 17:44:57 +0000 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | subsys_initcall(opal_init); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 350 | |
| 351 | void opal_shutdown(void) |
| 352 | { |
| 353 | unsigned int i; |
| 354 | |
| 355 | for (i = 0; i < opal_irq_count; i++) { |
| 356 | if (opal_irqs[i]) |
Anton Blanchard | b0d436c | 2013-08-07 02:01:24 +1000 | [diff] [blame] | 357 | free_irq(opal_irqs[i], NULL); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 358 | opal_irqs[i] = 0; |
| 359 | } |
| 360 | } |