2 * PowerNV OPAL high level interfaces
4 * Copyright 2011 IBM Corp.
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.
14 #include <linux/types.h>
16 #include <linux/of_platform.h>
17 #include <linux/interrupt.h>
19 #include <asm/firmware.h>
28 static struct device_node
*opal_node
;
29 static DEFINE_SPINLOCK(opal_write_lock
);
30 extern u64 opal_mc_secondary_handler
[];
32 int __init
early_init_dt_scan_opal(unsigned long node
,
33 const char *uname
, int depth
, void *data
)
35 const void *basep
, *entryp
;
36 unsigned long basesz
, entrysz
;
39 if (depth
!= 1 || strcmp(uname
, "ibm,opal") != 0)
42 basep
= of_get_flat_dt_prop(node
, "opal-base-address", &basesz
);
43 entryp
= of_get_flat_dt_prop(node
, "opal-entry-address", &entrysz
);
45 if (!basep
|| !entryp
)
48 opal
.base
= of_read_number(basep
, basesz
/4);
49 opal
.entry
= of_read_number(entryp
, entrysz
/4);
51 pr_debug("OPAL Base = 0x%llx (basep=%p basesz=%ld)\n",
52 opal
.base
, basep
, basesz
);
53 pr_debug("OPAL Entry = 0x%llx (entryp=%p basesz=%ld)\n",
54 opal
.entry
, entryp
, entrysz
);
56 powerpc_firmware_features
|= FW_FEATURE_OPAL
;
57 if (of_flat_dt_is_compatible(node
, "ibm,opal-v2")) {
58 powerpc_firmware_features
|= FW_FEATURE_OPALv2
;
59 printk("OPAL V2 detected !\n");
61 printk("OPAL V1 detected !\n");
64 /* Hookup some exception handlers. We use the fwnmi area at 0x7000
65 * to provide the glue space to OPAL
68 opal_register_exception_handler(OPAL_MACHINE_CHECK_HANDLER
,
69 __pa(opal_mc_secondary_handler
[0]),
72 opal_register_exception_handler(OPAL_HYPERVISOR_MAINTENANCE_HANDLER
,
75 opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER
, 0, glue
);
80 int opal_get_chars(uint32_t vtermno
, char *buf
, int count
)
87 opal_poll_events(&evt
);
88 if ((evt
& OPAL_EVENT_CONSOLE_INPUT
) == 0)
91 rc
= opal_console_read(vtermno
, &len
, buf
);
92 if (rc
== OPAL_SUCCESS
)
97 int opal_put_chars(uint32_t vtermno
, const char *data
, int total_len
)
107 /* We want put_chars to be atomic to avoid mangling of hvsi
108 * packets. To do that, we first test for room and return
109 * -EAGAIN if there isn't enough.
111 * Unfortunately, opal_console_write_buffer_space() doesn't
112 * appear to work on opal v1, so we just assume there is
113 * enough room and be done with it
115 spin_lock_irqsave(&opal_write_lock
, flags
);
116 if (firmware_has_feature(FW_FEATURE_OPALv2
)) {
117 rc
= opal_console_write_buffer_space(vtermno
, &len
);
118 if (rc
|| len
< total_len
) {
119 spin_unlock_irqrestore(&opal_write_lock
, flags
);
120 /* Closed -> drop characters */
123 opal_poll_events(&evt
);
128 /* We still try to handle partial completions, though they
129 * should no longer happen.
132 while(total_len
> 0 && (rc
== OPAL_BUSY
||
133 rc
== OPAL_BUSY_EVENT
|| rc
== OPAL_SUCCESS
)) {
135 rc
= opal_console_write(vtermno
, &len
, data
);
136 if (rc
== OPAL_SUCCESS
) {
141 /* This is a bit nasty but we need that for the console to
142 * flush when there aren't any interrupts. We will clean
143 * things a bit later to limit that to synchronous path
144 * such as the kernel console and xmon/udbg
147 opal_poll_events(&evt
);
148 while(rc
== OPAL_SUCCESS
&& (evt
& OPAL_EVENT_CONSOLE_OUTPUT
));
150 spin_unlock_irqrestore(&opal_write_lock
, flags
);
154 int opal_machine_check(struct pt_regs
*regs
)
156 struct opal_machine_check_event
*opal_evt
= get_paca()->opal_mc_evt
;
157 struct opal_machine_check_event evt
;
158 const char *level
, *sevstr
, *subtype
;
159 static const char *opal_mc_ue_types
[] = {
162 "Page table walk ifetch",
164 "Page table walk Load/Store",
166 static const char *opal_mc_slb_types
[] = {
171 static const char *opal_mc_erat_types
[] = {
176 static const char *opal_mc_tlb_types
[] = {
182 /* Copy the event structure and release the original */
184 opal_evt
->in_use
= 0;
186 /* Print things out */
187 if (evt
.version
!= OpalMCE_V1
) {
188 pr_err("Machine Check Exception, Unknown event version %d !\n",
192 switch(evt
.severity
) {
193 case OpalMCE_SEV_NO_ERROR
:
197 case OpalMCE_SEV_WARNING
:
198 level
= KERN_WARNING
;
201 case OpalMCE_SEV_ERROR_SYNC
:
205 case OpalMCE_SEV_FATAL
:
212 printk("%s%s Machine check interrupt [%s]\n", level
, sevstr
,
213 evt
.disposition
== OpalMCE_DISPOSITION_RECOVERED
?
214 "Recovered" : "[Not recovered");
215 printk("%s Initiator: %s\n", level
,
216 evt
.initiator
== OpalMCE_INITIATOR_CPU
? "CPU" : "Unknown");
217 switch(evt
.error_type
) {
218 case OpalMCE_ERROR_TYPE_UE
:
219 subtype
= evt
.u
.ue_error
.ue_error_type
<
220 ARRAY_SIZE(opal_mc_ue_types
) ?
221 opal_mc_ue_types
[evt
.u
.ue_error
.ue_error_type
]
223 printk("%s Error type: UE [%s]\n", level
, subtype
);
224 if (evt
.u
.ue_error
.effective_address_provided
)
225 printk("%s Effective address: %016llx\n",
226 level
, evt
.u
.ue_error
.effective_address
);
227 if (evt
.u
.ue_error
.physical_address_provided
)
228 printk("%s Physial address: %016llx\n",
229 level
, evt
.u
.ue_error
.physical_address
);
231 case OpalMCE_ERROR_TYPE_SLB
:
232 subtype
= evt
.u
.slb_error
.slb_error_type
<
233 ARRAY_SIZE(opal_mc_slb_types
) ?
234 opal_mc_slb_types
[evt
.u
.slb_error
.slb_error_type
]
236 printk("%s Error type: SLB [%s]\n", level
, subtype
);
237 if (evt
.u
.slb_error
.effective_address_provided
)
238 printk("%s Effective address: %016llx\n",
239 level
, evt
.u
.slb_error
.effective_address
);
241 case OpalMCE_ERROR_TYPE_ERAT
:
242 subtype
= evt
.u
.erat_error
.erat_error_type
<
243 ARRAY_SIZE(opal_mc_erat_types
) ?
244 opal_mc_erat_types
[evt
.u
.erat_error
.erat_error_type
]
246 printk("%s Error type: ERAT [%s]\n", level
, subtype
);
247 if (evt
.u
.erat_error
.effective_address_provided
)
248 printk("%s Effective address: %016llx\n",
249 level
, evt
.u
.erat_error
.effective_address
);
251 case OpalMCE_ERROR_TYPE_TLB
:
252 subtype
= evt
.u
.tlb_error
.tlb_error_type
<
253 ARRAY_SIZE(opal_mc_tlb_types
) ?
254 opal_mc_tlb_types
[evt
.u
.tlb_error
.tlb_error_type
]
256 printk("%s Error type: TLB [%s]\n", level
, subtype
);
257 if (evt
.u
.tlb_error
.effective_address_provided
)
258 printk("%s Effective address: %016llx\n",
259 level
, evt
.u
.tlb_error
.effective_address
);
262 case OpalMCE_ERROR_TYPE_UNKNOWN
:
263 printk("%s Error type: Unknown\n", level
);
266 return evt
.severity
== OpalMCE_SEV_FATAL
? 0 : 1;
269 static irqreturn_t
opal_interrupt(int irq
, void *data
)
273 opal_handle_interrupt(virq_to_hw(irq
), &events
);
275 /* XXX TODO: Do something with the events */
280 static int __init
opal_init(void)
282 struct device_node
*np
, *consoles
;
286 opal_node
= of_find_node_by_path("/ibm,opal");
288 pr_warn("opal: Node not found\n");
291 if (firmware_has_feature(FW_FEATURE_OPALv2
))
292 consoles
= of_find_node_by_path("/ibm,opal/consoles");
294 consoles
= of_node_get(opal_node
);
296 /* Register serial ports */
297 for_each_child_of_node(consoles
, np
) {
298 if (strcmp(np
->name
, "serial"))
300 of_platform_device_create(np
, NULL
, NULL
);
302 of_node_put(consoles
);
304 /* Find all OPAL interrupts and request them */
305 irqs
= of_get_property(opal_node
, "opal-interrupts", &irqlen
);
306 pr_debug("opal: Found %d interrupts reserved for OPAL\n",
307 irqs
? (irqlen
/ 4) : 0);
308 for (i
= 0; irqs
&& i
< (irqlen
/ 4); i
++, irqs
++) {
309 unsigned int hwirq
= be32_to_cpup(irqs
);
310 unsigned int irq
= irq_create_mapping(NULL
, hwirq
);
312 pr_warning("opal: Failed to map irq 0x%x\n", hwirq
);
315 rc
= request_irq(irq
, opal_interrupt
, 0, "opal", NULL
);
317 pr_warning("opal: Error %d requesting irq %d"
318 " (0x%x)\n", rc
, irq
, hwirq
);
322 subsys_initcall(opal_init
);