hvc_dcc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (c) 2010, Code Aurora Forum. 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. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. */
  17. #include <linux/console.h>
  18. #include <linux/delay.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/types.h>
  23. #include <asm/processor.h>
  24. #include "hvc_console.h"
  25. /* DCC Status Bits */
  26. #define DCC_STATUS_RX (1 << 30)
  27. #define DCC_STATUS_TX (1 << 29)
  28. static inline u32 __dcc_getstatus(void)
  29. {
  30. u32 __ret;
  31. asm volatile("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
  32. : "=r" (__ret) : : "cc");
  33. return __ret;
  34. }
  35. static inline char __dcc_getchar(void)
  36. {
  37. char __c;
  38. asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
  39. : "=r" (__c));
  40. isb();
  41. return __c;
  42. }
  43. static inline void __dcc_putchar(char c)
  44. {
  45. asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
  46. : /* no output register */
  47. : "r" (c));
  48. isb();
  49. }
  50. static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
  51. {
  52. int i;
  53. for (i = 0; i < count; i++) {
  54. while (__dcc_getstatus() & DCC_STATUS_TX)
  55. cpu_relax();
  56. __dcc_putchar(buf[i]);
  57. }
  58. return count;
  59. }
  60. static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
  61. {
  62. int i;
  63. for (i = 0; i < count; ++i)
  64. if (__dcc_getstatus() & DCC_STATUS_RX)
  65. buf[i] = __dcc_getchar();
  66. else
  67. break;
  68. return i;
  69. }
  70. static const struct hv_ops hvc_dcc_get_put_ops = {
  71. .get_chars = hvc_dcc_get_chars,
  72. .put_chars = hvc_dcc_put_chars,
  73. };
  74. static int __init hvc_dcc_console_init(void)
  75. {
  76. hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
  77. return 0;
  78. }
  79. console_initcall(hvc_dcc_console_init);
  80. static int __init hvc_dcc_init(void)
  81. {
  82. hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
  83. return 0;
  84. }
  85. device_initcall(hvc_dcc_init);