hvc_rtas.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * IBM RTAS driver interface to hvc_console.c
  3. *
  4. * (C) Copyright IBM Corporation 2001-2005
  5. * (C) Copyright Red Hat, Inc. 2005
  6. *
  7. * Author(s): Maximino Augilar <IBM STI Design Center>
  8. * : Ryan S. Arnold <rsa@us.ibm.com>
  9. * : Utz Bacher <utz.bacher@de.ibm.com>
  10. * : David Woodhouse <dwmw2@infradead.org>
  11. *
  12. * inspired by drivers/char/hvc_console.c
  13. * written by Anton Blanchard and Paul Mackerras
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. #include <linux/console.h>
  30. #include <linux/delay.h>
  31. #include <linux/err.h>
  32. #include <linux/init.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/types.h>
  35. #include <asm/irq.h>
  36. #include <asm/rtas.h>
  37. #include "hvc_console.h"
  38. #define hvc_rtas_cookie 0x67781e15
  39. struct hvc_struct *hvc_rtas_dev;
  40. #define RTASCONS_PUT_ATTEMPTS 16
  41. static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE;
  42. static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE;
  43. static int rtascons_put_delay = 100;
  44. module_param_named(put_delay, rtascons_put_delay, int, 0644);
  45. static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, int count)
  46. {
  47. int done;
  48. /* if there is more than one character to be displayed, wait a bit */
  49. for (done = 0; done < count; done++) {
  50. int result;
  51. result = rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[done]);
  52. if (result)
  53. break;
  54. }
  55. /* the calling routine expects to receive the number of bytes sent */
  56. return done;
  57. }
  58. static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
  59. {
  60. int i;
  61. for (i = 0; i < count; i++) {
  62. int c, err;
  63. err = rtas_call(rtascons_get_char_token, 0, 2, &c);
  64. if (err)
  65. break;
  66. buf[i] = c;
  67. }
  68. return i;
  69. }
  70. static struct hv_ops hvc_rtas_get_put_ops = {
  71. .get_chars = hvc_rtas_read_console,
  72. .put_chars = hvc_rtas_write_console,
  73. };
  74. static int hvc_rtas_init(void)
  75. {
  76. struct hvc_struct *hp;
  77. if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
  78. rtascons_put_char_token = rtas_token("put-term-char");
  79. if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
  80. return -EIO;
  81. if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
  82. rtascons_get_char_token = rtas_token("get-term-char");
  83. if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
  84. return -EIO;
  85. BUG_ON(hvc_rtas_dev);
  86. /* Allocate an hvc_struct for the console device we instantiated
  87. * earlier. Save off hp so that we can return it on exit */
  88. hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops);
  89. if (IS_ERR(hp))
  90. return PTR_ERR(hp);
  91. hvc_rtas_dev = hp;
  92. return 0;
  93. }
  94. module_init(hvc_rtas_init);
  95. /* This will tear down the tty portion of the driver */
  96. static void __exit hvc_rtas_exit(void)
  97. {
  98. /* Really the fun isn't over until the worker thread breaks down and the
  99. * tty cleans up */
  100. if (hvc_rtas_dev)
  101. hvc_remove(hvc_rtas_dev);
  102. }
  103. module_exit(hvc_rtas_exit);
  104. /* This will happen prior to module init. There is no tty at this time? */
  105. static int hvc_rtas_console_init(void)
  106. {
  107. rtascons_put_char_token = rtas_token("put-term-char");
  108. if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
  109. return -EIO;
  110. rtascons_get_char_token = rtas_token("get-term-char");
  111. if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
  112. return -EIO;
  113. hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops );
  114. add_preferred_console("hvc", 0, NULL);
  115. return 0;
  116. }
  117. console_initcall(hvc_rtas_console_init);