hvc_riscv_sbi.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2008 David Gibson, IBM Corporation
  4. * Copyright (C) 2012 Regents of the University of California
  5. * Copyright (C) 2017 SiFive
  6. */
  7. #include <linux/console.h>
  8. #include <linux/err.h>
  9. #include <linux/init.h>
  10. #include <linux/moduleparam.h>
  11. #include <linux/types.h>
  12. #include <asm/sbi.h>
  13. #include "hvc_console.h"
  14. static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
  15. {
  16. int i;
  17. for (i = 0; i < count; i++)
  18. sbi_console_putchar(buf[i]);
  19. return i;
  20. }
  21. static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
  22. {
  23. int i, c;
  24. for (i = 0; i < count; i++) {
  25. c = sbi_console_getchar();
  26. if (c < 0)
  27. break;
  28. buf[i] = c;
  29. }
  30. return i;
  31. }
  32. static const struct hv_ops hvc_sbi_ops = {
  33. .get_chars = hvc_sbi_tty_get,
  34. .put_chars = hvc_sbi_tty_put,
  35. };
  36. static int __init hvc_sbi_init(void)
  37. {
  38. return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
  39. }
  40. device_initcall(hvc_sbi_init);
  41. static int __init hvc_sbi_console_init(void)
  42. {
  43. hvc_instantiate(0, 0, &hvc_sbi_ops);
  44. return 0;
  45. }
  46. console_initcall(hvc_sbi_console_init);