blob: 5e8eb33b8e54067290aa10762239c48dde9ff07d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Procedures for interfacing to the RTAS on CHRP machines.
4 *
5 * Peter Bergner, IBM March 2001.
6 * Copyright (C) 2001 IBM.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#include <stdarg.h>
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/spinlock.h>
18#include <linux/module.h>
19#include <linux/init.h>
20
21#include <asm/prom.h>
22#include <asm/rtas.h>
23#include <asm/semaphore.h>
24#include <asm/machdep.h>
25#include <asm/page.h>
26#include <asm/param.h>
27#include <asm/system.h>
28#include <asm/abs_addr.h>
29#include <asm/udbg.h>
30#include <asm/delay.h>
31#include <asm/uaccess.h>
32#include <asm/systemcfg.h>
33
34struct flash_block_list_header rtas_firmware_flash_list = {0, NULL};
35
36struct rtas_t rtas = {
37 .lock = SPIN_LOCK_UNLOCKED
38};
39
40EXPORT_SYMBOL(rtas);
41
42char rtas_err_buf[RTAS_ERROR_LOG_MAX];
43
44DEFINE_SPINLOCK(rtas_data_buf_lock);
45char rtas_data_buf[RTAS_DATA_BUF_SIZE]__page_aligned;
46unsigned long rtas_rmo_buf;
47
48void
49call_rtas_display_status(unsigned char c)
50{
51 struct rtas_args *args = &rtas.args;
52 unsigned long s;
53
54 if (!rtas.base)
55 return;
56 spin_lock_irqsave(&rtas.lock, s);
57
58 args->token = 10;
59 args->nargs = 1;
60 args->nret = 1;
61 args->rets = (rtas_arg_t *)&(args->args[1]);
62 args->args[0] = (int)c;
63
64 enter_rtas(__pa(args));
65
66 spin_unlock_irqrestore(&rtas.lock, s);
67}
68
69void
70call_rtas_display_status_delay(unsigned char c)
71{
72 static int pending_newline = 0; /* did last write end with unprinted newline? */
73 static int width = 16;
74
75 if (c == '\n') {
76 while (width-- > 0)
77 call_rtas_display_status(' ');
78 width = 16;
79 udelay(500000);
80 pending_newline = 1;
81 } else {
82 if (pending_newline) {
83 call_rtas_display_status('\r');
84 call_rtas_display_status('\n');
85 }
86 pending_newline = 0;
87 if (width--) {
88 call_rtas_display_status(c);
89 udelay(10000);
90 }
91 }
92}
93
Arnd Bergmann6566c6f2005-06-23 09:43:28 +100094void
95rtas_progress(char *s, unsigned short hex)
96{
97 struct device_node *root;
98 int width, *p;
99 char *os;
100 static int display_character, set_indicator;
Mike Strosaker8f586b22005-06-23 16:09:41 +1000101 static int display_width, display_lines, *row_width, form_feed;
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000102 static DEFINE_SPINLOCK(progress_lock);
Mike Strosaker8f586b22005-06-23 16:09:41 +1000103 static int current_line;
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000104 static int pending_newline = 0; /* did last write end with unprinted newline? */
105
106 if (!rtas.base)
107 return;
108
Mike Strosaker8f586b22005-06-23 16:09:41 +1000109 if (display_width == 0) {
110 display_width = 0x10;
111 if ((root = find_path_device("/rtas"))) {
112 if ((p = (unsigned int *)get_property(root,
113 "ibm,display-line-length", NULL)))
114 display_width = *p;
115 if ((p = (unsigned int *)get_property(root,
116 "ibm,form-feed", NULL)))
117 form_feed = *p;
118 if ((p = (unsigned int *)get_property(root,
119 "ibm,display-number-of-lines", NULL)))
120 display_lines = *p;
121 row_width = (unsigned int *)get_property(root,
122 "ibm,display-truncation-length", NULL);
123 }
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000124 display_character = rtas_token("display-character");
125 set_indicator = rtas_token("set-indicator");
126 }
127
128 if (display_character == RTAS_UNKNOWN_SERVICE) {
129 /* use hex display if available */
130 if (set_indicator != RTAS_UNKNOWN_SERVICE)
131 rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
132 return;
133 }
134
135 spin_lock(&progress_lock);
136
137 /*
138 * Last write ended with newline, but we didn't print it since
139 * it would just clear the bottom line of output. Print it now
140 * instead.
141 *
Mike Strosaker8f586b22005-06-23 16:09:41 +1000142 * If no newline is pending and form feed is supported, clear the
143 * display with a form feed; otherwise, print a CR to start output
144 * at the beginning of the line.
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000145 */
146 if (pending_newline) {
147 rtas_call(display_character, 1, 1, NULL, '\r');
148 rtas_call(display_character, 1, 1, NULL, '\n');
149 pending_newline = 0;
150 } else {
Mike Strosaker8f586b22005-06-23 16:09:41 +1000151 current_line = 0;
152 if (form_feed)
153 rtas_call(display_character, 1, 1, NULL,
154 (char)form_feed);
155 else
156 rtas_call(display_character, 1, 1, NULL, '\r');
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000157 }
158
Mike Strosaker8f586b22005-06-23 16:09:41 +1000159 if (row_width)
160 width = row_width[current_line];
161 else
162 width = display_width;
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000163 os = s;
164 while (*os) {
165 if (*os == '\n' || *os == '\r') {
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000166 /* If newline is the last character, save it
167 * until next call to avoid bumping up the
168 * display output.
169 */
170 if (*os == '\n' && !os[1]) {
171 pending_newline = 1;
Mike Strosaker8f586b22005-06-23 16:09:41 +1000172 current_line++;
173 if (current_line > display_lines-1)
174 current_line = display_lines-1;
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000175 spin_unlock(&progress_lock);
176 return;
177 }
178
179 /* RTAS wants CR-LF, not just LF */
180
181 if (*os == '\n') {
182 rtas_call(display_character, 1, 1, NULL, '\r');
183 rtas_call(display_character, 1, 1, NULL, '\n');
184 } else {
185 /* CR might be used to re-draw a line, so we'll
186 * leave it alone and not add LF.
187 */
188 rtas_call(display_character, 1, 1, NULL, *os);
189 }
190
Mike Strosaker8f586b22005-06-23 16:09:41 +1000191 if (row_width)
192 width = row_width[current_line];
193 else
194 width = display_width;
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000195 } else {
196 width--;
197 rtas_call(display_character, 1, 1, NULL, *os);
198 }
199
200 os++;
201
202 /* if we overwrite the screen length */
203 if (width <= 0)
204 while ((*os != 0) && (*os != '\n') && (*os != '\r'))
205 os++;
206 }
207
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000208 spin_unlock(&progress_lock);
209}
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211int
212rtas_token(const char *service)
213{
214 int *tokp;
215 if (rtas.dev == NULL) {
216 PPCDBG(PPCDBG_RTAS,"\tNo rtas device in device-tree...\n");
217 return RTAS_UNKNOWN_SERVICE;
218 }
219 tokp = (int *) get_property(rtas.dev, service, NULL);
220 return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
221}
222
223/*
224 * Return the firmware-specified size of the error log buffer
225 * for all rtas calls that require an error buffer argument.
226 * This includes 'check-exception' and 'rtas-last-error'.
227 */
228int rtas_get_error_log_max(void)
229{
230 static int rtas_error_log_max;
231 if (rtas_error_log_max)
232 return rtas_error_log_max;
233
234 rtas_error_log_max = rtas_token ("rtas-error-log-max");
235 if ((rtas_error_log_max == RTAS_UNKNOWN_SERVICE) ||
236 (rtas_error_log_max > RTAS_ERROR_LOG_MAX)) {
237 printk (KERN_WARNING "RTAS: bad log buffer size %d\n", rtas_error_log_max);
238 rtas_error_log_max = RTAS_ERROR_LOG_MAX;
239 }
240 return rtas_error_log_max;
241}
242
243
244/** Return a copy of the detailed error text associated with the
245 * most recent failed call to rtas. Because the error text
246 * might go stale if there are any other intervening rtas calls,
247 * this routine must be called atomically with whatever produced
248 * the error (i.e. with rtas.lock still held from the previous call).
249 */
250static int
251__fetch_rtas_last_error(void)
252{
253 struct rtas_args err_args, save_args;
254 u32 bufsz;
255
256 bufsz = rtas_get_error_log_max();
257
258 err_args.token = rtas_token("rtas-last-error");
259 err_args.nargs = 2;
260 err_args.nret = 1;
261
262 err_args.args[0] = (rtas_arg_t)__pa(rtas_err_buf);
263 err_args.args[1] = bufsz;
264 err_args.args[2] = 0;
265
266 save_args = rtas.args;
267 rtas.args = err_args;
268
269 enter_rtas(__pa(&rtas.args));
270
271 err_args = rtas.args;
272 rtas.args = save_args;
273
274 return err_args.args[2];
275}
276
277int rtas_call(int token, int nargs, int nret, int *outputs, ...)
278{
279 va_list list;
280 int i, logit = 0;
281 unsigned long s;
282 struct rtas_args *rtas_args;
283 char * buff_copy = NULL;
284 int ret;
285
286 PPCDBG(PPCDBG_RTAS, "Entering rtas_call\n");
287 PPCDBG(PPCDBG_RTAS, "\ttoken = 0x%x\n", token);
288 PPCDBG(PPCDBG_RTAS, "\tnargs = %d\n", nargs);
289 PPCDBG(PPCDBG_RTAS, "\tnret = %d\n", nret);
290 PPCDBG(PPCDBG_RTAS, "\t&outputs = 0x%lx\n", outputs);
291 if (token == RTAS_UNKNOWN_SERVICE)
292 return -1;
293
294 /* Gotta do something different here, use global lock for now... */
295 spin_lock_irqsave(&rtas.lock, s);
296 rtas_args = &rtas.args;
297
298 rtas_args->token = token;
299 rtas_args->nargs = nargs;
300 rtas_args->nret = nret;
301 rtas_args->rets = (rtas_arg_t *)&(rtas_args->args[nargs]);
302 va_start(list, outputs);
303 for (i = 0; i < nargs; ++i) {
304 rtas_args->args[i] = va_arg(list, rtas_arg_t);
305 PPCDBG(PPCDBG_RTAS, "\tnarg[%d] = 0x%x\n", i, rtas_args->args[i]);
306 }
307 va_end(list);
308
309 for (i = 0; i < nret; ++i)
310 rtas_args->rets[i] = 0;
311
312 PPCDBG(PPCDBG_RTAS, "\tentering rtas with 0x%lx\n",
313 __pa(rtas_args));
314 enter_rtas(__pa(rtas_args));
315 PPCDBG(PPCDBG_RTAS, "\treturned from rtas ...\n");
316
317 /* A -1 return code indicates that the last command couldn't
318 be completed due to a hardware error. */
319 if (rtas_args->rets[0] == -1)
320 logit = (__fetch_rtas_last_error() == 0);
321
322 ifppcdebug(PPCDBG_RTAS) {
323 for(i=0; i < nret ;i++)
324 udbg_printf("\tnret[%d] = 0x%lx\n", i, (ulong)rtas_args->rets[i]);
325 }
326
327 if (nret > 1 && outputs != NULL)
328 for (i = 0; i < nret-1; ++i)
329 outputs[i] = rtas_args->rets[i+1];
330 ret = (nret > 0)? rtas_args->rets[0]: 0;
331
332 /* Log the error in the unlikely case that there was one. */
333 if (unlikely(logit)) {
334 buff_copy = rtas_err_buf;
335 if (mem_init_done) {
336 buff_copy = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);
337 if (buff_copy)
338 memcpy(buff_copy, rtas_err_buf,
339 RTAS_ERROR_LOG_MAX);
340 }
341 }
342
343 /* Gotta do something different here, use global lock for now... */
344 spin_unlock_irqrestore(&rtas.lock, s);
345
346 if (buff_copy) {
347 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
348 if (mem_init_done)
349 kfree(buff_copy);
350 }
351 return ret;
352}
353
354/* Given an RTAS status code of 990n compute the hinted delay of 10^n
355 * (last digit) milliseconds. For now we bound at n=5 (100 sec).
356 */
357unsigned int
358rtas_extended_busy_delay_time(int status)
359{
360 int order = status - 9900;
361 unsigned long ms;
362
363 if (order < 0)
364 order = 0; /* RTC depends on this for -2 clock busy */
365 else if (order > 5)
366 order = 5; /* bound */
367
368 /* Use microseconds for reasonable accuracy */
369 for (ms=1; order > 0; order--)
370 ms *= 10;
371
372 return ms;
373}
374
375int rtas_error_rc(int rtas_rc)
376{
377 int rc;
378
379 switch (rtas_rc) {
380 case -1: /* Hardware Error */
381 rc = -EIO;
382 break;
383 case -3: /* Bad indicator/domain/etc */
384 rc = -EINVAL;
385 break;
386 case -9000: /* Isolation error */
387 rc = -EFAULT;
388 break;
389 case -9001: /* Outstanding TCE/PTE */
390 rc = -EEXIST;
391 break;
392 case -9002: /* No usable slot */
393 rc = -ENODEV;
394 break;
395 default:
396 printk(KERN_ERR "%s: unexpected RTAS error %d\n",
397 __FUNCTION__, rtas_rc);
398 rc = -ERANGE;
399 break;
400 }
401 return rc;
402}
403
404int rtas_get_power_level(int powerdomain, int *level)
405{
406 int token = rtas_token("get-power-level");
407 int rc;
408
409 if (token == RTAS_UNKNOWN_SERVICE)
410 return -ENOENT;
411
412 while ((rc = rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
413 udelay(1);
414
415 if (rc < 0)
416 return rtas_error_rc(rc);
417 return rc;
418}
419
420int rtas_set_power_level(int powerdomain, int level, int *setlevel)
421{
422 int token = rtas_token("set-power-level");
423 unsigned int wait_time;
424 int rc;
425
426 if (token == RTAS_UNKNOWN_SERVICE)
427 return -ENOENT;
428
429 while (1) {
430 rc = rtas_call(token, 2, 2, setlevel, powerdomain, level);
431 if (rc == RTAS_BUSY)
432 udelay(1);
433 else if (rtas_is_extended_busy(rc)) {
434 wait_time = rtas_extended_busy_delay_time(rc);
435 udelay(wait_time * 1000);
436 } else
437 break;
438 }
439
440 if (rc < 0)
441 return rtas_error_rc(rc);
442 return rc;
443}
444
445int rtas_get_sensor(int sensor, int index, int *state)
446{
447 int token = rtas_token("get-sensor-state");
448 unsigned int wait_time;
449 int rc;
450
451 if (token == RTAS_UNKNOWN_SERVICE)
452 return -ENOENT;
453
454 while (1) {
455 rc = rtas_call(token, 2, 2, state, sensor, index);
456 if (rc == RTAS_BUSY)
457 udelay(1);
458 else if (rtas_is_extended_busy(rc)) {
459 wait_time = rtas_extended_busy_delay_time(rc);
460 udelay(wait_time * 1000);
461 } else
462 break;
463 }
464
465 if (rc < 0)
466 return rtas_error_rc(rc);
467 return rc;
468}
469
470int rtas_set_indicator(int indicator, int index, int new_value)
471{
472 int token = rtas_token("set-indicator");
473 unsigned int wait_time;
474 int rc;
475
476 if (token == RTAS_UNKNOWN_SERVICE)
477 return -ENOENT;
478
479 while (1) {
480 rc = rtas_call(token, 3, 1, NULL, indicator, index, new_value);
481 if (rc == RTAS_BUSY)
482 udelay(1);
483 else if (rtas_is_extended_busy(rc)) {
484 wait_time = rtas_extended_busy_delay_time(rc);
485 udelay(wait_time * 1000);
486 }
487 else
488 break;
489 }
490
491 if (rc < 0)
492 return rtas_error_rc(rc);
493 return rc;
494}
495
496#define FLASH_BLOCK_LIST_VERSION (1UL)
497static void
498rtas_flash_firmware(void)
499{
500 unsigned long image_size;
501 struct flash_block_list *f, *next, *flist;
502 unsigned long rtas_block_list;
503 int i, status, update_token;
504
505 update_token = rtas_token("ibm,update-flash-64-and-reboot");
506 if (update_token == RTAS_UNKNOWN_SERVICE) {
507 printk(KERN_ALERT "FLASH: ibm,update-flash-64-and-reboot is not available -- not a service partition?\n");
508 printk(KERN_ALERT "FLASH: firmware will not be flashed\n");
509 return;
510 }
511
512 /* NOTE: the "first" block list is a global var with no data
513 * blocks in the kernel data segment. We do this because
514 * we want to ensure this block_list addr is under 4GB.
515 */
516 rtas_firmware_flash_list.num_blocks = 0;
517 flist = (struct flash_block_list *)&rtas_firmware_flash_list;
518 rtas_block_list = virt_to_abs(flist);
519 if (rtas_block_list >= 4UL*1024*1024*1024) {
520 printk(KERN_ALERT "FLASH: kernel bug...flash list header addr above 4GB\n");
521 return;
522 }
523
524 printk(KERN_ALERT "FLASH: preparing saved firmware image for flash\n");
525 /* Update the block_list in place. */
526 image_size = 0;
527 for (f = flist; f; f = next) {
528 /* Translate data addrs to absolute */
529 for (i = 0; i < f->num_blocks; i++) {
530 f->blocks[i].data = (char *)virt_to_abs(f->blocks[i].data);
531 image_size += f->blocks[i].length;
532 }
533 next = f->next;
534 /* Don't translate NULL pointer for last entry */
535 if (f->next)
536 f->next = (struct flash_block_list *)virt_to_abs(f->next);
537 else
538 f->next = NULL;
539 /* make num_blocks into the version/length field */
540 f->num_blocks = (FLASH_BLOCK_LIST_VERSION << 56) | ((f->num_blocks+1)*16);
541 }
542
543 printk(KERN_ALERT "FLASH: flash image is %ld bytes\n", image_size);
544 printk(KERN_ALERT "FLASH: performing flash and reboot\n");
Arnd Bergmann6566c6f2005-06-23 09:43:28 +1000545 rtas_progress("Flashing \n", 0x0);
546 rtas_progress("Please Wait... ", 0x0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 printk(KERN_ALERT "FLASH: this will take several minutes. Do not power off!\n");
548 status = rtas_call(update_token, 1, 1, NULL, rtas_block_list);
549 switch (status) { /* should only get "bad" status */
550 case 0:
551 printk(KERN_ALERT "FLASH: success\n");
552 break;
553 case -1:
554 printk(KERN_ALERT "FLASH: hardware error. Firmware may not be not flashed\n");
555 break;
556 case -3:
557 printk(KERN_ALERT "FLASH: image is corrupt or not correct for this platform. Firmware not flashed\n");
558 break;
559 case -4:
560 printk(KERN_ALERT "FLASH: flash failed when partially complete. System may not reboot\n");
561 break;
562 default:
563 printk(KERN_ALERT "FLASH: unknown flash return code %d\n", status);
564 break;
565 }
566}
567
568void rtas_flash_bypass_warning(void)
569{
570 printk(KERN_ALERT "FLASH: firmware flash requires a reboot\n");
571 printk(KERN_ALERT "FLASH: the firmware image will NOT be flashed\n");
572}
573
574
575void
576rtas_restart(char *cmd)
577{
578 if (rtas_firmware_flash_list.next)
579 rtas_flash_firmware();
580
581 printk("RTAS system-reboot returned %d\n",
582 rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
583 for (;;);
584}
585
586void
587rtas_power_off(void)
588{
589 if (rtas_firmware_flash_list.next)
590 rtas_flash_bypass_warning();
591 /* allow power on only with power button press */
592 printk("RTAS power-off returned %d\n",
593 rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
594 for (;;);
595}
596
597void
598rtas_halt(void)
599{
600 if (rtas_firmware_flash_list.next)
601 rtas_flash_bypass_warning();
602 rtas_power_off();
603}
604
605/* Must be in the RMO region, so we place it here */
606static char rtas_os_term_buf[2048];
607
608void rtas_os_term(char *str)
609{
610 int status;
611
612 if (RTAS_UNKNOWN_SERVICE == rtas_token("ibm,os-term"))
613 return;
614
615 snprintf(rtas_os_term_buf, 2048, "OS panic: %s", str);
616
617 do {
618 status = rtas_call(rtas_token("ibm,os-term"), 1, 1, NULL,
619 __pa(rtas_os_term_buf));
620
621 if (status == RTAS_BUSY)
622 udelay(1);
623 else if (status != 0)
624 printk(KERN_EMERG "ibm,os-term call failed %d\n",
625 status);
626 } while (status == RTAS_BUSY);
627}
628
629
630asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
631{
632 struct rtas_args args;
633 unsigned long flags;
634 char * buff_copy;
635 int nargs;
636 int err_rc = 0;
637
638 if (!capable(CAP_SYS_ADMIN))
639 return -EPERM;
640
641 if (copy_from_user(&args, uargs, 3 * sizeof(u32)) != 0)
642 return -EFAULT;
643
644 nargs = args.nargs;
645 if (nargs > ARRAY_SIZE(args.args)
646 || args.nret > ARRAY_SIZE(args.args)
647 || nargs + args.nret > ARRAY_SIZE(args.args))
648 return -EINVAL;
649
650 /* Copy in args. */
651 if (copy_from_user(args.args, uargs->args,
652 nargs * sizeof(rtas_arg_t)) != 0)
653 return -EFAULT;
654
655 buff_copy = kmalloc(RTAS_ERROR_LOG_MAX, GFP_KERNEL);
656
657 spin_lock_irqsave(&rtas.lock, flags);
658
659 rtas.args = args;
660 enter_rtas(__pa(&rtas.args));
661 args = rtas.args;
662
663 args.rets = &args.args[nargs];
664
665 /* A -1 return code indicates that the last command couldn't
666 be completed due to a hardware error. */
667 if (args.rets[0] == -1) {
668 err_rc = __fetch_rtas_last_error();
669 if ((err_rc == 0) && buff_copy) {
670 memcpy(buff_copy, rtas_err_buf, RTAS_ERROR_LOG_MAX);
671 }
672 }
673
674 spin_unlock_irqrestore(&rtas.lock, flags);
675
676 if (buff_copy) {
677 if ((args.rets[0] == -1) && (err_rc == 0)) {
678 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
679 }
680 kfree(buff_copy);
681 }
682
683 /* Copy out args. */
684 if (copy_to_user(uargs->args + nargs,
685 args.args + nargs,
686 args.nret * sizeof(rtas_arg_t)) != 0)
687 return -EFAULT;
688
689 return 0;
690}
691
692/* This version can't take the spinlock, because it never returns */
693
694struct rtas_args rtas_stop_self_args = {
695 /* The token is initialized for real in setup_system() */
696 .token = RTAS_UNKNOWN_SERVICE,
697 .nargs = 0,
698 .nret = 1,
699 .rets = &rtas_stop_self_args.args[0],
700};
701
702void rtas_stop_self(void)
703{
704 struct rtas_args *rtas_args = &rtas_stop_self_args;
705
706 local_irq_disable();
707
708 BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE);
709
710 printk("cpu %u (hwid %u) Ready to die...\n",
711 smp_processor_id(), hard_smp_processor_id());
712 enter_rtas(__pa(rtas_args));
713
714 panic("Alas, I survived.\n");
715}
716
717/*
718 * Call early during boot, before mem init or bootmem, to retreive the RTAS
719 * informations from the device-tree and allocate the RMO buffer for userland
720 * accesses.
721 */
722void __init rtas_initialize(void)
723{
724 /* Get RTAS dev node and fill up our "rtas" structure with infos
725 * about it.
726 */
727 rtas.dev = of_find_node_by_name(NULL, "rtas");
728 if (rtas.dev) {
729 u32 *basep, *entryp;
730 u32 *sizep;
731
732 basep = (u32 *)get_property(rtas.dev, "linux,rtas-base", NULL);
733 sizep = (u32 *)get_property(rtas.dev, "rtas-size", NULL);
734 if (basep != NULL && sizep != NULL) {
735 rtas.base = *basep;
736 rtas.size = *sizep;
737 entryp = (u32 *)get_property(rtas.dev, "linux,rtas-entry", NULL);
738 if (entryp == NULL) /* Ugh */
739 rtas.entry = rtas.base;
740 else
741 rtas.entry = *entryp;
742 } else
743 rtas.dev = NULL;
744 }
745 /* If RTAS was found, allocate the RMO buffer for it and look for
746 * the stop-self token if any
747 */
748 if (rtas.dev) {
749 unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
750 if (systemcfg->platform == PLATFORM_PSERIES_LPAR)
751 rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX);
752
753 rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE,
754 rtas_region);
755
756#ifdef CONFIG_HOTPLUG_CPU
757 rtas_stop_self_args.token = rtas_token("stop-self");
758#endif /* CONFIG_HOTPLUG_CPU */
759 }
760
761}
762
763
764EXPORT_SYMBOL(rtas_firmware_flash_list);
765EXPORT_SYMBOL(rtas_token);
766EXPORT_SYMBOL(rtas_call);
767EXPORT_SYMBOL(rtas_data_buf);
768EXPORT_SYMBOL(rtas_data_buf_lock);
769EXPORT_SYMBOL(rtas_extended_busy_delay_time);
770EXPORT_SYMBOL(rtas_get_sensor);
771EXPORT_SYMBOL(rtas_get_power_level);
772EXPORT_SYMBOL(rtas_set_power_level);
773EXPORT_SYMBOL(rtas_set_indicator);
774EXPORT_SYMBOL(rtas_get_error_log_max);