Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: console.c,v 1.25 2001/10/30 04:54:22 davem Exp $ |
| 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> |
| 13 | #include <asm/sun4prom.h> |
| 14 | #include <asm/oplib.h> |
| 15 | #include <asm/system.h> |
| 16 | #include <linux/string.h> |
| 17 | |
| 18 | extern void restore_current(void); |
| 19 | |
| 20 | static char con_name_jmc[] = "/obio/su@"; /* "/obio/su@0,3002f8"; */ |
| 21 | #define CON_SIZE_JMC (sizeof(con_name_jmc)) |
| 22 | |
| 23 | /* Non blocking get character from console input device, returns -1 |
| 24 | * if no input was taken. This can be used for polling. |
| 25 | */ |
| 26 | int |
| 27 | prom_nbgetchar(void) |
| 28 | { |
| 29 | static char inc; |
| 30 | int i = -1; |
| 31 | unsigned long flags; |
| 32 | |
| 33 | spin_lock_irqsave(&prom_lock, flags); |
| 34 | switch(prom_vers) { |
| 35 | case PROM_V0: |
| 36 | case PROM_SUN4: |
| 37 | i = (*(romvec->pv_nbgetchar))(); |
| 38 | break; |
| 39 | case PROM_V2: |
| 40 | case PROM_V3: |
| 41 | if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) { |
| 42 | i = inc; |
| 43 | } else { |
| 44 | i = -1; |
| 45 | } |
| 46 | break; |
| 47 | default: |
| 48 | i = -1; |
| 49 | break; |
| 50 | }; |
| 51 | restore_current(); |
| 52 | spin_unlock_irqrestore(&prom_lock, flags); |
| 53 | return i; /* Ugh, we could spin forever on unsupported proms ;( */ |
| 54 | } |
| 55 | |
| 56 | /* Non blocking put character to console device, returns -1 if |
| 57 | * unsuccessful. |
| 58 | */ |
| 59 | int |
| 60 | prom_nbputchar(char c) |
| 61 | { |
| 62 | static char outc; |
| 63 | unsigned long flags; |
| 64 | int i = -1; |
| 65 | |
| 66 | spin_lock_irqsave(&prom_lock, flags); |
| 67 | switch(prom_vers) { |
| 68 | case PROM_V0: |
| 69 | case PROM_SUN4: |
| 70 | i = (*(romvec->pv_nbputchar))(c); |
| 71 | break; |
| 72 | case PROM_V2: |
| 73 | case PROM_V3: |
| 74 | outc = c; |
| 75 | if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1) |
| 76 | i = 0; |
| 77 | else |
| 78 | i = -1; |
| 79 | break; |
| 80 | default: |
| 81 | i = -1; |
| 82 | break; |
| 83 | }; |
| 84 | restore_current(); |
| 85 | spin_unlock_irqrestore(&prom_lock, flags); |
| 86 | return i; /* Ugh, we could spin forever on unsupported proms ;( */ |
| 87 | } |
| 88 | |
| 89 | /* Blocking version of get character routine above. */ |
| 90 | char |
| 91 | prom_getchar(void) |
| 92 | { |
| 93 | int character; |
| 94 | while((character = prom_nbgetchar()) == -1) ; |
| 95 | return (char) character; |
| 96 | } |
| 97 | |
| 98 | /* Blocking version of put character routine above. */ |
| 99 | void |
| 100 | prom_putchar(char c) |
| 101 | { |
| 102 | while(prom_nbputchar(c) == -1) ; |
| 103 | return; |
| 104 | } |