[PATCH] powerpc: declare arch syscalls in <asm/syscalls.h>
[deliverable/linux.git] / arch / powerpc / kernel / rtas.c
CommitLineData
1da177e4
LT
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>
a9415644 20#include <linux/capability.h>
21fe3301 21#include <linux/delay.h>
1da177e4
LT
22
23#include <asm/prom.h>
24#include <asm/rtas.h>
31a7f67e 25#include <asm/hvcall.h>
1da177e4
LT
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>
1da177e4
LT
31#include <asm/delay.h>
32#include <asm/uaccess.h>
033ef338 33#include <asm/lmb.h>
296167ae 34#include <asm/udbg.h>
a7f31841 35#include <asm/syscalls.h>
1da177e4 36
033ef338 37struct rtas_t rtas = {
1da177e4
LT
38 .lock = SPIN_LOCK_UNLOCKED
39};
40
91dc182c
DB
41struct rtas_suspend_me_data {
42 long waiting;
43 struct rtas_args *args;
44};
45
1da177e4
LT
46EXPORT_SYMBOL(rtas);
47
1da177e4 48DEFINE_SPINLOCK(rtas_data_buf_lock);
033ef338 49char rtas_data_buf[RTAS_DATA_BUF_SIZE] __cacheline_aligned;
1da177e4
LT
50unsigned long rtas_rmo_buf;
51
f4fcbbe9
PM
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 */
56void (*rtas_flash_term_hook)(int);
57EXPORT_SYMBOL(rtas_flash_term_hook);
58
033ef338
PM
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 */
296167ae 64static void call_rtas_display_status(char c)
1da177e4
LT
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]);
296167ae 77 args->args[0] = (unsigned char)c;
1da177e4
LT
78
79 enter_rtas(__pa(args));
80
81 spin_unlock_irqrestore(&rtas.lock, s);
82}
83
296167ae 84static void call_rtas_display_status_delay(char c)
1da177e4
LT
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;
21fe3301 93 mdelay(500);
1da177e4
LT
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
296167ae
ME
108void __init udbg_init_rtas(void)
109{
110 udbg_putc = call_rtas_display_status_delay;
111}
112
033ef338 113void rtas_progress(char *s, unsigned short hex)
6566c6f1
AB
114{
115 struct device_node *root;
116 int width, *p;
117 char *os;
118 static int display_character, set_indicator;
8f586b22 119 static int display_width, display_lines, *row_width, form_feed;
6566c6f1 120 static DEFINE_SPINLOCK(progress_lock);
8f586b22 121 static int current_line;
6566c6f1
AB
122 static int pending_newline = 0; /* did last write end with unprinted newline? */
123
124 if (!rtas.base)
125 return;
126
8f586b22
MS
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 }
6566c6f1
AB
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 *
8f586b22
MS
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.
6566c6f1
AB
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 {
8f586b22
MS
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');
6566c6f1
AB
175 }
176
8f586b22
MS
177 if (row_width)
178 width = row_width[current_line];
179 else
180 width = display_width;
6566c6f1
AB
181 os = s;
182 while (*os) {
183 if (*os == '\n' || *os == '\r') {
6566c6f1
AB
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;
8f586b22
MS
190 current_line++;
191 if (current_line > display_lines-1)
192 current_line = display_lines-1;
6566c6f1
AB
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
8f586b22
MS
209 if (row_width)
210 width = row_width[current_line];
211 else
212 width = display_width;
6566c6f1
AB
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
6566c6f1
AB
226 spin_unlock(&progress_lock);
227}
f4fcbbe9 228EXPORT_SYMBOL(rtas_progress); /* needed by rtas_flash module */
6566c6f1 229
033ef338 230int rtas_token(const char *service)
1da177e4
LT
231{
232 int *tokp;
033ef338 233 if (rtas.dev == NULL)
1da177e4 234 return RTAS_UNKNOWN_SERVICE;
1da177e4
LT
235 tokp = (int *) get_property(rtas.dev, service, NULL);
236 return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
237}
238
033ef338 239#ifdef CONFIG_RTAS_ERROR_LOGGING
1da177e4
LT
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 */
245int 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)) {
033ef338
PM
254 printk (KERN_WARNING "RTAS: bad log buffer size %d\n",
255 rtas_error_log_max);
1da177e4
LT
256 rtas_error_log_max = RTAS_ERROR_LOG_MAX;
257 }
258 return rtas_error_log_max;
259}
033ef338 260EXPORT_SYMBOL(rtas_get_error_log_max);
1da177e4
LT
261
262
033ef338
PM
263char rtas_err_buf[RTAS_ERROR_LOG_MAX];
264int rtas_last_error_token;
265
1da177e4
LT
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 */
033ef338 272static char *__fetch_rtas_last_error(char *altbuf)
1da177e4
LT
273{
274 struct rtas_args err_args, save_args;
275 u32 bufsz;
033ef338
PM
276 char *buf = NULL;
277
278 if (rtas_last_error_token == -1)
279 return NULL;
1da177e4
LT
280
281 bufsz = rtas_get_error_log_max();
282
033ef338 283 err_args.token = rtas_last_error_token;
1da177e4
LT
284 err_args.nargs = 2;
285 err_args.nret = 1;
1da177e4
LT
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
033ef338
PM
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;
1da177e4
LT
312}
313
033ef338
PM
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
1da177e4
LT
321int rtas_call(int token, int nargs, int nret, int *outputs, ...)
322{
323 va_list list;
033ef338 324 int i;
1da177e4
LT
325 unsigned long s;
326 struct rtas_args *rtas_args;
033ef338 327 char *buff_copy = NULL;
1da177e4
LT
328 int ret;
329
1da177e4
LT
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);
033ef338 342 for (i = 0; i < nargs; ++i)
1da177e4 343 rtas_args->args[i] = va_arg(list, rtas_arg_t);
1da177e4
LT
344 va_end(list);
345
346 for (i = 0; i < nret; ++i)
347 rtas_args->rets[i] = 0;
348
1da177e4 349 enter_rtas(__pa(rtas_args));
1da177e4
LT
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)
033ef338 354 buff_copy = __fetch_rtas_last_error(NULL);
1da177e4
LT
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
1da177e4
LT
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 */
033ef338 375unsigned int rtas_extended_busy_delay_time(int status)
1da177e4
LT
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 */
033ef338 386 for (ms = 1; order > 0; order--)
1da177e4
LT
387 ms *= 10;
388
389 return ms;
390}
391
392int 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
421int 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
437int 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
462int 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
487int 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
033ef338 513void rtas_restart(char *cmd)
1da177e4 514{
f4fcbbe9
PM
515 if (rtas_flash_term_hook)
516 rtas_flash_term_hook(SYS_RESTART);
1da177e4
LT
517 printk("RTAS system-reboot returned %d\n",
518 rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
519 for (;;);
520}
521
033ef338 522void rtas_power_off(void)
1da177e4 523{
f4fcbbe9
PM
524 if (rtas_flash_term_hook)
525 rtas_flash_term_hook(SYS_POWER_OFF);
1da177e4
LT
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
033ef338 532void rtas_halt(void)
1da177e4 533{
f4fcbbe9
PM
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 (;;);
1da177e4
LT
540}
541
542/* Must be in the RMO region, so we place it here */
543static char rtas_os_term_buf[2048];
544
545void 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
91dc182c
DB
566static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
567#ifdef CONFIG_PPC_PSERIES
568static void rtas_percpu_suspend_me(void *info)
569{
82a4df74 570 int i;
91dc182c
DB
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;
c4cb8ecc
DB
593 data->args->args[data->args->nargs] =
594 rtas_call(ibm_suspend_me_token, 0, 1, NULL);
82a4df74
DB
595 for_each_cpu(i)
596 plpar_hcall_norets(H_PROD,i);
91dc182c
DB
597 } else {
598 data->waiting = -EBUSY;
599 printk(KERN_ERR "Error on H_Join hypervisor call\n");
600 }
601
602out:
91dc182c
DB
603 local_irq_restore(flags);
604 return;
605}
606
607static 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 */
634static int rtas_ibm_suspend_me(struct rtas_args *args)
635{
636 return -ENOSYS;
637}
638#endif
1da177e4
LT
639
640asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
641{
642 struct rtas_args args;
643 unsigned long flags;
033ef338 644 char *buff_copy, *errbuf = NULL;
1da177e4 645 int nargs;
91dc182c 646 int rc;
1da177e4
LT
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
91dc182c
DB
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
033ef338 676 buff_copy = get_errorlog_buffer();
1da177e4
LT
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. */
033ef338
PM
688 if (args.rets[0] == -1)
689 errbuf = __fetch_rtas_last_error(buff_copy);
1da177e4
LT
690
691 spin_unlock_irqrestore(&rtas.lock, flags);
692
693 if (buff_copy) {
033ef338
PM
694 if (errbuf)
695 log_error(errbuf, ERR_TYPE_RTAS_LOG, 0);
1da177e4
LT
696 kfree(buff_copy);
697 }
698
91dc182c 699 copy_return:
1da177e4
LT
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
711struct 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
719void 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/*
943ffb58 735 * Call early during boot, before mem init or bootmem, to retrieve the RTAS
1da177e4
LT
736 * informations from the device-tree and allocate the RMO buffer for userland
737 * accesses.
738 */
739void __init rtas_initialize(void)
740{
033ef338
PM
741 unsigned long rtas_region = RTAS_INSTANTIATE_MAX;
742
1da177e4
LT
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 }
033ef338
PM
764 if (!rtas.dev)
765 return;
766
1da177e4
LT
767 /* If RTAS was found, allocate the RMO buffer for it and look for
768 * the stop-self token if any
769 */
033ef338 770#ifdef CONFIG_PPC64
91dc182c 771 if (_machine == PLATFORM_PSERIES_LPAR) {
033ef338 772 rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX);
91dc182c
DB
773 ibm_suspend_me_token = rtas_token("ibm,suspend-me");
774 }
033ef338
PM
775#endif
776 rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region);
1da177e4
LT
777
778#ifdef CONFIG_HOTPLUG_CPU
033ef338 779 rtas_stop_self_args.token = rtas_token("stop-self");
1da177e4 780#endif /* CONFIG_HOTPLUG_CPU */
033ef338
PM
781#ifdef CONFIG_RTAS_ERROR_LOGGING
782 rtas_last_error_token = rtas_token("rtas-last-error");
783#endif
1da177e4
LT
784}
785
786
1da177e4
LT
787EXPORT_SYMBOL(rtas_token);
788EXPORT_SYMBOL(rtas_call);
789EXPORT_SYMBOL(rtas_data_buf);
790EXPORT_SYMBOL(rtas_data_buf_lock);
791EXPORT_SYMBOL(rtas_extended_busy_delay_time);
792EXPORT_SYMBOL(rtas_get_sensor);
793EXPORT_SYMBOL(rtas_get_power_level);
794EXPORT_SYMBOL(rtas_set_power_level);
795EXPORT_SYMBOL(rtas_set_indicator);
This page took 0.291137 seconds and 5 git commands to generate.