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