kbdvar.h revision 1.7.6.1 1 /* $NetBSD: kbdvar.h,v 1.7.6.1 2001/10/11 00:02:27 fvdl Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)kbd.c 8.2 (Berkeley) 10/30/93
45 */
46
47 #include <sys/callout.h>
48
49 /*
50 * How many input characters we can buffer.
51 * The port-specific var.h may override this.
52 * Note: must be a power of two!
53 */
54 #define KBD_RX_RING_SIZE 256
55 #define KBD_RX_RING_MASK (KBD_RX_RING_SIZE-1)
56 /*
57 * Output buffer. Only need a few chars.
58 */
59 #define KBD_TX_RING_SIZE 16
60 #define KBD_TX_RING_MASK (KBD_TX_RING_SIZE-1)
61 /*
62 * Keyboard serial line speed is fixed at 1200 bps.
63 */
64 #define KBD_BPS 1200
65 #define KBD_RESET_TIMO 1000 /* mS. */
66
67 /*
68 * XXX - Historical comment - no longer quite right...
69 * Keyboard driver state. The ascii and kbd links go up and down and
70 * we just sit in the middle doing translation. Note that it is possible
71 * to get just one of the two links, in which case /dev/kbd is unavailable.
72 * The downlink supplies us with `internal' open and close routines which
73 * will enable dataflow across the downlink. We promise to call open when
74 * we are willing to take keystrokes, and to call close when we are not.
75 * If /dev/kbd is not the console tty input source, we do this whenever
76 * /dev/kbd is in use; otherwise we just leave it open forever.
77 */
78 struct zs_chanstate;
79 struct ucom_softc;
80 struct vnode;
81
82 struct kbd_softc {
83 struct device k_dev; /* required first: base device */
84
85 /* Stuff our parent setup */
86 union {
87 struct zs_chanstate *ku_cs;
88 struct ucom_softc *ku_usc;
89 void *ku_priv;
90 } k_u;
91 #define k_cs k_u.ku_cs
92 #define k_usc k_u.ku_usc
93 #define k_priv k_u.ku_priv
94
95 /*
96 * The deviopen and deviclose routines are provided
97 * by the lower level driver and used as a back door
98 * when opening and closing the internal device.
99 */
100 int (*k_deviopen) __P((struct device *, int, struct vnode *));
101 int (*k_deviclose) __P((struct device *, int, struct vnode *));
102 void (*k_write_data) __P((struct kbd_softc *, int));
103
104 dev_t k_rdev;
105 struct vnode *k_devvp;
106
107 /* Flags to communicate with kbd_softint() */
108 volatile int k_intr_flags;
109 #define INTR_RX_OVERRUN 1
110 #define INTR_TX_EMPTY 2
111 #define INTR_ST_CHECK 4
112
113 /* Transmit state */
114 volatile int k_txflags;
115 #define K_TXBUSY 1
116 #define K_TXWANT 2
117
118 /*
119 * State of upper interface.
120 */
121 int k_isopen; /* set if open has been done */
122 int k_evmode; /* set if we should produce events */
123 struct evvar k_events; /* event queue state */
124
125 /*
126 * ACSI translation state
127 */
128 int k_repeat_start; /* initial delay */
129 int k_repeat_step; /* inter-char delay */
130 int k_repeatsym; /* repeating symbol */
131 int k_repeating; /* we've called timeout() */
132 struct kbd_state k_state; /* ASCII translation state */
133
134 struct callout k_repeat_ch;
135
136 /* Console hooks */
137 char k_isconsole;
138 struct cons_channel *k_cc;
139
140 /*
141 * Magic sequence stuff (L1-A)
142 */
143 char k_magic1_down;
144 u_char k_magic1; /* L1 */
145 u_char k_magic2; /* A */
146
147 /*
148 * The transmit ring buffer.
149 */
150 volatile u_int k_tbget; /* transmit buffer `get' index */
151 volatile u_int k_tbput; /* transmit buffer `put' index */
152 u_char k_tbuf[KBD_TX_RING_SIZE]; /* data */
153
154 /*
155 * The receive ring buffer.
156 */
157 u_int k_rbget; /* ring buffer `get' index */
158 volatile u_int k_rbput; /* ring buffer `put' index */
159 u_short k_rbuf[KBD_RX_RING_SIZE]; /* rr1, data pairs */
160
161 };
162
163 /* functions used between backend/frontend keyboard drivers */
164 void kbd_input_raw __P((struct kbd_softc *k, int));
165 void kbd_output(struct kbd_softc *k, int c);
166 void kbd_start_tx(struct kbd_softc *k);
167 int kbd_cc_open __P((struct cons_channel *, struct vnode *));
168 int kbd_cc_close __P((struct cons_channel *, struct vnode *));
169
170 /*
171 * kbd console input channel interface.
172 * XXX - does not belong in this header; but for now, kbd is the only user..
173 */
174 struct cons_channel {
175 /* Provided by lower driver */
176 void *cc_dev; /* Lower device private data */
177 struct callout cc_callout;
178 int (*cc_iopen) /* Open lower device */
179 __P((struct cons_channel *, struct vnode *));
180 int (*cc_iclose) /* Close lower device */
181 __P((struct cons_channel *, struct vnode *));
182
183 /* Provided by upper driver */
184 void (*cc_upstream)__P((int)); /* Send a character upstream */
185 };
186
187 /* Special hook to attach the keyboard driver to the console */
188 void cons_attach_input __P((struct cons_channel *, struct consdev *));
189