2011-09-20 00:44:57 +07:00
|
|
|
/*
|
|
|
|
* PowerNV OPAL high level interfaces
|
|
|
|
*
|
|
|
|
* Copyright 2011 IBM Corp.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/of.h>
|
2013-09-26 19:40:04 +07:00
|
|
|
#include <linux/of_fdt.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <linux/of_platform.h>
|
2011-09-20 00:45:03 +07:00
|
|
|
#include <linux/interrupt.h>
|
2013-06-20 17:13:22 +07:00
|
|
|
#include <linux/notifier.h>
|
2013-05-10 13:59:18 +07:00
|
|
|
#include <linux/slab.h>
|
2013-10-30 21:36:13 +07:00
|
|
|
#include <linux/sched.h>
|
2013-08-27 16:39:52 +07:00
|
|
|
#include <linux/kobject.h>
|
2014-01-15 13:02:04 +07:00
|
|
|
#include <linux/delay.h>
|
2013-12-16 12:16:24 +07:00
|
|
|
#include <linux/memblock.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <asm/opal.h>
|
|
|
|
#include <asm/firmware.h>
|
2013-10-30 21:35:40 +07:00
|
|
|
#include <asm/mce.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
#include "powernv.h"
|
|
|
|
|
2013-08-27 16:39:52 +07:00
|
|
|
/* /sys/firmware/opal */
|
|
|
|
struct kobject *opal_kobj;
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
struct opal {
|
|
|
|
u64 base;
|
|
|
|
u64 entry;
|
2013-12-16 12:16:24 +07:00
|
|
|
u64 size;
|
2011-09-20 00:44:57 +07:00
|
|
|
} opal;
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
struct mcheck_recoverable_range {
|
|
|
|
u64 start_addr;
|
|
|
|
u64 end_addr;
|
|
|
|
u64 recover_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mcheck_recoverable_range *mc_recoverable_range;
|
|
|
|
static int mc_recoverable_range_len;
|
|
|
|
|
2014-04-01 10:58:19 +07:00
|
|
|
struct device_node *opal_node;
|
2011-09-20 00:44:57 +07:00
|
|
|
static DEFINE_SPINLOCK(opal_write_lock);
|
2011-09-20 00:45:04 +07:00
|
|
|
extern u64 opal_mc_secondary_handler[];
|
2013-05-10 13:59:18 +07:00
|
|
|
static unsigned int *opal_irqs;
|
|
|
|
static unsigned int opal_irq_count;
|
2013-06-20 17:13:22 +07:00
|
|
|
static ATOMIC_NOTIFIER_HEAD(opal_notifier_head);
|
2013-11-18 17:05:58 +07:00
|
|
|
static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
|
2013-06-20 17:13:22 +07:00
|
|
|
static DEFINE_SPINLOCK(opal_notifier_lock);
|
|
|
|
static uint64_t last_notified_mask = 0x0ul;
|
|
|
|
static atomic_t opal_notifier_hold = ATOMIC_INIT(0);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
int __init early_init_dt_scan_opal(unsigned long node,
|
|
|
|
const char *uname, int depth, void *data)
|
|
|
|
{
|
2013-12-16 12:16:24 +07:00
|
|
|
const void *basep, *entryp, *sizep;
|
|
|
|
unsigned long basesz, entrysz, runtimesz;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (depth != 1 || strcmp(uname, "ibm,opal") != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
basep = of_get_flat_dt_prop(node, "opal-base-address", &basesz);
|
|
|
|
entryp = of_get_flat_dt_prop(node, "opal-entry-address", &entrysz);
|
2013-12-16 12:16:24 +07:00
|
|
|
sizep = of_get_flat_dt_prop(node, "opal-runtime-size", &runtimesz);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
if (!basep || !entryp || !sizep)
|
2011-09-20 00:44:57 +07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
opal.base = of_read_number(basep, basesz/4);
|
|
|
|
opal.entry = of_read_number(entryp, entrysz/4);
|
2013-12-16 12:16:24 +07:00
|
|
|
opal.size = of_read_number(sizep, runtimesz/4);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
pr_debug("OPAL Base = 0x%llx (basep=%p basesz=%ld)\n",
|
|
|
|
opal.base, basep, basesz);
|
|
|
|
pr_debug("OPAL Entry = 0x%llx (entryp=%p basesz=%ld)\n",
|
|
|
|
opal.entry, entryp, entrysz);
|
2013-12-16 12:16:24 +07:00
|
|
|
pr_debug("OPAL Entry = 0x%llx (sizep=%p runtimesz=%ld)\n",
|
|
|
|
opal.size, sizep, runtimesz);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
powerpc_firmware_features |= FW_FEATURE_OPAL;
|
2013-05-14 12:10:02 +07:00
|
|
|
if (of_flat_dt_is_compatible(node, "ibm,opal-v3")) {
|
|
|
|
powerpc_firmware_features |= FW_FEATURE_OPALv2;
|
|
|
|
powerpc_firmware_features |= FW_FEATURE_OPALv3;
|
|
|
|
printk("OPAL V3 detected !\n");
|
|
|
|
} else if (of_flat_dt_is_compatible(node, "ibm,opal-v2")) {
|
2011-09-20 00:44:57 +07:00
|
|
|
powerpc_firmware_features |= FW_FEATURE_OPALv2;
|
|
|
|
printk("OPAL V2 detected !\n");
|
|
|
|
} else {
|
|
|
|
printk("OPAL V1 detected !\n");
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
int __init early_init_dt_scan_recoverable_ranges(unsigned long node,
|
|
|
|
const char *uname, int depth, void *data)
|
|
|
|
{
|
2014-03-30 12:33:23 +07:00
|
|
|
unsigned long i, psize, size;
|
2013-12-16 12:16:24 +07:00
|
|
|
const __be32 *prop;
|
|
|
|
|
|
|
|
if (depth != 1 || strcmp(uname, "ibm,opal") != 0)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
prop = of_get_flat_dt_prop(node, "mcheck-recoverable-ranges", &psize);
|
2013-12-16 12:16:24 +07:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pr_debug("Found machine check recoverable ranges.\n");
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
/*
|
|
|
|
* Calculate number of available entries.
|
|
|
|
*
|
|
|
|
* Each recoverable address range entry is (start address, len,
|
|
|
|
* recovery address), 2 cells each for start and recovery address,
|
|
|
|
* 1 cell for len, totalling 5 cells per entry.
|
|
|
|
*/
|
|
|
|
mc_recoverable_range_len = psize / (sizeof(*prop) * 5);
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (!mc_recoverable_range_len)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Size required to hold all the entries. */
|
|
|
|
size = mc_recoverable_range_len *
|
|
|
|
sizeof(struct mcheck_recoverable_range);
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
/*
|
|
|
|
* Allocate a buffer to hold the MC recoverable ranges. We would be
|
|
|
|
* accessing them in real mode, hence it needs to be within
|
|
|
|
* RMO region.
|
|
|
|
*/
|
|
|
|
mc_recoverable_range =__va(memblock_alloc_base(size, __alignof__(u64),
|
|
|
|
ppc64_rma_size));
|
|
|
|
memset(mc_recoverable_range, 0, size);
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
for (i = 0; i < mc_recoverable_range_len; i++) {
|
2013-12-16 12:16:24 +07:00
|
|
|
mc_recoverable_range[i].start_addr =
|
|
|
|
of_read_number(prop + (i * 5) + 0, 2);
|
|
|
|
mc_recoverable_range[i].end_addr =
|
|
|
|
mc_recoverable_range[i].start_addr +
|
|
|
|
of_read_number(prop + (i * 5) + 2, 1);
|
|
|
|
mc_recoverable_range[i].recover_addr =
|
|
|
|
of_read_number(prop + (i * 5) + 3, 2);
|
|
|
|
|
|
|
|
pr_debug("Machine check recoverable range: %llx..%llx: %llx\n",
|
|
|
|
mc_recoverable_range[i].start_addr,
|
|
|
|
mc_recoverable_range[i].end_addr,
|
|
|
|
mc_recoverable_range[i].recover_addr);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
static int __init opal_register_exception_handlers(void)
|
|
|
|
{
|
2013-09-23 09:05:04 +07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2013-05-02 05:31:50 +07:00
|
|
|
u64 glue;
|
|
|
|
|
|
|
|
if (!(powerpc_firmware_features & FW_FEATURE_OPAL))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-10-30 21:35:58 +07:00
|
|
|
/* Hookup some exception handlers except machine check. We use the
|
|
|
|
* fwnmi area at 0x7000 to provide the glue space to OPAL
|
2011-09-20 00:45:04 +07:00
|
|
|
*/
|
|
|
|
glue = 0x7000;
|
|
|
|
opal_register_exception_handler(OPAL_HYPERVISOR_MAINTENANCE_HANDLER,
|
|
|
|
0, glue);
|
|
|
|
glue += 128;
|
|
|
|
opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue);
|
2013-09-23 09:05:04 +07:00
|
|
|
#endif
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
return 0;
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
early_initcall(opal_register_exception_handlers);
|
|
|
|
|
2013-06-20 17:13:22 +07:00
|
|
|
int opal_notifier_register(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
if (!nb) {
|
|
|
|
pr_warning("%s: Invalid argument (%p)\n",
|
|
|
|
__func__, nb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_notifier_chain_register(&opal_notifier_head, nb);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-03-28 09:36:31 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_notifier_register);
|
|
|
|
|
|
|
|
int opal_notifier_unregister(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
if (!nb) {
|
|
|
|
pr_warning("%s: Invalid argument (%p)\n",
|
|
|
|
__func__, nb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_notifier_chain_unregister(&opal_notifier_head, nb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(opal_notifier_unregister);
|
2013-06-20 17:13:22 +07:00
|
|
|
|
|
|
|
static void opal_do_notifier(uint64_t events)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
uint64_t changed_mask;
|
|
|
|
|
|
|
|
if (atomic_read(&opal_notifier_hold))
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&opal_notifier_lock, flags);
|
|
|
|
changed_mask = last_notified_mask ^ events;
|
|
|
|
last_notified_mask = events;
|
|
|
|
spin_unlock_irqrestore(&opal_notifier_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We feed with the event bits and changed bits for
|
|
|
|
* enough information to the callback.
|
|
|
|
*/
|
|
|
|
atomic_notifier_call_chain(&opal_notifier_head,
|
|
|
|
events, (void *)changed_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void opal_notifier_update_evt(uint64_t evt_mask,
|
|
|
|
uint64_t evt_val)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&opal_notifier_lock, flags);
|
|
|
|
last_notified_mask &= ~evt_mask;
|
|
|
|
last_notified_mask |= evt_val;
|
|
|
|
spin_unlock_irqrestore(&opal_notifier_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void opal_notifier_enable(void)
|
|
|
|
{
|
|
|
|
int64_t rc;
|
|
|
|
uint64_t evt = 0;
|
|
|
|
|
|
|
|
atomic_set(&opal_notifier_hold, 0);
|
|
|
|
|
|
|
|
/* Process pending events */
|
|
|
|
rc = opal_poll_events(&evt);
|
|
|
|
if (rc == OPAL_SUCCESS && evt)
|
|
|
|
opal_do_notifier(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void opal_notifier_disable(void)
|
|
|
|
{
|
|
|
|
atomic_set(&opal_notifier_hold, 1);
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
/*
|
|
|
|
* Opal message notifier based on message type. Allow subscribers to get
|
|
|
|
* notified for specific messgae type.
|
|
|
|
*/
|
|
|
|
int opal_message_notifier_register(enum OpalMessageType msg_type,
|
|
|
|
struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
if (!nb) {
|
|
|
|
pr_warning("%s: Invalid argument (%p)\n",
|
|
|
|
__func__, nb);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (msg_type > OPAL_MSG_TYPE_MAX) {
|
|
|
|
pr_warning("%s: Invalid message type argument (%d)\n",
|
|
|
|
__func__, msg_type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return atomic_notifier_chain_register(
|
|
|
|
&opal_msg_notifier_head[msg_type], nb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opal_message_do_notify(uint32_t msg_type, void *msg)
|
|
|
|
{
|
|
|
|
/* notify subscribers */
|
|
|
|
atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type],
|
|
|
|
msg_type, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opal_handle_message(void)
|
|
|
|
{
|
|
|
|
s64 ret;
|
|
|
|
/*
|
|
|
|
* TODO: pre-allocate a message buffer depending on opal-msg-size
|
|
|
|
* value in /proc/device-tree.
|
|
|
|
*/
|
|
|
|
static struct opal_msg msg;
|
2014-03-28 12:33:33 +07:00
|
|
|
u32 type;
|
2013-11-18 17:05:58 +07:00
|
|
|
|
|
|
|
ret = opal_get_msg(__pa(&msg), sizeof(msg));
|
|
|
|
/* No opal message pending. */
|
|
|
|
if (ret == OPAL_RESOURCE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* check for errors. */
|
|
|
|
if (ret) {
|
|
|
|
pr_warning("%s: Failed to retrive opal message, err=%lld\n",
|
|
|
|
__func__, ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-28 12:33:33 +07:00
|
|
|
type = be32_to_cpu(msg.msg_type);
|
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
/* Sanity check */
|
2014-03-28 12:33:33 +07:00
|
|
|
if (type > OPAL_MSG_TYPE_MAX) {
|
|
|
|
pr_warning("%s: Unknown message type: %u\n", __func__, type);
|
2013-11-18 17:05:58 +07:00
|
|
|
return;
|
|
|
|
}
|
2014-03-28 12:33:33 +07:00
|
|
|
opal_message_do_notify(type, (void *)&msg);
|
2013-11-18 17:05:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int opal_message_notify(struct notifier_block *nb,
|
|
|
|
unsigned long events, void *change)
|
|
|
|
{
|
|
|
|
if (events & OPAL_EVENT_MSG_PENDING)
|
|
|
|
opal_handle_message();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block opal_message_nb = {
|
|
|
|
.notifier_call = opal_message_notify,
|
|
|
|
.next = NULL,
|
|
|
|
.priority = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init opal_message_init(void)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
for (i = 0; i < OPAL_MSG_TYPE_MAX; i++)
|
|
|
|
ATOMIC_INIT_NOTIFIER_HEAD(&opal_msg_notifier_head[i]);
|
|
|
|
|
|
|
|
ret = opal_notifier_register(&opal_message_nb);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: Can't register OPAL event notifier (%d)\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_initcall(opal_message_init);
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
int opal_get_chars(uint32_t vtermno, char *buf, int count)
|
|
|
|
{
|
2013-09-23 09:05:02 +07:00
|
|
|
s64 rc;
|
|
|
|
__be64 evt, len;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (!opal.entry)
|
2011-09-20 00:44:59 +07:00
|
|
|
return -ENODEV;
|
2011-09-20 00:44:57 +07:00
|
|
|
opal_poll_events(&evt);
|
2013-09-23 09:05:02 +07:00
|
|
|
if ((be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_INPUT) == 0)
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
2013-09-23 09:05:02 +07:00
|
|
|
len = cpu_to_be64(count);
|
|
|
|
rc = opal_console_read(vtermno, &len, buf);
|
2011-09-20 00:44:57 +07:00
|
|
|
if (rc == OPAL_SUCCESS)
|
2013-09-23 09:05:02 +07:00
|
|
|
return be64_to_cpu(len);
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
|
|
|
|
{
|
|
|
|
int written = 0;
|
2013-09-23 09:05:02 +07:00
|
|
|
__be64 olen;
|
2011-09-20 00:44:59 +07:00
|
|
|
s64 len, rc;
|
2011-09-20 00:44:57 +07:00
|
|
|
unsigned long flags;
|
2013-09-23 09:05:02 +07:00
|
|
|
__be64 evt;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (!opal.entry)
|
2011-09-20 00:44:59 +07:00
|
|
|
return -ENODEV;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
/* We want put_chars to be atomic to avoid mangling of hvsi
|
|
|
|
* packets. To do that, we first test for room and return
|
2011-09-20 00:44:59 +07:00
|
|
|
* -EAGAIN if there isn't enough.
|
|
|
|
*
|
|
|
|
* Unfortunately, opal_console_write_buffer_space() doesn't
|
|
|
|
* appear to work on opal v1, so we just assume there is
|
|
|
|
* enough room and be done with it
|
2011-09-20 00:44:57 +07:00
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&opal_write_lock, flags);
|
2011-09-20 00:44:59 +07:00
|
|
|
if (firmware_has_feature(FW_FEATURE_OPALv2)) {
|
2013-09-23 09:05:02 +07:00
|
|
|
rc = opal_console_write_buffer_space(vtermno, &olen);
|
|
|
|
len = be64_to_cpu(olen);
|
2011-09-20 00:44:59 +07:00
|
|
|
if (rc || len < total_len) {
|
|
|
|
spin_unlock_irqrestore(&opal_write_lock, flags);
|
|
|
|
/* Closed -> drop characters */
|
|
|
|
if (rc)
|
|
|
|
return total_len;
|
2013-09-23 09:05:02 +07:00
|
|
|
opal_poll_events(NULL);
|
2011-09-20 00:44:59 +07:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We still try to handle partial completions, though they
|
|
|
|
* should no longer happen.
|
|
|
|
*/
|
2011-09-20 00:44:59 +07:00
|
|
|
rc = OPAL_BUSY;
|
2011-09-20 00:44:57 +07:00
|
|
|
while(total_len > 0 && (rc == OPAL_BUSY ||
|
|
|
|
rc == OPAL_BUSY_EVENT || rc == OPAL_SUCCESS)) {
|
2013-09-23 09:05:02 +07:00
|
|
|
olen = cpu_to_be64(total_len);
|
|
|
|
rc = opal_console_write(vtermno, &olen, data);
|
|
|
|
len = be64_to_cpu(olen);
|
2013-05-08 11:14:26 +07:00
|
|
|
|
|
|
|
/* Closed or other error drop */
|
|
|
|
if (rc != OPAL_SUCCESS && rc != OPAL_BUSY &&
|
|
|
|
rc != OPAL_BUSY_EVENT) {
|
|
|
|
written = total_len;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-20 00:44:57 +07:00
|
|
|
if (rc == OPAL_SUCCESS) {
|
|
|
|
total_len -= len;
|
|
|
|
data += len;
|
|
|
|
written += len;
|
|
|
|
}
|
|
|
|
/* This is a bit nasty but we need that for the console to
|
|
|
|
* flush when there aren't any interrupts. We will clean
|
|
|
|
* things a bit later to limit that to synchronous path
|
|
|
|
* such as the kernel console and xmon/udbg
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
opal_poll_events(&evt);
|
2013-09-23 09:05:02 +07:00
|
|
|
while(rc == OPAL_SUCCESS &&
|
|
|
|
(be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT));
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&opal_write_lock, flags);
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:36:13 +07:00
|
|
|
static int opal_recover_mce(struct pt_regs *regs,
|
|
|
|
struct machine_check_event *evt)
|
|
|
|
{
|
|
|
|
int recovered = 0;
|
|
|
|
uint64_t ea = get_mce_fault_addr(evt);
|
|
|
|
|
|
|
|
if (!(regs->msr & MSR_RI)) {
|
|
|
|
/* If MSR_RI isn't set, we cannot recover */
|
|
|
|
recovered = 0;
|
|
|
|
} else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
|
|
|
|
/* Platform corrected itself */
|
|
|
|
recovered = 1;
|
|
|
|
} else if (ea && !is_kernel_addr(ea)) {
|
|
|
|
/*
|
|
|
|
* Faulting address is not in kernel text. We should be fine.
|
|
|
|
* We need to find which process uses this address.
|
|
|
|
* For now, kill the task if we have received exception when
|
|
|
|
* in userspace.
|
|
|
|
*
|
|
|
|
* TODO: Queue up this address for hwpoisioning later.
|
|
|
|
*/
|
|
|
|
if (user_mode(regs) && !is_global_init(current)) {
|
|
|
|
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
|
|
|
|
recovered = 1;
|
|
|
|
} else
|
|
|
|
recovered = 0;
|
|
|
|
} else if (user_mode(regs) && !is_global_init(current) &&
|
|
|
|
evt->severity == MCE_SEV_ERROR_SYNC) {
|
|
|
|
/*
|
|
|
|
* If we have received a synchronous error when in userspace
|
|
|
|
* kill the task.
|
|
|
|
*/
|
|
|
|
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
|
|
|
|
recovered = 1;
|
|
|
|
}
|
|
|
|
return recovered;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:45:04 +07:00
|
|
|
int opal_machine_check(struct pt_regs *regs)
|
|
|
|
{
|
2013-10-30 21:35:40 +07:00
|
|
|
struct machine_check_event evt;
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-10-30 21:35:40 +07:00
|
|
|
if (!get_mce_event(&evt, MCE_EVENT_RELEASE))
|
|
|
|
return 0;
|
2011-09-20 00:45:04 +07:00
|
|
|
|
|
|
|
/* Print things out */
|
2013-10-30 21:35:40 +07:00
|
|
|
if (evt.version != MCE_V1) {
|
2011-09-20 00:45:04 +07:00
|
|
|
pr_err("Machine Check Exception, Unknown event version %d !\n",
|
|
|
|
evt.version);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-30 21:35:49 +07:00
|
|
|
machine_check_print_event_info(&evt);
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-10-30 21:36:13 +07:00
|
|
|
if (opal_recover_mce(regs, &evt))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2011-09-20 00:45:04 +07:00
|
|
|
}
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
static uint64_t find_recovery_address(uint64_t nip)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < mc_recoverable_range_len; i++)
|
|
|
|
if ((nip >= mc_recoverable_range[i].start_addr) &&
|
|
|
|
(nip < mc_recoverable_range[i].end_addr))
|
|
|
|
return mc_recoverable_range[i].recover_addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool opal_mce_check_early_recovery(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
uint64_t recover_addr = 0;
|
|
|
|
|
|
|
|
if (!opal.base || !opal.size)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ((regs->nip >= opal.base) &&
|
|
|
|
(regs->nip <= (opal.base + opal.size)))
|
|
|
|
recover_addr = find_recovery_address(regs->nip);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup regs->nip to rfi into fixup address.
|
|
|
|
*/
|
|
|
|
if (recover_addr)
|
|
|
|
regs->nip = recover_addr;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return !!recover_addr;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:45:03 +07:00
|
|
|
static irqreturn_t opal_interrupt(int irq, void *data)
|
|
|
|
{
|
2013-09-23 09:05:06 +07:00
|
|
|
__be64 events;
|
2011-09-20 00:45:03 +07:00
|
|
|
|
|
|
|
opal_handle_interrupt(virq_to_hw(irq), &events);
|
|
|
|
|
2013-06-20 17:13:22 +07:00
|
|
|
opal_do_notifier(events);
|
2011-09-20 00:45:03 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-08-27 16:39:52 +07:00
|
|
|
static int opal_sysfs_init(void)
|
|
|
|
{
|
|
|
|
opal_kobj = kobject_create_and_add("opal", firmware_kobj);
|
|
|
|
if (!opal_kobj) {
|
|
|
|
pr_warn("kobject_create_and_add opal failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
static int __init opal_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *np, *consoles;
|
2013-09-23 09:04:54 +07:00
|
|
|
const __be32 *irqs;
|
2011-09-20 00:45:03 +07:00
|
|
|
int rc, i, irqlen;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
opal_node = of_find_node_by_path("/ibm,opal");
|
|
|
|
if (!opal_node) {
|
|
|
|
pr_warn("opal: Node not found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2013-07-15 10:03:14 +07:00
|
|
|
|
|
|
|
/* Register OPAL consoles if any ports */
|
2011-09-20 00:44:57 +07:00
|
|
|
if (firmware_has_feature(FW_FEATURE_OPALv2))
|
|
|
|
consoles = of_find_node_by_path("/ibm,opal/consoles");
|
|
|
|
else
|
|
|
|
consoles = of_node_get(opal_node);
|
2013-07-15 10:03:14 +07:00
|
|
|
if (consoles) {
|
|
|
|
for_each_child_of_node(consoles, np) {
|
|
|
|
if (strcmp(np->name, "serial"))
|
|
|
|
continue;
|
|
|
|
of_platform_device_create(np, NULL, NULL);
|
|
|
|
}
|
|
|
|
of_node_put(consoles);
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
2011-09-20 00:45:03 +07:00
|
|
|
|
|
|
|
/* Find all OPAL interrupts and request them */
|
|
|
|
irqs = of_get_property(opal_node, "opal-interrupts", &irqlen);
|
|
|
|
pr_debug("opal: Found %d interrupts reserved for OPAL\n",
|
|
|
|
irqs ? (irqlen / 4) : 0);
|
2013-05-10 13:59:18 +07:00
|
|
|
opal_irq_count = irqlen / 4;
|
|
|
|
opal_irqs = kzalloc(opal_irq_count * sizeof(unsigned int), GFP_KERNEL);
|
2011-09-20 00:45:03 +07:00
|
|
|
for (i = 0; irqs && i < (irqlen / 4); i++, irqs++) {
|
|
|
|
unsigned int hwirq = be32_to_cpup(irqs);
|
|
|
|
unsigned int irq = irq_create_mapping(NULL, hwirq);
|
|
|
|
if (irq == NO_IRQ) {
|
|
|
|
pr_warning("opal: Failed to map irq 0x%x\n", hwirq);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rc = request_irq(irq, opal_interrupt, 0, "opal", NULL);
|
|
|
|
if (rc)
|
|
|
|
pr_warning("opal: Error %d requesting irq %d"
|
|
|
|
" (0x%x)\n", rc, irq, hwirq);
|
2013-05-10 13:59:18 +07:00
|
|
|
opal_irqs[i] = irq;
|
2011-09-20 00:45:03 +07:00
|
|
|
}
|
2013-08-27 16:39:52 +07:00
|
|
|
|
|
|
|
/* Create "opal" kobject under /sys/firmware */
|
|
|
|
rc = opal_sysfs_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
if (rc == 0) {
|
powerpc/powernv: Read OPAL error log and export it through sysfs
Based on a patch by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
This patch adds support to read error logs from OPAL and export
them to userspace through a sysfs interface.
We export each log entry as a directory in /sys/firmware/opal/elog/
Currently, OPAL will buffer up to 128 error log records, we don't
need to have any knowledge of this limit on the Linux side as that
is actually largely transparent to us.
Each error log entry has the following files: id, type, acknowledge, raw.
Currently we just export the raw binary error log in the 'raw' attribute.
In a future patch, we may parse more of the error log to make it a bit
easier for userspace (e.g. to be able to display a brief summary in
petitboot without having to have a full parser).
If we have >128 logs from OPAL, we'll only be notified of 128 until
userspace starts acknowledging them. This limitation may be lifted in
the future and with this patch, that should "just work" from the linux side.
A userspace daemon should:
- wait for error log entries using normal mechanisms (we announce creation)
- read error log entry
- save error log entry safely to disk
- acknowledge the error log entry
- rinse, repeat.
On the Linux side, we read the error log when we're notified of it. This
possibly isn't ideal as it would be better to only read them on-demand.
However, this doesn't really work with current OPAL interface, so we
read the error log immediately when notified at the moment.
I've tested this pretty extensively and am rather confident that the
linux side of things works rather well. There is currently an issue with
the service processor side of things for >128 error logs though.
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-02-28 07:58:32 +07:00
|
|
|
/* Setup error log interface */
|
|
|
|
rc = opal_elog_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
/* Setup code update interface */
|
|
|
|
opal_flash_init();
|
2014-03-03 06:25:42 +07:00
|
|
|
/* Setup platform dump extract interface */
|
|
|
|
opal_platform_dump_init();
|
2014-03-07 12:32:09 +07:00
|
|
|
/* Setup system parameters interface */
|
|
|
|
opal_sys_param_init();
|
2014-04-01 10:58:19 +07:00
|
|
|
/* Setup message log interface. */
|
|
|
|
opal_msglog_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
}
|
2013-08-27 16:39:52 +07:00
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(opal_init);
|
2013-05-10 13:59:18 +07:00
|
|
|
|
|
|
|
void opal_shutdown(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2014-01-15 13:02:04 +07:00
|
|
|
long rc = OPAL_BUSY;
|
2013-05-10 13:59:18 +07:00
|
|
|
|
2014-01-15 13:02:04 +07:00
|
|
|
/* First free interrupts, which will also mask them */
|
2013-05-10 13:59:18 +07:00
|
|
|
for (i = 0; i < opal_irq_count; i++) {
|
|
|
|
if (opal_irqs[i])
|
2013-08-06 23:01:24 +07:00
|
|
|
free_irq(opal_irqs[i], NULL);
|
2013-05-10 13:59:18 +07:00
|
|
|
opal_irqs[i] = 0;
|
|
|
|
}
|
2014-01-15 13:02:04 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Then sync with OPAL which ensure anything that can
|
|
|
|
* potentially write to our memory has completed such
|
|
|
|
* as an ongoing dump retrieval
|
|
|
|
*/
|
|
|
|
while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
|
|
|
|
rc = opal_sync_host_reboot();
|
|
|
|
if (rc == OPAL_BUSY)
|
|
|
|
opal_poll_events(NULL);
|
|
|
|
else
|
|
|
|
mdelay(10);
|
|
|
|
}
|
2013-05-10 13:59:18 +07:00
|
|
|
}
|
2014-04-01 10:58:20 +07:00
|
|
|
|
|
|
|
/* Export this so that test modules can use it */
|
|
|
|
EXPORT_SYMBOL_GPL(opal_invalid_call);
|