xref: /titanic_53/usr/src/uts/common/sys/conskbd.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_CONSKBD_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_CONSKBD_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/kbd.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/kbtrans.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Lower Queue State:
44*7c478bd9Sstevel@tonic-gate  *
45*7c478bd9Sstevel@tonic-gate  * Every physical keyboard has a corresponding STREAMS queue. We call this
46*7c478bd9Sstevel@tonic-gate  * queue lower queue. To describe this kind of queue, we define a structure
47*7c478bd9Sstevel@tonic-gate  * (refer conskbd_lower_queue_t). Every lower queue has a state, transform
48*7c478bd9Sstevel@tonic-gate  * of the state describes the process from a keyborad attached to system to
49*7c478bd9Sstevel@tonic-gate  * the keyboard is plumbed into conskbd or rejected.
50*7c478bd9Sstevel@tonic-gate  *  Rule:
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * 1) LQS_UNINITIALIZED 	--->	LQS_KIOCTYPE_ACK_PENDING;
53*7c478bd9Sstevel@tonic-gate  * 	send a KIOCTYPE to lower queue, and then wait response;
54*7c478bd9Sstevel@tonic-gate  *
55*7c478bd9Sstevel@tonic-gate  * 2) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_INITIALIZED_LEGACY;
56*7c478bd9Sstevel@tonic-gate  * 	receive nak to KIOCTYPE, the corresponding keyboard can not
57*7c478bd9Sstevel@tonic-gate  * 	multiplexed with other keyboards. so the conskbd is bypassed,
58*7c478bd9Sstevel@tonic-gate  * 	only one keyboard is supported.
59*7c478bd9Sstevel@tonic-gate  *
60*7c478bd9Sstevel@tonic-gate  * 3) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_KIOCTRANS_ACK_PENDING;
61*7c478bd9Sstevel@tonic-gate  *	receive ack to KIOCTYPE, and send KIOCTRANS to lower queue,
62*7c478bd9Sstevel@tonic-gate  *
63*7c478bd9Sstevel@tonic-gate  * 4) LQS_KIOCTRANS_ACK_PENDING	--->	LQS_KIOCLAYOUT_ACK_PENDING;
64*7c478bd9Sstevel@tonic-gate  * 	receive ack to KIOCTRANS, and send KIOCLAYOUT to lower queue
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  * 5) LQS_KIOCLAYOUT_ACK_PENDING --->	LQS_KIOCSLED_ACK_PENDING;
67*7c478bd9Sstevel@tonic-gate  * 	receive ack/nak to KIOCLAYOUT, and send KIOCSLED to lower queue
68*7c478bd9Sstevel@tonic-gate  *
69*7c478bd9Sstevel@tonic-gate  * 6) LQS_KIOCSLED_ACK_PENDING	--->	Destroy
70*7c478bd9Sstevel@tonic-gate  * 	receive nak to KIOCTRANS, it is a fatal error so that this
71*7c478bd9Sstevel@tonic-gate  * 	keyboard is not avilable. destroy the lower queue struct.
72*7c478bd9Sstevel@tonic-gate  *
73*7c478bd9Sstevel@tonic-gate  * 7) LQS_KIOCSLED_ACK_PENDING	--->	LQS_INITIALIZED
74*7c478bd9Sstevel@tonic-gate  * 	receive ack, the keyboard is linked under conskbd, multiplexed
75*7c478bd9Sstevel@tonic-gate  * 	with other keyboards.
76*7c478bd9Sstevel@tonic-gate  *
77*7c478bd9Sstevel@tonic-gate  * 8) when lower queue is in the state of LQS_INITIALIZED_LEGACY or
78*7c478bd9Sstevel@tonic-gate  *    LQS_INITIALIZED, no state transform occures unless the lower
79*7c478bd9Sstevel@tonic-gate  *    queue is destroyed.
80*7c478bd9Sstevel@tonic-gate  */
81*7c478bd9Sstevel@tonic-gate enum conskbd_lqs_state {
82*7c478bd9Sstevel@tonic-gate 	LQS_UNINITIALIZED = 0,
83*7c478bd9Sstevel@tonic-gate 	LQS_KIOCTYPE_ACK_PENDING = 1,	/* waiting ACK for KIOCTYPE */
84*7c478bd9Sstevel@tonic-gate 	LQS_KIOCTRANS_ACK_PENDING = 2, /* waiting ACK for KIOCTRANS */
85*7c478bd9Sstevel@tonic-gate 	LQS_KIOCLAYOUT_ACK_PENDING = 3, /* waiting ACK for KIOCLAYOUT */
86*7c478bd9Sstevel@tonic-gate 	LQS_KIOCSLED_ACK_PENDING = 4, /* waiting ACK for KIOCSLED */
87*7c478bd9Sstevel@tonic-gate 	LQS_INITIALIZED_LEGACY = 5, /* only one lower legacy keyboard */
88*7c478bd9Sstevel@tonic-gate 	LQS_INITIALIZED = 6 /* virtual keyboard initialized */
89*7c478bd9Sstevel@tonic-gate };
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate struct conskbd_state;
92*7c478bd9Sstevel@tonic-gate struct conskbd_lower_queue;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate  * state of lower queue.
96*7c478bd9Sstevel@tonic-gate  */
97*7c478bd9Sstevel@tonic-gate typedef struct conskbd_lower_queue	conskbd_lower_queue_t;
98*7c478bd9Sstevel@tonic-gate struct conskbd_lower_queue {
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	conskbd_lower_queue_t	*lqs_next;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	queue_t		*lqs_queue; /* streams queue of lower driver */
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	queue_t		*lqs_pending_queue; /* queue of pending message from */
105*7c478bd9Sstevel@tonic-gate 	mblk_t		*lqs_pending_plink; /* pending I_PLINK message */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	/* state of lower queue */
108*7c478bd9Sstevel@tonic-gate 	enum conskbd_lqs_state		lqs_state;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	/* polled I/O interface structure of lower keyboard driver */
111*7c478bd9Sstevel@tonic-gate 	struct cons_polledio	*lqs_polledio;
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	/* key status (key-down/key-up) of each key */
114*7c478bd9Sstevel@tonic-gate 	enum keystate	lqs_key_state[KBTRANS_KEYNUMS_MAX];
115*7c478bd9Sstevel@tonic-gate };
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate  * Pending message structure.
119*7c478bd9Sstevel@tonic-gate  *
120*7c478bd9Sstevel@tonic-gate  * Note:
121*7c478bd9Sstevel@tonic-gate  *     When conskbd receives message from its upper module, it has to
122*7c478bd9Sstevel@tonic-gate  * clone the message and send a copy to each of its lower queues. The
123*7c478bd9Sstevel@tonic-gate  * conskbd_pending_msg structure is used to track the process of handling
124*7c478bd9Sstevel@tonic-gate  * this kind of messages.
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate typedef struct conskbd_pending_msg	conskbd_pending_msg_t;
127*7c478bd9Sstevel@tonic-gate struct conskbd_pending_msg {
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	conskbd_pending_msg_t	*kpm_next;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	/* the upper queue from which request message is sent out */
132*7c478bd9Sstevel@tonic-gate 	queue_t	*kpm_upper_queue;
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	mblk_t	*kpm_req_msg;	/* the message block from upper */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	/* message ID and Command Code of the message pointed by kpm_req_msg */
137*7c478bd9Sstevel@tonic-gate 	uint_t	kpm_req_id;
138*7c478bd9Sstevel@tonic-gate 	int	kpm_req_cmd;
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	/* number of request message's copies sent down to lower queues */
141*7c478bd9Sstevel@tonic-gate 	int	kpm_req_nums;
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	/* number of responses to request message received from lower queues */
144*7c478bd9Sstevel@tonic-gate 	int	kpm_resp_nums;
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	mblk_t	*kpm_resp_list;	/* chain of responses from lower */
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	kmutex_t kpm_lock;	/* lock for this structure */
149*7c478bd9Sstevel@tonic-gate };
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate  * software state structure for virtual keyboard
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate struct conskbd_state {
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	/* kbtrans of virtual keyboard */
157*7c478bd9Sstevel@tonic-gate 	struct kbtrans		*conskbd_kbtrans;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	/* polled I/O interface structure of virutal keyboard */
160*7c478bd9Sstevel@tonic-gate 	struct cons_polledio	conskbd_polledio;
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	/* chain of lower physical keyboard queues */
163*7c478bd9Sstevel@tonic-gate 	conskbd_lower_queue_t	*conskbd_lqueue_list;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	/* the number of lower physical keyboard queues */
166*7c478bd9Sstevel@tonic-gate 	int	conskbd_lqueue_nums;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	int	conskbd_layout;	 /* layout of virtual keyboard */
169*7c478bd9Sstevel@tonic-gate 	int	conskbd_led_state; /* LED state of virtual keyboard */
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 	boolean_t	conskbd_directio; /* upstream directory */
172*7c478bd9Sstevel@tonic-gate 	boolean_t	conskbd_bypassed; /* is virtual keyboard disabled ? */
173*7c478bd9Sstevel@tonic-gate };
174*7c478bd9Sstevel@tonic-gate typedef struct conskbd_state	conskbd_state_t;
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate #endif
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_CONSKBD_H */
181