1 /*
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1992 OMRON Corporation.
4 * Copyright (c) 1990, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department.
10 *
11 * %sccs.include.redist.c%
12 *
13 * from: Utah $Hdr: cons.c 1.1 90/07/09$
14 *
15 * from: hp300/hp300/cons.c 7.1 (Berkeley) 6/4/92
16 *
17 * @(#)cons.c 8.1 (Berkeley) 06/10/93
18 */
19
20 #include <sys/param.h>
21 #include <sys/proc.h>
22 #include <sys/systm.h>
23 #include <sys/buf.h>
24 #include <sys/ioctl.h>
25 #include <sys/tty.h>
26 #include <sys/file.h>
27 #include <sys/conf.h>
28
29 #include <luna68k/luna68k/cons.h>
30
31 #include "bmc.h"
32 #include "sio.h"
33
34 #if NBMC > 0
35 int bmccnprobe(), bmccninit(), bmccngetc(), bmccnputc();
36 #endif
37
38 #if NSIO > 0
39 int siocnprobe(), siocninit(), siocngetc(), siocnputc();
40 #endif
41
42 struct consdev constab[] = {
43 #if NBMC > 0
44 { bmccnprobe, bmccninit, bmccngetc, bmccnputc },
45 #endif
46 #if NSIO > 0
47 { siocnprobe, siocninit, siocngetc, siocnputc },
48 #endif
49 { 0 },
50 };
51
52
53 struct tty *constty = 0; /* virtual console output device */
54 struct consdev *cn_tab; /* physical console device info */
55 struct tty *cn_tty; /* XXX: console tty struct for tprintf */
56
cninit()57 cninit()
58 {
59 register struct consdev *cp;
60
61 /*
62 * Collect information about all possible consoles
63 * and find the one with highest priority
64 */
65 for (cp = constab; cp->cn_probe; cp++) {
66 (*cp->cn_probe)(cp);
67 if (cp->cn_pri > CN_DEAD &&
68 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
69 cn_tab = cp;
70 }
71 /*
72 * No console, we can handle it
73 */
74 if ((cp = cn_tab) == NULL)
75 return;
76 /*
77 * Turn on console
78 */
79 cn_tty = cp->cn_tp;
80 (*cp->cn_init)(cp);
81 }
82
cnopen(dev,flag,mode,p)83 cnopen(dev, flag, mode, p)
84 dev_t dev;
85 int flag, mode;
86 struct proc *p;
87 {
88 if (cn_tab == NULL)
89 return (0);
90 dev = cn_tab->cn_dev;
91 return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
92 }
93
cnclose(dev,flag,mode,p)94 cnclose(dev, flag, mode, p)
95 dev_t dev;
96 int flag, mode;
97 struct proc *p;
98 {
99 if (cn_tab == NULL)
100 return (0);
101 dev = cn_tab->cn_dev;
102 return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
103 }
104
cnread(dev,uio,flag)105 cnread(dev, uio, flag)
106 dev_t dev;
107 struct uio *uio;
108 {
109 if (cn_tab == NULL)
110 return (0);
111 dev = cn_tab->cn_dev;
112 return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
113 }
114
cnwrite(dev,uio,flag)115 cnwrite(dev, uio, flag)
116 dev_t dev;
117 struct uio *uio;
118 {
119 if (cn_tab == NULL)
120 return (0);
121 dev = cn_tab->cn_dev;
122 return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
123 }
124
cnioctl(dev,cmd,data,flag,p)125 cnioctl(dev, cmd, data, flag, p)
126 dev_t dev;
127 caddr_t data;
128 struct proc *p;
129 {
130 int error;
131
132 if (cn_tab == NULL)
133 return (0);
134 /*
135 * Superuser can always use this to wrest control of console
136 * output from the "virtual" console.
137 */
138 if (cmd == TIOCCONS && constty) {
139 error = suser(p->p_ucred, (u_short *) NULL);
140 if (error)
141 return (error);
142 constty = NULL;
143 return (0);
144 }
145 dev = cn_tab->cn_dev;
146 return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
147 }
148
149 /*ARGSUSED*/
cnselect(dev,rw,p)150 cnselect(dev, rw, p)
151 dev_t dev;
152 int rw;
153 struct proc *p;
154 {
155 if (cn_tab == NULL)
156 return (1);
157 return (ttselect(cn_tab->cn_dev, rw, p));
158 }
159
cngetc()160 cngetc()
161 {
162 if (cn_tab == NULL)
163 return (0);
164 return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
165 }
166
cnputc(c)167 cnputc(c)
168 register int c;
169 {
170 if (cn_tab == NULL)
171 return;
172 if (c) {
173 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
174 if (c == '\n')
175 (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
176 }
177 }
178