xref: /illumos-gate/usr/src/uts/common/sys/kbtrans.h (revision cd2135d0)
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
599d47a04Slq  * Common Development and Distribution License (the "License").
699d47a04Slq  * 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  */
2199d47a04Slq 
227c478bd9Sstevel@tonic-gate /*
23*cd2135d0Spengcheng chen - Sun Microsystems - Beijing China  * Copyright 2009 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 /*
317c478bd9Sstevel@tonic-gate  * Interface between hardware keyboard driver and generic keyboard
327c478bd9Sstevel@tonic-gate  * translation module.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef __cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
4202b00a15Sqz  * The default value (0) indicates that the keyboard layout isn't
4302b00a15Sqz  * configured in kernel.
447c478bd9Sstevel@tonic-gate  */
4502b00a15Sqz #define	KBTRANS_USBKB_DEFAULT_LAYOUT	0
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Maximum of keys in a keyboard
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	KBTRANS_KEYNUMS_MAX		255
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Do not expose the internals of these structures to kbtrans clients
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate struct kbtrans_hardware;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate struct kbtrans;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate enum kbtrans_message_response {
607c478bd9Sstevel@tonic-gate 	KBTRANS_MESSAGE_HANDLED = 0,
617c478bd9Sstevel@tonic-gate 	KBTRANS_MESSAGE_NOT_HANDLED = 1
627c478bd9Sstevel@tonic-gate };
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *,
657c478bd9Sstevel@tonic-gate 			kbtrans_key_t *, enum keystate *);
667c478bd9Sstevel@tonic-gate struct hw_polledio {
677c478bd9Sstevel@tonic-gate 	void *polled_argument;
687c478bd9Sstevel@tonic-gate 	polled_keycode_func *polled_keycode;
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Callbacks registered by the hardware specific driver/module
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate struct kbtrans_callbacks {
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* Routine to set the LED's in non-polled mode */
797c478bd9Sstevel@tonic-gate 	void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/* Routine to set the LED's in polled mode */
827c478bd9Sstevel@tonic-gate 	void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/* Routine to indicate that a scande is available in polled mode */
857c478bd9Sstevel@tonic-gate 	boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *,
867c478bd9Sstevel@tonic-gate 		kbtrans_key_t *, enum keystate *);
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * kbtrans_streams_init():
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * Initializes the generic keyboard translation module.  Must be
937c478bd9Sstevel@tonic-gate  * called from the hardware module's open(9e) routine.
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  * Arguments:
967c478bd9Sstevel@tonic-gate  *	- queue_t *q
977c478bd9Sstevel@tonic-gate  *       	The read queue.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  *   	- int sflag
1007c478bd9Sstevel@tonic-gate  *        	sflag from the streams open routine
1017c478bd9Sstevel@tonic-gate  *
1027c478bd9Sstevel@tonic-gate  *   	- struct kbtrans_hardware *hw
1037c478bd9Sstevel@tonic-gate  *       	hardware-specific data, passed to hardware callbacks
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  *    	- struct kbtrans_callbacks *hw_callbacks
1067c478bd9Sstevel@tonic-gate  *       	hardware support callbacks (see below)
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  *    	- struct kbtrans **kbtrans
1097c478bd9Sstevel@tonic-gate  *        	returned state structure pointer
1107c478bd9Sstevel@tonic-gate  *
1117c478bd9Sstevel@tonic-gate  *    	- int initial_leds
1127c478bd9Sstevel@tonic-gate  *    	- int initial_led_mask
1137c478bd9Sstevel@tonic-gate  *        	Provides state information (if available) about the current
1147c478bd9Sstevel@tonic-gate  *        	keyboard state, in the form of LED state.  initial_leds shows
1157c478bd9Sstevel@tonic-gate  *        	which LEDs are lit; initial_led_mask shows which bits in
1167c478bd9Sstevel@tonic-gate  *        	initial_leds are valid.  This mechanism exists primarily to
1177c478bd9Sstevel@tonic-gate  *        	retain the existing state of NumLock across the transition
1187c478bd9Sstevel@tonic-gate  *       	from firmware to the OS.
1197c478bd9Sstevel@tonic-gate  */
120*cd2135d0Spengcheng chen - Sun Microsystems - Beijing China extern int kbtrans_streams_init(queue_t *, int, struct kbtrans_hardware *,
121*cd2135d0Spengcheng chen - Sun Microsystems - Beijing China 	struct kbtrans_callbacks *, struct kbtrans **, int, int);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * kbtrans_streams_fini():
1257c478bd9Sstevel@tonic-gate  *
1267c478bd9Sstevel@tonic-gate  * Shuts down the generic translation module.  Must be called from
1277c478bd9Sstevel@tonic-gate  * the hardware module's close(9e) routine.
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * kbtrans_streams_message():
1337c478bd9Sstevel@tonic-gate  *
1347c478bd9Sstevel@tonic-gate  * The hardware module should pass all streams messages received from
1357c478bd9Sstevel@tonic-gate  * above to this routine.  The generic translation module will process
1367c478bd9Sstevel@tonic-gate  * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that
1377c478bd9Sstevel@tonic-gate  * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that
1387c478bd9Sstevel@tonic-gate  * it did not handle.  For KBTRANS_MESSAGE_HANDLED, the hardware module
1397c478bd9Sstevel@tonic-gate  * should take no further action on the message.  For
1407c478bd9Sstevel@tonic-gate  * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for
1417c478bd9Sstevel@tonic-gate  * any action, including returning an appropriate error.
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * Must be called from the hardware module's write put(9e) or srv(9e)
1447c478bd9Sstevel@tonic-gate  * routine.
1457c478bd9Sstevel@tonic-gate  */
1467c478bd9Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *,
1477c478bd9Sstevel@tonic-gate 	mblk_t *);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * kbtrans_streams_key():
1517c478bd9Sstevel@tonic-gate  *
1527c478bd9Sstevel@tonic-gate  * When a key is pressed or released, the hardware module should
1537c478bd9Sstevel@tonic-gate  * call kbtrans, passing the key number and its new
1547c478bd9Sstevel@tonic-gate  * state.  kbtrans is responsible for autorepeat handling;
1557c478bd9Sstevel@tonic-gate  * the hardware module should report only actual press/release
1567c478bd9Sstevel@tonic-gate  * events, suppressing any hardware-generated autorepeat.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key,
1597c478bd9Sstevel@tonic-gate 	enum keystate state);
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * kbtrans_streams_set_keyboard():
1637c478bd9Sstevel@tonic-gate  *
1647c478bd9Sstevel@tonic-gate  * At any time after calling kbtrans_streams_init, the hardware
1657c478bd9Sstevel@tonic-gate  * module should make this call to report the type of keyboard
1667c478bd9Sstevel@tonic-gate  * attached.  "type" is the keyboard type, typically KB_SUN4,
1677c478bd9Sstevel@tonic-gate  * KB_PC, or KB_USB.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int,
1707c478bd9Sstevel@tonic-gate 	struct keyboard *);
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * kbtrans_streams_has_reset():
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * At any time between kbtrans_streams_init and kbtrans_streams_fini,
1767c478bd9Sstevel@tonic-gate  * the hardware module can call this routine to report that the
1777c478bd9Sstevel@tonic-gate  * keyboard has been reset, e.g. by being unplugged and reattached.
1787c478bd9Sstevel@tonic-gate  *
1797c478bd9Sstevel@tonic-gate  * This function is for use by keyboard devices that do not formally
1807c478bd9Sstevel@tonic-gate  * support hotplug.  If the keyboard hardware spontaneously resets
1817c478bd9Sstevel@tonic-gate  * itself in a case other than hotplug, this routine is called to
1827c478bd9Sstevel@tonic-gate  * report the rest.
1837c478bd9Sstevel@tonic-gate  *
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * kbtrans_ischar():
1897c478bd9Sstevel@tonic-gate  * kbtrans_getchar():
1907c478bd9Sstevel@tonic-gate  *
1917c478bd9Sstevel@tonic-gate  * These routines are used for polled input, e.g. for kmdb or PROM
1927c478bd9Sstevel@tonic-gate  * input.  Note that, with suitable casting, these routines are usable
1937c478bd9Sstevel@tonic-gate  * as CONSOPENPOLLEDIO routines.
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  * May only be called from single-threaded code, e.g. kmdb.
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *);
1987c478bd9Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * kbtrans_streams_enable():
2027c478bd9Sstevel@tonic-gate  *	Routine to be called from the hardware specific module when
2037c478bd9Sstevel@tonic-gate  * 	the stream is ready to take messages.
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *);
2067c478bd9Sstevel@tonic-gate 
20799d47a04Slq /*
20899d47a04Slq  * kbtrans_streams_setled():
20999d47a04Slq  *	Routine to be called to only update the led state in kbtrans.
21099d47a04Slq  */
21199d47a04Slq extern void kbtrans_streams_setled(struct kbtrans *, int);
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * kbtrans_streams_releaseall():
2157c478bd9Sstevel@tonic-gate  *	Release all the keys that are held down.
2167c478bd9Sstevel@tonic-gate  */
2177c478bd9Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * kbtrans_streams_set_queue():
2217c478bd9Sstevel@tonic-gate  *      Change the queue above the device, to support multiplexors.
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * kbtrans_streams_get_queue():
2277c478bd9Sstevel@tonic-gate  * Retrieve the current queue above the device.
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * kbtrans_streams_untimeout():
2337c478bd9Sstevel@tonic-gate  * Clear timeout
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate #endif
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */
242