Annotation of sys/arch/vax/vax/gencons.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: gencons.c,v 1.17 2006/07/19 20:21:08 miod Exp $ */
2: /* $NetBSD: gencons.c,v 1.22 2000/01/24 02:40:33 matt Exp $ */
3:
4: /*
5: * Copyright (c) 1994 Gordon W. Ross
6: * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
7: * All rights reserved.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: * 3. All advertising materials mentioning features or use of this software
18: * must display the following acknowledgement:
19: * This product includes software developed at Ludd, University of Lule}.
20: * 4. The name of the author may not be used to endorse or promote products
21: * derived from this software without specific prior written permission
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33: *
34: * kd.c,v 1.2 1994/05/05 04:46:51 gwr Exp $
35: */
36:
37: /* All bugs are subject to removal without further notice */
38:
39: #include <sys/param.h>
40: #include <sys/proc.h>
41: #include <sys/systm.h>
42: #include <sys/ioctl.h>
43: #include <sys/tty.h>
44: #include <sys/file.h>
45: #include <sys/conf.h>
46: #include <sys/device.h>
47: #include <sys/reboot.h>
48:
49: #include <dev/cons.h>
50:
51: #include <machine/mtpr.h>
52: #include <machine/sid.h>
53: #include <machine/cpu.h>
54: #include <machine/scb.h>
55: #include <machine/../vax/gencons.h>
56:
57: struct tty *gencn_tty[4];
58:
59: int consopened = 0;
60: int maxttys = 1;
61:
62: int pr_txcs[4] = {PR_TXCS, PR_TXCS1, PR_TXCS2, PR_TXCS3};
63: int pr_rxcs[4] = {PR_RXCS, PR_RXCS1, PR_RXCS2, PR_RXCS3};
64: int pr_txdb[4] = {PR_TXDB, PR_TXDB1, PR_TXDB2, PR_TXDB3};
65: int pr_rxdb[4] = {PR_RXDB, PR_RXDB1, PR_RXDB2, PR_RXDB3};
66:
67: cons_decl(gen);
68: cdev_decl(gencn);
69:
70: int gencnparam(struct tty *, struct termios *);
71: void gencnstart(struct tty *);
72: void gencnrint(void *);
73: void gencntint(void *);
74:
75: int
76: gencnopen(dev, flag, mode, p)
77: dev_t dev;
78: int flag, mode;
79: struct proc *p;
80: {
81: int unit;
82: struct tty *tp;
83:
84: unit = minor(dev);
85: if (unit >= maxttys)
86: return ENXIO;
87:
88: if (gencn_tty[unit] == NULL)
89: gencn_tty[unit] = ttymalloc();
90:
91: tp = gencn_tty[unit];
92:
93: tp->t_oproc = gencnstart;
94: tp->t_param = gencnparam;
95: tp->t_dev = dev;
96: if ((tp->t_state & TS_ISOPEN) == 0) {
97: ttychars(tp);
98: tp->t_iflag = TTYDEF_IFLAG;
99: tp->t_oflag = TTYDEF_OFLAG;
100: tp->t_cflag = TTYDEF_CFLAG;
101: tp->t_lflag = TTYDEF_LFLAG;
102: tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
103: gencnparam(tp, &tp->t_termios);
104: ttsetwater(tp);
105: } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0)
106: return EBUSY;
107: tp->t_state |= TS_CARR_ON;
108: if (unit == 0)
109: consopened = 1;
110: mtpr(GC_RIE, pr_rxcs[unit]); /* Turn on interrupts */
111: mtpr(GC_TIE, pr_txcs[unit]);
112:
113: return ((*linesw[tp->t_line].l_open)(dev, tp));
114: }
115:
116: int
117: gencnclose(dev, flag, mode, p)
118: dev_t dev;
119: int flag, mode;
120: struct proc *p;
121: {
122: struct tty *tp = gencn_tty[minor(dev)];
123:
124: if (minor(dev) == 0)
125: consopened = 0;
126: (*linesw[tp->t_line].l_close)(tp, flag);
127: ttyclose(tp);
128: return (0);
129: }
130:
131: struct tty *
132: gencntty(dev_t dev)
133: {
134: return gencn_tty[minor(dev)];
135: }
136:
137: int
138: gencnread(dev_t dev, struct uio *uio, int flag)
139: {
140: struct tty *tp = gencn_tty[minor(dev)];
141:
142: return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
143: }
144:
145: int
146: gencnwrite(dev_t dev, struct uio *uio, int flag)
147: {
148: struct tty *tp = gencn_tty[minor(dev)];
149:
150: return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
151: }
152:
153: int
154: gencnioctl(dev, cmd, data, flag, p)
155: dev_t dev;
156: u_long cmd;
157: caddr_t data;
158: int flag;
159: struct proc *p;
160: {
161: struct tty *tp = gencn_tty[minor(dev)];
162: int error;
163:
164: error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
165: if (error >= 0)
166: return error;
167: error = ttioctl(tp, cmd, data, flag, p);
168: if (error >= 0)
169: return error;
170:
171: return ENOTTY;
172: }
173:
174: void
175: gencnstart(struct tty *tp)
176: {
177: struct clist *cl;
178: int s, ch;
179:
180: s = spltty();
181: if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
182: goto out;
183: cl = &tp->t_outq;
184:
185: if(cl->c_cc){
186: tp->t_state |= TS_BUSY;
187: ch = getc(cl);
188: mtpr(ch, pr_txdb[minor(tp->t_dev)]);
189: } else {
190: if (tp->t_state & TS_ASLEEP) {
191: tp->t_state &= ~TS_ASLEEP;
192: wakeup((caddr_t)cl);
193: }
194: selwakeup(&tp->t_wsel);
195: }
196:
197: out: splx(s);
198: }
199:
200: void
201: gencnrint(void *arg)
202: {
203: struct tty *tp = *(struct tty **) arg;
204: int unit = (struct tty **) arg - gencn_tty;
205: int i;
206:
207: i = mfpr(pr_rxdb[unit]) & 0377; /* Mask status flags etc... */
208:
209: #ifdef DDB
210: if (tp->t_dev == cn_tab->cn_dev) {
211: int j = kdbrint(i);
212:
213: if (j == 1) /* Escape received, just return */
214: return;
215:
216: if (j == 2) /* Second char wasn't 'D' */
217: (*linesw[tp->t_line].l_rint)(27, tp);
218: }
219: #endif
220:
221: (*linesw[tp->t_line].l_rint)(i, tp);
222: return;
223: }
224:
225: int
226: gencnstop(struct tty *tp, int flag)
227: {
228: return 0;
229: }
230:
231: void
232: gencntint(void *arg)
233: {
234: struct tty *tp = *(struct tty **) arg;
235:
236: tp->t_state &= ~TS_BUSY;
237:
238: gencnstart(tp);
239: }
240:
241: int
242: gencnparam(struct tty *tp, struct termios *t)
243: {
244: /* XXX - These are ignored... */
245: tp->t_ispeed = t->c_ispeed;
246: tp->t_ospeed = t->c_ospeed;
247: tp->t_cflag = t->c_cflag;
248: return 0;
249: }
250:
251: void
252: gencnprobe(struct consdev *cndev)
253: {
254: if ((vax_cputype < VAX_TYP_UV2) || /* All older has MTPR console */
255: (vax_boardtype == VAX_BTYP_9RR) ||
256: (vax_boardtype == VAX_BTYP_630) ||
257: (vax_boardtype == VAX_BTYP_650) ||
258: (vax_boardtype == VAX_BTYP_660) ||
259: (vax_boardtype == VAX_BTYP_670) ||
260: (vax_boardtype == VAX_BTYP_1301) ||
261: (vax_boardtype == VAX_BTYP_1305)) {
262: cndev->cn_dev = makedev(25, 0);
263: cndev->cn_pri = CN_NORMAL;
264: }
265: }
266:
267: void
268: gencninit(struct consdev *cndev)
269: {
270:
271: /* Allocate interrupt vectors */
272: scb_vecalloc(SCB_G0R, gencnrint, &gencn_tty[0], SCB_ISTACK, NULL);
273: scb_vecalloc(SCB_G0T, gencntint, &gencn_tty[0], SCB_ISTACK, NULL);
274:
275: if (vax_cputype == VAX_TYP_8SS) {
276: maxttys = 4;
277: scb_vecalloc(SCB_G1R, gencnrint, &gencn_tty[1], SCB_ISTACK, NULL);
278: scb_vecalloc(SCB_G1T, gencntint, &gencn_tty[1], SCB_ISTACK, NULL);
279:
280: scb_vecalloc(SCB_G2R, gencnrint, &gencn_tty[2], SCB_ISTACK, NULL);
281: scb_vecalloc(SCB_G2T, gencntint, &gencn_tty[2], SCB_ISTACK, NULL);
282:
283: scb_vecalloc(SCB_G3R, gencnrint, &gencn_tty[3], SCB_ISTACK, NULL);
284: scb_vecalloc(SCB_G3T, gencntint, &gencn_tty[3], SCB_ISTACK, NULL);
285: }
286: mtpr(0, PR_RXCS);
287: mtpr(0, PR_TXCS);
288: mtpr(0, PR_TBIA); /* ??? */
289: }
290:
291: void
292: gencnputc(dev_t dev, int ch)
293: {
294: #ifdef VAX8800
295: /*
296: * On KA88 we may get C-S/C-Q from the console.
297: * XXX - this will cause a loop at spltty() in kernel and will
298: * interfere with other console communication. Fortunately
299: * kernel printf's are uncommon.
300: */
301: if (vax_cputype == VAX_TYP_8NN) {
302: int s = spltty();
303:
304: while (mfpr(PR_RXCS) & GC_DON) {
305: if ((mfpr(PR_RXDB) & 0x7f) == 19) {
306: while (1) {
307: while ((mfpr(PR_RXCS) & GC_DON) == 0)
308: ;
309: if ((mfpr(PR_RXDB) & 0x7f) == 17)
310: break;
311: }
312: }
313: }
314: splx(s);
315: }
316: #endif
317:
318: while ((mfpr(PR_TXCS) & GC_RDY) == 0) /* Wait until xmit ready */
319: ;
320: mtpr(ch, PR_TXDB); /* xmit character */
321: if(ch == 10)
322: gencnputc(dev, 13); /* CR/LF */
323:
324: }
325:
326: int
327: gencngetc(dev_t dev)
328: {
329: int i;
330:
331: while ((mfpr(PR_RXCS) & GC_DON) == 0) /* Receive chr */
332: ;
333: i = mfpr(PR_RXDB) & 0x7f;
334: if (i == 13)
335: i = 10;
336: return i;
337: }
338:
339: void
340: gencnpollc(dev_t dev, int pollflag)
341: {
342: if (pollflag) {
343: mtpr(0, PR_RXCS);
344: mtpr(0, PR_TXCS);
345: } else if (consopened) {
346: mtpr(GC_RIE, PR_RXCS);
347: mtpr(GC_TIE, PR_TXCS);
348: }
349: }
CVSweb