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