hvc_beat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Beat hypervisor console driver
  3. *
  4. * (C) Copyright 2006 TOSHIBA CORPORATION
  5. *
  6. * This code is based on drivers/char/hvc_rtas.c:
  7. * (C) Copyright IBM Corporation 2001-2005
  8. * (C) Copyright Red Hat, Inc. 2005
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/err.h>
  27. #include <linux/string.h>
  28. #include <linux/console.h>
  29. #include <asm/prom.h>
  30. #include <asm/hvconsole.h>
  31. #include <asm/firmware.h>
  32. #include "hvc_console.h"
  33. extern int64_t beat_get_term_char(uint64_t, uint64_t *, uint64_t *, uint64_t *);
  34. extern int64_t beat_put_term_char(uint64_t, uint64_t, uint64_t, uint64_t);
  35. struct hvc_struct *hvc_beat_dev = NULL;
  36. /* bug: only one queue is available regardless of vtermno */
  37. static int hvc_beat_get_chars(uint32_t vtermno, char *buf, int cnt)
  38. {
  39. static unsigned char q[sizeof(unsigned long) * 2]
  40. __attribute__((aligned(sizeof(unsigned long))));
  41. static int qlen = 0;
  42. unsigned long got;
  43. again:
  44. if (qlen) {
  45. if (qlen > cnt) {
  46. memcpy(buf, q, cnt);
  47. qlen -= cnt;
  48. memmove(q + cnt, q, qlen);
  49. return cnt;
  50. } else { /* qlen <= cnt */
  51. int r;
  52. memcpy(buf, q, qlen);
  53. r = qlen;
  54. qlen = 0;
  55. return r;
  56. }
  57. }
  58. if (beat_get_term_char(vtermno, &got,
  59. ((unsigned long *)q), ((unsigned long *)q) + 1) == 0) {
  60. qlen = got;
  61. goto again;
  62. }
  63. return 0;
  64. }
  65. static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
  66. {
  67. unsigned long kb[2];
  68. int rest, nlen;
  69. for (rest = cnt; rest > 0; rest -= nlen) {
  70. nlen = (rest > 16) ? 16 : rest;
  71. memcpy(kb, buf, nlen);
  72. beat_put_term_char(vtermno, rest, kb[0], kb[1]);
  73. rest -= nlen;
  74. }
  75. return cnt;
  76. }
  77. static struct hv_ops hvc_beat_get_put_ops = {
  78. .get_chars = hvc_beat_get_chars,
  79. .put_chars = hvc_beat_put_chars,
  80. };
  81. static int hvc_beat_useit = 1;
  82. static int hvc_beat_config(char *p)
  83. {
  84. hvc_beat_useit = simple_strtoul(p, NULL, 0);
  85. return 0;
  86. }
  87. static int hvc_beat_console_init(void)
  88. {
  89. if (hvc_beat_useit && machine_is_compatible("Beat")) {
  90. hvc_instantiate(0, 0, &hvc_beat_get_put_ops);
  91. }
  92. return 0;
  93. }
  94. /* temp */
  95. static int hvc_beat_init(void)
  96. {
  97. struct hvc_struct *hp;
  98. if (!firmware_has_feature(FW_FEATURE_BEAT))
  99. return -ENODEV;
  100. hp = hvc_alloc(0, NO_IRQ, &hvc_beat_get_put_ops, 16);
  101. if (IS_ERR(hp))
  102. return PTR_ERR(hp);
  103. hvc_beat_dev = hp;
  104. return 0;
  105. }
  106. static void __exit hvc_beat_exit(void)
  107. {
  108. if (hvc_beat_dev)
  109. hvc_remove(hvc_beat_dev);
  110. }
  111. module_init(hvc_beat_init);
  112. module_exit(hvc_beat_exit);
  113. __setup("hvc_beat=", hvc_beat_config);
  114. console_initcall(hvc_beat_console_init);