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