15 #include <linux/kernel.h>
16 #include <linux/types.h>
18 #include <linux/export.h>
20 #include <linux/capability.h>
26 #include <linux/slab.h>
27 #include <linux/reboot.h>
32 #include <asm/machdep.h>
35 #include <asm/param.h>
36 #include <asm/delay.h>
37 #include <asm/uaccess.h>
39 #include <asm/syscalls.h>
44 #include <asm/topology.h>
72 static unsigned long lock_rtas(
void)
82 static void unlock_rtas(
unsigned long flags)
94 static void call_rtas_display_status(
char c)
106 args->rets = (rtas_arg_t *)&(args->args[1]);
107 args->args[0] = (
unsigned char)c;
109 enter_rtas(
__pa(args));
114 static void call_rtas_display_status_delay(
char c)
116 static int pending_newline = 0;
117 static int width = 16;
121 call_rtas_display_status(
' ');
126 if (pending_newline) {
127 call_rtas_display_status(
'\r');
128 call_rtas_display_status(
'\n');
132 call_rtas_display_status(c);
140 udbg_putc = call_rtas_display_status_delay;
143 #ifdef CONFIG_UDBG_RTAS_CONSOLE
149 static unsigned int rtas_putchar_token = RTAS_UNKNOWN_SERVICE;
150 static unsigned int rtas_getchar_token = RTAS_UNKNOWN_SERVICE;
152 static void udbg_rtascon_putc(
char c)
161 udbg_rtascon_putc(
'\r');
164 for (tries = 0; tries < 16; tries++) {
171 static int udbg_rtascon_getc_poll(
void)
178 if (
rtas_call(rtas_getchar_token, 0, 2, &c))
184 static int udbg_rtascon_getc(
void)
188 while ((c = udbg_rtascon_getc_poll()) == -1)
195 void __init udbg_init_rtas_console(
void)
209 static int display_character, set_indicator;
211 static const int *row_width;
213 static int current_line;
214 static int pending_newline = 0;
219 if (display_width == 0) {
220 display_width = 0x10;
223 "ibm,display-line-length",
NULL)))
226 "ibm,form-feed",
NULL)))
229 "ibm,display-number-of-lines",
NULL)))
232 "ibm,display-truncation-length",
NULL);
235 display_character =
rtas_token(
"display-character");
239 if (display_character == RTAS_UNKNOWN_SERVICE) {
241 if (set_indicator != RTAS_UNKNOWN_SERVICE)
246 spin_lock(&progress_lock);
257 if (pending_newline) {
271 width = row_width[current_line];
276 if (*os ==
'\n' || *os ==
'\r') {
281 if (*os ==
'\n' && !os[1]) {
284 if (current_line > display_lines-1)
285 current_line = display_lines-1;
286 spin_unlock(&progress_lock);
303 width = row_width[current_line];
315 while ((*os != 0) && (*os !=
'\n') && (*os !=
'\r'))
319 spin_unlock(&progress_lock);
327 return RTAS_UNKNOWN_SERVICE;
329 return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
335 return rtas_token(service) != RTAS_UNKNOWN_SERVICE;
339 #ifdef CONFIG_RTAS_ERROR_LOGGING
345 int rtas_get_error_log_max(
void)
347 static int rtas_error_log_max;
348 if (rtas_error_log_max)
349 return rtas_error_log_max;
351 rtas_error_log_max =
rtas_token (
"rtas-error-log-max");
352 if ((rtas_error_log_max == RTAS_UNKNOWN_SERVICE) ||
353 (rtas_error_log_max > RTAS_ERROR_LOG_MAX)) {
356 rtas_error_log_max = RTAS_ERROR_LOG_MAX;
358 return rtas_error_log_max;
363 static char rtas_err_buf[RTAS_ERROR_LOG_MAX];
364 static int rtas_last_error_token;
374 struct rtas_args err_args, save_args;
378 if (rtas_last_error_token == -1)
381 bufsz = rtas_get_error_log_max();
383 err_args.token = rtas_last_error_token;
386 err_args.args[0] = (rtas_arg_t)
__pa(rtas_err_buf);
387 err_args.args[1] = bufsz;
388 err_args.args[2] = 0;
390 save_args =
rtas.args;
391 rtas.args = err_args;
395 err_args =
rtas.args;
396 rtas.args = save_args;
399 if (
unlikely(err_args.args[2] == 0)) {
408 memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX);
414 #define get_errorlog_buffer() kmalloc(RTAS_ERROR_LOG_MAX, GFP_KERNEL)
417 #define __fetch_rtas_last_error(x) NULL
418 #define get_errorlog_buffer() NULL
426 struct rtas_args *rtas_args;
427 char *buff_copy =
NULL;
430 if (!
rtas.entry || token == RTAS_UNKNOWN_SERVICE)
434 rtas_args = &
rtas.args;
436 rtas_args->token =
token;
437 rtas_args->nargs = nargs;
438 rtas_args->nret = nret;
439 rtas_args->rets = (rtas_arg_t *)&(rtas_args->args[nargs]);
441 for (i = 0; i < nargs; ++
i)
442 rtas_args->args[i] =
va_arg(list, rtas_arg_t);
445 for (i = 0; i < nret; ++
i)
446 rtas_args->rets[i] = 0;
448 enter_rtas(
__pa(rtas_args));
452 if (rtas_args->rets[0] == -1)
455 if (nret > 1 && outputs !=
NULL)
456 for (i = 0; i < nret-1; ++
i)
457 outputs[i] = rtas_args->rets[i+1];
458 ret = (nret > 0)? rtas_args->rets[0]: 0;
463 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
479 if (status == RTAS_BUSY) {
481 }
else if (status >= 9900 && status <= 9905) {
482 order = status - 9900;
483 for (ms = 1; order > 0; order--)
498 if (ms && need_resched())
505 static int rtas_error_rc(
int rtas_rc)
539 if (token == RTAS_UNKNOWN_SERVICE)
542 while ((rc =
rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
546 return rtas_error_rc(rc);
556 if (token == RTAS_UNKNOWN_SERVICE)
560 rc =
rtas_call(token, 2, 2, setlevel, powerdomain, level);
564 return rtas_error_rc(rc);
574 if (token == RTAS_UNKNOWN_SERVICE)
578 rc =
rtas_call(token, 2, 2, state, sensor, index);
582 return rtas_error_rc(rc);
590 const struct indicator_elem {
599 count = proplen /
sizeof(
struct indicator_elem);
601 for (i = 0; i <
count; i++) {
602 if (indicators[i].token != token)
605 *maxindex = indicators[
i].maxindex;
618 if (token == RTAS_UNKNOWN_SERVICE)
622 rc =
rtas_call(token, 3, 1,
NULL, indicator, index, new_value);
626 return rtas_error_rc(rc);
639 if (token == RTAS_UNKNOWN_SERVICE)
642 rc =
rtas_call(token, 3, 1,
NULL, indicator, index, new_value);
644 WARN_ON(rc == -2 || (rc >= 9900 && rc <= 9905));
647 return rtas_error_rc(rc);
656 printk(
"RTAS system-reboot returned %d\n",
666 printk(
"RTAS power-off returned %d\n",
676 printk(
"RTAS power-off returned %d\n",
682 static char rtas_os_term_buf[2048];
694 if (RTAS_UNKNOWN_SERVICE ==
rtas_token(
"ibm,os-term") ||
695 RTAS_UNKNOWN_SERVICE ==
rtas_token(
"ibm,extended-os-term"))
698 snprintf(rtas_os_term_buf, 2048,
"OS panic: %s", str);
702 __pa(rtas_os_term_buf));
709 static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
710 #ifdef CONFIG_PPC_PSERIES
711 static int __rtas_suspend_last_cpu(
struct rtas_suspend_me_data *
data,
int wake_when_done)
714 int rc = H_MULTI_THREADS_ACTIVE;
720 while (rc == H_MULTI_THREADS_ACTIVE && !
atomic_read(&data->done) &&
735 if (wake_when_done) {
739 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu));
748 int rtas_suspend_last_cpu(
struct rtas_suspend_me_data *data)
751 return __rtas_suspend_last_cpu(data, 0);
754 static int __rtas_suspend_cpu(
struct rtas_suspend_me_data *data,
int wake_when_done)
757 unsigned long msr_save;
764 mtmsr(msr_save & ~(
MSR_EE));
767 rc = plpar_hcall_norets(H_JOIN);
771 if (rc == H_SUCCESS) {
774 }
else if (rc == H_CONTINUE) {
778 return __rtas_suspend_last_cpu(data, wake_when_done);
785 if (wake_when_done) {
793 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu));
801 int rtas_suspend_cpu(
struct rtas_suspend_me_data *data)
803 return __rtas_suspend_cpu(data, 0);
806 static void rtas_percpu_suspend_me(
void *
info)
808 __rtas_suspend_cpu((
struct rtas_suspend_me_data *)info, 1);
815 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
816 struct rtas_suspend_me_data data;
823 rc = plpar_hcall(H_VASI_STATE, retbuf,
824 ((
u64)args->args[0] << 32) | args->args[1]);
829 printk(
KERN_ERR "rtas_ibm_suspend_me: vasi_state returned %ld\n",rc);
831 }
else if (state == H_VASI_ENABLED) {
832 args->args[args->nargs] = RTAS_NOT_SUSPENDABLE;
834 }
else if (state != H_VASI_SUSPENDING) {
835 printk(
KERN_ERR "rtas_ibm_suspend_me: vasi_state returned state %ld\n",
837 args->args[args->nargs] = -1;
845 data.complete = &
done;
846 stop_topology_update();
859 start_topology_update();
880 struct rtas_ext_event_log_v6 *ext_log =
881 (
struct rtas_ext_event_log_v6 *)log->buffer;
882 struct pseries_errorlog *
sect;
883 unsigned char *
p, *log_end;
886 if (log->extended_log_length <
sizeof(
struct rtas_ext_event_log_v6) ||
887 ext_log->log_format != RTAS_V6EXT_LOG_FORMAT_EVENT_LOG ||
888 ext_log->company_id != RTAS_V6EXT_COMPANY_ID_IBM)
891 log_end = log->buffer + log->extended_log_length;
892 p = ext_log->vendor_log;
894 while (p < log_end) {
895 sect = (
struct pseries_errorlog *)p;
896 if (
sect->id == section_id)
906 struct rtas_args args;
908 char *buff_copy, *errbuf =
NULL;
926 nargs *
sizeof(rtas_arg_t)) != 0)
929 if (args.token == RTAS_UNKNOWN_SERVICE)
932 args.rets = &args.args[nargs];
933 memset(args.rets, 0, args.nret *
sizeof(rtas_arg_t));
936 if (args.token == ibm_suspend_me_token) {
953 if (args.rets[0] == -1)
968 args.nret *
sizeof(rtas_arg_t)) != 0)
981 unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
988 const u32 *basep, *entryp, *sizep;
992 if (basep !=
NULL && sizep !=
NULL) {
996 "linux,rtas-entry",
NULL);
1000 rtas.entry = *entryp;
1011 if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR)) {
1012 rtas_region =
min(ppc64_rma_size, RTAS_INSTANTIATE_MAX);
1013 ibm_suspend_me_token =
rtas_token(
"ibm,suspend-me");
1018 #ifdef CONFIG_RTAS_ERROR_LOGGING
1019 rtas_last_error_token =
rtas_token(
"rtas-last-error");
1024 const char *uname,
int depth,
void *data)
1026 u32 *basep, *entryp, *sizep;
1028 if (depth != 1 ||
strcmp(uname,
"rtas") != 0)
1031 basep = of_get_flat_dt_prop(node,
"linux,rtas-base",
NULL);
1032 entryp = of_get_flat_dt_prop(node,
"linux,rtas-entry",
NULL);
1033 sizep = of_get_flat_dt_prop(node,
"rtas-size",
NULL);
1035 if (basep && entryp && sizep) {
1037 rtas.entry = *entryp;
1041 #ifdef CONFIG_UDBG_RTAS_CONSOLE
1042 basep = of_get_flat_dt_prop(node,
"put-term-char",
NULL);
1044 rtas_putchar_token = *basep;
1046 basep = of_get_flat_dt_prop(node,
"get-term-char",
NULL);
1048 rtas_getchar_token = *basep;
1050 if (rtas_putchar_token != RTAS_UNKNOWN_SERVICE &&
1051 rtas_getchar_token != RTAS_UNKNOWN_SERVICE)
1052 udbg_init_rtas_console();
1061 static u64 timebase = 0;
1065 unsigned long flags;
1071 timebase = get_tb();
1085 set_tb(timebase >> 32, timebase & 0xffffffff);