hvconsole.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * hvconsole.c
  4. * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
  5. * Copyright (C) 2004 IBM Corporation
  6. *
  7. * Additional Author(s):
  8. * Ryan S. Arnold <[email protected]>
  9. *
  10. * LPAR console support.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/export.h>
  14. #include <linux/errno.h>
  15. #include <asm/hvcall.h>
  16. #include <asm/hvconsole.h>
  17. #include <asm/plpar_wrappers.h>
  18. /**
  19. * hvc_get_chars - retrieve characters from firmware for denoted vterm adapter
  20. * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
  21. * data.
  22. * @buf: The character buffer into which to put the character data fetched from
  23. * firmware.
  24. * @count: not used?
  25. */
  26. int hvc_get_chars(uint32_t vtermno, char *buf, int count)
  27. {
  28. long ret;
  29. unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
  30. unsigned long *lbuf = (unsigned long *)buf;
  31. ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
  32. lbuf[0] = be64_to_cpu(retbuf[1]);
  33. lbuf[1] = be64_to_cpu(retbuf[2]);
  34. if (ret == H_SUCCESS)
  35. return retbuf[0];
  36. return 0;
  37. }
  38. EXPORT_SYMBOL(hvc_get_chars);
  39. /**
  40. * hvc_put_chars: send characters to firmware for denoted vterm adapter
  41. * @vtermno: The vtermno or unit_address of the adapter from which the data
  42. * originated.
  43. * @buf: The character buffer that contains the character data to send to
  44. * firmware. Must be at least 16 bytes, even if count is less than 16.
  45. * @count: Send this number of characters.
  46. */
  47. int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
  48. {
  49. unsigned long *lbuf = (unsigned long *) buf;
  50. long ret;
  51. /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
  52. if (count > MAX_VIO_PUT_CHARS)
  53. count = MAX_VIO_PUT_CHARS;
  54. ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
  55. cpu_to_be64(lbuf[0]),
  56. cpu_to_be64(lbuf[1]));
  57. if (ret == H_SUCCESS)
  58. return count;
  59. if (ret == H_BUSY)
  60. return -EAGAIN;
  61. return -EIO;
  62. }
  63. EXPORT_SYMBOL(hvc_put_chars);