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