xref: /titanic_53/usr/src/uts/common/sys/kbtrans.h (revision 02b00a1531d0ffe22af35bee73e2cd4e00c1733b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
599d47a04Slq150181  * Common Development and Distribution License (the "License").
699d47a04Slq150181  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2199d47a04Slq150181 
227c478bd9Sstevel@tonic-gate /*
23*02b00a15Sqz150045  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_KBTRANS_H
287c478bd9Sstevel@tonic-gate #define	_SYS_KBTRANS_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Interface between hardware keyboard driver and generic keyboard
347c478bd9Sstevel@tonic-gate  * translation module.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
44*02b00a15Sqz150045  * The default value (0) indicates that the keyboard layout isn't
45*02b00a15Sqz150045  * configured in kernel.
467c478bd9Sstevel@tonic-gate  */
47*02b00a15Sqz150045 #define	KBTRANS_USBKB_DEFAULT_LAYOUT	0
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Maximum of keys in a keyboard
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	KBTRANS_KEYNUMS_MAX		255
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Do not expose the internals of these structures to kbtrans clients
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate struct kbtrans_hardware;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate struct kbtrans;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate enum kbtrans_message_response {
627c478bd9Sstevel@tonic-gate 	KBTRANS_MESSAGE_HANDLED = 0,
637c478bd9Sstevel@tonic-gate 	KBTRANS_MESSAGE_NOT_HANDLED = 1
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *,
677c478bd9Sstevel@tonic-gate 			kbtrans_key_t *, enum keystate *);
687c478bd9Sstevel@tonic-gate struct hw_polledio {
697c478bd9Sstevel@tonic-gate 	void *polled_argument;
707c478bd9Sstevel@tonic-gate 	polled_keycode_func *polled_keycode;
717c478bd9Sstevel@tonic-gate };
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Callbacks registered by the hardware specific driver/module
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate struct kbtrans_callbacks {
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/* Routine to set the LED's in non-polled mode */
817c478bd9Sstevel@tonic-gate 	void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/* Routine to set the LED's in polled mode */
847c478bd9Sstevel@tonic-gate 	void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	/* Routine to indicate that a scande is available in polled mode */
877c478bd9Sstevel@tonic-gate 	boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *,
887c478bd9Sstevel@tonic-gate 		kbtrans_key_t *, enum keystate *);
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * kbtrans_streams_init():
937c478bd9Sstevel@tonic-gate  *
947c478bd9Sstevel@tonic-gate  * Initializes the generic keyboard translation module.  Must be
957c478bd9Sstevel@tonic-gate  * called from the hardware module's open(9e) routine.
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * Arguments:
987c478bd9Sstevel@tonic-gate  *	- queue_t *q
997c478bd9Sstevel@tonic-gate  *       	The read queue.
1007c478bd9Sstevel@tonic-gate  *
1017c478bd9Sstevel@tonic-gate  *   	- int sflag
1027c478bd9Sstevel@tonic-gate  *        	sflag from the streams open routine
1037c478bd9Sstevel@tonic-gate  *
1047c478bd9Sstevel@tonic-gate  *   	- cred_t *crp
1057c478bd9Sstevel@tonic-gate  *        	credentials from open
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  *   	- struct kbtrans_hardware *hw
1087c478bd9Sstevel@tonic-gate  *       	hardware-specific data, passed to hardware callbacks
1097c478bd9Sstevel@tonic-gate  *
1107c478bd9Sstevel@tonic-gate  *    	- struct kbtrans_callbacks *hw_callbacks
1117c478bd9Sstevel@tonic-gate  *       	hardware support callbacks (see below)
1127c478bd9Sstevel@tonic-gate  *
1137c478bd9Sstevel@tonic-gate  *    	- struct kbtrans **kbtrans
1147c478bd9Sstevel@tonic-gate  *        	returned state structure pointer
1157c478bd9Sstevel@tonic-gate  *
1167c478bd9Sstevel@tonic-gate  *    	- int initial_leds
1177c478bd9Sstevel@tonic-gate  *    	- int initial_led_mask
1187c478bd9Sstevel@tonic-gate  *        	Provides state information (if available) about the current
1197c478bd9Sstevel@tonic-gate  *        	keyboard state, in the form of LED state.  initial_leds shows
1207c478bd9Sstevel@tonic-gate  *        	which LEDs are lit; initial_led_mask shows which bits in
1217c478bd9Sstevel@tonic-gate  *        	initial_leds are valid.  This mechanism exists primarily to
1227c478bd9Sstevel@tonic-gate  *        	retain the existing state of NumLock across the transition
1237c478bd9Sstevel@tonic-gate  *       	from firmware to the OS.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate extern int kbtrans_streams_init(queue_t *, int, cred_t *,
1267c478bd9Sstevel@tonic-gate 	struct kbtrans_hardware *, struct kbtrans_callbacks *,
1277c478bd9Sstevel@tonic-gate 	struct kbtrans **, int, int);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * kbtrans_streams_fini():
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  * Shuts down the generic translation module.  Must be called from
1337c478bd9Sstevel@tonic-gate  * the hardware module's close(9e) routine.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *);
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * kbtrans_streams_message():
1397c478bd9Sstevel@tonic-gate  *
1407c478bd9Sstevel@tonic-gate  * The hardware module should pass all streams messages received from
1417c478bd9Sstevel@tonic-gate  * above to this routine.  The generic translation module will process
1427c478bd9Sstevel@tonic-gate  * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that
1437c478bd9Sstevel@tonic-gate  * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that
1447c478bd9Sstevel@tonic-gate  * it did not handle.  For KBTRANS_MESSAGE_HANDLED, the hardware module
1457c478bd9Sstevel@tonic-gate  * should take no further action on the message.  For
1467c478bd9Sstevel@tonic-gate  * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for
1477c478bd9Sstevel@tonic-gate  * any action, including returning an appropriate error.
1487c478bd9Sstevel@tonic-gate  *
1497c478bd9Sstevel@tonic-gate  * Must be called from the hardware module's write put(9e) or srv(9e)
1507c478bd9Sstevel@tonic-gate  * routine.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *,
1537c478bd9Sstevel@tonic-gate 	mblk_t *);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * kbtrans_streams_key():
1577c478bd9Sstevel@tonic-gate  *
1587c478bd9Sstevel@tonic-gate  * When a key is pressed or released, the hardware module should
1597c478bd9Sstevel@tonic-gate  * call kbtrans, passing the key number and its new
1607c478bd9Sstevel@tonic-gate  * state.  kbtrans is responsible for autorepeat handling;
1617c478bd9Sstevel@tonic-gate  * the hardware module should report only actual press/release
1627c478bd9Sstevel@tonic-gate  * events, suppressing any hardware-generated autorepeat.
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key,
1657c478bd9Sstevel@tonic-gate 	enum keystate state);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * kbtrans_streams_set_keyboard():
1697c478bd9Sstevel@tonic-gate  *
1707c478bd9Sstevel@tonic-gate  * At any time after calling kbtrans_streams_init, the hardware
1717c478bd9Sstevel@tonic-gate  * module should make this call to report the type of keyboard
1727c478bd9Sstevel@tonic-gate  * attached.  "type" is the keyboard type, typically KB_SUN4,
1737c478bd9Sstevel@tonic-gate  * KB_PC, or KB_USB.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int,
1767c478bd9Sstevel@tonic-gate 	struct keyboard *);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * kbtrans_streams_has_reset():
1807c478bd9Sstevel@tonic-gate  *
1817c478bd9Sstevel@tonic-gate  * At any time between kbtrans_streams_init and kbtrans_streams_fini,
1827c478bd9Sstevel@tonic-gate  * the hardware module can call this routine to report that the
1837c478bd9Sstevel@tonic-gate  * keyboard has been reset, e.g. by being unplugged and reattached.
1847c478bd9Sstevel@tonic-gate  *
1857c478bd9Sstevel@tonic-gate  * This function is for use by keyboard devices that do not formally
1867c478bd9Sstevel@tonic-gate  * support hotplug.  If the keyboard hardware spontaneously resets
1877c478bd9Sstevel@tonic-gate  * itself in a case other than hotplug, this routine is called to
1887c478bd9Sstevel@tonic-gate  * report the rest.
1897c478bd9Sstevel@tonic-gate  *
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * kbtrans_ischar():
1957c478bd9Sstevel@tonic-gate  * kbtrans_getchar():
1967c478bd9Sstevel@tonic-gate  *
1977c478bd9Sstevel@tonic-gate  * These routines are used for polled input, e.g. for kmdb or PROM
1987c478bd9Sstevel@tonic-gate  * input.  Note that, with suitable casting, these routines are usable
1997c478bd9Sstevel@tonic-gate  * as CONSOPENPOLLEDIO routines.
2007c478bd9Sstevel@tonic-gate  *
2017c478bd9Sstevel@tonic-gate  * May only be called from single-threaded code, e.g. kmdb.
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *);
2047c478bd9Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * kbtrans_streams_enable():
2087c478bd9Sstevel@tonic-gate  *	Routine to be called from the hardware specific module when
2097c478bd9Sstevel@tonic-gate  * 	the stream is ready to take messages.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *);
2127c478bd9Sstevel@tonic-gate 
21399d47a04Slq150181 /*
21499d47a04Slq150181  * kbtrans_streams_setled():
21599d47a04Slq150181  *	Routine to be called to only update the led state in kbtrans.
21699d47a04Slq150181  */
21799d47a04Slq150181 extern void kbtrans_streams_setled(struct kbtrans *, int);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * kbtrans_streams_releaseall():
2217c478bd9Sstevel@tonic-gate  *	Release all the keys that are held down.
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * kbtrans_streams_set_queue():
2277c478bd9Sstevel@tonic-gate  *      Change the queue above the device, to support multiplexors.
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * kbtrans_streams_get_queue():
2337c478bd9Sstevel@tonic-gate  * Retrieve the current queue above the device.
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * kbtrans_streams_untimeout():
2397c478bd9Sstevel@tonic-gate  * Clear timeout
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate #endif
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */
248