Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 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 | |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/init.h> |
Ryan S. Arnold | 45d607e | 2006-03-27 21:25:16 +0200 | [diff] [blame] | 34 | |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 35 | #include <asm/hvconsole.h> |
| 36 | #include <asm/vio.h> |
| 37 | #include <asm/prom.h> |
Stephen Rothwell | de0138d | 2006-09-25 13:30:51 +1000 | [diff] [blame] | 38 | #include <asm/firmware.h> |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 39 | |
Ryan S. Arnold | 45d607e | 2006-03-27 21:25:16 +0200 | [diff] [blame] | 40 | #include "hvc_console.h" |
| 41 | |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 42 | char hvc_driver_name[] = "hvc_console"; |
| 43 | |
| 44 | static struct vio_device_id hvc_driver_table[] __devinitdata = { |
| 45 | {"serial", "hvterm1"}, |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 46 | { "", "" } |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 47 | }; |
| 48 | MODULE_DEVICE_TABLE(vio, hvc_driver_table); |
| 49 | |
Milton Miller | 70b234a | 2005-07-07 17:56:26 -0700 | [diff] [blame] | 50 | static int filtered_get_chars(uint32_t vtermno, char *buf, int count) |
| 51 | { |
| 52 | unsigned long got; |
| 53 | int i; |
| 54 | |
Ryan S. Arnold | 45d607e | 2006-03-27 21:25:16 +0200 | [diff] [blame] | 55 | /* |
| 56 | * Vio firmware will read up to SIZE_VIO_GET_CHARS at its own discretion |
| 57 | * so we play safe and avoid the situation where got > count which could |
| 58 | * overload the flip buffer. |
| 59 | */ |
| 60 | if (count < SIZE_VIO_GET_CHARS) |
| 61 | return -EAGAIN; |
| 62 | |
Milton Miller | 70b234a | 2005-07-07 17:56:26 -0700 | [diff] [blame] | 63 | got = hvc_get_chars(vtermno, buf, count); |
| 64 | |
| 65 | /* |
| 66 | * Work around a HV bug where it gives us a null |
| 67 | * after every \r. -- paulus |
| 68 | */ |
| 69 | for (i = 1; i < got; ++i) { |
| 70 | if (buf[i] == 0 && buf[i-1] == '\r') { |
| 71 | --got; |
| 72 | if (i < got) |
| 73 | memmove(&buf[i], &buf[i+1], |
| 74 | got - i); |
| 75 | } |
| 76 | } |
| 77 | return got; |
| 78 | } |
| 79 | |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame] | 80 | static struct hv_ops hvc_get_put_ops = { |
Milton Miller | 70b234a | 2005-07-07 17:56:26 -0700 | [diff] [blame] | 81 | .get_chars = filtered_get_chars, |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame] | 82 | .put_chars = hvc_put_chars, |
Christian Borntraeger | 611e097 | 2008-06-20 15:24:08 +0200 | [diff] [blame] | 83 | .notifier_add = notifier_add_irq, |
| 84 | .notifier_del = notifier_del_irq, |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 87 | static int __devinit hvc_vio_probe(struct vio_dev *vdev, |
| 88 | const struct vio_device_id *id) |
| 89 | { |
| 90 | struct hvc_struct *hp; |
| 91 | |
| 92 | /* probed with invalid parameters. */ |
| 93 | if (!vdev || !id) |
| 94 | return -EPERM; |
| 95 | |
Stephen Rothwell | 4e9e95a | 2006-07-13 18:53:32 +1000 | [diff] [blame] | 96 | hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops, |
| 97 | MAX_VIO_PUT_CHARS); |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 98 | if (IS_ERR(hp)) |
| 99 | return PTR_ERR(hp); |
| 100 | dev_set_drvdata(&vdev->dev, hp); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int __devexit hvc_vio_remove(struct vio_dev *vdev) |
| 106 | { |
| 107 | struct hvc_struct *hp = dev_get_drvdata(&vdev->dev); |
| 108 | |
| 109 | return hvc_remove(hp); |
| 110 | } |
| 111 | |
| 112 | static struct vio_driver hvc_vio_driver = { |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 113 | .id_table = hvc_driver_table, |
| 114 | .probe = hvc_vio_probe, |
| 115 | .remove = hvc_vio_remove, |
| 116 | .driver = { |
Stephen Rothwell | 6fdf539 | 2005-10-24 14:53:21 +1000 | [diff] [blame] | 117 | .name = hvc_driver_name, |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 118 | .owner = THIS_MODULE, |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | static int hvc_vio_init(void) |
| 123 | { |
| 124 | int rc; |
| 125 | |
Stephen Rothwell | de0138d | 2006-09-25 13:30:51 +1000 | [diff] [blame] | 126 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
| 127 | return -EIO; |
| 128 | |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 129 | /* Register as a vio device to receive callbacks */ |
| 130 | rc = vio_register_driver(&hvc_vio_driver); |
| 131 | |
| 132 | return rc; |
| 133 | } |
| 134 | module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */ |
| 135 | |
| 136 | static void hvc_vio_exit(void) |
| 137 | { |
| 138 | vio_unregister_driver(&hvc_vio_driver); |
| 139 | } |
| 140 | module_exit(hvc_vio_exit); |
| 141 | |
| 142 | /* the device tree order defines our numbering */ |
| 143 | static int hvc_find_vtys(void) |
| 144 | { |
| 145 | struct device_node *vty; |
| 146 | int num_found = 0; |
| 147 | |
| 148 | for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL; |
| 149 | vty = of_find_node_by_name(vty, "vty")) { |
Jeremy Kerr | 954a46e | 2006-07-12 15:39:43 +1000 | [diff] [blame] | 150 | const uint32_t *vtermno; |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 151 | |
| 152 | /* We have statically defined space for only a certain number |
| 153 | * of console adapters. |
| 154 | */ |
| 155 | if (num_found >= MAX_NR_HVC_CONSOLES) |
| 156 | break; |
| 157 | |
Stephen Rothwell | 01b2726 | 2007-04-27 13:41:15 +1000 | [diff] [blame] | 158 | vtermno = of_get_property(vty, "reg", NULL); |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 159 | if (!vtermno) |
| 160 | continue; |
| 161 | |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 162 | if (of_device_is_compatible(vty, "hvterm1")) { |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame] | 163 | hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops); |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 164 | ++num_found; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return num_found; |
| 169 | } |
| 170 | console_initcall(hvc_find_vtys); |