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 <linux/string.h>
15 /* Non blocking get character from console input device, returns -1
16 * if no input was taken. This can be used for polling.
24 local_irq_save(flags
);
25 i
= (*(romvec
->pv_nbgetchar
))();
26 local_irq_restore(flags
);
27 return i
; /* Ugh, we could spin forever on unsupported proms ;( */
30 /* Non blocking put character to console device, returns -1 if
34 prom_nbputchar(char c
)
39 local_irq_save(flags
);
40 i
= (*(romvec
->pv_nbputchar
))(c
);
41 local_irq_restore(flags
);
42 return i
; /* Ugh, we could spin forever on unsupported proms ;( */
45 /* Blocking version of get character routine above. */
50 while((character
= prom_nbgetchar()) == -1) ;
51 return (char) character
;
54 /* Blocking version of put character routine above. */
58 while(prom_nbputchar(c
) == -1) ;
62 /* Query for input device type */
64 enum prom_input_device
65 prom_query_input_device()
76 switch(*romvec
->pv_stdin
) {
77 case PROMDEV_KBD
: return PROMDEV_IKBD
;
78 case PROMDEV_TTYA
: return PROMDEV_ITTYA
;
79 case PROMDEV_TTYB
: return PROMDEV_ITTYB
;
85 local_irq_save(flags
);
86 st_p
= (*romvec
->pv_v2devops
.v2_inst2pkg
)(*romvec
->pv_v2bootargs
.fd_stdin
);
87 __asm__
__volatile__("ld [%0], %%g6\n\t" : :
88 "r" (¤t_set
[smp_processor_id()]) :
90 local_irq_restore(flags
);
91 if(prom_node_has_property(st_p
, "keyboard"))
93 prom_getproperty(st_p
, "device_type", propb
, sizeof(propb
));
94 if(strncmp(propb
, "serial", sizeof("serial")))
96 prom_getproperty(prom_root_node
, "stdin-path", propb
, sizeof(propb
));
98 while(*p
) p
++; p
-= 2;
101 return PROMDEV_ITTYA
;
103 return PROMDEV_ITTYB
;
105 return PROMDEV_I_UNK
;
110 /* Query for output device type */
113 enum prom_output_device
114 prom_query_output_device()
124 switch(*romvec
->pv_stdin
) {
125 case PROMDEV_SCREEN
: return PROMDEV_OSCREEN
;
126 case PROMDEV_TTYA
: return PROMDEV_OTTYA
;
127 case PROMDEV_TTYB
: return PROMDEV_OTTYB
;
133 local_irq_save(flags
);
134 st_p
= (*romvec
->pv_v2devops
.v2_inst2pkg
)(*romvec
->pv_v2bootargs
.fd_stdout
);
135 __asm__
__volatile__("ld [%0], %%g6\n\t" : :
136 "r" (¤t_set
[smp_processor_id()]) :
138 local_irq_restore(flags
);
139 propl
= prom_getproperty(st_p
, "device_type", propb
, sizeof(propb
));
140 if (propl
>= 0 && propl
== sizeof("display") &&
141 strncmp("display", propb
, sizeof("display")) == 0)
143 return PROMDEV_OSCREEN
;
145 if(prom_vers
== PROM_V3
) {
146 if(strncmp("serial", propb
, sizeof("serial")))
147 return PROMDEV_O_UNK
;
148 prom_getproperty(prom_root_node
, "stdout-path", propb
, sizeof(propb
));
150 while(*p
) p
++; p
-= 2;
153 return PROMDEV_OTTYA
;
155 return PROMDEV_OTTYB
;
157 return PROMDEV_O_UNK
;
159 /* This works on SS-2 (an early OpenFirmware) still. */
160 switch(*romvec
->pv_stdin
) {
161 case PROMDEV_TTYA
: return PROMDEV_OTTYA
;
162 case PROMDEV_TTYB
: return PROMDEV_OTTYB
;
167 return PROMDEV_O_UNK
;