/* Do the actual re-init, This will clobber all FPRs, VRs, etc... * * It will preserve non volatile GPRs and HSPRG0/1. It will * also restore HIDs and other SPRs to their original value * but it might clobber a bunch.
*/ #ifdef __BIG_ENDIAN__
reinit_flags |= OPAL_REINIT_CPUS_HILE_BE; #else
reinit_flags |= OPAL_REINIT_CPUS_HILE_LE; #endif
/* * 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);
/* * Allocate a buffer to hold the MC recoverable ranges.
*/
mc_recoverable_range = memblock_alloc_or_panic(size, __alignof__(u64));
for (i = 0; i < mc_recoverable_range_len; i++) {
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);
if (!(powerpc_firmware_features & FW_FEATURE_OPAL)) return -ENODEV;
/* Hookup some exception handlers except machine check. We use the * fwnmi area at 0x7000 to provide the glue space to OPAL
*/
glue = 0x7000;
/* * Only ancient OPAL firmware requires this. * Specifically, firmware from FW810.00 (released June 2014) * through FW810.20 (Released October 2014). * * Check if we are running on newer (post Oct 2014) firmware that * exports the OPAL_HANDLE_HMI token. If yes, then don't ask OPAL to * patch the HMI interrupt and we catch it directly in Linux. * * For older firmware (i.e < FW810.20), we fallback to old behavior and * let OPAL patch the HMI vector and handle it inside OPAL firmware. * * For newer firmware we catch/handle the HMI directly in Linux.
*/ if (!opal_check_token(OPAL_HANDLE_HMI)) {
pr_info("Old firmware detected, OPAL handles HMIs.\n");
opal_register_exception_handler(
OPAL_HYPERVISOR_MAINTENANCE_HANDLER,
0, glue);
glue += 128;
}
/* * Only applicable to ancient firmware, all modern * (post March 2015/skiboot 5.0) firmware will just return * OPAL_UNSUPPORTED.
*/
opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue); #endif
/* * Opal message notifier based on message type. Allow subscribers to get * notified for specific messgae type.
*/ int opal_message_notifier_register(enum opal_msg_type msg_type, struct notifier_block *nb)
{ int ret; unsignedlong flags;
spin_lock_irqsave(&msg_list_lock, flags);
ret = atomic_notifier_chain_register(
&opal_msg_notifier_head[msg_type], nb);
/* * If the registration succeeded, replay any queued messages that came * in prior to the notifier chain registration. msg_list_lock held here * to ensure they're delivered prior to any subsequent messages.
*/ if (ret == 0)
dequeue_replay_msg(msg_type);
spin_lock_irqsave(&msg_list_lock, flags); if (opal_msg_notifier_head[msg_type].head == NULL) { /* * Queue up the msg since no notifiers have registered * yet for this msg_type.
*/
queue_replay_msg(msg);
queued = true;
}
spin_unlock_irqrestore(&msg_list_lock, flags);
if (atomic)
spin_lock_irqsave(&opal_write_lock, flags);
rc = opal_console_write_buffer_space(vtermno, &olen); if (rc || be64_to_cpu(olen) < total_len) { /* Closed -> drop characters */ if (rc)
written = total_len; else
written = -EAGAIN; goto out;
}
/* Should not get a partial write here because space is available. */
olen = cpu_to_be64(total_len);
rc = opal_console_write(vtermno, &olen, data); if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { if (rc == OPAL_BUSY_EVENT)
opal_poll_events(NULL);
written = -EAGAIN; goto out;
}
/* Closed or other error drop */ if (rc != OPAL_SUCCESS) {
written = opal_error_code(rc); goto out;
}
written = be64_to_cpu(olen); if (written < total_len) { if (atomic) { /* Should not happen */
pr_warn("atomic console write returned partial " "len=%zu written=%zd\n", total_len, written);
} if (!written)
written = -EAGAIN;
}
out: if (atomic)
spin_unlock_irqrestore(&opal_write_lock, flags);
/* * opal_put_chars_atomic will not perform partial-writes. Data will be * atomically written to the terminal or not at all. This is not strictly * true at the moment because console space can race with OPAL's console * writes.
*/
ssize_t opal_put_chars_atomic(uint32_t vtermno, const u8 *data,
size_t total_len)
{ return __opal_put_chars(vtermno, data, total_len, true);
}
if (!opal_check_token(OPAL_CONSOLE_FLUSH)) {
__be64 evt;
/* * If OPAL_CONSOLE_FLUSH is not implemented in the firmware, * the console can still be flushed by calling the polling * function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
*/
WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
opal_poll_events(&evt); if (!(be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT)) return OPAL_SUCCESS; return OPAL_BUSY;
/* * opal_flush_console spins until the console is flushed
*/ int opal_flush_console(uint32_t vtermno)
{ for (;;) {
s64 rc = __opal_flush_console(vtermno);
/* * opal_flush_chars is an hvc interface that sleeps until the console is * flushed if wait, otherwise it will return -EBUSY if the console has data, * -EAGAIN if it has data and some of it was flushed.
*/ int opal_flush_chars(uint32_t vtermno, bool wait)
{ for (;;) {
s64 rc = __opal_flush_console(vtermno);
if (rc == OPAL_BUSY || rc == OPAL_PARTIAL) { if (wait) {
msleep(OPAL_BUSY_DELAY_MS); continue;
} if (rc == OPAL_PARTIAL) return -EAGAIN;
}
if (!recovered && evt->sync_error) { /* * Try to kill processes if we get a synchronous machine check * (e.g., one caused by execution of this instruction). This * will devolve into a panic if we try to kill init or are in * an interrupt etc. * * TODO: Queue up this address for hwpoisioning later. * TODO: This is not quite right for d-side machine * checks ->nip is not necessarily the important * address.
*/ if ((user_mode(regs))) {
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
recovered = 1;
} elseif (die_will_crash()) { /* * die() would kill the kernel, so better to go via * the platform reboot code that will log the * machine check.
*/
recovered = 0;
} else {
die_mce("Machine check", regs, SIGBUS);
recovered = 1;
}
}
pr_emerg("Hardware platform error: %s\n", msg); if (regs)
show_regs(regs);
smp_send_stop();
panic_flush_kmsg_end();
/* * Don't bother to shut things down because this will * xstop the system.
*/ if (opal_cec_reboot2(OPAL_REBOOT_PLATFORM_ERROR, msg)
== OPAL_UNSUPPORTED) {
pr_emerg("Reboot type %d not supported for %s\n",
OPAL_REBOOT_PLATFORM_ERROR, msg);
}
/* * We reached here. There can be three possibilities: * 1. We are running on a firmware level that do not support * opal_cec_reboot2() * 2. We are running on a firmware level that do not support * OPAL_REBOOT_PLATFORM_ERROR reboot type. * 3. We are running on FSP based system that does not need * opal to trigger checkstop explicitly for error analysis. * The FSP PRD component would have already got notified * about this error through other channels. * 4. We are running on a newer skiboot that by default does * not cause a checkstop, drops us back to the kernel to * extract context and state at the time of the error.
*/
panic(msg);
}
int opal_machine_check(struct pt_regs *regs)
{ struct machine_check_event evt;
if (!get_mce_event(&evt, MCE_EVENT_RELEASE)) return 0;
/* Print things out */ if (evt.version != MCE_V1) {
pr_err("Machine Check Exception, Unknown event version %d !\n",
evt.version); return 0;
}
machine_check_print_event_info(&evt, user_mode(regs), false);
/* Early hmi handler called in real mode. */ int opal_hmi_exception_early(struct pt_regs *regs)
{
s64 rc;
/* * call opal hmi handler. Pass paca address as token. * The return value OPAL_SUCCESS is an indication that there is * an HMI event generated waiting to pull by Linux.
*/
rc = opal_handle_hmi(); if (rc == OPAL_SUCCESS) {
local_paca->hmi_event_available = 1; return 1;
} return 0;
}
int opal_hmi_exception_early2(struct pt_regs *regs)
{
s64 rc;
__be64 out_flags;
/* * call opal hmi handler. * Check 64-bit flag mask to find out if an event was generated, * and whether TB is still valid or not etc.
*/
rc = opal_handle_hmi2(&out_flags); if (rc != OPAL_SUCCESS) return 0;
if (be64_to_cpu(out_flags) & OPAL_HMI_FLAGS_NEW_EVENT)
local_paca->hmi_event_available = 1; if (be64_to_cpu(out_flags) & OPAL_HMI_FLAGS_TOD_TB_FAIL)
tb_invalid = true; return 1;
}
/* HMI exception handler called in virtual mode when irqs are next enabled. */ int opal_handle_hmi_exception(struct pt_regs *regs)
{ /* * Check if HMI event is available. * if Yes, then wake kopald to process them.
*/ if (!local_paca->hmi_event_available) return 0;
child_kobj = kobject_create_and_add(child->name, kobj); if (!child_kobj) {
pr_err("Unable to create export dir for %pOF\n", child); continue;
}
opal_add_exported_attrs(child, child_kobj);
}
}
/* * opal_export_attrs: creates a sysfs node for each property listed in * the device-tree under /ibm,opal/firmware/exports/ * All new sysfs nodes are created under /opal/exports/. * This allows for reserved memory regions (e.g. HDAT) to be read. * The new sysfs nodes are only readable by root.
*/ staticvoid opal_export_attrs(void)
{ struct device_node *np; struct kobject *kobj; int rc;
np = of_find_node_by_path("/ibm,opal/firmware/exports"); if (!np) return;
/* Create new 'exports' directory - /sys/firmware/opal/exports */
kobj = kobject_create_and_add("exports", opal_kobj); if (!kobj) {
pr_warn("kobject_create_and_add() of exports failed\n");
of_node_put(np); return;
}
opal_add_exported_attrs(np, kobj);
/* * NB: symbol_map existed before the generic export interface so it * lives under the top level opal_kobj.
*/
rc = opal_add_one_export(opal_kobj, "symbol_map",
np->parent, "symbol-map"); if (rc)
pr_warn("Error %d creating OPAL symbols file\n", rc);
of_node_put(np);
}
staticvoid __init opal_dump_region_init(void)
{ void *addr;
uint64_t size; int rc;
if (!opal_check_token(OPAL_REGISTER_DUMP_REGION)) return;
rc = opal_register_dump_region(OPAL_DUMP_REGION_LOG_BUF,
__pa(addr), size); /* Don't warn if this is just an older OPAL that doesn't * know about that call
*/ if (rc && rc != OPAL_UNSUPPORTED)
pr_warn("DUMP: Failed to register kernel log buffer. " "rc = %d\n", rc);
}
set_current_state(TASK_INTERRUPTIBLE); if (opal_have_pending_events())
__set_current_state(TASK_RUNNING); else
schedule_timeout(timeout);
} while (!kthread_should_stop());
return 0;
}
void opal_wake_poller(void)
{ if (kopald_tsk)
wake_up_process(kopald_tsk);
}
staticvoid __init opal_init_heartbeat(void)
{ /* Old firwmware, we assume the HVC heartbeat is sufficient */ if (of_property_read_u32(opal_node, "ibm,heartbeat-ms",
&opal_heartbeat) != 0)
opal_heartbeat = 0;
if (opal_heartbeat)
kopald_tsk = kthread_run(kopald, NULL, "kopald");
}
/* * 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);
}
/* Unregister memory dump region */ if (opal_check_token(OPAL_UNREGISTER_DUMP_REGION))
opal_unregister_dump_region(OPAL_DUMP_REGION_LOG_BUF);
}
/* Export this so that test modules can use it */
EXPORT_SYMBOL_GPL(opal_invalid_call);
EXPORT_SYMBOL_GPL(opal_xscom_read);
EXPORT_SYMBOL_GPL(opal_xscom_write);
EXPORT_SYMBOL_GPL(opal_ipmi_send);
EXPORT_SYMBOL_GPL(opal_ipmi_recv);
EXPORT_SYMBOL_GPL(opal_flash_read);
EXPORT_SYMBOL_GPL(opal_flash_write);
EXPORT_SYMBOL_GPL(opal_flash_erase);
EXPORT_SYMBOL_GPL(opal_prd_msg);
EXPORT_SYMBOL_GPL(opal_check_token);
/* Convert a region of vmalloc memory to an opal sg list */ struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr, unsignedlong vmalloc_size)
{ struct opal_sg_list *sg, *first = NULL; unsignedlong i = 0;
sg = kzalloc(PAGE_SIZE, GFP_KERNEL); if (!sg) goto nomem;
first = sg;
while (vmalloc_size > 0) {
uint64_t data = vmalloc_to_pfn(vmalloc_addr) << PAGE_SHIFT;
uint64_t length = min(vmalloc_size, PAGE_SIZE);
void opal_free_sg_list(struct opal_sg_list *sg)
{ while (sg) {
uint64_t next = be64_to_cpu(sg->next);
kfree(sg);
if (next)
sg = __va(next); else
sg = NULL;
}
}
int opal_error_code(int rc)
{ switch (rc) { case OPAL_SUCCESS: return 0;
case OPAL_PARAMETER: return -EINVAL; case OPAL_ASYNC_COMPLETION: return -EINPROGRESS; case OPAL_BUSY: case OPAL_BUSY_EVENT: return -EBUSY; case OPAL_NO_MEM: return -ENOMEM; case OPAL_PERMISSION: return -EPERM;
case OPAL_UNSUPPORTED: return -EIO; case OPAL_HARDWARE: return -EIO; case OPAL_INTERNAL_ERROR: return -EIO; case OPAL_TIMEOUT: return -ETIMEDOUT; default:
pr_err("%s: unexpected OPAL error %d\n", __func__, rc); return -EIO;
}
}
void powernv_set_nmmu_ptcr(unsignedlong ptcr)
{ int rc;
if (firmware_has_feature(FW_FEATURE_OPAL)) {
rc = opal_nmmu_set_ptcr(-1UL, ptcr); if (rc != OPAL_SUCCESS && rc != OPAL_UNSUPPORTED)
pr_warn("%s: Unable to set nest mmu ptcr\n", __func__);
}
}
EXPORT_SYMBOL_GPL(opal_poll_events);
EXPORT_SYMBOL_GPL(opal_rtc_read);
EXPORT_SYMBOL_GPL(opal_rtc_write);
EXPORT_SYMBOL_GPL(opal_tpo_read);
EXPORT_SYMBOL_GPL(opal_tpo_write);
EXPORT_SYMBOL_GPL(opal_i2c_request); /* Export these symbols for PowerNV LED class driver */
EXPORT_SYMBOL_GPL(opal_leds_get_ind);
EXPORT_SYMBOL_GPL(opal_leds_set_ind); /* Export this symbol for PowerNV Operator Panel class driver */
EXPORT_SYMBOL_GPL(opal_write_oppanel_async); /* Export this for KVM */
EXPORT_SYMBOL_GPL(opal_int_set_mfrr);
EXPORT_SYMBOL_GPL(opal_int_eoi);
EXPORT_SYMBOL_GPL(opal_error_code); /* Export the below symbol for NX compression */
EXPORT_SYMBOL(opal_nx_coproc_init);
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.