1 /* $Id: console.c,v 1.10 1996/12/18 06:46:54 tridge Exp $
2 * console.c: Routines that deal with sending and receiving IO
3 * to/from the current console device using the PROM.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <asm/openprom.h>
12 #include <asm/oplib.h>
13 #include <asm/system.h>
14 #include <linux/string.h>
16 /* Non blocking get character from console input device, returns -1
17 * if no input was taken. This can be used for polling.
25 local_irq_save(flags
);
26 i
= (*(romvec
->pv_nbgetchar
))();
27 local_irq_restore(flags
);
28 return i
; /* Ugh, we could spin forever on unsupported proms ;( */
31 /* Non blocking put character to console device, returns -1 if
35 prom_nbputchar(char c
)
40 local_irq_save(flags
);
41 i
= (*(romvec
->pv_nbputchar
))(c
);
42 local_irq_restore(flags
);
43 return i
; /* Ugh, we could spin forever on unsupported proms ;( */
46 /* Blocking version of get character routine above. */
51 while((character
= prom_nbgetchar()) == -1) ;
52 return (char) character
;
55 /* Blocking version of put character routine above. */
59 while(prom_nbputchar(c
) == -1) ;
63 /* Query for input device type */
65 enum prom_input_device
66 prom_query_input_device()
77 switch(*romvec
->pv_stdin
) {
78 case PROMDEV_KBD
: return PROMDEV_IKBD
;
79 case PROMDEV_TTYA
: return PROMDEV_ITTYA
;
80 case PROMDEV_TTYB
: return PROMDEV_ITTYB
;
86 local_irq_save(flags
);
87 st_p
= (*romvec
->pv_v2devops
.v2_inst2pkg
)(*romvec
->pv_v2bootargs
.fd_stdin
);
88 __asm__
__volatile__("ld [%0], %%g6\n\t" : :
89 "r" (¤t_set
[smp_processor_id()]) :
91 local_irq_restore(flags
);
92 if(prom_node_has_property(st_p
, "keyboard"))
94 prom_getproperty(st_p
, "device_type", propb
, sizeof(propb
));
95 if(strncmp(propb
, "serial", sizeof("serial")))
97 prom_getproperty(prom_root_node
, "stdin-path", propb
, sizeof(propb
));
99 while(*p
) p
++; p
-= 2;
102 return PROMDEV_ITTYA
;
104 return PROMDEV_ITTYB
;
106 return PROMDEV_I_UNK
;
108 return PROMDEV_I_UNK
;
113 /* Query for output device type */
116 enum prom_output_device
117 prom_query_output_device()
127 switch(*romvec
->pv_stdin
) {
128 case PROMDEV_SCREEN
: return PROMDEV_OSCREEN
;
129 case PROMDEV_TTYA
: return PROMDEV_OTTYA
;
130 case PROMDEV_TTYB
: return PROMDEV_OTTYB
;
136 local_irq_save(flags
);
137 st_p
= (*romvec
->pv_v2devops
.v2_inst2pkg
)(*romvec
->pv_v2bootargs
.fd_stdout
);
138 __asm__
__volatile__("ld [%0], %%g6\n\t" : :
139 "r" (¤t_set
[smp_processor_id()]) :
141 local_irq_restore(flags
);
142 propl
= prom_getproperty(st_p
, "device_type", propb
, sizeof(propb
));
143 if (propl
>= 0 && propl
== sizeof("display") &&
144 strncmp("display", propb
, sizeof("display")) == 0)
146 return PROMDEV_OSCREEN
;
148 if(prom_vers
== PROM_V3
) {
149 if(strncmp("serial", propb
, sizeof("serial")))
150 return PROMDEV_O_UNK
;
151 prom_getproperty(prom_root_node
, "stdout-path", propb
, sizeof(propb
));
153 while(*p
) p
++; p
-= 2;
156 return PROMDEV_OTTYA
;
158 return PROMDEV_OTTYB
;
160 return PROMDEV_O_UNK
;
162 /* This works on SS-2 (an early OpenFirmware) still. */
163 switch(*romvec
->pv_stdin
) {
164 case PROMDEV_TTYA
: return PROMDEV_OTTYA
;
165 case PROMDEV_TTYB
: return PROMDEV_OTTYB
;
170 return PROMDEV_I_UNK
;
172 return PROMDEV_O_UNK
;