[POWERPC] Move RTAS exports next to their declarations
[safe/jmp/linux-2.6] / arch / powerpc / kernel / rtas.c
1 /*
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 #include <linux/capability.h>
21 #include <linux/delay.h>
22
23 #include <asm/prom.h>
24 #include <asm/rtas.h>
25 #include <asm/hvcall.h>
26 #include <asm/semaphore.h>
27 #include <asm/machdep.h>
28 #include <asm/firmware.h>
29 #include <asm/page.h>
30 #include <asm/param.h>
31 #include <asm/system.h>
32 #include <asm/delay.h>
33 #include <asm/uaccess.h>
34 #include <asm/lmb.h>
35 #include <asm/udbg.h>
36 #include <asm/syscalls.h>
37
38 struct rtas_t rtas = {
39         .lock = SPIN_LOCK_UNLOCKED
40 };
41 EXPORT_SYMBOL(rtas);
42
43 struct rtas_suspend_me_data {
44         long waiting;
45         struct rtas_args *args;
46 };
47
48 DEFINE_SPINLOCK(rtas_data_buf_lock);
49 EXPORT_SYMBOL(rtas_data_buf_lock);
50
51 char rtas_data_buf[RTAS_DATA_BUF_SIZE] __cacheline_aligned;
52 EXPORT_SYMBOL(rtas_data_buf);
53
54 unsigned long rtas_rmo_buf;
55
56 /*
57  * If non-NULL, this gets called when the kernel terminates.
58  * This is done like this so rtas_flash can be a module.
59  */
60 void (*rtas_flash_term_hook)(int);
61 EXPORT_SYMBOL(rtas_flash_term_hook);
62
63 /*
64  * call_rtas_display_status and call_rtas_display_status_delay
65  * are designed only for very early low-level debugging, which
66  * is why the token is hard-coded to 10.
67  */
68 static void call_rtas_display_status(char c)
69 {
70         struct rtas_args *args = &rtas.args;
71         unsigned long s;
72
73         if (!rtas.base)
74                 return;
75         spin_lock_irqsave(&rtas.lock, s);
76
77         args->token = 10;
78         args->nargs = 1;
79         args->nret  = 1;
80         args->rets  = (rtas_arg_t *)&(args->args[1]);
81         args->args[0] = (unsigned char)c;
82
83         enter_rtas(__pa(args));
84
85         spin_unlock_irqrestore(&rtas.lock, s);
86 }
87
88 static void call_rtas_display_status_delay(char c)
89 {
90         static int pending_newline = 0;  /* did last write end with unprinted newline? */
91         static int width = 16;
92
93         if (c == '\n') {        
94                 while (width-- > 0)
95                         call_rtas_display_status(' ');
96                 width = 16;
97                 mdelay(500);
98                 pending_newline = 1;
99         } else {
100                 if (pending_newline) {
101                         call_rtas_display_status('\r');
102                         call_rtas_display_status('\n');
103                 } 
104                 pending_newline = 0;
105                 if (width--) {
106                         call_rtas_display_status(c);
107                         udelay(10000);
108                 }
109         }
110 }
111
112 void __init udbg_init_rtas(void)
113 {
114         udbg_putc = call_rtas_display_status_delay;
115 }
116
117 void rtas_progress(char *s, unsigned short hex)
118 {
119         struct device_node *root;
120         int width, *p;
121         char *os;
122         static int display_character, set_indicator;
123         static int display_width, display_lines, *row_width, form_feed;
124         static DEFINE_SPINLOCK(progress_lock);
125         static int current_line;
126         static int pending_newline = 0;  /* did last write end with unprinted newline? */
127
128         if (!rtas.base)
129                 return;
130
131         if (display_width == 0) {
132                 display_width = 0x10;
133                 if ((root = find_path_device("/rtas"))) {
134                         if ((p = (unsigned int *)get_property(root,
135                                         "ibm,display-line-length", NULL)))
136                                 display_width = *p;
137                         if ((p = (unsigned int *)get_property(root,
138                                         "ibm,form-feed", NULL)))
139                                 form_feed = *p;
140                         if ((p = (unsigned int *)get_property(root,
141                                         "ibm,display-number-of-lines", NULL)))
142                                 display_lines = *p;
143                         row_width = (unsigned int *)get_property(root,
144                                         "ibm,display-truncation-length", NULL);
145                 }
146                 display_character = rtas_token("display-character");
147                 set_indicator = rtas_token("set-indicator");
148         }
149
150         if (display_character == RTAS_UNKNOWN_SERVICE) {
151                 /* use hex display if available */
152                 if (set_indicator != RTAS_UNKNOWN_SERVICE)
153                         rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
154                 return;
155         }
156
157         spin_lock(&progress_lock);
158
159         /*
160          * Last write ended with newline, but we didn't print it since
161          * it would just clear the bottom line of output. Print it now
162          * instead.
163          *
164          * If no newline is pending and form feed is supported, clear the
165          * display with a form feed; otherwise, print a CR to start output
166          * at the beginning of the line.
167          */
168         if (pending_newline) {
169                 rtas_call(display_character, 1, 1, NULL, '\r');
170                 rtas_call(display_character, 1, 1, NULL, '\n');
171                 pending_newline = 0;
172         } else {
173                 current_line = 0;
174                 if (form_feed)
175                         rtas_call(display_character, 1, 1, NULL,
176                                   (char)form_feed);
177                 else
178                         rtas_call(display_character, 1, 1, NULL, '\r');
179         }
180  
181         if (row_width)
182                 width = row_width[current_line];
183         else
184                 width = display_width;
185         os = s;
186         while (*os) {
187                 if (*os == '\n' || *os == '\r') {
188                         /* If newline is the last character, save it
189                          * until next call to avoid bumping up the
190                          * display output.
191                          */
192                         if (*os == '\n' && !os[1]) {
193                                 pending_newline = 1;
194                                 current_line++;
195                                 if (current_line > display_lines-1)
196                                         current_line = display_lines-1;
197                                 spin_unlock(&progress_lock);
198                                 return;
199                         }
200  
201                         /* RTAS wants CR-LF, not just LF */
202  
203                         if (*os == '\n') {
204                                 rtas_call(display_character, 1, 1, NULL, '\r');
205                                 rtas_call(display_character, 1, 1, NULL, '\n');
206                         } else {
207                                 /* CR might be used to re-draw a line, so we'll
208                                  * leave it alone and not add LF.
209                                  */
210                                 rtas_call(display_character, 1, 1, NULL, *os);
211                         }
212  
213                         if (row_width)
214                                 width = row_width[current_line];
215                         else
216                                 width = display_width;
217                 } else {
218                         width--;
219                         rtas_call(display_character, 1, 1, NULL, *os);
220                 }
221  
222                 os++;
223  
224                 /* if we overwrite the screen length */
225                 if (width <= 0)
226                         while ((*os != 0) && (*os != '\n') && (*os != '\r'))
227                                 os++;
228         }
229  
230         spin_unlock(&progress_lock);
231 }
232 EXPORT_SYMBOL(rtas_progress);           /* needed by rtas_flash module */
233
234 int rtas_token(const char *service)
235 {
236         int *tokp;
237         if (rtas.dev == NULL)
238                 return RTAS_UNKNOWN_SERVICE;
239         tokp = (int *) get_property(rtas.dev, service, NULL);
240         return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
241 }
242 EXPORT_SYMBOL(rtas_token);
243
244 #ifdef CONFIG_RTAS_ERROR_LOGGING
245 /*
246  * Return the firmware-specified size of the error log buffer
247  *  for all rtas calls that require an error buffer argument.
248  *  This includes 'check-exception' and 'rtas-last-error'.
249  */
250 int rtas_get_error_log_max(void)
251 {
252         static int rtas_error_log_max;
253         if (rtas_error_log_max)
254                 return rtas_error_log_max;
255
256         rtas_error_log_max = rtas_token ("rtas-error-log-max");
257         if ((rtas_error_log_max == RTAS_UNKNOWN_SERVICE) ||
258             (rtas_error_log_max > RTAS_ERROR_LOG_MAX)) {
259                 printk (KERN_WARNING "RTAS: bad log buffer size %d\n",
260                         rtas_error_log_max);
261                 rtas_error_log_max = RTAS_ERROR_LOG_MAX;
262         }
263         return rtas_error_log_max;
264 }
265 EXPORT_SYMBOL(rtas_get_error_log_max);
266
267
268 char rtas_err_buf[RTAS_ERROR_LOG_MAX];
269 int rtas_last_error_token;
270
271 /** Return a copy of the detailed error text associated with the
272  *  most recent failed call to rtas.  Because the error text
273  *  might go stale if there are any other intervening rtas calls,
274  *  this routine must be called atomically with whatever produced
275  *  the error (i.e. with rtas.lock still held from the previous call).
276  */
277 static char *__fetch_rtas_last_error(char *altbuf)
278 {
279         struct rtas_args err_args, save_args;
280         u32 bufsz;
281         char *buf = NULL;
282
283         if (rtas_last_error_token == -1)
284                 return NULL;
285
286         bufsz = rtas_get_error_log_max();
287
288         err_args.token = rtas_last_error_token;
289         err_args.nargs = 2;
290         err_args.nret = 1;
291         err_args.args[0] = (rtas_arg_t)__pa(rtas_err_buf);
292         err_args.args[1] = bufsz;
293         err_args.args[2] = 0;
294
295         save_args = rtas.args;
296         rtas.args = err_args;
297
298         enter_rtas(__pa(&rtas.args));
299
300         err_args = rtas.args;
301         rtas.args = save_args;
302
303         /* Log the error in the unlikely case that there was one. */
304         if (unlikely(err_args.args[2] == 0)) {
305                 if (altbuf) {
306                         buf = altbuf;
307                 } else {
308                         buf = rtas_err_buf;
309                         if (mem_init_done)
310                                 buf = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);
311                 }
312                 if (buf)
313                         memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX);
314         }
315
316         return buf;
317 }
318
319 #define get_errorlog_buffer()   kmalloc(RTAS_ERROR_LOG_MAX, GFP_KERNEL)
320
321 #else /* CONFIG_RTAS_ERROR_LOGGING */
322 #define __fetch_rtas_last_error(x)      NULL
323 #define get_errorlog_buffer()           NULL
324 #endif
325
326 int rtas_call(int token, int nargs, int nret, int *outputs, ...)
327 {
328         va_list list;
329         int i;
330         unsigned long s;
331         struct rtas_args *rtas_args;
332         char *buff_copy = NULL;
333         int ret;
334
335         if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE)
336                 return -1;
337
338         /* Gotta do something different here, use global lock for now... */
339         spin_lock_irqsave(&rtas.lock, s);
340         rtas_args = &rtas.args;
341
342         rtas_args->token = token;
343         rtas_args->nargs = nargs;
344         rtas_args->nret  = nret;
345         rtas_args->rets  = (rtas_arg_t *)&(rtas_args->args[nargs]);
346         va_start(list, outputs);
347         for (i = 0; i < nargs; ++i)
348                 rtas_args->args[i] = va_arg(list, rtas_arg_t);
349         va_end(list);
350
351         for (i = 0; i < nret; ++i)
352                 rtas_args->rets[i] = 0;
353
354         enter_rtas(__pa(rtas_args));
355
356         /* A -1 return code indicates that the last command couldn't
357            be completed due to a hardware error. */
358         if (rtas_args->rets[0] == -1)
359                 buff_copy = __fetch_rtas_last_error(NULL);
360
361         if (nret > 1 && outputs != NULL)
362                 for (i = 0; i < nret-1; ++i)
363                         outputs[i] = rtas_args->rets[i+1];
364         ret = (nret > 0)? rtas_args->rets[0]: 0;
365
366         /* Gotta do something different here, use global lock for now... */
367         spin_unlock_irqrestore(&rtas.lock, s);
368
369         if (buff_copy) {
370                 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
371                 if (mem_init_done)
372                         kfree(buff_copy);
373         }
374         return ret;
375 }
376 EXPORT_SYMBOL(rtas_call);
377
378 /* For RTAS_BUSY (-2), delay for 1 millisecond.  For an extended busy status
379  * code of 990n, perform the hinted delay of 10^n (last digit) milliseconds.
380  */
381 unsigned int rtas_busy_delay_time(int status)
382 {
383         int order;
384         unsigned int ms = 0;
385
386         if (status == RTAS_BUSY) {
387                 ms = 1;
388         } else if (status >= 9900 && status <= 9905) {
389                 order = status - 9900;
390                 for (ms = 1; order > 0; order--)
391                         ms *= 10;
392         }
393
394         return ms;
395 }
396 EXPORT_SYMBOL(rtas_busy_delay_time);
397
398 /* For an RTAS busy status code, perform the hinted delay. */
399 unsigned int rtas_busy_delay(int status)
400 {
401         unsigned int ms;
402
403         might_sleep();
404         ms = rtas_busy_delay_time(status);
405         if (ms)
406                 msleep(ms);
407
408         return ms;
409 }
410 EXPORT_SYMBOL(rtas_busy_delay);
411
412 int rtas_error_rc(int rtas_rc)
413 {
414         int rc;
415
416         switch (rtas_rc) {
417                 case -1:                /* Hardware Error */
418                         rc = -EIO;
419                         break;
420                 case -3:                /* Bad indicator/domain/etc */
421                         rc = -EINVAL;
422                         break;
423                 case -9000:             /* Isolation error */
424                         rc = -EFAULT;
425                         break;
426                 case -9001:             /* Outstanding TCE/PTE */
427                         rc = -EEXIST;
428                         break;
429                 case -9002:             /* No usable slot */
430                         rc = -ENODEV;
431                         break;
432                 default:
433                         printk(KERN_ERR "%s: unexpected RTAS error %d\n",
434                                         __FUNCTION__, rtas_rc);
435                         rc = -ERANGE;
436                         break;
437         }
438         return rc;
439 }
440
441 int rtas_get_power_level(int powerdomain, int *level)
442 {
443         int token = rtas_token("get-power-level");
444         int rc;
445
446         if (token == RTAS_UNKNOWN_SERVICE)
447                 return -ENOENT;
448
449         while ((rc = rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
450                 udelay(1);
451
452         if (rc < 0)
453                 return rtas_error_rc(rc);
454         return rc;
455 }
456 EXPORT_SYMBOL(rtas_get_power_level);
457
458 int rtas_set_power_level(int powerdomain, int level, int *setlevel)
459 {
460         int token = rtas_token("set-power-level");
461         int rc;
462
463         if (token == RTAS_UNKNOWN_SERVICE)
464                 return -ENOENT;
465
466         do {
467                 rc = rtas_call(token, 2, 2, setlevel, powerdomain, level);
468         } while (rtas_busy_delay(rc));
469
470         if (rc < 0)
471                 return rtas_error_rc(rc);
472         return rc;
473 }
474 EXPORT_SYMBOL(rtas_set_power_level);
475
476 int rtas_get_sensor(int sensor, int index, int *state)
477 {
478         int token = rtas_token("get-sensor-state");
479         int rc;
480
481         if (token == RTAS_UNKNOWN_SERVICE)
482                 return -ENOENT;
483
484         do {
485                 rc = rtas_call(token, 2, 2, state, sensor, index);
486         } while (rtas_busy_delay(rc));
487
488         if (rc < 0)
489                 return rtas_error_rc(rc);
490         return rc;
491 }
492 EXPORT_SYMBOL(rtas_get_sensor);
493
494 int rtas_set_indicator(int indicator, int index, int new_value)
495 {
496         int token = rtas_token("set-indicator");
497         int rc;
498
499         if (token == RTAS_UNKNOWN_SERVICE)
500                 return -ENOENT;
501
502         do {
503                 rc = rtas_call(token, 3, 1, NULL, indicator, index, new_value);
504         } while (rtas_busy_delay(rc));
505
506         if (rc < 0)
507                 return rtas_error_rc(rc);
508         return rc;
509 }
510 EXPORT_SYMBOL(rtas_set_indicator);
511
512 void rtas_restart(char *cmd)
513 {
514         if (rtas_flash_term_hook)
515                 rtas_flash_term_hook(SYS_RESTART);
516         printk("RTAS system-reboot returned %d\n",
517                rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
518         for (;;);
519 }
520
521 void rtas_power_off(void)
522 {
523         if (rtas_flash_term_hook)
524                 rtas_flash_term_hook(SYS_POWER_OFF);
525         /* allow power on only with power button press */
526         printk("RTAS power-off returned %d\n",
527                rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
528         for (;;);
529 }
530
531 void rtas_halt(void)
532 {
533         if (rtas_flash_term_hook)
534                 rtas_flash_term_hook(SYS_HALT);
535         /* allow power on only with power button press */
536         printk("RTAS power-off returned %d\n",
537                rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
538         for (;;);
539 }
540
541 /* Must be in the RMO region, so we place it here */
542 static char rtas_os_term_buf[2048];
543
544 void rtas_os_term(char *str)
545 {
546         int status;
547
548         if (RTAS_UNKNOWN_SERVICE == rtas_token("ibm,os-term"))
549                 return;
550
551         snprintf(rtas_os_term_buf, 2048, "OS panic: %s", str);
552
553         do {
554                 status = rtas_call(rtas_token("ibm,os-term"), 1, 1, NULL,
555                                    __pa(rtas_os_term_buf));
556         } while (rtas_busy_delay(status));
557
558         if (status != 0)
559                 printk(KERN_EMERG "ibm,os-term call failed %d\n",
560                                status);
561 }
562
563 static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
564 #ifdef CONFIG_PPC_PSERIES
565 static void rtas_percpu_suspend_me(void *info)
566 {
567         int i;
568         long rc;
569         long flags;
570         struct rtas_suspend_me_data *data =
571                 (struct rtas_suspend_me_data *)info;
572
573         /*
574          * We use "waiting" to indicate our state.  As long
575          * as it is >0, we are still trying to all join up.
576          * If it goes to 0, we have successfully joined up and
577          * one thread got H_CONTINUE.  If any error happens,
578          * we set it to <0.
579          */
580         local_irq_save(flags);
581         do {
582                 rc = plpar_hcall_norets(H_JOIN);
583                 smp_rmb();
584         } while (rc == H_SUCCESS && data->waiting > 0);
585         if (rc == H_SUCCESS)
586                 goto out;
587
588         if (rc == H_CONTINUE) {
589                 data->waiting = 0;
590                 data->args->args[data->args->nargs] =
591                         rtas_call(ibm_suspend_me_token, 0, 1, NULL);
592                 for_each_possible_cpu(i)
593                         plpar_hcall_norets(H_PROD,i);
594         } else {
595                 data->waiting = -EBUSY;
596                 printk(KERN_ERR "Error on H_JOIN hypervisor call\n");
597         }
598
599 out:
600         local_irq_restore(flags);
601         return;
602 }
603
604 static int rtas_ibm_suspend_me(struct rtas_args *args)
605 {
606         int i;
607         long state;
608         long rc;
609         unsigned long dummy;
610
611         struct rtas_suspend_me_data data;
612
613         /* Make sure the state is valid */
614         rc = plpar_hcall(H_VASI_STATE,
615                          ((u64)args->args[0] << 32) | args->args[1],
616                          0, 0, 0,
617                          &state, &dummy, &dummy);
618
619         if (rc) {
620                 printk(KERN_ERR "rtas_ibm_suspend_me: vasi_state returned %ld\n",rc);
621                 return rc;
622         } else if (state == H_VASI_ENABLED) {
623                 args->args[args->nargs] = RTAS_NOT_SUSPENDABLE;
624                 return 0;
625         } else if (state != H_VASI_SUSPENDING) {
626                 printk(KERN_ERR "rtas_ibm_suspend_me: vasi_state returned state %ld\n",
627                        state);
628                 args->args[args->nargs] = -1;
629                 return 0;
630         }
631
632         data.waiting = 1;
633         data.args = args;
634
635         /* Call function on all CPUs.  One of us will make the
636          * rtas call
637          */
638         if (on_each_cpu(rtas_percpu_suspend_me, &data, 1, 0))
639                 data.waiting = -EINVAL;
640
641         if (data.waiting != 0)
642                 printk(KERN_ERR "Error doing global join\n");
643
644         /* Prod each CPU.  This won't hurt, and will wake
645          * anyone we successfully put to sleep with H_JOIN.
646          */
647         for_each_possible_cpu(i)
648                 plpar_hcall_norets(H_PROD, i);
649
650         return data.waiting;
651 }
652 #else /* CONFIG_PPC_PSERIES */
653 static int rtas_ibm_suspend_me(struct rtas_args *args)
654 {
655         return -ENOSYS;
656 }
657 #endif
658
659 asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
660 {
661         struct rtas_args args;
662         unsigned long flags;
663         char *buff_copy, *errbuf = NULL;
664         int nargs;
665         int rc;
666
667         if (!capable(CAP_SYS_ADMIN))
668                 return -EPERM;
669
670         if (copy_from_user(&args, uargs, 3 * sizeof(u32)) != 0)
671                 return -EFAULT;
672
673         nargs = args.nargs;
674         if (nargs > ARRAY_SIZE(args.args)
675             || args.nret > ARRAY_SIZE(args.args)
676             || nargs + args.nret > ARRAY_SIZE(args.args))
677                 return -EINVAL;
678
679         /* Copy in args. */
680         if (copy_from_user(args.args, uargs->args,
681                            nargs * sizeof(rtas_arg_t)) != 0)
682                 return -EFAULT;
683
684         if (args.token == RTAS_UNKNOWN_SERVICE)
685                 return -EINVAL;
686
687         /* Need to handle ibm,suspend_me call specially */
688         if (args.token == ibm_suspend_me_token) {
689                 rc = rtas_ibm_suspend_me(&args);
690                 if (rc)
691                         return rc;
692                 goto copy_return;
693         }
694
695         buff_copy = get_errorlog_buffer();
696
697         spin_lock_irqsave(&rtas.lock, flags);
698
699         rtas.args = args;
700         enter_rtas(__pa(&rtas.args));
701         args = rtas.args;
702
703         args.rets = &args.args[nargs];
704
705         /* A -1 return code indicates that the last command couldn't
706            be completed due to a hardware error. */
707         if (args.rets[0] == -1)
708                 errbuf = __fetch_rtas_last_error(buff_copy);
709
710         spin_unlock_irqrestore(&rtas.lock, flags);
711
712         if (buff_copy) {
713                 if (errbuf)
714                         log_error(errbuf, ERR_TYPE_RTAS_LOG, 0);
715                 kfree(buff_copy);
716         }
717
718  copy_return:
719         /* Copy out args. */
720         if (copy_to_user(uargs->args + nargs,
721                          args.args + nargs,
722                          args.nret * sizeof(rtas_arg_t)) != 0)
723                 return -EFAULT;
724
725         return 0;
726 }
727
728 /* This version can't take the spinlock, because it never returns */
729
730 struct rtas_args rtas_stop_self_args = {
731         /* The token is initialized for real in setup_system() */
732         .token = RTAS_UNKNOWN_SERVICE,
733         .nargs = 0,
734         .nret = 1,
735         .rets = &rtas_stop_self_args.args[0],
736 };
737
738 void rtas_stop_self(void)
739 {
740         struct rtas_args *rtas_args = &rtas_stop_self_args;
741
742         local_irq_disable();
743
744         BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE);
745
746         printk("cpu %u (hwid %u) Ready to die...\n",
747                smp_processor_id(), hard_smp_processor_id());
748         enter_rtas(__pa(rtas_args));
749
750         panic("Alas, I survived.\n");
751 }
752
753 /*
754  * Call early during boot, before mem init or bootmem, to retrieve the RTAS
755  * informations from the device-tree and allocate the RMO buffer for userland
756  * accesses.
757  */
758 void __init rtas_initialize(void)
759 {
760         unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
761
762         /* Get RTAS dev node and fill up our "rtas" structure with infos
763          * about it.
764          */
765         rtas.dev = of_find_node_by_name(NULL, "rtas");
766         if (rtas.dev) {
767                 u32 *basep, *entryp;
768                 u32 *sizep;
769
770                 basep = (u32 *)get_property(rtas.dev, "linux,rtas-base", NULL);
771                 sizep = (u32 *)get_property(rtas.dev, "rtas-size", NULL);
772                 if (basep != NULL && sizep != NULL) {
773                         rtas.base = *basep;
774                         rtas.size = *sizep;
775                         entryp = (u32 *)get_property(rtas.dev, "linux,rtas-entry", NULL);
776                         if (entryp == NULL) /* Ugh */
777                                 rtas.entry = rtas.base;
778                         else
779                                 rtas.entry = *entryp;
780                 } else
781                         rtas.dev = NULL;
782         }
783         if (!rtas.dev)
784                 return;
785
786         /* If RTAS was found, allocate the RMO buffer for it and look for
787          * the stop-self token if any
788          */
789 #ifdef CONFIG_PPC64
790         if (machine_is(pseries) && firmware_has_feature(FW_FEATURE_LPAR)) {
791                 rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX);
792                 ibm_suspend_me_token = rtas_token("ibm,suspend-me");
793         }
794 #endif
795         rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region);
796
797 #ifdef CONFIG_HOTPLUG_CPU
798         rtas_stop_self_args.token = rtas_token("stop-self");
799 #endif /* CONFIG_HOTPLUG_CPU */
800 #ifdef CONFIG_RTAS_ERROR_LOGGING
801         rtas_last_error_token = rtas_token("rtas-last-error");
802 #endif
803 }