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