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_KBTRANS_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_KBTRANS_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Interface between hardware keyboard driver and generic keyboard 34*7c478bd9Sstevel@tonic-gate * translation module. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 38*7c478bd9Sstevel@tonic-gate extern "C" { 39*7c478bd9Sstevel@tonic-gate #endif 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #include <sys/consdev.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate /* 44*7c478bd9Sstevel@tonic-gate * By default, set conskbd's layout to US 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate #define KBTRANS_USBKB_LAYOUT_US 0x21 47*7c478bd9Sstevel@tonic-gate #define KBTRANS_USBKB_DEFAULT_LAYOUT KBTRANS_USBKB_LAYOUT_US 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* 50*7c478bd9Sstevel@tonic-gate * Maximum of keys in a keyboard 51*7c478bd9Sstevel@tonic-gate */ 52*7c478bd9Sstevel@tonic-gate #define KBTRANS_KEYNUMS_MAX 255 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /* 55*7c478bd9Sstevel@tonic-gate * Do not expose the internals of these structures to kbtrans clients 56*7c478bd9Sstevel@tonic-gate */ 57*7c478bd9Sstevel@tonic-gate struct kbtrans_hardware; 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate struct kbtrans; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate enum kbtrans_message_response { 62*7c478bd9Sstevel@tonic-gate KBTRANS_MESSAGE_HANDLED = 0, 63*7c478bd9Sstevel@tonic-gate KBTRANS_MESSAGE_NOT_HANDLED = 1 64*7c478bd9Sstevel@tonic-gate }; 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *, 67*7c478bd9Sstevel@tonic-gate kbtrans_key_t *, enum keystate *); 68*7c478bd9Sstevel@tonic-gate struct hw_polledio { 69*7c478bd9Sstevel@tonic-gate void *polled_argument; 70*7c478bd9Sstevel@tonic-gate polled_keycode_func *polled_keycode; 71*7c478bd9Sstevel@tonic-gate }; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate /* 76*7c478bd9Sstevel@tonic-gate * Callbacks registered by the hardware specific driver/module 77*7c478bd9Sstevel@tonic-gate */ 78*7c478bd9Sstevel@tonic-gate struct kbtrans_callbacks { 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* Routine to set the LED's in non-polled mode */ 81*7c478bd9Sstevel@tonic-gate void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int); 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate /* Routine to set the LED's in polled mode */ 84*7c478bd9Sstevel@tonic-gate void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int); 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate /* Routine to indicate that a scande is available in polled mode */ 87*7c478bd9Sstevel@tonic-gate boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *, 88*7c478bd9Sstevel@tonic-gate kbtrans_key_t *, enum keystate *); 89*7c478bd9Sstevel@tonic-gate }; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* 92*7c478bd9Sstevel@tonic-gate * kbtrans_streams_init(): 93*7c478bd9Sstevel@tonic-gate * 94*7c478bd9Sstevel@tonic-gate * Initializes the generic keyboard translation module. Must be 95*7c478bd9Sstevel@tonic-gate * called from the hardware module's open(9e) routine. 96*7c478bd9Sstevel@tonic-gate * 97*7c478bd9Sstevel@tonic-gate * Arguments: 98*7c478bd9Sstevel@tonic-gate * - queue_t *q 99*7c478bd9Sstevel@tonic-gate * The read queue. 100*7c478bd9Sstevel@tonic-gate * 101*7c478bd9Sstevel@tonic-gate * - int sflag 102*7c478bd9Sstevel@tonic-gate * sflag from the streams open routine 103*7c478bd9Sstevel@tonic-gate * 104*7c478bd9Sstevel@tonic-gate * - cred_t *crp 105*7c478bd9Sstevel@tonic-gate * credentials from open 106*7c478bd9Sstevel@tonic-gate * 107*7c478bd9Sstevel@tonic-gate * - struct kbtrans_hardware *hw 108*7c478bd9Sstevel@tonic-gate * hardware-specific data, passed to hardware callbacks 109*7c478bd9Sstevel@tonic-gate * 110*7c478bd9Sstevel@tonic-gate * - struct kbtrans_callbacks *hw_callbacks 111*7c478bd9Sstevel@tonic-gate * hardware support callbacks (see below) 112*7c478bd9Sstevel@tonic-gate * 113*7c478bd9Sstevel@tonic-gate * - struct kbtrans **kbtrans 114*7c478bd9Sstevel@tonic-gate * returned state structure pointer 115*7c478bd9Sstevel@tonic-gate * 116*7c478bd9Sstevel@tonic-gate * - int initial_leds 117*7c478bd9Sstevel@tonic-gate * - int initial_led_mask 118*7c478bd9Sstevel@tonic-gate * Provides state information (if available) about the current 119*7c478bd9Sstevel@tonic-gate * keyboard state, in the form of LED state. initial_leds shows 120*7c478bd9Sstevel@tonic-gate * which LEDs are lit; initial_led_mask shows which bits in 121*7c478bd9Sstevel@tonic-gate * initial_leds are valid. This mechanism exists primarily to 122*7c478bd9Sstevel@tonic-gate * retain the existing state of NumLock across the transition 123*7c478bd9Sstevel@tonic-gate * from firmware to the OS. 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate extern int kbtrans_streams_init(queue_t *, int, cred_t *, 126*7c478bd9Sstevel@tonic-gate struct kbtrans_hardware *, struct kbtrans_callbacks *, 127*7c478bd9Sstevel@tonic-gate struct kbtrans **, int, int); 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate /* 130*7c478bd9Sstevel@tonic-gate * kbtrans_streams_fini(): 131*7c478bd9Sstevel@tonic-gate * 132*7c478bd9Sstevel@tonic-gate * Shuts down the generic translation module. Must be called from 133*7c478bd9Sstevel@tonic-gate * the hardware module's close(9e) routine. 134*7c478bd9Sstevel@tonic-gate */ 135*7c478bd9Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *); 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * kbtrans_streams_message(): 139*7c478bd9Sstevel@tonic-gate * 140*7c478bd9Sstevel@tonic-gate * The hardware module should pass all streams messages received from 141*7c478bd9Sstevel@tonic-gate * above to this routine. The generic translation module will process 142*7c478bd9Sstevel@tonic-gate * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that 143*7c478bd9Sstevel@tonic-gate * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that 144*7c478bd9Sstevel@tonic-gate * it did not handle. For KBTRANS_MESSAGE_HANDLED, the hardware module 145*7c478bd9Sstevel@tonic-gate * should take no further action on the message. For 146*7c478bd9Sstevel@tonic-gate * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for 147*7c478bd9Sstevel@tonic-gate * any action, including returning an appropriate error. 148*7c478bd9Sstevel@tonic-gate * 149*7c478bd9Sstevel@tonic-gate * Must be called from the hardware module's write put(9e) or srv(9e) 150*7c478bd9Sstevel@tonic-gate * routine. 151*7c478bd9Sstevel@tonic-gate */ 152*7c478bd9Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *, 153*7c478bd9Sstevel@tonic-gate mblk_t *); 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate /* 156*7c478bd9Sstevel@tonic-gate * kbtrans_streams_key(): 157*7c478bd9Sstevel@tonic-gate * 158*7c478bd9Sstevel@tonic-gate * When a key is pressed or released, the hardware module should 159*7c478bd9Sstevel@tonic-gate * call kbtrans, passing the key number and its new 160*7c478bd9Sstevel@tonic-gate * state. kbtrans is responsible for autorepeat handling; 161*7c478bd9Sstevel@tonic-gate * the hardware module should report only actual press/release 162*7c478bd9Sstevel@tonic-gate * events, suppressing any hardware-generated autorepeat. 163*7c478bd9Sstevel@tonic-gate */ 164*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key, 165*7c478bd9Sstevel@tonic-gate enum keystate state); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /* 168*7c478bd9Sstevel@tonic-gate * kbtrans_streams_set_keyboard(): 169*7c478bd9Sstevel@tonic-gate * 170*7c478bd9Sstevel@tonic-gate * At any time after calling kbtrans_streams_init, the hardware 171*7c478bd9Sstevel@tonic-gate * module should make this call to report the type of keyboard 172*7c478bd9Sstevel@tonic-gate * attached. "type" is the keyboard type, typically KB_SUN4, 173*7c478bd9Sstevel@tonic-gate * KB_PC, or KB_USB. 174*7c478bd9Sstevel@tonic-gate */ 175*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int, 176*7c478bd9Sstevel@tonic-gate struct keyboard *); 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* 179*7c478bd9Sstevel@tonic-gate * kbtrans_streams_has_reset(): 180*7c478bd9Sstevel@tonic-gate * 181*7c478bd9Sstevel@tonic-gate * At any time between kbtrans_streams_init and kbtrans_streams_fini, 182*7c478bd9Sstevel@tonic-gate * the hardware module can call this routine to report that the 183*7c478bd9Sstevel@tonic-gate * keyboard has been reset, e.g. by being unplugged and reattached. 184*7c478bd9Sstevel@tonic-gate * 185*7c478bd9Sstevel@tonic-gate * This function is for use by keyboard devices that do not formally 186*7c478bd9Sstevel@tonic-gate * support hotplug. If the keyboard hardware spontaneously resets 187*7c478bd9Sstevel@tonic-gate * itself in a case other than hotplug, this routine is called to 188*7c478bd9Sstevel@tonic-gate * report the rest. 189*7c478bd9Sstevel@tonic-gate * 190*7c478bd9Sstevel@tonic-gate */ 191*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /* 194*7c478bd9Sstevel@tonic-gate * kbtrans_ischar(): 195*7c478bd9Sstevel@tonic-gate * kbtrans_getchar(): 196*7c478bd9Sstevel@tonic-gate * 197*7c478bd9Sstevel@tonic-gate * These routines are used for polled input, e.g. for kmdb or PROM 198*7c478bd9Sstevel@tonic-gate * input. Note that, with suitable casting, these routines are usable 199*7c478bd9Sstevel@tonic-gate * as CONSOPENPOLLEDIO routines. 200*7c478bd9Sstevel@tonic-gate * 201*7c478bd9Sstevel@tonic-gate * May only be called from single-threaded code, e.g. kmdb. 202*7c478bd9Sstevel@tonic-gate */ 203*7c478bd9Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *); 204*7c478bd9Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *); 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate /* 207*7c478bd9Sstevel@tonic-gate * kbtrans_streams_enable(): 208*7c478bd9Sstevel@tonic-gate * Routine to be called from the hardware specific module when 209*7c478bd9Sstevel@tonic-gate * the stream is ready to take messages. 210*7c478bd9Sstevel@tonic-gate */ 211*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *); 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate /* 215*7c478bd9Sstevel@tonic-gate * kbtrans_streams_releaseall(): 216*7c478bd9Sstevel@tonic-gate * Release all the keys that are held down. 217*7c478bd9Sstevel@tonic-gate */ 218*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *); 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * kbtrans_streams_set_queue(): 222*7c478bd9Sstevel@tonic-gate * Change the queue above the device, to support multiplexors. 223*7c478bd9Sstevel@tonic-gate */ 224*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *); 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate /* 227*7c478bd9Sstevel@tonic-gate * kbtrans_streams_get_queue(): 228*7c478bd9Sstevel@tonic-gate * Retrieve the current queue above the device. 229*7c478bd9Sstevel@tonic-gate */ 230*7c478bd9Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *); 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate /* 233*7c478bd9Sstevel@tonic-gate * kbtrans_streams_untimeout(): 234*7c478bd9Sstevel@tonic-gate * Clear timeout 235*7c478bd9Sstevel@tonic-gate */ 236*7c478bd9Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *); 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate #endif 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */ 243