hvconsole.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * hvconsole.c
  3. * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
  4. * Copyright (C) 2004 IBM Corporation
  5. *
  6. * Additional Author(s):
  7. * Ryan S. Arnold <rsa@us.ibm.com>
  8. *
  9. * LPAR console support.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <asm/hvcall.h>
  28. #include <asm/hvconsole.h>
  29. #include <asm/prom.h>
  30. /**
  31. * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper
  32. * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
  33. * data.
  34. * @buf: The character buffer into which to put the character data fetched from
  35. * firmware.
  36. * @count: not used?
  37. */
  38. int hvc_get_chars(uint32_t vtermno, char *buf, int count)
  39. {
  40. unsigned long got;
  41. if (plpar_hcall(H_GET_TERM_CHAR, vtermno, 0, 0, 0, &got,
  42. (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) {
  43. /*
  44. * Work around a HV bug where it gives us a null
  45. * after every \r. -- paulus
  46. */
  47. if (got > 0) {
  48. int i;
  49. for (i = 1; i < got; ++i) {
  50. if (buf[i] == 0 && buf[i-1] == '\r') {
  51. --got;
  52. if (i < got)
  53. memmove(&buf[i], &buf[i+1],
  54. got - i);
  55. }
  56. }
  57. }
  58. return got;
  59. }
  60. return 0;
  61. }
  62. EXPORT_SYMBOL(hvc_get_chars);
  63. /**
  64. * hvc_put_chars: send characters to firmware for denoted vterm adapter
  65. * @vtermno: The vtermno or unit_address of the adapter from which the data
  66. * originated.
  67. * @buf: The character buffer that contains the character data to send to
  68. * firmware.
  69. * @count: Send this number of characters.
  70. */
  71. int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
  72. {
  73. unsigned long *lbuf = (unsigned long *) buf;
  74. long ret;
  75. ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0],
  76. lbuf[1]);
  77. if (ret == H_Success)
  78. return count;
  79. if (ret == H_Busy)
  80. return 0;
  81. return -EIO;
  82. }
  83. EXPORT_SYMBOL(hvc_put_chars);
  84. /*
  85. * We hope/assume that the first vty found corresponds to the first console
  86. * device.
  87. */
  88. int hvc_find_vtys(void)
  89. {
  90. struct device_node *vty;
  91. int num_found = 0;
  92. for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
  93. vty = of_find_node_by_name(vty, "vty")) {
  94. uint32_t *vtermno;
  95. /* We have statically defined space for only a certain number of
  96. * console adapters. */
  97. if (num_found >= MAX_NR_HVC_CONSOLES)
  98. break;
  99. vtermno = (uint32_t *)get_property(vty, "reg", NULL);
  100. if (!vtermno)
  101. continue;
  102. if (device_is_compatible(vty, "hvterm1")) {
  103. hvc_instantiate(*vtermno, num_found);
  104. ++num_found;
  105. }
  106. }
  107. return num_found;
  108. }