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> |
| 14 | #include <asm/system.h> |
| 15 | #include <linux/string.h> |
| 16 | |
| 17 | extern void restore_current(void); |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | /* Non blocking put character to console device, returns -1 if |
| 20 | * unsuccessful. |
| 21 | */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 22 | static int prom_nbputchar(const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | unsigned long flags; |
| 25 | int i = -1; |
| 26 | |
| 27 | spin_lock_irqsave(&prom_lock, flags); |
| 28 | switch(prom_vers) { |
| 29 | case PROM_V0: |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 30 | if ((*(romvec->pv_nbputchar))(*buf)) |
| 31 | i = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | break; |
| 33 | case PROM_V2: |
| 34 | case PROM_V3: |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 35 | if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, |
| 36 | buf, 0x1) == 1) |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 37 | i = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | break; |
| 39 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | break; |
Joe Perches | 6cb79b3 | 2011-06-03 14:45:23 +0000 | [diff] [blame] | 41 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | restore_current(); |
| 43 | spin_unlock_irqrestore(&prom_lock, flags); |
| 44 | return i; /* Ugh, we could spin forever on unsupported proms ;( */ |
| 45 | } |
| 46 | |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 47 | void prom_console_write_buf(const char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 49 | while (len) { |
| 50 | int n = prom_nbputchar(buf); |
Julian Calaby | 1543376 | 2010-12-03 17:56:45 +0000 | [diff] [blame] | 51 | if (n < 0) |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 52 | continue; |
| 53 | len--; |
| 54 | buf++; |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame] | 55 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
David S. Miller | 595a251 | 2010-11-30 20:15:58 -0800 | [diff] [blame] | 57 | |