hvconsole.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/export.h>
  27. #include <linux/errno.h>
  28. #include <asm/hvcall.h>
  29. #include <asm/hvconsole.h>
  30. #include <asm/plpar_wrappers.h>
  31. /**
  32. * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper
  33. * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
  34. * data.
  35. * @buf: The character buffer into which to put the character data fetched from
  36. * firmware.
  37. * @count: not used?
  38. */
  39. int hvc_get_chars(uint32_t vtermno, char *buf, int count)
  40. {
  41. long ret;
  42. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  43. unsigned long *lbuf = (unsigned long *)buf;
  44. ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
  45. lbuf[0] = be64_to_cpu(retbuf[1]);
  46. lbuf[1] = be64_to_cpu(retbuf[2]);
  47. if (ret == H_SUCCESS)
  48. return retbuf[0];
  49. return 0;
  50. }
  51. EXPORT_SYMBOL(hvc_get_chars);
  52. /**
  53. * hvc_put_chars: send characters to firmware for denoted vterm adapter
  54. * @vtermno: The vtermno or unit_address of the adapter from which the data
  55. * originated.
  56. * @buf: The character buffer that contains the character data to send to
  57. * firmware.
  58. * @count: Send this number of characters.
  59. */
  60. int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
  61. {
  62. unsigned long *lbuf = (unsigned long *) buf;
  63. long ret;
  64. /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
  65. if (count > MAX_VIO_PUT_CHARS)
  66. count = MAX_VIO_PUT_CHARS;
  67. ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
  68. cpu_to_be64(lbuf[0]),
  69. cpu_to_be64(lbuf[1]));
  70. if (ret == H_SUCCESS)
  71. return count;
  72. if (ret == H_BUSY)
  73. return -EAGAIN;
  74. return -EIO;
  75. }
  76. EXPORT_SYMBOL(hvc_put_chars);