conskbd.h revision 1272:a00430fa9b7a
1129203Scognet/*
2129203Scognet * CDDL HEADER START
3129203Scognet *
4129203Scognet * The contents of this file are subject to the terms of the
5129203Scognet * Common Development and Distribution License (the "License").
6129203Scognet * You may not use this file except in compliance with the License.
7129203Scognet *
8129203Scognet * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9129203Scognet * or http://www.opensolaris.org/os/licensing.
10129203Scognet * See the License for the specific language governing permissions
11129203Scognet * and limitations under the License.
12129203Scognet *
13129203Scognet * When distributing Covered Code, include this CDDL HEADER in each
14129203Scognet * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15129203Scognet * If applicable, add the following below this CDDL HEADER, with the
16129203Scognet * fields enclosed by brackets "[]" replaced with your own identifying
17129203Scognet * information: Portions Copyright [yyyy] [name of copyright owner]
18129203Scognet *
19129203Scognet * CDDL HEADER END
20129203Scognet */
21129203Scognet
22129203Scognet/*
23129203Scognet * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24129203Scognet * Use is subject to license terms.
25129203Scognet */
26129203Scognet
27129203Scognet#ifndef	_SYS_CONSKBD_H
28129203Scognet#define	_SYS_CONSKBD_H
29129203Scognet
30129203Scognet#pragma ident	"%Z%%M%	%I%	%E% SMI"
31129203Scognet
32129203Scognet#include <sys/types.h>
33129203Scognet#include <sys/stream.h>
34129203Scognet#include <sys/consdev.h>
35129203Scognet#include <sys/kbd.h>
36129203Scognet#include <sys/kbtrans.h>
37129203Scognet
38129203Scognet#ifdef	__cplusplus
39129203Scognetextern "C" {
40129203Scognet#endif
41129203Scognet
42129203Scognet/*
43129203Scognet * Lower Queue State:
44129203Scognet *
45129203Scognet * Every physical keyboard has a corresponding STREAMS queue. We call this
46129203Scognet * queue lower queue. To describe this kind of queue, we define a structure
47129203Scognet * (refer conskbd_lower_queue_t). Every lower queue has a state, transform
48129203Scognet * of the state describes the process from a keyborad attached to system to
49129203Scognet * the keyboard is plumbed into conskbd or rejected.
50129203Scognet *  Rule:
51129203Scognet *
52129203Scognet * 1) LQS_UNINITIALIZED 	--->	LQS_KIOCTYPE_ACK_PENDING;
53129203Scognet * 	send a KIOCTYPE to lower queue, and then wait response;
54129203Scognet *
55129203Scognet * 2) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_INITIALIZED_LEGACY;
56129203Scognet * 	receive nak to KIOCTYPE, the corresponding keyboard can not
57129203Scognet * 	multiplexed with other keyboards. so the conskbd is bypassed,
58129203Scognet * 	only one keyboard is supported.
59129203Scognet *
60129203Scognet * 3) LQS_KIOCTYPE_ACK_PENDING	--->	LQS_KIOCTRANS_ACK_PENDING;
61129203Scognet *	receive ack to KIOCTYPE, and send KIOCTRANS to lower queue,
62129203Scognet *
63129203Scognet * 4) LQS_KIOCTRANS_ACK_PENDING	--->	LQS_KIOCLAYOUT_ACK_PENDING;
64129203Scognet * 	receive ack to KIOCTRANS, and send KIOCLAYOUT to lower queue
65129203Scognet *
66129203Scognet * 5) LQS_KIOCTRANS_ACK_PENDING --->	Destroy
67129203Scognet * 	receive nak to KIOCTRANS, it is a fatal error so that this
68129203Scognet * 	keyboard is not avilable. destroy the lower queue struct.
69129203Scognet *
70129203Scognet * 6) LQS_KIOCLAYOUT_ACK_PENDING --->	LQS_KIOCSLED_ACK_PENDING;
71129203Scognet * 	receive ack/nak to KIOCLAYOUT, and send KIOCSLED/KIOCGLED to
72129203Scognet *	lower queue.
73129203Scognet *
74129203Scognet * 7) LQS_KIOCSLED_ACK_PENDING	--->	LQS_INITIALIZED
75129203Scognet * 	receive ack/nak, the keyboard is linked under conskbd, multiplexed
76129203Scognet * 	with other keyboards.
77129203Scognet *
78129203Scognet * 8) when lower queue is in the state of LQS_INITIALIZED_LEGACY or
79129203Scognet *    LQS_INITIALIZED, no state transform occures unless the lower
80138590Scognet *    queue is destroyed.
81129203Scognet */
82129203Scognetenum conskbd_lqs_state {
83129203Scognet	LQS_UNINITIALIZED = 0,
84129203Scognet	LQS_KIOCTYPE_ACK_PENDING = 1,	/* waiting ACK for KIOCTYPE */
85129203Scognet	LQS_KIOCTRANS_ACK_PENDING = 2, /* waiting ACK for KIOCTRANS */
86129203Scognet	LQS_KIOCLAYOUT_ACK_PENDING = 3, /* waiting ACK for KIOCLAYOUT */
87129203Scognet	LQS_KIOCSLED_ACK_PENDING = 4, /* waiting ACK for KIOCSLED/KIOCGLED */
88129203Scognet	LQS_INITIALIZED_LEGACY = 5, /* only one lower legacy keyboard */
89129203Scognet	LQS_INITIALIZED = 6 /* virtual keyboard initialized */
90129203Scognet};
91129203Scognet
92129203Scognetstruct conskbd_state;
93129203Scognetstruct conskbd_lower_queue;
94129203Scognet
95129203Scognet/*
96129203Scognet * state of lower queue.
97129203Scognet */
98129203Scognettypedef struct conskbd_lower_queue	conskbd_lower_queue_t;
99129203Scognetstruct conskbd_lower_queue {
100129203Scognet
101129203Scognet	conskbd_lower_queue_t	*lqs_next;
102129203Scognet
103129203Scognet	queue_t		*lqs_queue; /* streams queue of lower driver */
104129203Scognet
105129203Scognet	queue_t		*lqs_pending_queue; /* queue of pending message from */
106129203Scognet	mblk_t		*lqs_pending_plink; /* pending I_PLINK message */
107129203Scognet
108129203Scognet	/* state of lower queue */
109129203Scognet	enum conskbd_lqs_state		lqs_state;
110129203Scognet
111129203Scognet	/* polled I/O interface structure of lower keyboard driver */
112129203Scognet	struct cons_polledio	*lqs_polledio;
113129203Scognet
114129203Scognet	/* key status (key-down/key-up) of each key */
115129203Scognet	enum keystate	lqs_key_state[KBTRANS_KEYNUMS_MAX];
116129203Scognet};
117129203Scognet
118129203Scognet/*
119129203Scognet * Pending message structure.
120129203Scognet *
121129203Scognet * Note:
122129203Scognet *     When conskbd receives message from its upper module, it has to
123129203Scognet * clone the message and send a copy to each of its lower queues. The
124129203Scognet * conskbd_pending_msg structure is used to track the process of handling
125129203Scognet * this kind of messages.
126129203Scognet */
127129203Scognettypedef struct conskbd_pending_msg	conskbd_pending_msg_t;
128129203Scognetstruct conskbd_pending_msg {
129129203Scognet
130129203Scognet	conskbd_pending_msg_t	*kpm_next;
131129203Scognet
132129203Scognet	/* the upper queue from which request message is sent out */
133129203Scognet	queue_t	*kpm_upper_queue;
134129203Scognet
135129203Scognet	mblk_t	*kpm_req_msg;	/* the message block from upper */
136129203Scognet
137129203Scognet	/* message ID and Command Code of the message pointed by kpm_req_msg */
138129203Scognet	uint_t	kpm_req_id;
139129203Scognet	int	kpm_req_cmd;
140129203Scognet
141129203Scognet	/* number of request message's copies sent down to lower queues */
142129203Scognet	int	kpm_req_nums;
143129203Scognet
144129203Scognet	/* number of responses to request message received from lower queues */
145129203Scognet	int	kpm_resp_nums;
146129203Scognet
147129203Scognet	mblk_t	*kpm_resp_list;	/* chain of responses from lower */
148129203Scognet
149129203Scognet	kmutex_t kpm_lock;	/* lock for this structure */
150129203Scognet};
151129203Scognet
152129203Scognet/*
153129203Scognet * software state structure for virtual keyboard
154129203Scognet */
155129203Scognetstruct conskbd_state {
156129203Scognet
157129203Scognet	/* kbtrans of virtual keyboard */
158129203Scognet	struct kbtrans		*conskbd_kbtrans;
159129203Scognet
160129203Scognet	/* polled I/O interface structure of virutal keyboard */
161129203Scognet	struct cons_polledio	conskbd_polledio;
162129203Scognet
163129203Scognet	/* chain of lower physical keyboard queues */
164129203Scognet	conskbd_lower_queue_t	*conskbd_lqueue_list;
165129203Scognet
166129203Scognet	/* the number of lower physical keyboard queues */
167129203Scognet	int	conskbd_lqueue_nums;
168129203Scognet
169129203Scognet	int	conskbd_layout;	 /* layout of virtual keyboard */
170129203Scognet	int	conskbd_led_state; /* LED state of virtual keyboard */
171129203Scognet
172129203Scognet	boolean_t	conskbd_directio; /* upstream directory */
173129203Scognet	boolean_t	conskbd_bypassed; /* is virtual keyboard disabled ? */
174129203Scognet};
175129203Scognettypedef struct conskbd_state	conskbd_state_t;
176129203Scognet
177129203Scognet#ifdef	__cplusplus
178129203Scognet}
179129203Scognet#endif
180129203Scognet
181129203Scognet#endif	/* _SYS_CONSKBD_H */
182129203Scognet