| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | *  PS3 virtual uart | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 2006 Sony Computer Entertainment Inc. | 
|  | 5 | *  Copyright 2006 Sony Corp. | 
|  | 6 | * | 
|  | 7 | *  This program is free software; you can redistribute it and/or modify | 
|  | 8 | *  it under the terms of the GNU General Public License as published by | 
|  | 9 | *  the Free Software Foundation; version 2 of the License. | 
|  | 10 | * | 
|  | 11 | *  This program is distributed in the hope that it will be useful, | 
|  | 12 | *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 13 | *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 14 | *  GNU General Public License for more details. | 
|  | 15 | * | 
|  | 16 | *  You should have received a copy of the GNU General Public License | 
|  | 17 | *  along with this program; if not, write to the Free Software | 
|  | 18 | *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|  | 19 | */ | 
|  | 20 |  | 
|  | 21 | #include <linux/kernel.h> | 
|  | 22 | #include <linux/module.h> | 
|  | 23 | #include <linux/interrupt.h> | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 24 | #include <linux/workqueue.h> | 
| Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 25 | #include <linux/bitops.h> | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 26 | #include <asm/ps3.h> | 
|  | 27 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 28 | #include <asm/firmware.h> | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 29 | #include <asm/lv1call.h> | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | #include "vuart.h" | 
|  | 32 |  | 
|  | 33 | MODULE_AUTHOR("Sony Corporation"); | 
|  | 34 | MODULE_LICENSE("GPL v2"); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 35 | MODULE_DESCRIPTION("PS3 vuart"); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 36 |  | 
|  | 37 | /** | 
|  | 38 | * vuart - An inter-partition data link service. | 
|  | 39 | *  port 0: PS3 AV Settings. | 
|  | 40 | *  port 2: PS3 System Manager. | 
|  | 41 | * | 
|  | 42 | * The vuart provides a bi-directional byte stream data link between logical | 
|  | 43 | * partitions.  Its primary role is as a communications link between the guest | 
|  | 44 | * OS and the system policy module.  The current HV does not support any | 
|  | 45 | * connections other than those listed. | 
|  | 46 | */ | 
|  | 47 |  | 
|  | 48 | enum {PORT_COUNT = 3,}; | 
|  | 49 |  | 
|  | 50 | enum vuart_param { | 
|  | 51 | PARAM_TX_TRIGGER = 0, | 
|  | 52 | PARAM_RX_TRIGGER = 1, | 
|  | 53 | PARAM_INTERRUPT_MASK = 2, | 
|  | 54 | PARAM_RX_BUF_SIZE = 3, /* read only */ | 
|  | 55 | PARAM_RX_BYTES = 4, /* read only */ | 
|  | 56 | PARAM_TX_BUF_SIZE = 5, /* read only */ | 
|  | 57 | PARAM_TX_BYTES = 6, /* read only */ | 
|  | 58 | PARAM_INTERRUPT_STATUS = 7, /* read only */ | 
|  | 59 | }; | 
|  | 60 |  | 
|  | 61 | enum vuart_interrupt_bit { | 
|  | 62 | INTERRUPT_BIT_TX = 0, | 
|  | 63 | INTERRUPT_BIT_RX = 1, | 
|  | 64 | INTERRUPT_BIT_DISCONNECT = 2, | 
|  | 65 | }; | 
|  | 66 |  | 
|  | 67 | enum vuart_interrupt_mask { | 
|  | 68 | INTERRUPT_MASK_TX = 1, | 
|  | 69 | INTERRUPT_MASK_RX = 2, | 
|  | 70 | INTERRUPT_MASK_DISCONNECT = 4, | 
|  | 71 | }; | 
|  | 72 |  | 
|  | 73 | /** | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 74 | * struct ps3_vuart_port_priv - private vuart device data. | 
|  | 75 | */ | 
|  | 76 |  | 
|  | 77 | struct ps3_vuart_port_priv { | 
|  | 78 | u64 interrupt_mask; | 
|  | 79 |  | 
|  | 80 | struct { | 
|  | 81 | spinlock_t lock; | 
|  | 82 | struct list_head head; | 
|  | 83 | } tx_list; | 
|  | 84 | struct { | 
|  | 85 | struct ps3_vuart_work work; | 
|  | 86 | unsigned long bytes_held; | 
|  | 87 | spinlock_t lock; | 
|  | 88 | struct list_head head; | 
|  | 89 | } rx_list; | 
|  | 90 | struct ps3_vuart_stats stats; | 
|  | 91 | }; | 
|  | 92 |  | 
|  | 93 | static struct ps3_vuart_port_priv *to_port_priv( | 
|  | 94 | struct ps3_system_bus_device *dev) | 
|  | 95 | { | 
|  | 96 | BUG_ON(!dev); | 
|  | 97 | BUG_ON(!dev->driver_priv); | 
|  | 98 | return (struct ps3_vuart_port_priv *)dev->driver_priv; | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | /** | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 102 | * struct ports_bmp - bitmap indicating ports needing service. | 
|  | 103 | * | 
|  | 104 | * A 256 bit read only bitmap indicating ports needing service.  Do not write | 
|  | 105 | * to these bits.  Must not cross a page boundary. | 
|  | 106 | */ | 
|  | 107 |  | 
|  | 108 | struct ports_bmp { | 
|  | 109 | u64 status; | 
|  | 110 | u64 unused[3]; | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 111 | } __attribute__((aligned(32))); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 112 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 113 | #define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__) | 
| Geoff Levand | 848cfdc | 2007-06-16 07:18:14 +1000 | [diff] [blame] | 114 | static void __maybe_unused _dump_ports_bmp( | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 115 | const struct ports_bmp *bmp, const char *func, int line) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 116 | { | 
| Stephen Rothwell | a9dad6e | 2009-01-13 20:10:06 +0000 | [diff] [blame] | 117 | pr_debug("%s:%d: ports_bmp: %016llxh\n", func, line, bmp->status); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 118 | } | 
|  | 119 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 120 | #define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__) | 
| Geoff Levand | 848cfdc | 2007-06-16 07:18:14 +1000 | [diff] [blame] | 121 | static void __maybe_unused _dump_port_params(unsigned int port_number, | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 122 | const char *func, int line) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 123 | { | 
|  | 124 | #if defined(DEBUG) | 
|  | 125 | static const char *strings[] = { | 
|  | 126 | "tx_trigger      ", | 
|  | 127 | "rx_trigger      ", | 
|  | 128 | "interrupt_mask  ", | 
|  | 129 | "rx_buf_size     ", | 
|  | 130 | "rx_bytes        ", | 
|  | 131 | "tx_buf_size     ", | 
|  | 132 | "tx_bytes        ", | 
|  | 133 | "interrupt_status", | 
|  | 134 | }; | 
|  | 135 | int result; | 
|  | 136 | unsigned int i; | 
|  | 137 | u64 value; | 
|  | 138 |  | 
|  | 139 | for (i = 0; i < ARRAY_SIZE(strings); i++) { | 
|  | 140 | result = lv1_get_virtual_uart_param(port_number, i, &value); | 
|  | 141 |  | 
|  | 142 | if (result) { | 
|  | 143 | pr_debug("%s:%d: port_%u: %s failed: %s\n", func, line, | 
|  | 144 | port_number, strings[i], ps3_result(result)); | 
|  | 145 | continue; | 
|  | 146 | } | 
|  | 147 | pr_debug("%s:%d: port_%u: %s = %lxh\n", | 
|  | 148 | func, line, port_number, strings[i], value); | 
|  | 149 | } | 
|  | 150 | #endif | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | struct vuart_triggers { | 
|  | 154 | unsigned long rx; | 
|  | 155 | unsigned long tx; | 
|  | 156 | }; | 
|  | 157 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 158 | int ps3_vuart_get_triggers(struct ps3_system_bus_device *dev, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 159 | struct vuart_triggers *trig) | 
|  | 160 | { | 
|  | 161 | int result; | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 162 | u64 size; | 
|  | 163 | u64 val; | 
|  | 164 | u64 tx; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 165 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 166 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 167 | PARAM_TX_TRIGGER, &tx); | 
|  | 168 | trig->tx = tx; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 169 |  | 
|  | 170 | if (result) { | 
|  | 171 | dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n", | 
|  | 172 | __func__, __LINE__, ps3_result(result)); | 
|  | 173 | return result; | 
|  | 174 | } | 
|  | 175 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 176 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 177 | PARAM_RX_BUF_SIZE, &size); | 
|  | 178 |  | 
|  | 179 | if (result) { | 
|  | 180 | dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n", | 
|  | 181 | __func__, __LINE__, ps3_result(result)); | 
|  | 182 | return result; | 
|  | 183 | } | 
|  | 184 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 185 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 186 | PARAM_RX_TRIGGER, &val); | 
|  | 187 |  | 
|  | 188 | if (result) { | 
|  | 189 | dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n", | 
|  | 190 | __func__, __LINE__, ps3_result(result)); | 
|  | 191 | return result; | 
|  | 192 | } | 
|  | 193 |  | 
|  | 194 | trig->rx = size - val; | 
|  | 195 |  | 
|  | 196 | dev_dbg(&dev->core, "%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__, | 
|  | 197 | trig->tx, trig->rx); | 
|  | 198 |  | 
|  | 199 | return result; | 
|  | 200 | } | 
|  | 201 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 202 | int ps3_vuart_set_triggers(struct ps3_system_bus_device *dev, unsigned int tx, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 203 | unsigned int rx) | 
|  | 204 | { | 
|  | 205 | int result; | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 206 | u64 size; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 207 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 208 | result = lv1_set_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 209 | PARAM_TX_TRIGGER, tx); | 
|  | 210 |  | 
|  | 211 | if (result) { | 
|  | 212 | dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n", | 
|  | 213 | __func__, __LINE__, ps3_result(result)); | 
|  | 214 | return result; | 
|  | 215 | } | 
|  | 216 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 217 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 218 | PARAM_RX_BUF_SIZE, &size); | 
|  | 219 |  | 
|  | 220 | if (result) { | 
|  | 221 | dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n", | 
|  | 222 | __func__, __LINE__, ps3_result(result)); | 
|  | 223 | return result; | 
|  | 224 | } | 
|  | 225 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 226 | result = lv1_set_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 227 | PARAM_RX_TRIGGER, size - rx); | 
|  | 228 |  | 
|  | 229 | if (result) { | 
|  | 230 | dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n", | 
|  | 231 | __func__, __LINE__, ps3_result(result)); | 
|  | 232 | return result; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | dev_dbg(&dev->core, "%s:%d: tx %xh, rx %xh\n", __func__, __LINE__, | 
|  | 236 | tx, rx); | 
|  | 237 |  | 
|  | 238 | return result; | 
|  | 239 | } | 
|  | 240 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 241 | static int ps3_vuart_get_rx_bytes_waiting(struct ps3_system_bus_device *dev, | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 242 | u64 *bytes_waiting) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 243 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 244 | int result; | 
|  | 245 |  | 
|  | 246 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 247 | PARAM_RX_BYTES, bytes_waiting); | 
|  | 248 |  | 
|  | 249 | if (result) | 
|  | 250 | dev_dbg(&dev->core, "%s:%d: rx_bytes failed: %s\n", | 
|  | 251 | __func__, __LINE__, ps3_result(result)); | 
|  | 252 |  | 
| Stephen Rothwell | a9dad6e | 2009-01-13 20:10:06 +0000 | [diff] [blame] | 253 | dev_dbg(&dev->core, "%s:%d: %llxh\n", __func__, __LINE__, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 254 | *bytes_waiting); | 
|  | 255 | return result; | 
|  | 256 | } | 
|  | 257 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 258 | /** | 
|  | 259 | * ps3_vuart_set_interrupt_mask - Enable/disable the port interrupt sources. | 
|  | 260 | * @dev: The struct ps3_system_bus_device instance. | 
|  | 261 | * @bmp: Logical OR of enum vuart_interrupt_mask values. A zero bit disables. | 
|  | 262 | */ | 
|  | 263 |  | 
|  | 264 | static int ps3_vuart_set_interrupt_mask(struct ps3_system_bus_device *dev, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 265 | unsigned long mask) | 
|  | 266 | { | 
|  | 267 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 268 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 269 |  | 
|  | 270 | dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask); | 
|  | 271 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 272 | priv->interrupt_mask = mask; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 273 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 274 | result = lv1_set_virtual_uart_param(dev->port_number, | 
|  | 275 | PARAM_INTERRUPT_MASK, priv->interrupt_mask); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 276 |  | 
|  | 277 | if (result) | 
|  | 278 | dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n", | 
|  | 279 | __func__, __LINE__, ps3_result(result)); | 
|  | 280 |  | 
|  | 281 | return result; | 
|  | 282 | } | 
|  | 283 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 284 | static int ps3_vuart_get_interrupt_status(struct ps3_system_bus_device *dev, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 285 | unsigned long *status) | 
|  | 286 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 287 | int result; | 
|  | 288 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 289 | u64 tmp; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 290 |  | 
|  | 291 | result = lv1_get_virtual_uart_param(dev->port_number, | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 292 | PARAM_INTERRUPT_STATUS, &tmp); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 293 |  | 
|  | 294 | if (result) | 
|  | 295 | dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n", | 
|  | 296 | __func__, __LINE__, ps3_result(result)); | 
|  | 297 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 298 | *status = tmp & priv->interrupt_mask; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 299 |  | 
| Stephen Rothwell | a9dad6e | 2009-01-13 20:10:06 +0000 | [diff] [blame] | 300 | dev_dbg(&dev->core, "%s:%d: m %llxh, s %llxh, m&s %lxh\n", | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 301 | __func__, __LINE__, priv->interrupt_mask, tmp, *status); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 302 |  | 
|  | 303 | return result; | 
|  | 304 | } | 
|  | 305 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 306 | int ps3_vuart_enable_interrupt_tx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 307 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 308 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 309 |  | 
|  | 310 | return (priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0 | 
|  | 311 | : ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 312 | | INTERRUPT_MASK_TX); | 
|  | 313 | } | 
|  | 314 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 315 | int ps3_vuart_enable_interrupt_rx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 316 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 317 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 318 |  | 
|  | 319 | return (priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0 | 
|  | 320 | : ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 321 | | INTERRUPT_MASK_RX); | 
|  | 322 | } | 
|  | 323 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 324 | int ps3_vuart_enable_interrupt_disconnect(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 325 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 326 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 327 |  | 
|  | 328 | return (priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0 | 
|  | 329 | : ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 330 | | INTERRUPT_MASK_DISCONNECT); | 
|  | 331 | } | 
|  | 332 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 333 | int ps3_vuart_disable_interrupt_tx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 334 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 335 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 336 |  | 
|  | 337 | return (priv->interrupt_mask & INTERRUPT_MASK_TX) | 
|  | 338 | ? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 339 | & ~INTERRUPT_MASK_TX) : 0; | 
|  | 340 | } | 
|  | 341 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 342 | int ps3_vuart_disable_interrupt_rx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 343 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 344 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 345 |  | 
|  | 346 | return (priv->interrupt_mask & INTERRUPT_MASK_RX) | 
|  | 347 | ? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 348 | & ~INTERRUPT_MASK_RX) : 0; | 
|  | 349 | } | 
|  | 350 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 351 | int ps3_vuart_disable_interrupt_disconnect(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 352 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 353 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 354 |  | 
|  | 355 | return (priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) | 
|  | 356 | ? ps3_vuart_set_interrupt_mask(dev, priv->interrupt_mask | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 357 | & ~INTERRUPT_MASK_DISCONNECT) : 0; | 
|  | 358 | } | 
|  | 359 |  | 
|  | 360 | /** | 
|  | 361 | * ps3_vuart_raw_write - Low level write helper. | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 362 | * @dev: The struct ps3_system_bus_device instance. | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 363 | * | 
|  | 364 | * Do not call ps3_vuart_raw_write directly, use ps3_vuart_write. | 
|  | 365 | */ | 
|  | 366 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 367 | static int ps3_vuart_raw_write(struct ps3_system_bus_device *dev, | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 368 | const void *buf, unsigned int bytes, u64 *bytes_written) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 369 | { | 
|  | 370 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 371 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 372 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 373 | result = lv1_write_virtual_uart(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 374 | ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written); | 
|  | 375 |  | 
|  | 376 | if (result) { | 
|  | 377 | dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: " | 
|  | 378 | "%s\n", __func__, __LINE__, ps3_result(result)); | 
|  | 379 | return result; | 
|  | 380 | } | 
|  | 381 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 382 | priv->stats.bytes_written += *bytes_written; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 383 |  | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 384 | dev_dbg(&dev->core, "%s:%d: wrote %llxh/%xh=>%lxh\n", __func__, __LINE__, | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 385 | *bytes_written, bytes, priv->stats.bytes_written); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 386 |  | 
|  | 387 | return result; | 
|  | 388 | } | 
|  | 389 |  | 
|  | 390 | /** | 
|  | 391 | * ps3_vuart_raw_read - Low level read helper. | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 392 | * @dev: The struct ps3_system_bus_device instance. | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 393 | * | 
|  | 394 | * Do not call ps3_vuart_raw_read directly, use ps3_vuart_read. | 
|  | 395 | */ | 
|  | 396 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 397 | static int ps3_vuart_raw_read(struct ps3_system_bus_device *dev, void *buf, | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 398 | unsigned int bytes, u64 *bytes_read) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 399 | { | 
|  | 400 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 401 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 402 |  | 
|  | 403 | dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes); | 
|  | 404 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 405 | result = lv1_read_virtual_uart(dev->port_number, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 406 | ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read); | 
|  | 407 |  | 
|  | 408 | if (result) { | 
|  | 409 | dev_dbg(&dev->core, "%s:%d: lv1_read_virtual_uart failed: %s\n", | 
|  | 410 | __func__, __LINE__, ps3_result(result)); | 
|  | 411 | return result; | 
|  | 412 | } | 
|  | 413 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 414 | priv->stats.bytes_read += *bytes_read; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 415 |  | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 416 | dev_dbg(&dev->core, "%s:%d: read %llxh/%xh=>%lxh\n", __func__, __LINE__, | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 417 | *bytes_read, bytes, priv->stats.bytes_read); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 418 |  | 
|  | 419 | return result; | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | /** | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 423 | * ps3_vuart_clear_rx_bytes - Discard bytes received. | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 424 | * @dev: The struct ps3_system_bus_device instance. | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 425 | * @bytes: Max byte count to discard, zero = all pending. | 
|  | 426 | * | 
|  | 427 | * Used to clear pending rx interrupt source.  Will not block. | 
|  | 428 | */ | 
|  | 429 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 430 | void ps3_vuart_clear_rx_bytes(struct ps3_system_bus_device *dev, | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 431 | unsigned int bytes) | 
|  | 432 | { | 
|  | 433 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 434 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 435 | u64 bytes_waiting; | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 436 | void *tmp; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 437 |  | 
|  | 438 | result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting); | 
|  | 439 |  | 
|  | 440 | BUG_ON(result); | 
|  | 441 |  | 
|  | 442 | bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting; | 
|  | 443 |  | 
|  | 444 | dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes); | 
|  | 445 |  | 
|  | 446 | if (!bytes) | 
|  | 447 | return; | 
|  | 448 |  | 
|  | 449 | /* Add some extra space for recently arrived data. */ | 
|  | 450 |  | 
|  | 451 | bytes += 128; | 
|  | 452 |  | 
|  | 453 | tmp = kmalloc(bytes, GFP_KERNEL); | 
|  | 454 |  | 
|  | 455 | if (!tmp) | 
|  | 456 | return; | 
|  | 457 |  | 
|  | 458 | ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting); | 
|  | 459 |  | 
|  | 460 | kfree(tmp); | 
|  | 461 |  | 
|  | 462 | /* Don't include these bytes in the stats. */ | 
|  | 463 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 464 | priv->stats.bytes_read -= bytes_waiting; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 465 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 466 | EXPORT_SYMBOL_GPL(ps3_vuart_clear_rx_bytes); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 467 |  | 
|  | 468 | /** | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 469 | * struct list_buffer - An element for a port device fifo buffer list. | 
|  | 470 | */ | 
|  | 471 |  | 
|  | 472 | struct list_buffer { | 
|  | 473 | struct list_head link; | 
|  | 474 | const unsigned char *head; | 
|  | 475 | const unsigned char *tail; | 
|  | 476 | unsigned long dbg_number; | 
|  | 477 | unsigned char data[]; | 
|  | 478 | }; | 
|  | 479 |  | 
|  | 480 | /** | 
|  | 481 | * ps3_vuart_write - the entry point for writing data to a port | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 482 | * @dev: The struct ps3_system_bus_device instance. | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 483 | * | 
|  | 484 | * If the port is idle on entry as much of the incoming data is written to | 
|  | 485 | * the port as the port will accept.  Otherwise a list buffer is created | 
|  | 486 | * and any remaning incoming data is copied to that buffer.  The buffer is | 
|  | 487 | * then enqueued for transmision via the transmit interrupt. | 
|  | 488 | */ | 
|  | 489 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 490 | int ps3_vuart_write(struct ps3_system_bus_device *dev, const void *buf, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 491 | unsigned int bytes) | 
|  | 492 | { | 
|  | 493 | static unsigned long dbg_number; | 
|  | 494 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 495 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 496 | unsigned long flags; | 
|  | 497 | struct list_buffer *lb; | 
|  | 498 |  | 
|  | 499 | dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, | 
|  | 500 | bytes, bytes); | 
|  | 501 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 502 | spin_lock_irqsave(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 503 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 504 | if (list_empty(&priv->tx_list.head)) { | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 505 | u64 bytes_written; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 506 |  | 
|  | 507 | result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written); | 
|  | 508 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 509 | spin_unlock_irqrestore(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 510 |  | 
|  | 511 | if (result) { | 
|  | 512 | dev_dbg(&dev->core, | 
|  | 513 | "%s:%d: ps3_vuart_raw_write failed\n", | 
|  | 514 | __func__, __LINE__); | 
|  | 515 | return result; | 
|  | 516 | } | 
|  | 517 |  | 
|  | 518 | if (bytes_written == bytes) { | 
|  | 519 | dev_dbg(&dev->core, "%s:%d: wrote %xh bytes\n", | 
|  | 520 | __func__, __LINE__, bytes); | 
|  | 521 | return 0; | 
|  | 522 | } | 
|  | 523 |  | 
|  | 524 | bytes -= bytes_written; | 
|  | 525 | buf += bytes_written; | 
|  | 526 | } else | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 527 | spin_unlock_irqrestore(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 528 |  | 
|  | 529 | lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL); | 
|  | 530 |  | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 531 | if (!lb) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 532 | return -ENOMEM; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 533 |  | 
|  | 534 | memcpy(lb->data, buf, bytes); | 
|  | 535 | lb->head = lb->data; | 
|  | 536 | lb->tail = lb->data + bytes; | 
|  | 537 | lb->dbg_number = ++dbg_number; | 
|  | 538 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 539 | spin_lock_irqsave(&priv->tx_list.lock, flags); | 
|  | 540 | list_add_tail(&lb->link, &priv->tx_list.head); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 541 | ps3_vuart_enable_interrupt_tx(dev); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 542 | spin_unlock_irqrestore(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 543 |  | 
|  | 544 | dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n", | 
|  | 545 | __func__, __LINE__, lb->dbg_number, bytes); | 
|  | 546 |  | 
|  | 547 | return 0; | 
|  | 548 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 549 | EXPORT_SYMBOL_GPL(ps3_vuart_write); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 550 |  | 
|  | 551 | /** | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 552 | * ps3_vuart_queue_rx_bytes - Queue waiting bytes into the buffer list. | 
|  | 553 | * @dev: The struct ps3_system_bus_device instance. | 
|  | 554 | * @bytes_queued: Number of bytes queued to the buffer list. | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 555 | * | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 556 | * Must be called with priv->rx_list.lock held. | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 557 | */ | 
|  | 558 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 559 | static int ps3_vuart_queue_rx_bytes(struct ps3_system_bus_device *dev, | 
|  | 560 | u64 *bytes_queued) | 
|  | 561 | { | 
|  | 562 | static unsigned long dbg_number; | 
|  | 563 | int result; | 
|  | 564 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 565 | struct list_buffer *lb; | 
|  | 566 | u64 bytes; | 
|  | 567 |  | 
|  | 568 | *bytes_queued = 0; | 
|  | 569 |  | 
|  | 570 | result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes); | 
|  | 571 | BUG_ON(result); | 
|  | 572 |  | 
|  | 573 | if (result) | 
|  | 574 | return -EIO; | 
|  | 575 |  | 
|  | 576 | if (!bytes) | 
|  | 577 | return 0; | 
|  | 578 |  | 
|  | 579 | /* Add some extra space for recently arrived data. */ | 
|  | 580 |  | 
|  | 581 | bytes += 128; | 
|  | 582 |  | 
|  | 583 | lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_ATOMIC); | 
|  | 584 |  | 
|  | 585 | if (!lb) | 
|  | 586 | return -ENOMEM; | 
|  | 587 |  | 
|  | 588 | ps3_vuart_raw_read(dev, lb->data, bytes, &bytes); | 
|  | 589 |  | 
|  | 590 | lb->head = lb->data; | 
|  | 591 | lb->tail = lb->data + bytes; | 
|  | 592 | lb->dbg_number = ++dbg_number; | 
|  | 593 |  | 
|  | 594 | list_add_tail(&lb->link, &priv->rx_list.head); | 
|  | 595 | priv->rx_list.bytes_held += bytes; | 
|  | 596 |  | 
| Stephen Rothwell | a9dad6e | 2009-01-13 20:10:06 +0000 | [diff] [blame] | 597 | dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %llxh bytes\n", | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 598 | __func__, __LINE__, lb->dbg_number, bytes); | 
|  | 599 |  | 
|  | 600 | *bytes_queued = bytes; | 
|  | 601 |  | 
|  | 602 | return 0; | 
|  | 603 | } | 
|  | 604 |  | 
|  | 605 | /** | 
|  | 606 | * ps3_vuart_read - The entry point for reading data from a port. | 
|  | 607 | * | 
|  | 608 | * Queue data waiting at the port, and if enough bytes to satisfy the request | 
|  | 609 | * are held in the buffer list those bytes are dequeued and copied to the | 
|  | 610 | * caller's buffer.  Emptied list buffers are retiered.  If the request cannot | 
|  | 611 | * be statified by bytes held in the list buffers -EAGAIN is returned. | 
|  | 612 | */ | 
|  | 613 |  | 
|  | 614 | int ps3_vuart_read(struct ps3_system_bus_device *dev, void *buf, | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 615 | unsigned int bytes) | 
|  | 616 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 617 | int result; | 
|  | 618 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 619 | unsigned long flags; | 
|  | 620 | struct list_buffer *lb, *n; | 
|  | 621 | unsigned long bytes_read; | 
|  | 622 |  | 
|  | 623 | dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, | 
|  | 624 | bytes, bytes); | 
|  | 625 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 626 | spin_lock_irqsave(&priv->rx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 627 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 628 | /* Queue rx bytes here for polled reads. */ | 
|  | 629 |  | 
|  | 630 | while (priv->rx_list.bytes_held < bytes) { | 
|  | 631 | u64 tmp; | 
|  | 632 |  | 
|  | 633 | result = ps3_vuart_queue_rx_bytes(dev, &tmp); | 
|  | 634 | if (result || !tmp) { | 
|  | 635 | dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n", | 
|  | 636 | __func__, __LINE__, | 
|  | 637 | bytes - priv->rx_list.bytes_held); | 
|  | 638 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
|  | 639 | return -EAGAIN; | 
|  | 640 | } | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 641 | } | 
|  | 642 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 643 | list_for_each_entry_safe(lb, n, &priv->rx_list.head, link) { | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 644 | bytes_read = min((unsigned int)(lb->tail - lb->head), bytes); | 
|  | 645 |  | 
|  | 646 | memcpy(buf, lb->head, bytes_read); | 
|  | 647 | buf += bytes_read; | 
|  | 648 | bytes -= bytes_read; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 649 | priv->rx_list.bytes_held -= bytes_read; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 650 |  | 
|  | 651 | if (bytes_read < lb->tail - lb->head) { | 
|  | 652 | lb->head += bytes_read; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 653 | dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh " | 
|  | 654 | "bytes\n", __func__, __LINE__, lb->dbg_number, | 
|  | 655 | bytes_read); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 656 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 657 | return 0; | 
|  | 658 | } | 
|  | 659 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 660 | dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh " | 
|  | 661 | "bytes\n", __func__, __LINE__, lb->dbg_number, | 
|  | 662 | bytes_read); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 663 |  | 
|  | 664 | list_del(&lb->link); | 
|  | 665 | kfree(lb); | 
|  | 666 | } | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 667 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 668 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 669 | return 0; | 
|  | 670 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 671 | EXPORT_SYMBOL_GPL(ps3_vuart_read); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 672 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 673 | /** | 
|  | 674 | * ps3_vuart_work - Asynchronous read handler. | 
|  | 675 | */ | 
|  | 676 |  | 
|  | 677 | static void ps3_vuart_work(struct work_struct *work) | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 678 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 679 | struct ps3_system_bus_device *dev = | 
|  | 680 | ps3_vuart_work_to_system_bus_dev(work); | 
|  | 681 | struct ps3_vuart_port_driver *drv = | 
|  | 682 | ps3_system_bus_dev_to_vuart_drv(dev); | 
|  | 683 |  | 
|  | 684 | BUG_ON(!drv); | 
|  | 685 | drv->work(dev); | 
|  | 686 | } | 
|  | 687 |  | 
|  | 688 | int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes) | 
|  | 689 | { | 
|  | 690 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 691 | unsigned long flags; | 
|  | 692 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 693 | if (priv->rx_list.work.trigger) { | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 694 | dev_dbg(&dev->core, "%s:%d: warning, multiple calls\n", | 
|  | 695 | __func__, __LINE__); | 
|  | 696 | return -EAGAIN; | 
|  | 697 | } | 
|  | 698 |  | 
|  | 699 | BUG_ON(!bytes); | 
|  | 700 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 701 | PREPARE_WORK(&priv->rx_list.work.work, ps3_vuart_work); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 702 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 703 | spin_lock_irqsave(&priv->rx_list.lock, flags); | 
|  | 704 | if (priv->rx_list.bytes_held >= bytes) { | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 705 | dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n", | 
|  | 706 | __func__, __LINE__, bytes); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 707 | schedule_work(&priv->rx_list.work.work); | 
|  | 708 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 709 | return 0; | 
|  | 710 | } | 
|  | 711 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 712 | priv->rx_list.work.trigger = bytes; | 
|  | 713 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 714 |  | 
|  | 715 | dev_dbg(&dev->core, "%s:%d: waiting for %u(%xh) bytes\n", __func__, | 
|  | 716 | __LINE__, bytes, bytes); | 
|  | 717 |  | 
|  | 718 | return 0; | 
|  | 719 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 720 | EXPORT_SYMBOL_GPL(ps3_vuart_read_async); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 721 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 722 | void ps3_vuart_cancel_async(struct ps3_system_bus_device *dev) | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 723 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 724 | to_port_priv(dev)->rx_list.work.trigger = 0; | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 725 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 726 | EXPORT_SYMBOL_GPL(ps3_vuart_cancel_async); | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 727 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 728 | /** | 
|  | 729 | * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler | 
|  | 730 | * | 
|  | 731 | * Services the transmit interrupt for the port.  Writes as much data from the | 
|  | 732 | * buffer list as the port will accept.  Retires any emptied list buffers and | 
|  | 733 | * adjusts the final list buffer state for a partial write. | 
|  | 734 | */ | 
|  | 735 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 736 | static int ps3_vuart_handle_interrupt_tx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 737 | { | 
|  | 738 | int result = 0; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 739 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 740 | unsigned long flags; | 
|  | 741 | struct list_buffer *lb, *n; | 
|  | 742 | unsigned long bytes_total = 0; | 
|  | 743 |  | 
|  | 744 | dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); | 
|  | 745 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 746 | spin_lock_irqsave(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 747 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 748 | list_for_each_entry_safe(lb, n, &priv->tx_list.head, link) { | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 749 |  | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 750 | u64 bytes_written; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 751 |  | 
|  | 752 | result = ps3_vuart_raw_write(dev, lb->head, lb->tail - lb->head, | 
|  | 753 | &bytes_written); | 
|  | 754 |  | 
|  | 755 | if (result) { | 
|  | 756 | dev_dbg(&dev->core, | 
|  | 757 | "%s:%d: ps3_vuart_raw_write failed\n", | 
|  | 758 | __func__, __LINE__); | 
|  | 759 | break; | 
|  | 760 | } | 
|  | 761 |  | 
|  | 762 | bytes_total += bytes_written; | 
|  | 763 |  | 
|  | 764 | if (bytes_written < lb->tail - lb->head) { | 
|  | 765 | lb->head += bytes_written; | 
|  | 766 | dev_dbg(&dev->core, | 
| Stephen Rothwell | b17b3df | 2009-01-13 19:59:41 +0000 | [diff] [blame] | 767 | "%s:%d cleared buf_%lu, %llxh bytes\n", | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 768 | __func__, __LINE__, lb->dbg_number, | 
|  | 769 | bytes_written); | 
|  | 770 | goto port_full; | 
|  | 771 | } | 
|  | 772 |  | 
|  | 773 | dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__, | 
|  | 774 | lb->dbg_number); | 
|  | 775 |  | 
|  | 776 | list_del(&lb->link); | 
|  | 777 | kfree(lb); | 
|  | 778 | } | 
|  | 779 |  | 
|  | 780 | ps3_vuart_disable_interrupt_tx(dev); | 
|  | 781 | port_full: | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 782 | spin_unlock_irqrestore(&priv->tx_list.lock, flags); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 783 | dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n", | 
|  | 784 | __func__, __LINE__, bytes_total); | 
|  | 785 | return result; | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | /** | 
|  | 789 | * ps3_vuart_handle_interrupt_rx - third stage receive interrupt handler | 
|  | 790 | * | 
|  | 791 | * Services the receive interrupt for the port.  Creates a list buffer and | 
|  | 792 | * copies all waiting port data to that buffer and enqueues the buffer in the | 
|  | 793 | * buffer list.  Buffer list data is dequeued via ps3_vuart_read. | 
|  | 794 | */ | 
|  | 795 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 796 | static int ps3_vuart_handle_interrupt_rx(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 797 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 798 | int result; | 
|  | 799 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 800 | unsigned long flags; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 801 | u64 bytes; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 802 |  | 
|  | 803 | dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); | 
|  | 804 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 805 | spin_lock_irqsave(&priv->rx_list.lock, flags); | 
|  | 806 | result = ps3_vuart_queue_rx_bytes(dev, &bytes); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 807 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 808 | if (result) { | 
|  | 809 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
|  | 810 | return result; | 
| Geoff Levand | ea1547d | 2007-02-06 14:23:47 -0800 | [diff] [blame] | 811 | } | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 812 |  | 
|  | 813 | if (priv->rx_list.work.trigger && priv->rx_list.bytes_held | 
|  | 814 | >= priv->rx_list.work.trigger) { | 
|  | 815 | dev_dbg(&dev->core, "%s:%d: schedule_work %lxh bytes\n", | 
|  | 816 | __func__, __LINE__, priv->rx_list.work.trigger); | 
|  | 817 | priv->rx_list.work.trigger = 0; | 
|  | 818 | schedule_work(&priv->rx_list.work.work); | 
|  | 819 | } | 
|  | 820 |  | 
|  | 821 | spin_unlock_irqrestore(&priv->rx_list.lock, flags); | 
|  | 822 | return result; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 823 | } | 
|  | 824 |  | 
|  | 825 | static int ps3_vuart_handle_interrupt_disconnect( | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 826 | struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 827 | { | 
|  | 828 | dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); | 
|  | 829 | BUG_ON("no support"); | 
|  | 830 | return -1; | 
|  | 831 | } | 
|  | 832 |  | 
|  | 833 | /** | 
|  | 834 | * ps3_vuart_handle_port_interrupt - second stage interrupt handler | 
|  | 835 | * | 
|  | 836 | * Services any pending interrupt types for the port.  Passes control to the | 
|  | 837 | * third stage type specific interrupt handler.  Returns control to the first | 
|  | 838 | * stage handler after one iteration. | 
|  | 839 | */ | 
|  | 840 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 841 | static int ps3_vuart_handle_port_interrupt(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 842 | { | 
|  | 843 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 844 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 845 | unsigned long status; | 
|  | 846 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 847 | result = ps3_vuart_get_interrupt_status(dev, &status); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 848 |  | 
|  | 849 | if (result) | 
|  | 850 | return result; | 
|  | 851 |  | 
|  | 852 | dev_dbg(&dev->core, "%s:%d: status: %lxh\n", __func__, __LINE__, | 
|  | 853 | status); | 
|  | 854 |  | 
|  | 855 | if (status & INTERRUPT_MASK_DISCONNECT) { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 856 | priv->stats.disconnect_interrupts++; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 857 | result = ps3_vuart_handle_interrupt_disconnect(dev); | 
|  | 858 | if (result) | 
|  | 859 | ps3_vuart_disable_interrupt_disconnect(dev); | 
|  | 860 | } | 
|  | 861 |  | 
|  | 862 | if (status & INTERRUPT_MASK_TX) { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 863 | priv->stats.tx_interrupts++; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 864 | result = ps3_vuart_handle_interrupt_tx(dev); | 
|  | 865 | if (result) | 
|  | 866 | ps3_vuart_disable_interrupt_tx(dev); | 
|  | 867 | } | 
|  | 868 |  | 
|  | 869 | if (status & INTERRUPT_MASK_RX) { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 870 | priv->stats.rx_interrupts++; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 871 | result = ps3_vuart_handle_interrupt_rx(dev); | 
|  | 872 | if (result) | 
|  | 873 | ps3_vuart_disable_interrupt_rx(dev); | 
|  | 874 | } | 
|  | 875 |  | 
|  | 876 | return 0; | 
|  | 877 | } | 
|  | 878 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 879 | struct vuart_bus_priv { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 880 | struct ports_bmp *bmp; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 881 | unsigned int virq; | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 882 | struct mutex probe_mutex; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 883 | int use_count; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 884 | struct ps3_system_bus_device *devices[PORT_COUNT]; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 885 | } static vuart_bus_priv; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 886 |  | 
|  | 887 | /** | 
|  | 888 | * ps3_vuart_irq_handler - first stage interrupt handler | 
|  | 889 | * | 
|  | 890 | * Loops finding any interrupting port and its associated instance data. | 
|  | 891 | * Passes control to the second stage port specific interrupt handler.  Loops | 
|  | 892 | * until all outstanding interrupts are serviced. | 
|  | 893 | */ | 
|  | 894 |  | 
|  | 895 | static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private) | 
|  | 896 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 897 | struct vuart_bus_priv *bus_priv = _private; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 898 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 899 | BUG_ON(!bus_priv); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 900 |  | 
|  | 901 | while (1) { | 
|  | 902 | unsigned int port; | 
|  | 903 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 904 | dump_ports_bmp(bus_priv->bmp); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 905 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 906 | port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp->status); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 907 |  | 
|  | 908 | if (port == BITS_PER_LONG) | 
|  | 909 | break; | 
|  | 910 |  | 
|  | 911 | BUG_ON(port >= PORT_COUNT); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 912 | BUG_ON(!bus_priv->devices[port]); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 913 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 914 | ps3_vuart_handle_port_interrupt(bus_priv->devices[port]); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 915 | } | 
|  | 916 |  | 
|  | 917 | return IRQ_HANDLED; | 
|  | 918 | } | 
|  | 919 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 920 | static int ps3_vuart_bus_interrupt_get(void) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 921 | { | 
|  | 922 | int result; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 923 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 924 | pr_debug(" -> %s:%d\n", __func__, __LINE__); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 925 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 926 | vuart_bus_priv.use_count++; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 927 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 928 | BUG_ON(vuart_bus_priv.use_count > 2); | 
|  | 929 |  | 
| Geert Uytterhoeven | d0e5c21 | 2008-01-19 07:32:19 +1100 | [diff] [blame] | 930 | if (vuart_bus_priv.use_count != 1) | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 931 | return 0; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 932 |  | 
|  | 933 | BUG_ON(vuart_bus_priv.bmp); | 
|  | 934 |  | 
|  | 935 | vuart_bus_priv.bmp = kzalloc(sizeof(struct ports_bmp), GFP_KERNEL); | 
|  | 936 |  | 
|  | 937 | if (!vuart_bus_priv.bmp) { | 
|  | 938 | pr_debug("%s:%d: kzalloc failed.\n", __func__, __LINE__); | 
|  | 939 | result = -ENOMEM; | 
|  | 940 | goto fail_bmp_malloc; | 
|  | 941 | } | 
|  | 942 |  | 
|  | 943 | result = ps3_vuart_irq_setup(PS3_BINDING_CPU_ANY, vuart_bus_priv.bmp, | 
|  | 944 | &vuart_bus_priv.virq); | 
|  | 945 |  | 
|  | 946 | if (result) { | 
|  | 947 | pr_debug("%s:%d: ps3_vuart_irq_setup failed (%d)\n", | 
|  | 948 | __func__, __LINE__, result); | 
|  | 949 | result = -EPERM; | 
|  | 950 | goto fail_alloc_irq; | 
|  | 951 | } | 
|  | 952 |  | 
|  | 953 | result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler, | 
|  | 954 | IRQF_DISABLED, "vuart", &vuart_bus_priv); | 
|  | 955 |  | 
|  | 956 | if (result) { | 
|  | 957 | pr_debug("%s:%d: request_irq failed (%d)\n", | 
|  | 958 | __func__, __LINE__, result); | 
|  | 959 | goto fail_request_irq; | 
|  | 960 | } | 
|  | 961 |  | 
|  | 962 | pr_debug(" <- %s:%d: ok\n", __func__, __LINE__); | 
|  | 963 | return result; | 
|  | 964 |  | 
|  | 965 | fail_request_irq: | 
|  | 966 | ps3_vuart_irq_destroy(vuart_bus_priv.virq); | 
|  | 967 | vuart_bus_priv.virq = NO_IRQ; | 
|  | 968 | fail_alloc_irq: | 
|  | 969 | kfree(vuart_bus_priv.bmp); | 
|  | 970 | vuart_bus_priv.bmp = NULL; | 
|  | 971 | fail_bmp_malloc: | 
|  | 972 | vuart_bus_priv.use_count--; | 
|  | 973 | pr_debug(" <- %s:%d: failed\n", __func__, __LINE__); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 974 | return result; | 
|  | 975 | } | 
|  | 976 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 977 | static int ps3_vuart_bus_interrupt_put(void) | 
|  | 978 | { | 
|  | 979 | pr_debug(" -> %s:%d\n", __func__, __LINE__); | 
|  | 980 |  | 
|  | 981 | vuart_bus_priv.use_count--; | 
|  | 982 |  | 
|  | 983 | BUG_ON(vuart_bus_priv.use_count < 0); | 
|  | 984 |  | 
|  | 985 | if (vuart_bus_priv.use_count != 0) | 
|  | 986 | return 0; | 
|  | 987 |  | 
|  | 988 | free_irq(vuart_bus_priv.virq, &vuart_bus_priv); | 
|  | 989 |  | 
|  | 990 | ps3_vuart_irq_destroy(vuart_bus_priv.virq); | 
|  | 991 | vuart_bus_priv.virq = NO_IRQ; | 
|  | 992 |  | 
|  | 993 | kfree(vuart_bus_priv.bmp); | 
|  | 994 | vuart_bus_priv.bmp = NULL; | 
|  | 995 |  | 
|  | 996 | pr_debug(" <- %s:%d\n", __func__, __LINE__); | 
|  | 997 | return 0; | 
|  | 998 | } | 
|  | 999 |  | 
|  | 1000 | static int ps3_vuart_probe(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1001 | { | 
|  | 1002 | int result; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1003 | struct ps3_vuart_port_driver *drv; | 
|  | 1004 | struct ps3_vuart_port_priv *priv = NULL; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1005 |  | 
|  | 1006 | dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); | 
|  | 1007 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1008 | drv = ps3_system_bus_dev_to_vuart_drv(dev); | 
|  | 1009 |  | 
|  | 1010 | dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__, | 
|  | 1011 | drv->core.core.name); | 
|  | 1012 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1013 | BUG_ON(!drv); | 
|  | 1014 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1015 | if (dev->port_number >= PORT_COUNT) { | 
|  | 1016 | BUG(); | 
|  | 1017 | return -EINVAL; | 
|  | 1018 | } | 
|  | 1019 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1020 | mutex_lock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1021 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1022 | result = ps3_vuart_bus_interrupt_get(); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1023 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1024 | if (result) | 
|  | 1025 | goto fail_setup_interrupt; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1026 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1027 | if (vuart_bus_priv.devices[dev->port_number]) { | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1028 | dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__, | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1029 | __LINE__, dev->port_number); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1030 | result = -EBUSY; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1031 | goto fail_busy; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1032 | } | 
|  | 1033 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1034 | vuart_bus_priv.devices[dev->port_number] = dev; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1035 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1036 | /* Setup dev->driver_priv. */ | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1037 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1038 | dev->driver_priv = kzalloc(sizeof(struct ps3_vuart_port_priv), | 
|  | 1039 | GFP_KERNEL); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1040 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1041 | if (!dev->driver_priv) { | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1042 | result = -ENOMEM; | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1043 | goto fail_dev_malloc; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1044 | } | 
|  | 1045 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1046 | priv = to_port_priv(dev); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1047 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1048 | INIT_LIST_HEAD(&priv->tx_list.head); | 
|  | 1049 | spin_lock_init(&priv->tx_list.lock); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1050 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1051 | INIT_LIST_HEAD(&priv->rx_list.head); | 
|  | 1052 | spin_lock_init(&priv->rx_list.lock); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1053 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1054 | INIT_WORK(&priv->rx_list.work.work, NULL); | 
|  | 1055 | priv->rx_list.work.trigger = 0; | 
|  | 1056 | priv->rx_list.work.dev = dev; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1057 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1058 | /* clear stale pending interrupts */ | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1059 |  | 
|  | 1060 | ps3_vuart_clear_rx_bytes(dev, 0); | 
|  | 1061 |  | 
|  | 1062 | ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1063 |  | 
|  | 1064 | ps3_vuart_set_triggers(dev, 1, 1); | 
|  | 1065 |  | 
|  | 1066 | if (drv->probe) | 
|  | 1067 | result = drv->probe(dev); | 
|  | 1068 | else { | 
|  | 1069 | result = 0; | 
|  | 1070 | dev_info(&dev->core, "%s:%d: no probe method\n", __func__, | 
|  | 1071 | __LINE__); | 
|  | 1072 | } | 
|  | 1073 |  | 
|  | 1074 | if (result) { | 
|  | 1075 | dev_dbg(&dev->core, "%s:%d: drv->probe failed\n", | 
|  | 1076 | __func__, __LINE__); | 
|  | 1077 | goto fail_probe; | 
|  | 1078 | } | 
|  | 1079 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1080 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1081 |  | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1082 | return result; | 
|  | 1083 |  | 
|  | 1084 | fail_probe: | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1085 | ps3_vuart_set_interrupt_mask(dev, 0); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1086 | kfree(dev->driver_priv); | 
|  | 1087 | dev->driver_priv = NULL; | 
|  | 1088 | fail_dev_malloc: | 
|  | 1089 | vuart_bus_priv.devices[dev->port_number] = NULL; | 
|  | 1090 | fail_busy: | 
|  | 1091 | ps3_vuart_bus_interrupt_put(); | 
|  | 1092 | fail_setup_interrupt: | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1093 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1094 | dev_dbg(&dev->core, "%s:%d: failed\n", __func__, __LINE__); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1095 | return result; | 
|  | 1096 | } | 
|  | 1097 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1098 | /** | 
|  | 1099 | * ps3_vuart_cleanup - common cleanup helper. | 
|  | 1100 | * @dev: The struct ps3_system_bus_device instance. | 
|  | 1101 | * | 
|  | 1102 | * Cleans interrupts and HV resources.  Must be called with | 
|  | 1103 | * vuart_bus_priv.probe_mutex held.  Used by ps3_vuart_remove and | 
|  | 1104 | * ps3_vuart_shutdown.  After this call, polled reading will still work. | 
|  | 1105 | */ | 
|  | 1106 |  | 
|  | 1107 | static int ps3_vuart_cleanup(struct ps3_system_bus_device *dev) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1108 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1109 | dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); | 
|  | 1110 |  | 
|  | 1111 | ps3_vuart_cancel_async(dev); | 
|  | 1112 | ps3_vuart_set_interrupt_mask(dev, 0); | 
|  | 1113 | ps3_vuart_bus_interrupt_put(); | 
|  | 1114 | return 0; | 
|  | 1115 | } | 
|  | 1116 |  | 
|  | 1117 | /** | 
|  | 1118 | * ps3_vuart_remove - Completely clean the device instance. | 
|  | 1119 | * @dev: The struct ps3_system_bus_device instance. | 
|  | 1120 | * | 
|  | 1121 | * Cleans all memory, interrupts and HV resources.  After this call the | 
|  | 1122 | * device can no longer be used. | 
|  | 1123 | */ | 
|  | 1124 |  | 
|  | 1125 | static int ps3_vuart_remove(struct ps3_system_bus_device *dev) | 
|  | 1126 | { | 
|  | 1127 | struct ps3_vuart_port_priv *priv = to_port_priv(dev); | 
|  | 1128 | struct ps3_vuart_port_driver *drv; | 
|  | 1129 |  | 
|  | 1130 | BUG_ON(!dev); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1131 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1132 | mutex_lock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1133 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1134 | dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__, | 
|  | 1135 | dev->match_id); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1136 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1137 | if (!dev->core.driver) { | 
|  | 1138 | dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__, | 
|  | 1139 | __LINE__); | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1140 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1141 | return 0; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1142 | } | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1143 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1144 | drv = ps3_system_bus_dev_to_vuart_drv(dev); | 
|  | 1145 |  | 
|  | 1146 | BUG_ON(!drv); | 
|  | 1147 |  | 
|  | 1148 | if (drv->remove) { | 
|  | 1149 | drv->remove(dev); | 
|  | 1150 | } else { | 
|  | 1151 | dev_dbg(&dev->core, "%s:%d: no remove method\n", __func__, | 
|  | 1152 | __LINE__); | 
|  | 1153 | BUG(); | 
|  | 1154 | } | 
|  | 1155 |  | 
|  | 1156 | ps3_vuart_cleanup(dev); | 
|  | 1157 |  | 
|  | 1158 | vuart_bus_priv.devices[dev->port_number] = NULL; | 
|  | 1159 | kfree(priv); | 
|  | 1160 | priv = NULL; | 
|  | 1161 |  | 
|  | 1162 | dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__); | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1163 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1164 | return 0; | 
|  | 1165 | } | 
|  | 1166 |  | 
|  | 1167 | /** | 
|  | 1168 | * ps3_vuart_shutdown - Cleans interrupts and HV resources. | 
|  | 1169 | * @dev: The struct ps3_system_bus_device instance. | 
|  | 1170 | * | 
|  | 1171 | * Cleans interrupts and HV resources.  After this call the | 
|  | 1172 | * device can still be used in polling mode.  This behavior required | 
|  | 1173 | * by sys-manager to be able to complete the device power operation | 
|  | 1174 | * sequence. | 
|  | 1175 | */ | 
|  | 1176 |  | 
|  | 1177 | static int ps3_vuart_shutdown(struct ps3_system_bus_device *dev) | 
|  | 1178 | { | 
|  | 1179 | struct ps3_vuart_port_driver *drv; | 
|  | 1180 |  | 
|  | 1181 | BUG_ON(!dev); | 
|  | 1182 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1183 | mutex_lock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1184 |  | 
|  | 1185 | dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__, | 
|  | 1186 | dev->match_id); | 
|  | 1187 |  | 
|  | 1188 | if (!dev->core.driver) { | 
|  | 1189 | dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__, | 
|  | 1190 | __LINE__); | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1191 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1192 | return 0; | 
|  | 1193 | } | 
|  | 1194 |  | 
|  | 1195 | drv = ps3_system_bus_dev_to_vuart_drv(dev); | 
|  | 1196 |  | 
|  | 1197 | BUG_ON(!drv); | 
|  | 1198 |  | 
|  | 1199 | if (drv->shutdown) | 
|  | 1200 | drv->shutdown(dev); | 
|  | 1201 | else if (drv->remove) { | 
|  | 1202 | dev_dbg(&dev->core, "%s:%d: no shutdown, calling remove\n", | 
|  | 1203 | __func__, __LINE__); | 
|  | 1204 | drv->remove(dev); | 
|  | 1205 | } else { | 
|  | 1206 | dev_dbg(&dev->core, "%s:%d: no shutdown method\n", __func__, | 
|  | 1207 | __LINE__); | 
|  | 1208 | BUG(); | 
|  | 1209 | } | 
|  | 1210 |  | 
|  | 1211 | ps3_vuart_cleanup(dev); | 
|  | 1212 |  | 
|  | 1213 | dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1214 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1215 | mutex_unlock(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1216 | return 0; | 
|  | 1217 | } | 
|  | 1218 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1219 | static int __init ps3_vuart_bus_init(void) | 
| Geert Uytterhoeven | 5b8e8ee | 2007-02-12 00:55:15 -0800 | [diff] [blame] | 1220 | { | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1221 | pr_debug("%s:%d:\n", __func__, __LINE__); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1222 |  | 
|  | 1223 | if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) | 
| Geert Uytterhoeven | ef596c6 | 2007-03-10 00:05:38 +0100 | [diff] [blame] | 1224 | return -ENODEV; | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1225 |  | 
| Geoff Levand | c4e6752 | 2008-01-19 07:32:53 +1100 | [diff] [blame] | 1226 | mutex_init(&vuart_bus_priv.probe_mutex); | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1227 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1228 | return 0; | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1229 | } | 
|  | 1230 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1231 | static void __exit ps3_vuart_bus_exit(void) | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1232 | { | 
|  | 1233 | pr_debug("%s:%d:\n", __func__, __LINE__); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1234 | } | 
|  | 1235 |  | 
| Geoff Levand | 75c86e7 | 2007-02-13 17:37:28 -0800 | [diff] [blame] | 1236 | core_initcall(ps3_vuart_bus_init); | 
|  | 1237 | module_exit(ps3_vuart_bus_exit); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1238 |  | 
|  | 1239 | /** | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1240 | * ps3_vuart_port_driver_register - Add a vuart port device driver. | 
|  | 1241 | */ | 
|  | 1242 |  | 
|  | 1243 | int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv) | 
|  | 1244 | { | 
|  | 1245 | int result; | 
|  | 1246 |  | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1247 | pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.core.name); | 
|  | 1248 |  | 
|  | 1249 | BUG_ON(!drv->core.match_id); | 
|  | 1250 | BUG_ON(!drv->core.core.name); | 
|  | 1251 |  | 
|  | 1252 | drv->core.probe = ps3_vuart_probe; | 
|  | 1253 | drv->core.remove = ps3_vuart_remove; | 
|  | 1254 | drv->core.shutdown = ps3_vuart_shutdown; | 
|  | 1255 |  | 
|  | 1256 | result = ps3_system_bus_driver_register(&drv->core); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1257 | return result; | 
|  | 1258 | } | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1259 | EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register); | 
|  | 1260 |  | 
|  | 1261 | /** | 
|  | 1262 | * ps3_vuart_port_driver_unregister - Remove a vuart port device driver. | 
|  | 1263 | */ | 
|  | 1264 |  | 
|  | 1265 | void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv) | 
|  | 1266 | { | 
| Geoff Levand | 7626e78 | 2007-06-16 08:01:06 +1000 | [diff] [blame] | 1267 | pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.core.name); | 
|  | 1268 | ps3_system_bus_driver_unregister(&drv->core); | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1269 | } | 
| Geoff Levand | 74e95d5d | 2006-12-08 18:27:47 -0800 | [diff] [blame] | 1270 | EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_unregister); |