156876Sakito /*
256876Sakito * Copyright (c) 1992 OMRON Corporation.
3*63192Sbostic * Copyright (c) 1992, 1993
4*63192Sbostic * The Regents of the University of California. All rights reserved.
556876Sakito *
656876Sakito * This code is derived from software contributed to Berkeley by
756876Sakito * OMRON Corporation.
856876Sakito *
956876Sakito * %sccs.include.redist.c%
1056876Sakito *
11*63192Sbostic * @(#)bmc.c 8.1 (Berkeley) 06/10/93
1256876Sakito */
1356876Sakito
1456876Sakito #include "bmc.h"
1556876Sakito #if NBMC > 0
1656876Sakito
1757059Sakito #include <sys/param.h>
1857059Sakito #include <sys/systm.h>
1957059Sakito #include <sys/ioctl.h>
2057059Sakito #include <sys/proc.h>
2157059Sakito #include <sys/tty.h>
2257059Sakito #include <sys/conf.h>
2357059Sakito #include <sys/file.h>
2457059Sakito #include <sys/uio.h>
2557059Sakito #include <sys/kernel.h>
2657059Sakito #include <sys/syslog.h>
2759646Sakito #include <machine/stinger.h>
2857059Sakito #include <luna68k/dev/device.h>
2957059Sakito #include <luna68k/dev/sioreg.h>
3057059Sakito #include <luna68k/dev/siovar.h>
3159646Sakito #include <luna68k/luna68k/cons.h>
3256876Sakito
3356876Sakito extern struct sio_portc *sio_port_assign();
3456876Sakito
3556876Sakito int bmcprobe();
3656876Sakito int bmcopen();
3756876Sakito void bmcstart();
3856876Sakito int bmcparam();
3956876Sakito int bmcintr();
4056876Sakito
4156876Sakito struct driver bmcdriver = {
4256876Sakito bmcprobe, "bmc",
4356876Sakito };
4456876Sakito
4556876Sakito struct bmc_softc {
4656876Sakito struct sio_portc *sc_pc;
4756876Sakito int sc_mask;
4856876Sakito };
4956876Sakito
5056876Sakito struct bmc_softc bmc_softc[NBMC];
5156876Sakito
5256876Sakito struct tty bmc_tty[NBMC];
5356876Sakito
5459646Sakito int bmc_active;
5557125Sakito int bmcconsole = -1;
5656876Sakito int bmcdefaultrate = B9600; /* speed of console line is fixed */
5757292Sakito int bmcmajor = 13;
5856876Sakito
5956876Sakito #define bmcunit(x) minor(x)
6056876Sakito
6157125Sakito extern struct tty *constty;
6256876Sakito
6356876Sakito /*
6457292Sakito * key-code decoding
6557292Sakito */
6657292Sakito
6757292Sakito struct bmc_keymap {
6857292Sakito int km_type;
6957292Sakito int km_code[2];
7057292Sakito };
7157292Sakito
7257292Sakito #define KC_CHAR 0x000000FF
7357292Sakito #define KC_TYPE 0x0000FF00
7457292Sakito #define KC_CODE 0x00000000
7557292Sakito #define KC_SHIFT 0x00000100
7657292Sakito #define KC_IGNORE 0x0000FF00
7757292Sakito
7857292Sakito #define KS_SHIFT 0
7957292Sakito #define KS_CTRL 1
8057292Sakito #define KS_META 2
8157292Sakito
8257292Sakito struct bmc_keymap bmc_keymap[] = {
8357292Sakito KC_IGNORE, 0, 0, /* 0 [0x00] */
8457292Sakito KC_IGNORE, 0, 0, /* 1 [0x01] */
8557292Sakito KC_IGNORE, 0, 0, /* 2 [0x02] */
8657292Sakito KC_IGNORE, 0, 0, /* 3 [0x03] */
8757292Sakito KC_IGNORE, 0, 0, /* 4 [0x04] */
8857292Sakito KC_IGNORE, 0, 0, /* 5 [0x05] */
8957292Sakito KC_IGNORE, 0, 0, /* 6 [0x06] */
9057292Sakito KC_IGNORE, 0, 0, /* 7 [0x07] */
9157292Sakito KC_IGNORE, 0, 0, /* 8 [0x08] */
9257292Sakito KC_CODE, 0x09, 0x09, /* 9 [0x09] TAB */
9357292Sakito KC_SHIFT, KS_CTRL, KS_CTRL, /* 10 [0x0A] CTRL */
9457292Sakito KC_IGNORE, 0, 0, /* 11 [0x0B] */
9557292Sakito KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 12 [0x0C] SHIFT */
9657292Sakito KC_SHIFT, KS_SHIFT, KS_SHIFT, /* 13 [0x0D] SHIFT */
9757292Sakito KC_IGNORE, 0, 0, /* 14 [0x0E] */
9857292Sakito KC_SHIFT, KS_META, KS_META, /* 15 [0x0F] META */
9957292Sakito KC_CODE, 0x1B, 0x1B, /* 16 [0x10] ESC */
10057292Sakito KC_CODE, 0x08, 0x08, /* 17 [0x11] BS */
10157292Sakito KC_CODE, 0x0D, 0x0D, /* 18 [0x12] CR */
10257292Sakito KC_IGNORE, 0, 0, /* 19 [0x13] */
10357292Sakito KC_CODE, 0x20, 0x20, /* 20 [0x14] SP */
10457292Sakito KC_CODE, 0x7F, 0x7F, /* 21 [0x15] DEL */
10557292Sakito KC_IGNORE, 0, 0, /* 22 [0x16] */
10657292Sakito KC_IGNORE, 0, 0, /* 23 [0x17] */
10757292Sakito KC_IGNORE, 0, 0, /* 24 [0x18] */
10857292Sakito KC_IGNORE, 0, 0, /* 25 [0x19] */
10957292Sakito KC_IGNORE, 0, 0, /* 26 [0x1A] */
11057292Sakito KC_IGNORE, 0, 0, /* 27 [0x1B] */
11157292Sakito KC_IGNORE, 0, 0, /* 28 [0x1C] */
11257292Sakito KC_IGNORE, 0, 0, /* 29 [0x1D] */
11357292Sakito KC_IGNORE, 0, 0, /* 30 [0x1E] */
11457292Sakito KC_IGNORE, 0, 0, /* 31 [0x1F] */
11557292Sakito KC_IGNORE, 0, 0, /* 32 [0x20] */
11657292Sakito KC_IGNORE, 0, 0, /* 33 [0x21] */
11757292Sakito KC_CODE, 0x31, 0x21, /* 34 [0x22] 1 */
11857292Sakito KC_CODE, 0x32, 0x22, /* 35 [0x23] 2 */
11957292Sakito KC_CODE, 0x33, 0x23, /* 36 [0x24] 3 */
12057292Sakito KC_CODE, 0x34, 0x24, /* 37 [0x25] 4 */
12157292Sakito KC_CODE, 0x35, 0x25, /* 38 [0x26] 5 */
12257292Sakito KC_CODE, 0x36, 0x26, /* 39 [0x27] 6 */
12357292Sakito KC_CODE, 0x37, 0x27, /* 40 [0x28] 7 */
12457292Sakito KC_CODE, 0x38, 0x28, /* 41 [0x29] 8 */
12557292Sakito KC_CODE, 0x39, 0x29, /* 42 [0x2A] 9 */
12657292Sakito KC_CODE, 0x30, 0x30, /* 43 [0x2B] 0 */
12757292Sakito KC_CODE, 0x2D, 0x3D, /* 44 [0x2C] - */
12857292Sakito KC_CODE, 0x5E, 0x7E, /* 45 [0x2D] ^ */
12957292Sakito KC_CODE, 0x5C, 0x7C, /* 46 [0x2E] \ */
13057292Sakito KC_IGNORE, 0, 0, /* 47 [0x2F] */
13157292Sakito KC_IGNORE, 0, 0, /* 48 [0x30] */
13257292Sakito KC_IGNORE, 0, 0, /* 49 [0x31] */
13357292Sakito KC_CODE, 0x71, 0x51, /* 50 [0x32] q */
13457292Sakito KC_CODE, 0x77, 0x57, /* 51 [0x33] w */
13557292Sakito KC_CODE, 0x65, 0x45, /* 52 [0x34] e */
13657292Sakito KC_CODE, 0x72, 0x52, /* 53 [0x35] r */
13757292Sakito KC_CODE, 0x74, 0x54, /* 54 [0x36] t */
13857292Sakito KC_CODE, 0x79, 0x59, /* 55 [0x37] y */
13957292Sakito KC_CODE, 0x75, 0x55, /* 56 [0x38] u */
14057292Sakito KC_CODE, 0x69, 0x49, /* 57 [0x39] i */
14157292Sakito KC_CODE, 0x6F, 0x4F, /* 58 [0x3A] o */
14257292Sakito KC_CODE, 0x70, 0x50, /* 59 [0x3B] p */
14357292Sakito KC_CODE, 0x40, 0x60, /* 60 [0x3C] @ */
14457292Sakito KC_CODE, 0x5B, 0x7B, /* 61 [0x3D] [ */
14557292Sakito KC_IGNORE, 0, 0, /* 62 [0x3E] */
14657292Sakito KC_IGNORE, 0, 0, /* 63 [0x3F] */
14757292Sakito KC_IGNORE, 0, 0, /* 64 [0x40] */
14857292Sakito KC_IGNORE, 0, 0, /* 65 [0x41] */
14957292Sakito KC_CODE, 0x61, 0x41, /* 66 [0x42] a */
15057292Sakito KC_CODE, 0x73, 0x53, /* 67 [0x43] s */
15157292Sakito KC_CODE, 0x64, 0x44, /* 68 [0x44] d */
15257292Sakito KC_CODE, 0x66, 0x46, /* 69 [0x45] f */
15357292Sakito KC_CODE, 0x67, 0x47, /* 70 [0x46] g */
15457292Sakito KC_CODE, 0x68, 0x48, /* 71 [0x47] h */
15557292Sakito KC_CODE, 0x6A, 0x4A, /* 72 [0x48] j */
15657292Sakito KC_CODE, 0x6B, 0x4B, /* 73 [0x49] k */
15757292Sakito KC_CODE, 0x6C, 0x4C, /* 74 [0x4A] l */
15857292Sakito KC_CODE, 0x3B, 0x2B, /* 75 [0x4B] ; */
15957292Sakito KC_CODE, 0x3A, 0x2A, /* 76 [0x4C] : */
16057292Sakito KC_CODE, 0x5D, 0x7D, /* 77 [0x4D] ] */
16157292Sakito KC_IGNORE, 0, 0, /* 78 [0x4E] */
16257292Sakito KC_IGNORE, 0, 0, /* 79 [0x4F] */
16357292Sakito KC_IGNORE, 0, 0, /* 80 [0x50] */
16457292Sakito KC_IGNORE, 0, 0, /* 81 [0x51] */
16557292Sakito KC_CODE, 0x7A, 0x5A, /* 82 [0x52] z */
16657292Sakito KC_CODE, 0x78, 0x58, /* 83 [0x53] x */
16757292Sakito KC_CODE, 0x63, 0x43, /* 84 [0x54] c */
16857292Sakito KC_CODE, 0x76, 0x56, /* 85 [0x55] v */
16957292Sakito KC_CODE, 0x62, 0x42, /* 86 [0x56] b */
17057292Sakito KC_CODE, 0x6E, 0x4E, /* 87 [0x57] n */
17157292Sakito KC_CODE, 0x6D, 0x4D, /* 88 [0x58] m */
17257292Sakito KC_CODE, 0x2C, 0x3C, /* 89 [0x59] , */
17357292Sakito KC_CODE, 0x2E, 0x3E, /* 90 [0x5A] . */
17457292Sakito KC_CODE, 0x2F, 0x3F, /* 91 [0x5B] / */
17557292Sakito KC_CODE, 0x5F, 0x5F, /* 92 [0x5C] _ */
17657292Sakito KC_IGNORE, 0, 0, /* 93 [0x5D] */
17757292Sakito KC_IGNORE, 0, 0, /* 94 [0x5E] */
17857292Sakito KC_IGNORE, 0, 0, /* 95 [0x5F] */
17957292Sakito KC_IGNORE, 0, 0, /* 96 [0x60] */
18057292Sakito KC_IGNORE, 0, 0, /* 97 [0x61] */
18157292Sakito KC_IGNORE, 0, 0, /* 98 [0x62] */
18257292Sakito KC_IGNORE, 0, 0, /* 99 [0x63] */
18357292Sakito KC_IGNORE, 0, 0, /* 100 [0x64] */
18457292Sakito KC_IGNORE, 0, 0, /* 101 [0x65] */
18557292Sakito KC_IGNORE, 0, 0, /* 102 [0x66] */
18657292Sakito KC_IGNORE, 0, 0, /* 103 [0x67] */
18757292Sakito KC_IGNORE, 0, 0, /* 104 [0x68] */
18857292Sakito KC_IGNORE, 0, 0, /* 105 [0x69] */
18957292Sakito KC_IGNORE, 0, 0, /* 106 [0x6A] */
19057292Sakito KC_IGNORE, 0, 0, /* 107 [0x6B] */
19157292Sakito KC_IGNORE, 0, 0, /* 108 [0x6C] */
19257292Sakito KC_IGNORE, 0, 0, /* 109 [0x6D] */
19357292Sakito KC_IGNORE, 0, 0, /* 110 [0x6E] */
19457292Sakito KC_IGNORE, 0, 0, /* 111 [0x6F] */
19557292Sakito KC_IGNORE, 0, 0, /* 112 [0x70] */
19657292Sakito KC_IGNORE, 0, 0, /* 113 [0x71] */
19757292Sakito KC_IGNORE, 0, 0, /* 114 [0x72] */
19857292Sakito KC_IGNORE, 0, 0, /* 115 [0x73] */
19957292Sakito KC_IGNORE, 0, 0, /* 116 [0x74] */
20057292Sakito KC_IGNORE, 0, 0, /* 117 [0x75] */
20157292Sakito KC_IGNORE, 0, 0, /* 118 [0x76] */
20257292Sakito KC_IGNORE, 0, 0, /* 119 [0x77] */
20357292Sakito KC_IGNORE, 0, 0, /* 120 [0x78] */
20457292Sakito KC_IGNORE, 0, 0, /* 121 [0x79] */
20557292Sakito KC_IGNORE, 0, 0, /* 122 [0x7A] */
20657292Sakito KC_IGNORE, 0, 0, /* 123 [0x7B] */
20757292Sakito KC_IGNORE, 0, 0, /* 124 [0x7C] */
20857292Sakito KC_IGNORE, 0, 0, /* 125 [0x7D] */
20957292Sakito KC_IGNORE, 0, 0, /* 126 [0x7E] */
21057292Sakito KC_IGNORE, 0, 0, /* 127 [0x7F] */
21157292Sakito };
21257292Sakito
21357292Sakito int shift_flag = 0;
21457292Sakito int ctrl_flag = 0;
21557292Sakito int meta_flag = 0;
21657292Sakito
bmc_decode(code)21757292Sakito bmc_decode(code)
21857292Sakito register u_char code;
21957292Sakito {
22057292Sakito register unsigned int c, updown;
22157292Sakito
22257292Sakito if (code & 0x80)
22357292Sakito updown = 1;
22457292Sakito else
22557292Sakito updown = 0;
22657292Sakito
22757292Sakito code &= 0x7F;
22857292Sakito
22957292Sakito c = bmc_keymap[code].km_type;
23057292Sakito
23157292Sakito switch(c) {
23257292Sakito
23357292Sakito case KC_CODE:
23457292Sakito if (updown)
23557292Sakito c = KC_IGNORE;
23657292Sakito break;
23757292Sakito
23857292Sakito case KC_SHIFT:
23957292Sakito switch(bmc_keymap[code].km_code[0]) {
24057292Sakito case KS_SHIFT:
24157292Sakito shift_flag = 1 - updown;
24257292Sakito break;
24357292Sakito
24457292Sakito case KS_CTRL:
24557292Sakito ctrl_flag = 1 - updown;
24657292Sakito break;
24757292Sakito
24857292Sakito case KS_META:
24957292Sakito meta_flag = 1 - updown;
25057292Sakito break;
25157292Sakito }
25257292Sakito break;
25357292Sakito
25457292Sakito default:
25557292Sakito break;
25657292Sakito }
25757292Sakito
25857292Sakito c |= bmc_keymap[code].km_code[shift_flag];
25957292Sakito
26057292Sakito if (bmc_keymap[code].km_type == KC_CODE) {
26157292Sakito if (meta_flag)
26257292Sakito c |= 0x0080;
26357292Sakito if (ctrl_flag)
26457292Sakito c &= 0xFF1F;
26557292Sakito }
26657292Sakito
26757292Sakito return(c);
26857292Sakito }
26957292Sakito
27057292Sakito
27157292Sakito /*
27256876Sakito * probe routine
27356876Sakito */
27456876Sakito
bmcprobe(hd)27556876Sakito bmcprobe(hd)
27656876Sakito register struct hp_device *hd;
27756876Sakito {
27859646Sakito int unit = hd->hp_unit;
27959646Sakito register struct bmc_softc *sc = &bmc_softc[unit];
28059646Sakito register struct sio_portc *pc;
28156876Sakito
28259646Sakito if (sc->sc_pc != 0) {
28359646Sakito pc = sc->sc_pc;
28459646Sakito printf("bmc%d: port %d, address 0x%x, intr 0x%x (console)\n",
28559646Sakito pc->pc_unit, pc->pc_port, pc->pc_addr, pc->pc_intr);
28662578Sakito return(1);
28759646Sakito }
28856876Sakito
28956876Sakito /*
29056876Sakito * Check out bitmap Interface board
29156876Sakito */
29256876Sakito
29359646Sakito if (KernInter.plane == 0) {
29456876Sakito return(0);
29559646Sakito }
29656876Sakito
29756876Sakito /* locate the major number */
29856876Sakito for (bmcmajor = 0; bmcmajor < nchrdev; bmcmajor++)
29956876Sakito if (cdevsw[bmcmajor].d_open == bmcopen)
30056876Sakito break;
30156876Sakito
30259646Sakito sc->sc_pc = pc = sio_port_assign(BMC_PORT, bmcmajor, unit, bmcintr);
30356876Sakito
30459646Sakito printf("bmc%d: port %d, address 0x%x, intr 0x%x\n",
30559646Sakito pc->pc_unit, pc->pc_port, pc->pc_addr, pc->pc_intr);
30656876Sakito
30756876Sakito bmdinit();
30856876Sakito
30959646Sakito bmc_active |= 1 << unit;
31056876Sakito return(1);
31156876Sakito }
31256876Sakito
31356876Sakito /*
31456876Sakito * entry routines
31556876Sakito */
31656876Sakito
31756876Sakito /* ARGSUSED */
31856876Sakito #ifdef __STDC__
bmcopen(dev_t dev,int flag,int mode,struct proc * p)31956876Sakito bmcopen(dev_t dev, int flag, int mode, struct proc *p)
32056876Sakito #else
32156876Sakito bmcopen(dev, flag, mode, p)
32256876Sakito dev_t dev;
32356876Sakito int flag, mode;
32456876Sakito struct proc *p;
32556876Sakito #endif
32656876Sakito {
32756876Sakito register struct tty *tp;
32856876Sakito register int unit;
32956876Sakito int error = 0;
33056876Sakito
33156876Sakito unit = bmcunit(dev);
33259646Sakito
33356876Sakito if (unit >= NBMC)
33456876Sakito return (ENXIO);
33559646Sakito if ((bmc_active & (1 << unit)) == 0)
33659646Sakito return (ENXIO);
33759646Sakito
33856876Sakito tp = &bmc_tty[unit];
33956876Sakito tp->t_oproc = bmcstart;
34056876Sakito tp->t_param = bmcparam;
34156876Sakito tp->t_dev = dev;
34256876Sakito if ((tp->t_state & TS_ISOPEN) == 0) {
34356876Sakito tp->t_state |= TS_WOPEN;
34456876Sakito ttychars(tp);
34556876Sakito if (tp->t_ispeed == 0) {
34656876Sakito tp->t_iflag = TTYDEF_IFLAG;
34756876Sakito tp->t_oflag = TTYDEF_OFLAG;
34856876Sakito tp->t_cflag = TTYDEF_CFLAG;
34956876Sakito /* tp->t_cflag = (CREAD | CS8 | HUPCL); */
35056876Sakito tp->t_lflag = TTYDEF_LFLAG;
35156876Sakito tp->t_ispeed = tp->t_ospeed = bmcdefaultrate;
35256876Sakito }
35356876Sakito bmcparam(tp, &tp->t_termios);
35456876Sakito ttsetwater(tp);
35556876Sakito } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0)
35656876Sakito return (EBUSY);
35756876Sakito tp->t_state |= TS_CARR_ON;
35856876Sakito (void) spltty();
35956876Sakito while ((flag&O_NONBLOCK) == 0 && (tp->t_cflag&CLOCAL) == 0 &&
36056876Sakito (tp->t_state & TS_CARR_ON) == 0) {
36156876Sakito tp->t_state |= TS_WOPEN;
36256876Sakito if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH,
36356876Sakito ttopen, 0))
36456876Sakito break;
36556876Sakito }
36656876Sakito (void) spl0();
36756876Sakito if (error == 0)
36856876Sakito error = (*linesw[tp->t_line].l_open)(dev, tp);
36956876Sakito
37056876Sakito return (error);
37156876Sakito }
37256876Sakito
37356876Sakito /*ARGSUSED*/
bmcclose(dev,flag,mode,p)37456876Sakito bmcclose(dev, flag, mode, p)
37556876Sakito dev_t dev;
37656876Sakito int flag, mode;
37756876Sakito struct proc *p;
37856876Sakito {
37956876Sakito register struct tty *tp;
38056876Sakito register int unit;
38156876Sakito
38256876Sakito unit = bmcunit(dev);
38356876Sakito tp = &bmc_tty[unit];
38456876Sakito (*linesw[tp->t_line].l_close)(tp, flag);
38556876Sakito ttyclose(tp);
38656876Sakito return (0);
38756876Sakito }
38856876Sakito
bmcread(dev,uio,flag)38956876Sakito bmcread(dev, uio, flag)
39056876Sakito dev_t dev;
39156876Sakito struct uio *uio;
39256876Sakito {
39356876Sakito register struct tty *tp = &bmc_tty[bmcunit(dev)];
39456876Sakito
39556876Sakito return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
39656876Sakito }
39756876Sakito
bmcwrite(dev,uio,flag)39856876Sakito bmcwrite(dev, uio, flag)
39956876Sakito dev_t dev;
40056876Sakito struct uio *uio;
40156876Sakito {
40257125Sakito register int unit = bmcunit(dev);
40357125Sakito register struct tty *tp = &bmc_tty[unit];
40456876Sakito
40557125Sakito if ((unit == bmcconsole) && constty &&
40657125Sakito (constty->t_state&(TS_CARR_ON|TS_ISOPEN))==(TS_CARR_ON|TS_ISOPEN))
40757125Sakito tp = constty;
40857125Sakito
40956876Sakito return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
41056876Sakito }
41156876Sakito
41256876Sakito /*
41356876Sakito * Stop output on a line.
41456876Sakito */
41556876Sakito /*ARGSUSED*/
bmcstop(tp,flag)41656876Sakito bmcstop(tp, flag)
41756876Sakito register struct tty *tp;
41856876Sakito {
41956876Sakito register int s;
42056876Sakito
42156876Sakito s = spltty();
42256876Sakito if (tp->t_state & TS_BUSY) {
42356876Sakito if ((tp->t_state&TS_TTSTOP)==0)
42456876Sakito tp->t_state |= TS_FLUSH;
42556876Sakito }
42656876Sakito splx(s);
42756876Sakito }
42856876Sakito
bmcioctl(dev,cmd,data,flag,p)42956876Sakito bmcioctl(dev, cmd, data, flag, p)
43056876Sakito dev_t dev;
43156876Sakito int cmd;
43256876Sakito caddr_t data;
43356876Sakito int flag;
43456876Sakito struct proc *p;
43556876Sakito {
43656876Sakito register struct tty *tp;
43756876Sakito register int unit = bmcunit(dev);
43856876Sakito register int error;
43956876Sakito
44056876Sakito tp = &bmc_tty[unit];
44156876Sakito error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
44256876Sakito if (error >= 0)
44356876Sakito return (error);
44456876Sakito error = ttioctl(tp, cmd, data, flag);
44556876Sakito if (error >= 0)
44656876Sakito return (error);
44756876Sakito
44856876Sakito switch (cmd) {
44956876Sakito default:
45056876Sakito return (ENOTTY);
45156876Sakito }
45256876Sakito return (0);
45356876Sakito }
45456876Sakito
45556876Sakito /*
45656876Sakito *
45756876Sakito */
45856876Sakito void
bmcstart(tp)45956876Sakito bmcstart(tp)
46056876Sakito register struct tty *tp;
46156876Sakito {
46256876Sakito int unit = bmcunit(tp->t_dev);
46356876Sakito register struct bmc_softc *sc = &bmc_softc[unit];
46456876Sakito register int cc, s;
46556876Sakito int hiwat = 0;
46656876Sakito
46756876Sakito s = spltty();
46856876Sakito if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
46956876Sakito splx(s);
47056876Sakito return;
47156876Sakito }
47256876Sakito tp->t_state |= TS_BUSY;
47356876Sakito cc = tp->t_outq.c_cc;
47456876Sakito if (cc <= tp->t_lowat) {
47556876Sakito if (tp->t_state & TS_ASLEEP) {
47656876Sakito tp->t_state &= ~TS_ASLEEP;
47756876Sakito wakeup((caddr_t)&tp->t_outq);
47856876Sakito }
47956876Sakito selwakeup(&tp->t_wsel);
48056876Sakito }
48156876Sakito /*
48256876Sakito * Limit the amount of output we do in one burst
48356876Sakito * to prevent hogging the CPU.
48456876Sakito */
48556876Sakito while (--cc >= 0) {
48656876Sakito register int c;
48756876Sakito
48856876Sakito c = getc(&tp->t_outq);
48956876Sakito /*
49056876Sakito * iteputchar() may take a long time and we don't want to
49156876Sakito * block all interrupts for long periods of time. Since
49256876Sakito * there is no need to stay at high priority while outputing
49356876Sakito * the character (since we don't have to worry about
49456876Sakito * interrupts), we don't. We just need to make sure that
49556876Sakito * we don't reenter iteputchar, which is guarenteed by the
49656876Sakito * earlier setting of TS_BUSY.
49756876Sakito */
49856876Sakito splx(s);
49956876Sakito bmdputc(c & sc->sc_mask);
50056876Sakito spltty();
50156876Sakito }
50256876Sakito tp->t_state &= ~TS_BUSY;
50356876Sakito splx(s);
50456876Sakito }
50556876Sakito
bmcparam(tp,t)50656876Sakito bmcparam(tp, t)
50756876Sakito register struct tty *tp;
50856876Sakito register struct termios *t;
50956876Sakito {
51056876Sakito int unit = bmcunit(tp->t_dev);
51156876Sakito register struct bmc_softc *sc = &bmc_softc[unit];
51256876Sakito register int cflag = t->c_cflag;
51356876Sakito
51456876Sakito /* and copy to tty */
51556876Sakito tp->t_ispeed = t->c_ispeed;
51656876Sakito tp->t_ospeed = t->c_ospeed;
51756876Sakito tp->t_cflag = cflag;
51856876Sakito
51956876Sakito /*
52056876Sakito * change line speed
52156876Sakito */
52256876Sakito
52356876Sakito switch (cflag&CSIZE) {
52456876Sakito case CS5:
52556876Sakito sc->sc_mask = 0x1F ; break;
52656876Sakito case CS6:
52756876Sakito sc->sc_mask = 0x3F ; break;
52856876Sakito case CS7:
52956876Sakito sc->sc_mask = 0x7F ; break;
53056876Sakito case CS8:
53156876Sakito sc->sc_mask = 0xFF ; break;
53256876Sakito }
53356876Sakito
53456876Sakito /*
53556876Sakito * parity
53656876Sakito */
53756876Sakito
53856876Sakito /*
53956876Sakito * stop bit
54056876Sakito */
54156876Sakito
54256876Sakito return (0);
54356876Sakito }
54456876Sakito
54556876Sakito
54656876Sakito /*
54756876Sakito * interrupt handling
54856876Sakito */
54956876Sakito
bmcintr(unit)55056876Sakito bmcintr(unit)
55156876Sakito register int unit;
55256876Sakito {
55356876Sakito register struct siodevice *sio = bmc_softc[unit].sc_pc->pc_addr;
55456876Sakito register struct tty *tp;
55556876Sakito register u_char code;
55656876Sakito register int c;
55756876Sakito int s, rr;
55856876Sakito
55956876Sakito tp = &bmc_tty[unit];
56056876Sakito rr = siogetreg(sio);
56156876Sakito
56256876Sakito if (rr & RR_RXRDY) {
56356876Sakito code = sio->sio_data;
56457292Sakito c = bmc_decode(code);
56556876Sakito if (c & KC_TYPE) /* skip special codes */
56656876Sakito return;
56756876Sakito code = (c & KC_CHAR);
56856876Sakito if ((tp->t_state & TS_ISOPEN) != 0)
56956876Sakito (*linesw[tp->t_line].l_rint)(code, tp);
57056876Sakito }
57157849Sakito
57257849Sakito if (rr & RR_TXRDY) {
57357849Sakito sio->sio_cmd = WR0_RSTPEND;
57457849Sakito }
57556876Sakito }
57656876Sakito
57756876Sakito /*
57856876Sakito * Following are all routines needed for SIO to act as console
57956876Sakito */
58056876Sakito
bmccnprobe(cp)58156876Sakito bmccnprobe(cp)
58256876Sakito register struct consdev *cp;
58356876Sakito {
58456876Sakito
58559646Sakito if ((KernInter.dipsw & KIFF_DIPSW_NOBM) || (KernInter.plane == 0)) {
58659646Sakito cp->cn_pri = CN_DEAD;
58759646Sakito return;
58859646Sakito }
58959646Sakito
59056876Sakito /* locate the major number */
59156876Sakito for (bmcmajor = 0; bmcmajor < nchrdev; bmcmajor++)
59256876Sakito if (cdevsw[bmcmajor].d_open == bmcopen)
59356876Sakito break;
59459646Sakito
59556876Sakito /* initialize required fields */
59656876Sakito cp->cn_dev = makedev(bmcmajor, 0);
59756876Sakito cp->cn_tp = &bmc_tty[0];
59856876Sakito cp->cn_pri = CN_INTERNAL;
59956876Sakito }
60056876Sakito
60156876Sakito bmccninit(cp)
60256876Sakito struct consdev *cp;
60356876Sakito {
60456876Sakito int unit = bmcunit(cp->cn_dev);
60556876Sakito register struct bmc_softc *sc = &bmc_softc[0];
60656876Sakito
60756876Sakito sioinit((struct siodevice *) SIO_HARDADDR, bmcdefaultrate);
60859646Sakito
60956876Sakito bmdinit();
61056876Sakito
61156876Sakito /* port assign */
61259646Sakito sc->sc_pc = sio_port_assign(BMC_PORT, bmcmajor, 0, bmcintr);
61356876Sakito
61456876Sakito bmcconsole = unit;
61559646Sakito bmc_active |= 1 << unit;
61656876Sakito }
61756876Sakito
bmccngetc(dev)61856876Sakito bmccngetc(dev)
61956876Sakito dev_t dev;
62056876Sakito {
62156876Sakito struct bmc_softc *sc = &bmc_softc[bmcunit(dev)];
62256876Sakito struct sio_portc *pc = sc->sc_pc;
62356876Sakito register int c;
62456876Sakito register u_char code;
62556876Sakito
62656876Sakito do {
62756876Sakito code = sio_imgetc(pc->pc_addr);
62857292Sakito } while ((c = bmc_decode(code)) & KC_TYPE);
62956876Sakito
63056876Sakito return(c);
63156876Sakito }
63256876Sakito
bmccnputc(dev,c)63356876Sakito bmccnputc(dev, c)
63456876Sakito dev_t dev;
63556876Sakito int c;
63656876Sakito {
63756876Sakito struct bmc_softc *sc = &bmc_softc[bmcunit(dev)];
63856876Sakito struct sio_portc *pc = sc->sc_pc;
63956876Sakito
64056876Sakito bmdputc(c);
64156876Sakito }
64256876Sakito #endif
643