Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * console.c: Routines that deal with sending and receiving IO |
| 3 | * to/from the current console device using the PROM. |
| 4 | * |
| 5 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 6 | * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <asm/openprom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/oplib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/string.h> |
| 15 | |
| 16 | extern void restore_current(void); |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | /* Non blocking put character to console device, returns -1 if |
| 19 | * unsuccessful. |
| 20 | */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 21 | static int prom_nbputchar(const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | unsigned long flags; |
| 24 | int i = -1; |
| 25 | |
| 26 | spin_lock_irqsave(&prom_lock, flags); |
| 27 | switch(prom_vers) { |
| 28 | case PROM_V0: |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 29 | if ((*(romvec->pv_nbputchar))(*buf)) |
| 30 | i = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | break; |
| 32 | case PROM_V2: |
| 33 | case PROM_V3: |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 34 | if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, |
| 35 | buf, 0x1) == 1) |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 36 | i = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | break; |
| 38 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | break; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 40 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | restore_current(); |
| 42 | spin_unlock_irqrestore(&prom_lock, flags); |
| 43 | return i; /* Ugh, we could spin forever on unsupported proms ;( */ |
| 44 | } |
| 45 | |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 46 | void prom_console_write_buf(const char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 48 | while (len) { |
| 49 | int n = prom_nbputchar(buf); |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 50 | if (n < 0) |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 51 | continue; |
| 52 | len--; |
| 53 | buf++; |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 54 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 56 | |