hvc_vio.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * vio driver interface to hvc_console.c
  3. *
  4. * This code was moved here to allow the remaing code to be reused as a
  5. * generic polling mode with semi-reliable transport driver core to the
  6. * console and tty subsystems.
  7. *
  8. *
  9. * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
  10. * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM
  11. * Copyright (C) 2004 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
  12. * Copyright (C) 2004 IBM Corporation
  13. *
  14. * Additional Author(s):
  15. * Ryan S. Arnold <rsa@us.ibm.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. */
  31. #include <linux/types.h>
  32. #include <linux/init.h>
  33. #include <asm/hvconsole.h>
  34. #include <asm/vio.h>
  35. #include <asm/prom.h>
  36. char hvc_driver_name[] = "hvc_console";
  37. static struct vio_device_id hvc_driver_table[] __devinitdata = {
  38. {"serial", "hvterm1"},
  39. { "", "" }
  40. };
  41. MODULE_DEVICE_TABLE(vio, hvc_driver_table);
  42. static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
  43. {
  44. unsigned long got;
  45. int i;
  46. got = hvc_get_chars(vtermno, buf, count);
  47. /*
  48. * Work around a HV bug where it gives us a null
  49. * after every \r. -- paulus
  50. */
  51. for (i = 1; i < got; ++i) {
  52. if (buf[i] == 0 && buf[i-1] == '\r') {
  53. --got;
  54. if (i < got)
  55. memmove(&buf[i], &buf[i+1],
  56. got - i);
  57. }
  58. }
  59. return got;
  60. }
  61. static struct hv_ops hvc_get_put_ops = {
  62. .get_chars = filtered_get_chars,
  63. .put_chars = hvc_put_chars,
  64. };
  65. static int __devinit hvc_vio_probe(struct vio_dev *vdev,
  66. const struct vio_device_id *id)
  67. {
  68. struct hvc_struct *hp;
  69. /* probed with invalid parameters. */
  70. if (!vdev || !id)
  71. return -EPERM;
  72. hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops);
  73. if (IS_ERR(hp))
  74. return PTR_ERR(hp);
  75. dev_set_drvdata(&vdev->dev, hp);
  76. return 0;
  77. }
  78. static int __devexit hvc_vio_remove(struct vio_dev *vdev)
  79. {
  80. struct hvc_struct *hp = dev_get_drvdata(&vdev->dev);
  81. return hvc_remove(hp);
  82. }
  83. static struct vio_driver hvc_vio_driver = {
  84. .id_table = hvc_driver_table,
  85. .probe = hvc_vio_probe,
  86. .remove = hvc_vio_remove,
  87. .driver = {
  88. .name = hvc_driver_name,
  89. .owner = THIS_MODULE,
  90. }
  91. };
  92. static int hvc_vio_init(void)
  93. {
  94. int rc;
  95. /* Register as a vio device to receive callbacks */
  96. rc = vio_register_driver(&hvc_vio_driver);
  97. return rc;
  98. }
  99. module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */
  100. static void hvc_vio_exit(void)
  101. {
  102. vio_unregister_driver(&hvc_vio_driver);
  103. }
  104. module_exit(hvc_vio_exit);
  105. /* the device tree order defines our numbering */
  106. static int hvc_find_vtys(void)
  107. {
  108. struct device_node *vty;
  109. int num_found = 0;
  110. for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
  111. vty = of_find_node_by_name(vty, "vty")) {
  112. uint32_t *vtermno;
  113. /* We have statically defined space for only a certain number
  114. * of console adapters.
  115. */
  116. if (num_found >= MAX_NR_HVC_CONSOLES)
  117. break;
  118. vtermno = (uint32_t *)get_property(vty, "reg", NULL);
  119. if (!vtermno)
  120. continue;
  121. if (device_is_compatible(vty, "hvterm1")) {
  122. hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
  123. ++num_found;
  124. }
  125. }
  126. return num_found;
  127. }
  128. console_initcall(hvc_find_vtys);