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/semaphore.h>
  24. #include <asm/machdep.h>
  25. #include <asm/page.h>
  26. #include <asm/param.h>
  27. #include <asm/system.h>
  28. #include <asm/delay.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/lmb.h>
  31. #include <asm/udbg.h>
  32. struct rtas_t rtas = {
  33. .lock = SPIN_LOCK_UNLOCKED
  34. };
  35. struct rtas_suspend_me_data {
  36. long waiting;
  37. struct rtas_args *args;
  38. };
  39. EXPORT_SYMBOL(rtas);
  40. DEFINE_SPINLOCK(rtas_data_buf_lock);
  41. char rtas_data_buf[RTAS_DATA_BUF_SIZE] __cacheline_aligned;
  42. unsigned long rtas_rmo_buf;
  43. /*
  44. * If non-NULL, this gets called when the kernel terminates.
  45. * This is done like this so rtas_flash can be a module.
  46. */
  47. void (*rtas_flash_term_hook)(int);
  48. EXPORT_SYMBOL(rtas_flash_term_hook);
  49. /*
  50. * call_rtas_display_status and call_rtas_display_status_delay
  51. * are designed only for very early low-level debugging, which
  52. * is why the token is hard-coded to 10.
  53. */
  54. static void call_rtas_display_status(char c)
  55. {
  56. struct rtas_args *args = &rtas.args;
  57. unsigned long s;
  58. if (!rtas.base)
  59. return;
  60. spin_lock_irqsave(&rtas.lock, s);
  61. args->token = 10;
  62. args->nargs = 1;
  63. args->nret = 1;
  64. args->rets = (rtas_arg_t *)&(args->args[1]);
  65. args->args[0] = (unsigned char)c;
  66. enter_rtas(__pa(args));
  67. spin_unlock_irqrestore(&rtas.lock, s);
  68. }
  69. static void call_rtas_display_status_delay(char c)
  70. {
  71. static int pending_newline = 0; /* did last write end with unprinted newline? */
  72. static int width = 16;
  73. if (c == '\n') {
  74. while (width-- > 0)
  75. call_rtas_display_status(' ');
  76. width = 16;
  77. mdelay(500);
  78. pending_newline = 1;
  79. } else {
  80. if (pending_newline) {
  81. call_rtas_display_status('\r');
  82. call_rtas_display_status('\n');
  83. }
  84. pending_newline = 0;
  85. if (width--) {
  86. call_rtas_display_status(c);
  87. udelay(10000);
  88. }
  89. }
  90. }
  91. void __init udbg_init_rtas(void)
  92. {
  93. udbg_putc = call_rtas_display_status_delay;
  94. }
  95. void rtas_progress(char *s, unsigned short hex)
  96. {
  97. struct device_node *root;
  98. int width, *p;
  99. char *os;
  100. static int display_character, set_indicator;
  101. static int display_width, display_lines, *row_width, form_feed;
  102. static DEFINE_SPINLOCK(progress_lock);
  103. static int current_line;
  104. static int pending_newline = 0; /* did last write end with unprinted newline? */
  105. if (!rtas.base)
  106. return;
  107. if (display_width == 0) {
  108. display_width = 0x10;
  109. if ((root = find_path_device("/rtas"))) {
  110. if ((p = (unsigned int *)get_property(root,
  111. "ibm,display-line-length", NULL)))
  112. display_width = *p;
  113. if ((p = (unsigned int *)get_property(root,
  114. "ibm,form-feed", NULL)))
  115. form_feed = *p;
  116. if ((p = (unsigned int *)get_property(root,
  117. "ibm,display-number-of-lines", NULL)))
  118. display_lines = *p;
  119. row_width = (unsigned int *)get_property(root,
  120. "ibm,display-truncation-length", NULL);
  121. }
  122. display_character = rtas_token("display-character");
  123. set_indicator = rtas_token("set-indicator");
  124. }
  125. if (display_character == RTAS_UNKNOWN_SERVICE) {
  126. /* use hex display if available */
  127. if (set_indicator != RTAS_UNKNOWN_SERVICE)
  128. rtas_call(set_indicator, 3, 1, NULL, 6, 0, hex);
  129. return;
  130. }
  131. spin_lock(&progress_lock);
  132. /*
  133. * Last write ended with newline, but we didn't print it since
  134. * it would just clear the bottom line of output. Print it now
  135. * instead.
  136. *
  137. * If no newline is pending and form feed is supported, clear the
  138. * display with a form feed; otherwise, print a CR to start output
  139. * at the beginning of the line.
  140. */
  141. if (pending_newline) {
  142. rtas_call(display_character, 1, 1, NULL, '\r');
  143. rtas_call(display_character, 1, 1, NULL, '\n');
  144. pending_newline = 0;
  145. } else {
  146. current_line = 0;
  147. if (form_feed)
  148. rtas_call(display_character, 1, 1, NULL,
  149. (char)form_feed);
  150. else
  151. rtas_call(display_character, 1, 1, NULL, '\r');
  152. }
  153. if (row_width)
  154. width = row_width[current_line];
  155. else
  156. width = display_width;
  157. os = s;
  158. while (*os) {
  159. if (*os == '\n' || *os == '\r') {
  160. /* If newline is the last character, save it
  161. * until next call to avoid bumping up the
  162. * display output.
  163. */
  164. if (*os == '\n' && !os[1]) {
  165. pending_newline = 1;
  166. current_line++;
  167. if (current_line > display_lines-1)
  168. current_line = display_lines-1;
  169. spin_unlock(&progress_lock);
  170. return;
  171. }
  172. /* RTAS wants CR-LF, not just LF */
  173. if (*os == '\n') {
  174. rtas_call(display_character, 1, 1, NULL, '\r');
  175. rtas_call(display_character, 1, 1, NULL, '\n');
  176. } else {
  177. /* CR might be used to re-draw a line, so we'll
  178. * leave it alone and not add LF.
  179. */
  180. rtas_call(display_character, 1, 1, NULL, *os);
  181. }
  182. if (row_width)
  183. width = row_width[current_line];
  184. else
  185. width = display_width;
  186. } else {
  187. width--;
  188. rtas_call(display_character, 1, 1, NULL, *os);
  189. }
  190. os++;
  191. /* if we overwrite the screen length */
  192. if (width <= 0)
  193. while ((*os != 0) && (*os != '\n') && (*os != '\r'))
  194. os++;
  195. }
  196. spin_unlock(&progress_lock);
  197. }
  198. EXPORT_SYMBOL(rtas_progress); /* needed by rtas_flash module */
  199. int rtas_token(const char *service)
  200. {
  201. int *tokp;
  202. if (rtas.dev == NULL)
  203. return RTAS_UNKNOWN_SERVICE;
  204. tokp = (int *) get_property(rtas.dev, service, NULL);
  205. return tokp ? *tokp : RTAS_UNKNOWN_SERVICE;
  206. }
  207. #ifdef CONFIG_RTAS_ERROR_LOGGING
  208. /*
  209. * Return the firmware-specified size of the error log buffer
  210. * for all rtas calls that require an error buffer argument.
  211. * This includes 'check-exception' and 'rtas-last-error'.
  212. */
  213. int rtas_get_error_log_max(void)
  214. {
  215. static int rtas_error_log_max;
  216. if (rtas_error_log_max)
  217. return rtas_error_log_max;
  218. rtas_error_log_max = rtas_token ("rtas-error-log-max");
  219. if ((rtas_error_log_max == RTAS_UNKNOWN_SERVICE) ||
  220. (rtas_error_log_max > RTAS_ERROR_LOG_MAX)) {
  221. printk (KERN_WARNING "RTAS: bad log buffer size %d\n",
  222. rtas_error_log_max);
  223. rtas_error_log_max = RTAS_ERROR_LOG_MAX;
  224. }
  225. return rtas_error_log_max;
  226. }
  227. EXPORT_SYMBOL(rtas_get_error_log_max);
  228. char rtas_err_buf[RTAS_ERROR_LOG_MAX];
  229. int rtas_last_error_token;
  230. /** Return a copy of the detailed error text associated with the
  231. * most recent failed call to rtas. Because the error text
  232. * might go stale if there are any other intervening rtas calls,
  233. * this routine must be called atomically with whatever produced
  234. * the error (i.e. with rtas.lock still held from the previous call).
  235. */
  236. static char *__fetch_rtas_last_error(char *altbuf)
  237. {
  238. struct rtas_args err_args, save_args;
  239. u32 bufsz;
  240. char *buf = NULL;
  241. if (rtas_last_error_token == -1)
  242. return NULL;
  243. bufsz = rtas_get_error_log_max();
  244. err_args.token = rtas_last_error_token;
  245. err_args.nargs = 2;
  246. err_args.nret = 1;
  247. err_args.args[0] = (rtas_arg_t)__pa(rtas_err_buf);
  248. err_args.args[1] = bufsz;
  249. err_args.args[2] = 0;
  250. save_args = rtas.args;
  251. rtas.args = err_args;
  252. enter_rtas(__pa(&rtas.args));
  253. err_args = rtas.args;
  254. rtas.args = save_args;
  255. /* Log the error in the unlikely case that there was one. */
  256. if (unlikely(err_args.args[2] == 0)) {
  257. if (altbuf) {
  258. buf = altbuf;
  259. } else {
  260. buf = rtas_err_buf;
  261. if (mem_init_done)
  262. buf = kmalloc(RTAS_ERROR_LOG_MAX, GFP_ATOMIC);
  263. }
  264. if (buf)
  265. memcpy(buf, rtas_err_buf, RTAS_ERROR_LOG_MAX);
  266. }
  267. return buf;
  268. }
  269. #define get_errorlog_buffer() kmalloc(RTAS_ERROR_LOG_MAX, GFP_KERNEL)
  270. #else /* CONFIG_RTAS_ERROR_LOGGING */
  271. #define __fetch_rtas_last_error(x) NULL
  272. #define get_errorlog_buffer() NULL
  273. #endif
  274. int rtas_call(int token, int nargs, int nret, int *outputs, ...)
  275. {
  276. va_list list;
  277. int i;
  278. unsigned long s;
  279. struct rtas_args *rtas_args;
  280. char *buff_copy = NULL;
  281. int ret;
  282. if (token == RTAS_UNKNOWN_SERVICE)
  283. return -1;
  284. /* Gotta do something different here, use global lock for now... */
  285. spin_lock_irqsave(&rtas.lock, s);
  286. rtas_args = &rtas.args;
  287. rtas_args->token = token;
  288. rtas_args->nargs = nargs;
  289. rtas_args->nret = nret;
  290. rtas_args->rets = (rtas_arg_t *)&(rtas_args->args[nargs]);
  291. va_start(list, outputs);
  292. for (i = 0; i < nargs; ++i)
  293. rtas_args->args[i] = va_arg(list, rtas_arg_t);
  294. va_end(list);
  295. for (i = 0; i < nret; ++i)
  296. rtas_args->rets[i] = 0;
  297. enter_rtas(__pa(rtas_args));
  298. /* A -1 return code indicates that the last command couldn't
  299. be completed due to a hardware error. */
  300. if (rtas_args->rets[0] == -1)
  301. buff_copy = __fetch_rtas_last_error(NULL);
  302. if (nret > 1 && outputs != NULL)
  303. for (i = 0; i < nret-1; ++i)
  304. outputs[i] = rtas_args->rets[i+1];
  305. ret = (nret > 0)? rtas_args->rets[0]: 0;
  306. /* Gotta do something different here, use global lock for now... */
  307. spin_unlock_irqrestore(&rtas.lock, s);
  308. if (buff_copy) {
  309. log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
  310. if (mem_init_done)
  311. kfree(buff_copy);
  312. }
  313. return ret;
  314. }
  315. /* Given an RTAS status code of 990n compute the hinted delay of 10^n
  316. * (last digit) milliseconds. For now we bound at n=5 (100 sec).
  317. */
  318. unsigned int rtas_extended_busy_delay_time(int status)
  319. {
  320. int order = status - 9900;
  321. unsigned long ms;
  322. if (order < 0)
  323. order = 0; /* RTC depends on this for -2 clock busy */
  324. else if (order > 5)
  325. order = 5; /* bound */
  326. /* Use microseconds for reasonable accuracy */
  327. for (ms = 1; order > 0; order--)
  328. ms *= 10;
  329. return ms;
  330. }
  331. int rtas_error_rc(int rtas_rc)
  332. {
  333. int rc;
  334. switch (rtas_rc) {
  335. case -1: /* Hardware Error */
  336. rc = -EIO;
  337. break;
  338. case -3: /* Bad indicator/domain/etc */
  339. rc = -EINVAL;
  340. break;
  341. case -9000: /* Isolation error */
  342. rc = -EFAULT;
  343. break;
  344. case -9001: /* Outstanding TCE/PTE */
  345. rc = -EEXIST;
  346. break;
  347. case -9002: /* No usable slot */
  348. rc = -ENODEV;
  349. break;
  350. default:
  351. printk(KERN_ERR "%s: unexpected RTAS error %d\n",
  352. __FUNCTION__, rtas_rc);
  353. rc = -ERANGE;
  354. break;
  355. }
  356. return rc;
  357. }
  358. int rtas_get_power_level(int powerdomain, int *level)
  359. {
  360. int token = rtas_token("get-power-level");
  361. int rc;
  362. if (token == RTAS_UNKNOWN_SERVICE)
  363. return -ENOENT;
  364. while ((rc = rtas_call(token, 1, 2, level, powerdomain)) == RTAS_BUSY)
  365. udelay(1);
  366. if (rc < 0)
  367. return rtas_error_rc(rc);
  368. return rc;
  369. }
  370. int rtas_set_power_level(int powerdomain, int level, int *setlevel)
  371. {
  372. int token = rtas_token("set-power-level");
  373. unsigned int wait_time;
  374. int rc;
  375. if (token == RTAS_UNKNOWN_SERVICE)
  376. return -ENOENT;
  377. while (1) {
  378. rc = rtas_call(token, 2, 2, setlevel, powerdomain, level);
  379. if (rc == RTAS_BUSY)
  380. udelay(1);
  381. else if (rtas_is_extended_busy(rc)) {
  382. wait_time = rtas_extended_busy_delay_time(rc);
  383. udelay(wait_time * 1000);
  384. } else
  385. break;
  386. }
  387. if (rc < 0)
  388. return rtas_error_rc(rc);
  389. return rc;
  390. }
  391. int rtas_get_sensor(int sensor, int index, int *state)
  392. {
  393. int token = rtas_token("get-sensor-state");
  394. unsigned int wait_time;
  395. int rc;
  396. if (token == RTAS_UNKNOWN_SERVICE)
  397. return -ENOENT;
  398. while (1) {
  399. rc = rtas_call(token, 2, 2, state, sensor, index);
  400. if (rc == RTAS_BUSY)
  401. udelay(1);
  402. else if (rtas_is_extended_busy(rc)) {
  403. wait_time = rtas_extended_busy_delay_time(rc);
  404. udelay(wait_time * 1000);
  405. } else
  406. break;
  407. }
  408. if (rc < 0)
  409. return rtas_error_rc(rc);
  410. return rc;
  411. }
  412. int rtas_set_indicator(int indicator, int index, int new_value)
  413. {
  414. int token = rtas_token("set-indicator");
  415. unsigned int wait_time;
  416. int rc;
  417. if (token == RTAS_UNKNOWN_SERVICE)
  418. return -ENOENT;
  419. while (1) {
  420. rc = rtas_call(token, 3, 1, NULL, indicator, index, new_value);
  421. if (rc == RTAS_BUSY)
  422. udelay(1);
  423. else if (rtas_is_extended_busy(rc)) {
  424. wait_time = rtas_extended_busy_delay_time(rc);
  425. udelay(wait_time * 1000);
  426. }
  427. else
  428. break;
  429. }
  430. if (rc < 0)
  431. return rtas_error_rc(rc);
  432. return rc;
  433. }
  434. void rtas_restart(char *cmd)
  435. {
  436. if (rtas_flash_term_hook)
  437. rtas_flash_term_hook(SYS_RESTART);
  438. printk("RTAS system-reboot returned %d\n",
  439. rtas_call(rtas_token("system-reboot"), 0, 1, NULL));
  440. for (;;);
  441. }
  442. void rtas_power_off(void)
  443. {
  444. if (rtas_flash_term_hook)
  445. rtas_flash_term_hook(SYS_POWER_OFF);
  446. /* allow power on only with power button press */
  447. printk("RTAS power-off returned %d\n",
  448. rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
  449. for (;;);
  450. }
  451. void rtas_halt(void)
  452. {
  453. if (rtas_flash_term_hook)
  454. rtas_flash_term_hook(SYS_HALT);
  455. /* allow power on only with power button press */
  456. printk("RTAS power-off returned %d\n",
  457. rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1));
  458. for (;;);
  459. }
  460. /* Must be in the RMO region, so we place it here */
  461. static char rtas_os_term_buf[2048];
  462. void rtas_os_term(char *str)
  463. {
  464. int status;
  465. if (RTAS_UNKNOWN_SERVICE == rtas_token("ibm,os-term"))
  466. return;
  467. snprintf(rtas_os_term_buf, 2048, "OS panic: %s", str);
  468. do {
  469. status = rtas_call(rtas_token("ibm,os-term"), 1, 1, NULL,
  470. __pa(rtas_os_term_buf));
  471. if (status == RTAS_BUSY)
  472. udelay(1);
  473. else if (status != 0)
  474. printk(KERN_EMERG "ibm,os-term call failed %d\n",
  475. status);
  476. } while (status == RTAS_BUSY);
  477. }
  478. static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
  479. #ifdef CONFIG_PPC_PSERIES
  480. static void rtas_percpu_suspend_me(void *info)
  481. {
  482. long rc;
  483. long flags;
  484. struct rtas_suspend_me_data *data =
  485. (struct rtas_suspend_me_data *)info;
  486. /*
  487. * We use "waiting" to indicate our state. As long
  488. * as it is >0, we are still trying to all join up.
  489. * If it goes to 0, we have successfully joined up and
  490. * one thread got H_Continue. If any error happens,
  491. * we set it to <0.
  492. */
  493. local_irq_save(flags);
  494. do {
  495. rc = plpar_hcall_norets(H_JOIN);
  496. smp_rmb();
  497. } while (rc == H_Success && data->waiting > 0);
  498. if (rc == H_Success)
  499. goto out;
  500. if (rc == H_Continue) {
  501. data->waiting = 0;
  502. rtas_call(ibm_suspend_me_token, 0, 1,
  503. data->args->args);
  504. } else {
  505. data->waiting = -EBUSY;
  506. printk(KERN_ERR "Error on H_Join hypervisor call\n");
  507. }
  508. out:
  509. /* before we restore interrupts, make sure we don't
  510. * generate a spurious soft lockup errors
  511. */
  512. touch_softlockup_watchdog();
  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);