// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM * * Communication to userspace based on kernel/printk.c
*/
/* RTAS service tokens */ staticunsignedint event_scan; staticunsignedint rtas_event_scan_rate;
staticbool full_rtas_msgs;
/* Stop logging to nvram after first fatal error */ staticint logging_enabled; /* Until we initialize everything, * make sure we don't try logging
* anything */ staticint error_log_cnt;
/* * Since we use 32 bit RTAS, the physical address of this must be below * 4G or else bad things happen. Allocate this in the kernel data and * make it big enough.
*/ staticunsignedchar logdata[RTAS_ERROR_LOG_MAX];
switch (type) { case RTAS_TYPE_EPOW: return"EPOW"; case RTAS_TYPE_PLATFORM: return"Platform Error"; case RTAS_TYPE_IO: return"I/O Event"; case RTAS_TYPE_INFO: return"Platform Information Event"; case RTAS_TYPE_DEALLOC: return"Resource Deallocation Event"; case RTAS_TYPE_DUMP: return"Dump Notification Event"; case RTAS_TYPE_PRRN: return"Platform Resource Reassignment Event"; case RTAS_TYPE_HOTPLUG: return"Hotplug Event";
}
return rtas_type[0];
}
/* To see this info, grep RTAS /var/log/messages and each entry * will be collected together with obvious begin/end. * There will be a unique identifier on the begin and end lines. * This will persist across reboots. * * format of error logs returned from RTAS: * bytes (size) : contents * -------------------------------------------------------- * 0-7 (8) : rtas_error_log * 8-47 (40) : extended info * 48-51 (4) : vendor id * 52-1023 (vendor specific) : location code and debug data
*/ staticvoid printk_log_rtas(char *buf, int len)
{
int i,j,n = 0; int perline = 16; char buffer[64]; char * str = "RTAS event";
if (full_rtas_msgs) {
printk(RTAS_DEBUG "%d -------- %s begin --------\n",
error_log_cnt, str);
/* * Print perline bytes on each line, each line will start * with RTAS and a changing number, so syslogd will * print lines that are otherwise the same. Separate every * 4 bytes with a space.
*/ for (i = 0; i < len; i++) {
j = i % perline; if (j == 0) {
memset(buffer, 0, sizeof(buffer));
n = sprintf(buffer, "RTAS %d:", i/perline);
}
if ((i % 4) == 0)
n += sprintf(buffer+n, " ");
n += sprintf(buffer+n, "%02x", (unsignedchar)buf[i]);
if (j == (perline-1))
printk(KERN_DEBUG "%s\n", buffer);
} if ((i % perline) != 0)
printk(KERN_DEBUG "%s\n", buffer);
/* extended header */
len += extended_log_length;
}
if (rtas_error_log_max == 0)
rtas_error_log_max = rtas_get_error_log_max();
if (len > rtas_error_log_max)
len = rtas_error_log_max;
return len;
}
/* * First write to nvram, if fatal error, that is the only * place we log the info. The error will be picked up * on the next reboot by rtasd. If not fatal, run the * method for the type of error. Currently, only RTAS * errors have methods implemented, but in the future * there might be a need to store data in nvram before a * call to panic(). * * XXX We write to nvram periodically, to indicate error has * been written and sync'd, but there is a possibility * that if we don't shutdown correctly, a duplicate error * record will be created on next reboot.
*/ void pSeries_log_error(char *buf, unsignedint err_type, int fatal)
{ unsignedlong offset; unsignedlong s; int len = 0;
pr_debug("rtasd: logging event\n"); if (buf == NULL) return;
spin_lock_irqsave(&rtasd_log_lock, s);
/* get length and increase count */ switch (err_type & ERR_TYPE_MASK) { case ERR_TYPE_RTAS_LOG:
len = log_rtas_len(buf); if (!(err_type & ERR_FLAG_BOOT))
error_log_cnt++; break; case ERR_TYPE_KERNEL_PANIC: default:
WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */
spin_unlock_irqrestore(&rtasd_log_lock, s); return;
}
/* * rtas errors can occur during boot, and we do want to capture * those somewhere, even if nvram isn't ready (why not?), and even * if rtasd isn't ready. Put them into the boot log, at least.
*/ if ((err_type & ERR_TYPE_MASK) == ERR_TYPE_RTAS_LOG)
printk_log_rtas(buf, len);
/* Check to see if we need to or have stopped logging */ if (fatal || !logging_enabled) {
logging_enabled = 0;
WARN_ON_ONCE(!irqs_disabled()); /* @@@ DEBUG @@@ */
spin_unlock_irqrestore(&rtasd_log_lock, s); return;
}
/* call type specific method for error */ switch (err_type & ERR_TYPE_MASK) { case ERR_TYPE_RTAS_LOG:
offset = rtas_error_log_buffer_max *
((rtas_log_start+rtas_log_size) & LOG_NUMBER_MASK);
/* First copy over sequence number */
memcpy(&rtas_log_buf[offset], (void *) &error_log_cnt, sizeof(int));
/* Second copy over error log data */
offset += sizeof(int);
memcpy(&rtas_log_buf[offset], buf, len);
/* This will check if all events are logged, if they are then, we * know that we can safely clear the events in NVRAM. * Next we'll sit and wait for something else to log.
*/ static ssize_t rtas_log_read(struct file * file, char __user * buf,
size_t count, loff_t *ppos)
{ int error; char *tmp; unsignedlong s; unsignedlong offset;
if (!buf || count < rtas_error_log_buffer_max) return -EINVAL;
count = rtas_error_log_buffer_max;
if (!access_ok(buf, count)) return -EFAULT;
tmp = kmalloc(count, GFP_KERNEL); if (!tmp) return -ENOMEM;
spin_lock_irqsave(&rtasd_log_lock, s);
/* if it's 0, then we know we got the last one (the one in NVRAM) */ while (rtas_log_size == 0) { if (file->f_flags & O_NONBLOCK) {
spin_unlock_irqrestore(&rtasd_log_lock, s);
error = -EAGAIN; goto out;
}
/* * Delay should be at least one second since some machines have problems if * we call event-scan too quickly.
*/ staticunsignedlong event_scan_delay = 1*HZ; staticint first_pass = 1;
/* raw_ OK because just using CPU as starting point. */
cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask); if (cpu >= nr_cpu_ids) {
cpu = cpumask_first(cpu_online_mask);
if (first_pass) {
first_pass = 0;
event_scan_delay = 30*HZ/rtas_event_scan_rate;
/* See if we have any error stored in NVRAM */
memset(logdata, 0, rtas_error_log_max);
rc = nvram_read_error_log(logdata, rtas_error_log_max,
&err_type, &error_log_cnt); /* We can use rtas_log_buf now */
logging_enabled = 1; if (!rc) { if (err_type != ERR_FLAG_ALREADY_LOGGED) {
pSeries_log_error(logdata, err_type | ERR_FLAG_BOOT, 0);
}
}
} #else/* CONFIG_PPC64 */ staticvoid __init retrieve_nvram_error_log(void)
{
} #endif/* CONFIG_PPC64 */
staticvoid __init start_event_scan(void)
{
printk(KERN_DEBUG "RTAS daemon started\n");
pr_debug("rtasd: will sleep for %d milliseconds\n",
(30000 / rtas_event_scan_rate));
/* Retrieve errors from nvram if any */
retrieve_nvram_error_log();
/* Cancel the rtas event scan work */ void rtas_cancel_event_scan(void)
{
cancel_delayed_work_sync(&event_scan_work);
}
EXPORT_SYMBOL_GPL(rtas_cancel_event_scan);
staticint __init rtas_event_scan_init(void)
{ int err;
if (!machine_is(pseries) && !machine_is(chrp)) return 0;
/* No RTAS */
event_scan = rtas_function_token(RTAS_FN_EVENT_SCAN); if (event_scan == RTAS_UNKNOWN_SERVICE) {
printk(KERN_INFO "rtasd: No event-scan on system\n"); return -ENODEV;
}
err = of_property_read_u32(rtas.dev, "rtas-event-scan-rate", &rtas_event_scan_rate); if (err) {
printk(KERN_ERR "rtasd: no rtas-event-scan-rate on system\n"); return -ENODEV;
}
if (!rtas_event_scan_rate) { /* Broken firmware: take a rate of zero to mean don't scan */
printk(KERN_DEBUG "rtasd: scan rate is 0, not scanning\n"); return 0;
}
/* Make room for the sequence number */
rtas_error_log_max = rtas_get_error_log_max();
rtas_error_log_buffer_max = rtas_error_log_max + sizeof(int);
rtas_log_buf = vmalloc(array_size(LOG_NUMBER,
rtas_error_log_buffer_max)); if (!rtas_log_buf) {
printk(KERN_ERR "rtasd: no memory\n"); return -ENOMEM;
}
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.