xref: /onnv-gate/usr/src/uts/common/sys/kbtrans.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _SYS_KBTRANS_H
28*0Sstevel@tonic-gate #define	_SYS_KBTRANS_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Interface between hardware keyboard driver and generic keyboard
34*0Sstevel@tonic-gate  * translation module.
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifdef __cplusplus
38*0Sstevel@tonic-gate extern "C" {
39*0Sstevel@tonic-gate #endif
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #include <sys/consdev.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * By default, set conskbd's layout to US
45*0Sstevel@tonic-gate  */
46*0Sstevel@tonic-gate #define	KBTRANS_USBKB_LAYOUT_US		0x21
47*0Sstevel@tonic-gate #define	KBTRANS_USBKB_DEFAULT_LAYOUT	KBTRANS_USBKB_LAYOUT_US
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  * Maximum of keys in a keyboard
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate #define	KBTRANS_KEYNUMS_MAX		255
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * Do not expose the internals of these structures to kbtrans clients
56*0Sstevel@tonic-gate  */
57*0Sstevel@tonic-gate struct kbtrans_hardware;
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate struct kbtrans;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate enum kbtrans_message_response {
62*0Sstevel@tonic-gate 	KBTRANS_MESSAGE_HANDLED = 0,
63*0Sstevel@tonic-gate 	KBTRANS_MESSAGE_NOT_HANDLED = 1
64*0Sstevel@tonic-gate };
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *,
67*0Sstevel@tonic-gate 			kbtrans_key_t *, enum keystate *);
68*0Sstevel@tonic-gate struct hw_polledio {
69*0Sstevel@tonic-gate 	void *polled_argument;
70*0Sstevel@tonic-gate 	polled_keycode_func *polled_keycode;
71*0Sstevel@tonic-gate };
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate  * Callbacks registered by the hardware specific driver/module
77*0Sstevel@tonic-gate  */
78*0Sstevel@tonic-gate struct kbtrans_callbacks {
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	/* Routine to set the LED's in non-polled mode */
81*0Sstevel@tonic-gate 	void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int);
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 	/* Routine to set the LED's in polled mode */
84*0Sstevel@tonic-gate 	void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int);
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	/* Routine to indicate that a scande is available in polled mode */
87*0Sstevel@tonic-gate 	boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *,
88*0Sstevel@tonic-gate 		kbtrans_key_t *, enum keystate *);
89*0Sstevel@tonic-gate };
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate /*
92*0Sstevel@tonic-gate  * kbtrans_streams_init():
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  * Initializes the generic keyboard translation module.  Must be
95*0Sstevel@tonic-gate  * called from the hardware module's open(9e) routine.
96*0Sstevel@tonic-gate  *
97*0Sstevel@tonic-gate  * Arguments:
98*0Sstevel@tonic-gate  *	- queue_t *q
99*0Sstevel@tonic-gate  *       	The read queue.
100*0Sstevel@tonic-gate  *
101*0Sstevel@tonic-gate  *   	- int sflag
102*0Sstevel@tonic-gate  *        	sflag from the streams open routine
103*0Sstevel@tonic-gate  *
104*0Sstevel@tonic-gate  *   	- cred_t *crp
105*0Sstevel@tonic-gate  *        	credentials from open
106*0Sstevel@tonic-gate  *
107*0Sstevel@tonic-gate  *   	- struct kbtrans_hardware *hw
108*0Sstevel@tonic-gate  *       	hardware-specific data, passed to hardware callbacks
109*0Sstevel@tonic-gate  *
110*0Sstevel@tonic-gate  *    	- struct kbtrans_callbacks *hw_callbacks
111*0Sstevel@tonic-gate  *       	hardware support callbacks (see below)
112*0Sstevel@tonic-gate  *
113*0Sstevel@tonic-gate  *    	- struct kbtrans **kbtrans
114*0Sstevel@tonic-gate  *        	returned state structure pointer
115*0Sstevel@tonic-gate  *
116*0Sstevel@tonic-gate  *    	- int initial_leds
117*0Sstevel@tonic-gate  *    	- int initial_led_mask
118*0Sstevel@tonic-gate  *        	Provides state information (if available) about the current
119*0Sstevel@tonic-gate  *        	keyboard state, in the form of LED state.  initial_leds shows
120*0Sstevel@tonic-gate  *        	which LEDs are lit; initial_led_mask shows which bits in
121*0Sstevel@tonic-gate  *        	initial_leds are valid.  This mechanism exists primarily to
122*0Sstevel@tonic-gate  *        	retain the existing state of NumLock across the transition
123*0Sstevel@tonic-gate  *       	from firmware to the OS.
124*0Sstevel@tonic-gate  */
125*0Sstevel@tonic-gate extern int kbtrans_streams_init(queue_t *, int, cred_t *,
126*0Sstevel@tonic-gate 	struct kbtrans_hardware *, struct kbtrans_callbacks *,
127*0Sstevel@tonic-gate 	struct kbtrans **, int, int);
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate /*
130*0Sstevel@tonic-gate  * kbtrans_streams_fini():
131*0Sstevel@tonic-gate  *
132*0Sstevel@tonic-gate  * Shuts down the generic translation module.  Must be called from
133*0Sstevel@tonic-gate  * the hardware module's close(9e) routine.
134*0Sstevel@tonic-gate  */
135*0Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *);
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate /*
138*0Sstevel@tonic-gate  * kbtrans_streams_message():
139*0Sstevel@tonic-gate  *
140*0Sstevel@tonic-gate  * The hardware module should pass all streams messages received from
141*0Sstevel@tonic-gate  * above to this routine.  The generic translation module will process
142*0Sstevel@tonic-gate  * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that
143*0Sstevel@tonic-gate  * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that
144*0Sstevel@tonic-gate  * it did not handle.  For KBTRANS_MESSAGE_HANDLED, the hardware module
145*0Sstevel@tonic-gate  * should take no further action on the message.  For
146*0Sstevel@tonic-gate  * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for
147*0Sstevel@tonic-gate  * any action, including returning an appropriate error.
148*0Sstevel@tonic-gate  *
149*0Sstevel@tonic-gate  * Must be called from the hardware module's write put(9e) or srv(9e)
150*0Sstevel@tonic-gate  * routine.
151*0Sstevel@tonic-gate  */
152*0Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *,
153*0Sstevel@tonic-gate 	mblk_t *);
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate /*
156*0Sstevel@tonic-gate  * kbtrans_streams_key():
157*0Sstevel@tonic-gate  *
158*0Sstevel@tonic-gate  * When a key is pressed or released, the hardware module should
159*0Sstevel@tonic-gate  * call kbtrans, passing the key number and its new
160*0Sstevel@tonic-gate  * state.  kbtrans is responsible for autorepeat handling;
161*0Sstevel@tonic-gate  * the hardware module should report only actual press/release
162*0Sstevel@tonic-gate  * events, suppressing any hardware-generated autorepeat.
163*0Sstevel@tonic-gate  */
164*0Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key,
165*0Sstevel@tonic-gate 	enum keystate state);
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate /*
168*0Sstevel@tonic-gate  * kbtrans_streams_set_keyboard():
169*0Sstevel@tonic-gate  *
170*0Sstevel@tonic-gate  * At any time after calling kbtrans_streams_init, the hardware
171*0Sstevel@tonic-gate  * module should make this call to report the type of keyboard
172*0Sstevel@tonic-gate  * attached.  "type" is the keyboard type, typically KB_SUN4,
173*0Sstevel@tonic-gate  * KB_PC, or KB_USB.
174*0Sstevel@tonic-gate  */
175*0Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int,
176*0Sstevel@tonic-gate 	struct keyboard *);
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate /*
179*0Sstevel@tonic-gate  * kbtrans_streams_has_reset():
180*0Sstevel@tonic-gate  *
181*0Sstevel@tonic-gate  * At any time between kbtrans_streams_init and kbtrans_streams_fini,
182*0Sstevel@tonic-gate  * the hardware module can call this routine to report that the
183*0Sstevel@tonic-gate  * keyboard has been reset, e.g. by being unplugged and reattached.
184*0Sstevel@tonic-gate  *
185*0Sstevel@tonic-gate  * This function is for use by keyboard devices that do not formally
186*0Sstevel@tonic-gate  * support hotplug.  If the keyboard hardware spontaneously resets
187*0Sstevel@tonic-gate  * itself in a case other than hotplug, this routine is called to
188*0Sstevel@tonic-gate  * report the rest.
189*0Sstevel@tonic-gate  *
190*0Sstevel@tonic-gate  */
191*0Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate /*
194*0Sstevel@tonic-gate  * kbtrans_ischar():
195*0Sstevel@tonic-gate  * kbtrans_getchar():
196*0Sstevel@tonic-gate  *
197*0Sstevel@tonic-gate  * These routines are used for polled input, e.g. for kmdb or PROM
198*0Sstevel@tonic-gate  * input.  Note that, with suitable casting, these routines are usable
199*0Sstevel@tonic-gate  * as CONSOPENPOLLEDIO routines.
200*0Sstevel@tonic-gate  *
201*0Sstevel@tonic-gate  * May only be called from single-threaded code, e.g. kmdb.
202*0Sstevel@tonic-gate  */
203*0Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *);
204*0Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *);
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate /*
207*0Sstevel@tonic-gate  * kbtrans_streams_enable():
208*0Sstevel@tonic-gate  *	Routine to be called from the hardware specific module when
209*0Sstevel@tonic-gate  * 	the stream is ready to take messages.
210*0Sstevel@tonic-gate  */
211*0Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *);
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate /*
215*0Sstevel@tonic-gate  * kbtrans_streams_releaseall():
216*0Sstevel@tonic-gate  *	Release all the keys that are held down.
217*0Sstevel@tonic-gate  */
218*0Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *);
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate /*
221*0Sstevel@tonic-gate  * kbtrans_streams_set_queue():
222*0Sstevel@tonic-gate  *      Change the queue above the device, to support multiplexors.
223*0Sstevel@tonic-gate  */
224*0Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate /*
227*0Sstevel@tonic-gate  * kbtrans_streams_get_queue():
228*0Sstevel@tonic-gate  * Retrieve the current queue above the device.
229*0Sstevel@tonic-gate  */
230*0Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *);
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate /*
233*0Sstevel@tonic-gate  * kbtrans_streams_untimeout():
234*0Sstevel@tonic-gate  * Clear timeout
235*0Sstevel@tonic-gate  */
236*0Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *);
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate #ifdef __cplusplus
239*0Sstevel@tonic-gate }
240*0Sstevel@tonic-gate #endif
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */
243