hvc_udbg.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * udbg interface to hvc_console.c
  4. *
  5. * (C) Copyright David Gibson, IBM Corporation 2008.
  6. */
  7. #include <linux/console.h>
  8. #include <linux/delay.h>
  9. #include <linux/err.h>
  10. #include <linux/init.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/types.h>
  13. #include <linux/irq.h>
  14. #include <asm/udbg.h>
  15. #include "hvc_console.h"
  16. struct hvc_struct *hvc_udbg_dev;
  17. static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
  18. {
  19. int i;
  20. for (i = 0; i < count && udbg_putc; i++)
  21. udbg_putc(buf[i]);
  22. return i;
  23. }
  24. static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
  25. {
  26. int i, c;
  27. if (!udbg_getc_poll)
  28. return 0;
  29. for (i = 0; i < count; i++) {
  30. if ((c = udbg_getc_poll()) == -1)
  31. break;
  32. buf[i] = c;
  33. }
  34. return i;
  35. }
  36. static const struct hv_ops hvc_udbg_ops = {
  37. .get_chars = hvc_udbg_get,
  38. .put_chars = hvc_udbg_put,
  39. };
  40. static int __init hvc_udbg_init(void)
  41. {
  42. struct hvc_struct *hp;
  43. if (!udbg_putc)
  44. return -ENODEV;
  45. BUG_ON(hvc_udbg_dev);
  46. hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16);
  47. if (IS_ERR(hp))
  48. return PTR_ERR(hp);
  49. hvc_udbg_dev = hp;
  50. return 0;
  51. }
  52. device_initcall(hvc_udbg_init);
  53. static int __init hvc_udbg_console_init(void)
  54. {
  55. if (!udbg_putc)
  56. return -ENODEV;
  57. hvc_instantiate(0, 0, &hvc_udbg_ops);
  58. add_preferred_console("hvc", 0, NULL);
  59. return 0;
  60. }
  61. console_initcall(hvc_udbg_console_init);