xref: /illumos-gate/usr/src/uts/common/sys/conskbd.h (revision 2d6eb4a5)
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
5*99d47a04Slq150181  * Common Development and Distribution License (the "License").
6*99d47a04Slq150181  * 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  */
21*99d47a04Slq150181 
227c478bd9Sstevel@tonic-gate /*
23*99d47a04Slq150181  * Copyright 2006 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_CONSKBD_H
287c478bd9Sstevel@tonic-gate #define	_SYS_CONSKBD_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/stream.h>
327c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
337c478bd9Sstevel@tonic-gate #include <sys/kbd.h>
347c478bd9Sstevel@tonic-gate #include <sys/kbtrans.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Lower Queue State:
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  * Every physical keyboard has a corresponding STREAMS queue. We call this
447c478bd9Sstevel@tonic-gate  * queue lower queue. To describe this kind of queue, we define a structure
457c478bd9Sstevel@tonic-gate  * (refer conskbd_lower_queue_t). Every lower queue has a state, transform
467c478bd9Sstevel@tonic-gate  * of the state describes the process from a keyborad attached to system to
477c478bd9Sstevel@tonic-gate  * the keyboard is plumbed into conskbd or rejected.
487c478bd9Sstevel@tonic-gate  *  Rule:
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  * 1) LQS_UNINITIALIZED 	--->	LQS_KIOCTYPE_ACK_PENDING;
517c478bd9Sstevel@tonic-gate  * 	send a KIOCTYPE to lower queue, and then wait response;
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * 2) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_INITIALIZED_LEGACY;
547c478bd9Sstevel@tonic-gate  * 	receive nak to KIOCTYPE, the corresponding keyboard can not
557c478bd9Sstevel@tonic-gate  * 	multiplexed with other keyboards. so the conskbd is bypassed,
567c478bd9Sstevel@tonic-gate  * 	only one keyboard is supported.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * 3) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_KIOCTRANS_ACK_PENDING;
597c478bd9Sstevel@tonic-gate  *	receive ack to KIOCTYPE, and send KIOCTRANS to lower queue,
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * 4) LQS_KIOCTRANS_ACK_PENDING	--->	LQS_KIOCLAYOUT_ACK_PENDING;
627c478bd9Sstevel@tonic-gate  * 	receive ack to KIOCTRANS, and send KIOCLAYOUT to lower queue
637c478bd9Sstevel@tonic-gate  *
64*99d47a04Slq150181  * 5) LQS_KIOCTRANS_ACK_PENDING --->	Destroy
657c478bd9Sstevel@tonic-gate  * 	receive nak to KIOCTRANS, it is a fatal error so that this
667c478bd9Sstevel@tonic-gate  * 	keyboard is not avilable. destroy the lower queue struct.
677c478bd9Sstevel@tonic-gate  *
68*99d47a04Slq150181  * 6) LQS_KIOCLAYOUT_ACK_PENDING --->	LQS_KIOCSLED_ACK_PENDING;
69*99d47a04Slq150181  * 	receive ack/nak to KIOCLAYOUT, and send KIOCSLED/KIOCGLED to
70*99d47a04Slq150181  *	lower queue.
71*99d47a04Slq150181  *
727c478bd9Sstevel@tonic-gate  * 7) LQS_KIOCSLED_ACK_PENDING	--->	LQS_INITIALIZED
73*99d47a04Slq150181  * 	receive ack/nak, the keyboard is linked under conskbd, multiplexed
747c478bd9Sstevel@tonic-gate  * 	with other keyboards.
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * 8) when lower queue is in the state of LQS_INITIALIZED_LEGACY or
777c478bd9Sstevel@tonic-gate  *    LQS_INITIALIZED, no state transform occures unless the lower
787c478bd9Sstevel@tonic-gate  *    queue is destroyed.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate enum conskbd_lqs_state {
817c478bd9Sstevel@tonic-gate 	LQS_UNINITIALIZED = 0,
827c478bd9Sstevel@tonic-gate 	LQS_KIOCTYPE_ACK_PENDING = 1,	/* waiting ACK for KIOCTYPE */
837c478bd9Sstevel@tonic-gate 	LQS_KIOCTRANS_ACK_PENDING = 2, /* waiting ACK for KIOCTRANS */
847c478bd9Sstevel@tonic-gate 	LQS_KIOCLAYOUT_ACK_PENDING = 3, /* waiting ACK for KIOCLAYOUT */
85*99d47a04Slq150181 	LQS_KIOCSLED_ACK_PENDING = 4, /* waiting ACK for KIOCSLED/KIOCGLED */
867c478bd9Sstevel@tonic-gate 	LQS_INITIALIZED_LEGACY = 5, /* only one lower legacy keyboard */
877c478bd9Sstevel@tonic-gate 	LQS_INITIALIZED = 6 /* virtual keyboard initialized */
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate struct conskbd_state;
917c478bd9Sstevel@tonic-gate struct conskbd_lower_queue;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * state of lower queue.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate typedef struct conskbd_lower_queue	conskbd_lower_queue_t;
977c478bd9Sstevel@tonic-gate struct conskbd_lower_queue {
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	conskbd_lower_queue_t	*lqs_next;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	queue_t		*lqs_queue; /* streams queue of lower driver */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	queue_t		*lqs_pending_queue; /* queue of pending message from */
1047c478bd9Sstevel@tonic-gate 	mblk_t		*lqs_pending_plink; /* pending I_PLINK message */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	/* state of lower queue */
1077c478bd9Sstevel@tonic-gate 	enum conskbd_lqs_state		lqs_state;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/* polled I/O interface structure of lower keyboard driver */
1107c478bd9Sstevel@tonic-gate 	struct cons_polledio	*lqs_polledio;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	/* key status (key-down/key-up) of each key */
1137c478bd9Sstevel@tonic-gate 	enum keystate	lqs_key_state[KBTRANS_KEYNUMS_MAX];
1147c478bd9Sstevel@tonic-gate };
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Pending message structure.
1187c478bd9Sstevel@tonic-gate  *
1197c478bd9Sstevel@tonic-gate  * Note:
1207c478bd9Sstevel@tonic-gate  *     When conskbd receives message from its upper module, it has to
1217c478bd9Sstevel@tonic-gate  * clone the message and send a copy to each of its lower queues. The
1227c478bd9Sstevel@tonic-gate  * conskbd_pending_msg structure is used to track the process of handling
1237c478bd9Sstevel@tonic-gate  * this kind of messages.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate typedef struct conskbd_pending_msg	conskbd_pending_msg_t;
1267c478bd9Sstevel@tonic-gate struct conskbd_pending_msg {
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	conskbd_pending_msg_t	*kpm_next;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/* the upper queue from which request message is sent out */
1317c478bd9Sstevel@tonic-gate 	queue_t	*kpm_upper_queue;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	mblk_t	*kpm_req_msg;	/* the message block from upper */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/* message ID and Command Code of the message pointed by kpm_req_msg */
1367c478bd9Sstevel@tonic-gate 	uint_t	kpm_req_id;
1377c478bd9Sstevel@tonic-gate 	int	kpm_req_cmd;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	/* number of request message's copies sent down to lower queues */
1407c478bd9Sstevel@tonic-gate 	int	kpm_req_nums;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	/* number of responses to request message received from lower queues */
1437c478bd9Sstevel@tonic-gate 	int	kpm_resp_nums;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	mblk_t	*kpm_resp_list;	/* chain of responses from lower */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	kmutex_t kpm_lock;	/* lock for this structure */
1487c478bd9Sstevel@tonic-gate };
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * software state structure for virtual keyboard
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate struct conskbd_state {
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/* kbtrans of virtual keyboard */
1567c478bd9Sstevel@tonic-gate 	struct kbtrans		*conskbd_kbtrans;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	/* polled I/O interface structure of virutal keyboard */
1597c478bd9Sstevel@tonic-gate 	struct cons_polledio	conskbd_polledio;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	/* chain of lower physical keyboard queues */
1627c478bd9Sstevel@tonic-gate 	conskbd_lower_queue_t	*conskbd_lqueue_list;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	/* the number of lower physical keyboard queues */
1657c478bd9Sstevel@tonic-gate 	int	conskbd_lqueue_nums;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	int	conskbd_layout;	 /* layout of virtual keyboard */
1687c478bd9Sstevel@tonic-gate 	int	conskbd_led_state; /* LED state of virtual keyboard */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	boolean_t	conskbd_directio; /* upstream directory */
1717c478bd9Sstevel@tonic-gate 	boolean_t	conskbd_bypassed; /* is virtual keyboard disabled ? */
1727c478bd9Sstevel@tonic-gate };
1737c478bd9Sstevel@tonic-gate typedef struct conskbd_state	conskbd_state_t;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate #endif
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #endif	/* _SYS_CONSKBD_H */
180