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