rtas.c 18 KB

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