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