xref: /onnv-gate/usr/src/uts/common/sys/kbtrans.h (revision 10617:ae54b3d31f50)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51272Slq150181  * Common Development and Distribution License (the "License").
61272Slq150181  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211272Slq150181 
220Sstevel@tonic-gate /*
23*10617SPengcheng.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_KBTRANS_H
280Sstevel@tonic-gate #define	_SYS_KBTRANS_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * Interface between hardware keyboard driver and generic keyboard
320Sstevel@tonic-gate  * translation module.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef __cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/consdev.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
423366Sqz150045  * The default value (0) indicates that the keyboard layout isn't
433366Sqz150045  * configured in kernel.
440Sstevel@tonic-gate  */
453366Sqz150045 #define	KBTRANS_USBKB_DEFAULT_LAYOUT	0
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate  * Maximum of keys in a keyboard
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate #define	KBTRANS_KEYNUMS_MAX		255
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Do not expose the internals of these structures to kbtrans clients
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate struct kbtrans_hardware;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate struct kbtrans;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate enum kbtrans_message_response {
600Sstevel@tonic-gate 	KBTRANS_MESSAGE_HANDLED = 0,
610Sstevel@tonic-gate 	KBTRANS_MESSAGE_NOT_HANDLED = 1
620Sstevel@tonic-gate };
630Sstevel@tonic-gate 
640Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *,
650Sstevel@tonic-gate 			kbtrans_key_t *, enum keystate *);
660Sstevel@tonic-gate struct hw_polledio {
670Sstevel@tonic-gate 	void *polled_argument;
680Sstevel@tonic-gate 	polled_keycode_func *polled_keycode;
690Sstevel@tonic-gate };
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * Callbacks registered by the hardware specific driver/module
750Sstevel@tonic-gate  */
760Sstevel@tonic-gate struct kbtrans_callbacks {
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	/* Routine to set the LED's in non-polled mode */
790Sstevel@tonic-gate 	void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int);
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	/* Routine to set the LED's in polled mode */
820Sstevel@tonic-gate 	void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int);
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	/* Routine to indicate that a scande is available in polled mode */
850Sstevel@tonic-gate 	boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *,
860Sstevel@tonic-gate 		kbtrans_key_t *, enum keystate *);
870Sstevel@tonic-gate };
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * kbtrans_streams_init():
910Sstevel@tonic-gate  *
920Sstevel@tonic-gate  * Initializes the generic keyboard translation module.  Must be
930Sstevel@tonic-gate  * called from the hardware module's open(9e) routine.
940Sstevel@tonic-gate  *
950Sstevel@tonic-gate  * Arguments:
960Sstevel@tonic-gate  *	- queue_t *q
970Sstevel@tonic-gate  *       	The read queue.
980Sstevel@tonic-gate  *
990Sstevel@tonic-gate  *   	- int sflag
1000Sstevel@tonic-gate  *        	sflag from the streams open routine
1010Sstevel@tonic-gate  *
1020Sstevel@tonic-gate  *   	- struct kbtrans_hardware *hw
1030Sstevel@tonic-gate  *       	hardware-specific data, passed to hardware callbacks
1040Sstevel@tonic-gate  *
1050Sstevel@tonic-gate  *    	- struct kbtrans_callbacks *hw_callbacks
1060Sstevel@tonic-gate  *       	hardware support callbacks (see below)
1070Sstevel@tonic-gate  *
1080Sstevel@tonic-gate  *    	- struct kbtrans **kbtrans
1090Sstevel@tonic-gate  *        	returned state structure pointer
1100Sstevel@tonic-gate  *
1110Sstevel@tonic-gate  *    	- int initial_leds
1120Sstevel@tonic-gate  *    	- int initial_led_mask
1130Sstevel@tonic-gate  *        	Provides state information (if available) about the current
1140Sstevel@tonic-gate  *        	keyboard state, in the form of LED state.  initial_leds shows
1150Sstevel@tonic-gate  *        	which LEDs are lit; initial_led_mask shows which bits in
1160Sstevel@tonic-gate  *        	initial_leds are valid.  This mechanism exists primarily to
1170Sstevel@tonic-gate  *        	retain the existing state of NumLock across the transition
1180Sstevel@tonic-gate  *       	from firmware to the OS.
1190Sstevel@tonic-gate  */
120*10617SPengcheng.Chen@Sun.COM extern int kbtrans_streams_init(queue_t *, int, struct kbtrans_hardware *,
121*10617SPengcheng.Chen@Sun.COM 	struct kbtrans_callbacks *, struct kbtrans **, int, int);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * kbtrans_streams_fini():
1250Sstevel@tonic-gate  *
1260Sstevel@tonic-gate  * Shuts down the generic translation module.  Must be called from
1270Sstevel@tonic-gate  * the hardware module's close(9e) routine.
1280Sstevel@tonic-gate  */
1290Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *);
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * kbtrans_streams_message():
1330Sstevel@tonic-gate  *
1340Sstevel@tonic-gate  * The hardware module should pass all streams messages received from
1350Sstevel@tonic-gate  * above to this routine.  The generic translation module will process
1360Sstevel@tonic-gate  * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that
1370Sstevel@tonic-gate  * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that
1380Sstevel@tonic-gate  * it did not handle.  For KBTRANS_MESSAGE_HANDLED, the hardware module
1390Sstevel@tonic-gate  * should take no further action on the message.  For
1400Sstevel@tonic-gate  * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for
1410Sstevel@tonic-gate  * any action, including returning an appropriate error.
1420Sstevel@tonic-gate  *
1430Sstevel@tonic-gate  * Must be called from the hardware module's write put(9e) or srv(9e)
1440Sstevel@tonic-gate  * routine.
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *,
1470Sstevel@tonic-gate 	mblk_t *);
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * kbtrans_streams_key():
1510Sstevel@tonic-gate  *
1520Sstevel@tonic-gate  * When a key is pressed or released, the hardware module should
1530Sstevel@tonic-gate  * call kbtrans, passing the key number and its new
1540Sstevel@tonic-gate  * state.  kbtrans is responsible for autorepeat handling;
1550Sstevel@tonic-gate  * the hardware module should report only actual press/release
1560Sstevel@tonic-gate  * events, suppressing any hardware-generated autorepeat.
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key,
1590Sstevel@tonic-gate 	enum keystate state);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * kbtrans_streams_set_keyboard():
1630Sstevel@tonic-gate  *
1640Sstevel@tonic-gate  * At any time after calling kbtrans_streams_init, the hardware
1650Sstevel@tonic-gate  * module should make this call to report the type of keyboard
1660Sstevel@tonic-gate  * attached.  "type" is the keyboard type, typically KB_SUN4,
1670Sstevel@tonic-gate  * KB_PC, or KB_USB.
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int,
1700Sstevel@tonic-gate 	struct keyboard *);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * kbtrans_streams_has_reset():
1740Sstevel@tonic-gate  *
1750Sstevel@tonic-gate  * At any time between kbtrans_streams_init and kbtrans_streams_fini,
1760Sstevel@tonic-gate  * the hardware module can call this routine to report that the
1770Sstevel@tonic-gate  * keyboard has been reset, e.g. by being unplugged and reattached.
1780Sstevel@tonic-gate  *
1790Sstevel@tonic-gate  * This function is for use by keyboard devices that do not formally
1800Sstevel@tonic-gate  * support hotplug.  If the keyboard hardware spontaneously resets
1810Sstevel@tonic-gate  * itself in a case other than hotplug, this routine is called to
1820Sstevel@tonic-gate  * report the rest.
1830Sstevel@tonic-gate  *
1840Sstevel@tonic-gate  */
1850Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *);
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate  * kbtrans_ischar():
1890Sstevel@tonic-gate  * kbtrans_getchar():
1900Sstevel@tonic-gate  *
1910Sstevel@tonic-gate  * These routines are used for polled input, e.g. for kmdb or PROM
1920Sstevel@tonic-gate  * input.  Note that, with suitable casting, these routines are usable
1930Sstevel@tonic-gate  * as CONSOPENPOLLEDIO routines.
1940Sstevel@tonic-gate  *
1950Sstevel@tonic-gate  * May only be called from single-threaded code, e.g. kmdb.
1960Sstevel@tonic-gate  */
1970Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *);
1980Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *);
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * kbtrans_streams_enable():
2020Sstevel@tonic-gate  *	Routine to be called from the hardware specific module when
2030Sstevel@tonic-gate  * 	the stream is ready to take messages.
2040Sstevel@tonic-gate  */
2050Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *);
2060Sstevel@tonic-gate 
2071272Slq150181 /*
2081272Slq150181  * kbtrans_streams_setled():
2091272Slq150181  *	Routine to be called to only update the led state in kbtrans.
2101272Slq150181  */
2111272Slq150181 extern void kbtrans_streams_setled(struct kbtrans *, int);
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate /*
2140Sstevel@tonic-gate  * kbtrans_streams_releaseall():
2150Sstevel@tonic-gate  *	Release all the keys that are held down.
2160Sstevel@tonic-gate  */
2170Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate  * kbtrans_streams_set_queue():
2210Sstevel@tonic-gate  *      Change the queue above the device, to support multiplexors.
2220Sstevel@tonic-gate  */
2230Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate /*
2260Sstevel@tonic-gate  * kbtrans_streams_get_queue():
2270Sstevel@tonic-gate  * Retrieve the current queue above the device.
2280Sstevel@tonic-gate  */
2290Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *);
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate  * kbtrans_streams_untimeout():
2330Sstevel@tonic-gate  * Clear timeout
2340Sstevel@tonic-gate  */
2350Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *);
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate #ifdef __cplusplus
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate #endif
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */
242