hvc_dcc.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (c) 2010, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/console.h>
  13. #include <linux/delay.h>
  14. #include <linux/err.h>
  15. #include <linux/init.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/types.h>
  18. #include <asm/processor.h>
  19. #include "hvc_console.h"
  20. /* DCC Status Bits */
  21. #define DCC_STATUS_RX (1 << 30)
  22. #define DCC_STATUS_TX (1 << 29)
  23. static inline u32 __dcc_getstatus(void)
  24. {
  25. u32 __ret;
  26. asm volatile("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
  27. : "=r" (__ret) : : "cc");
  28. return __ret;
  29. }
  30. static inline char __dcc_getchar(void)
  31. {
  32. char __c;
  33. asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
  34. : "=r" (__c));
  35. isb();
  36. return __c;
  37. }
  38. static inline void __dcc_putchar(char c)
  39. {
  40. asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
  41. : /* no output register */
  42. : "r" (c));
  43. isb();
  44. }
  45. static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
  46. {
  47. int i;
  48. for (i = 0; i < count; i++) {
  49. while (__dcc_getstatus() & DCC_STATUS_TX)
  50. cpu_relax();
  51. __dcc_putchar(buf[i]);
  52. }
  53. return count;
  54. }
  55. static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
  56. {
  57. int i;
  58. for (i = 0; i < count; ++i)
  59. if (__dcc_getstatus() & DCC_STATUS_RX)
  60. buf[i] = __dcc_getchar();
  61. else
  62. break;
  63. return i;
  64. }
  65. static const struct hv_ops hvc_dcc_get_put_ops = {
  66. .get_chars = hvc_dcc_get_chars,
  67. .put_chars = hvc_dcc_put_chars,
  68. };
  69. static int __init hvc_dcc_console_init(void)
  70. {
  71. hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
  72. return 0;
  73. }
  74. console_initcall(hvc_dcc_console_init);
  75. static int __init hvc_dcc_init(void)
  76. {
  77. hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
  78. return 0;
  79. }
  80. device_initcall(hvc_dcc_init);