10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51272Slq150181 * Common Development and Distribution License (the "License"). 61272Slq150181 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211272Slq150181 220Sstevel@tonic-gate /* 23*3366Sqz150045 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_KBTRANS_H 280Sstevel@tonic-gate #define _SYS_KBTRANS_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Interface between hardware keyboard driver and generic keyboard 340Sstevel@tonic-gate * translation module. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include <sys/consdev.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 44*3366Sqz150045 * The default value (0) indicates that the keyboard layout isn't 45*3366Sqz150045 * configured in kernel. 460Sstevel@tonic-gate */ 47*3366Sqz150045 #define KBTRANS_USBKB_DEFAULT_LAYOUT 0 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * Maximum of keys in a keyboard 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate #define KBTRANS_KEYNUMS_MAX 255 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Do not expose the internals of these structures to kbtrans clients 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate struct kbtrans_hardware; 580Sstevel@tonic-gate 590Sstevel@tonic-gate struct kbtrans; 600Sstevel@tonic-gate 610Sstevel@tonic-gate enum kbtrans_message_response { 620Sstevel@tonic-gate KBTRANS_MESSAGE_HANDLED = 0, 630Sstevel@tonic-gate KBTRANS_MESSAGE_NOT_HANDLED = 1 640Sstevel@tonic-gate }; 650Sstevel@tonic-gate 660Sstevel@tonic-gate typedef boolean_t (*polled_keycode_func)(struct kbtrans_hardware *, 670Sstevel@tonic-gate kbtrans_key_t *, enum keystate *); 680Sstevel@tonic-gate struct hw_polledio { 690Sstevel@tonic-gate void *polled_argument; 700Sstevel@tonic-gate polled_keycode_func *polled_keycode; 710Sstevel@tonic-gate }; 720Sstevel@tonic-gate 730Sstevel@tonic-gate 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * Callbacks registered by the hardware specific driver/module 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate struct kbtrans_callbacks { 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* Routine to set the LED's in non-polled mode */ 810Sstevel@tonic-gate void (*kbtrans_streams_setled)(struct kbtrans_hardware *, int); 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* Routine to set the LED's in polled mode */ 840Sstevel@tonic-gate void (*kbtrans_polled_setled)(struct kbtrans_hardware *, int); 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* Routine to indicate that a scande is available in polled mode */ 870Sstevel@tonic-gate boolean_t (*kbtrans_polled_keycheck)(struct kbtrans_hardware *, 880Sstevel@tonic-gate kbtrans_key_t *, enum keystate *); 890Sstevel@tonic-gate }; 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * kbtrans_streams_init(): 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * Initializes the generic keyboard translation module. Must be 950Sstevel@tonic-gate * called from the hardware module's open(9e) routine. 960Sstevel@tonic-gate * 970Sstevel@tonic-gate * Arguments: 980Sstevel@tonic-gate * - queue_t *q 990Sstevel@tonic-gate * The read queue. 1000Sstevel@tonic-gate * 1010Sstevel@tonic-gate * - int sflag 1020Sstevel@tonic-gate * sflag from the streams open routine 1030Sstevel@tonic-gate * 1040Sstevel@tonic-gate * - cred_t *crp 1050Sstevel@tonic-gate * credentials from open 1060Sstevel@tonic-gate * 1070Sstevel@tonic-gate * - struct kbtrans_hardware *hw 1080Sstevel@tonic-gate * hardware-specific data, passed to hardware callbacks 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * - struct kbtrans_callbacks *hw_callbacks 1110Sstevel@tonic-gate * hardware support callbacks (see below) 1120Sstevel@tonic-gate * 1130Sstevel@tonic-gate * - struct kbtrans **kbtrans 1140Sstevel@tonic-gate * returned state structure pointer 1150Sstevel@tonic-gate * 1160Sstevel@tonic-gate * - int initial_leds 1170Sstevel@tonic-gate * - int initial_led_mask 1180Sstevel@tonic-gate * Provides state information (if available) about the current 1190Sstevel@tonic-gate * keyboard state, in the form of LED state. initial_leds shows 1200Sstevel@tonic-gate * which LEDs are lit; initial_led_mask shows which bits in 1210Sstevel@tonic-gate * initial_leds are valid. This mechanism exists primarily to 1220Sstevel@tonic-gate * retain the existing state of NumLock across the transition 1230Sstevel@tonic-gate * from firmware to the OS. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate extern int kbtrans_streams_init(queue_t *, int, cred_t *, 1260Sstevel@tonic-gate struct kbtrans_hardware *, struct kbtrans_callbacks *, 1270Sstevel@tonic-gate struct kbtrans **, int, int); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* 1300Sstevel@tonic-gate * kbtrans_streams_fini(): 1310Sstevel@tonic-gate * 1320Sstevel@tonic-gate * Shuts down the generic translation module. Must be called from 1330Sstevel@tonic-gate * the hardware module's close(9e) routine. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate extern int kbtrans_streams_fini(struct kbtrans *); 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* 1380Sstevel@tonic-gate * kbtrans_streams_message(): 1390Sstevel@tonic-gate * 1400Sstevel@tonic-gate * The hardware module should pass all streams messages received from 1410Sstevel@tonic-gate * above to this routine. The generic translation module will process 1420Sstevel@tonic-gate * most of them, returning KBTRANS_MESSAGE_HANDLED for the ones that 1430Sstevel@tonic-gate * it has handled and KBTRANS_MESSAGE_NOT_HANDLED for the ones that 1440Sstevel@tonic-gate * it did not handle. For KBTRANS_MESSAGE_HANDLED, the hardware module 1450Sstevel@tonic-gate * should take no further action on the message. For 1460Sstevel@tonic-gate * KBTRANS_MESSAGE_NOT_HANDLED, the hardware module is responsible for 1470Sstevel@tonic-gate * any action, including returning an appropriate error. 1480Sstevel@tonic-gate * 1490Sstevel@tonic-gate * Must be called from the hardware module's write put(9e) or srv(9e) 1500Sstevel@tonic-gate * routine. 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate extern enum kbtrans_message_response kbtrans_streams_message(struct kbtrans *, 1530Sstevel@tonic-gate mblk_t *); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * kbtrans_streams_key(): 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * When a key is pressed or released, the hardware module should 1590Sstevel@tonic-gate * call kbtrans, passing the key number and its new 1600Sstevel@tonic-gate * state. kbtrans is responsible for autorepeat handling; 1610Sstevel@tonic-gate * the hardware module should report only actual press/release 1620Sstevel@tonic-gate * events, suppressing any hardware-generated autorepeat. 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate extern void kbtrans_streams_key(struct kbtrans *, kbtrans_key_t key, 1650Sstevel@tonic-gate enum keystate state); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * kbtrans_streams_set_keyboard(): 1690Sstevel@tonic-gate * 1700Sstevel@tonic-gate * At any time after calling kbtrans_streams_init, the hardware 1710Sstevel@tonic-gate * module should make this call to report the type of keyboard 1720Sstevel@tonic-gate * attached. "type" is the keyboard type, typically KB_SUN4, 1730Sstevel@tonic-gate * KB_PC, or KB_USB. 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate extern void kbtrans_streams_set_keyboard(struct kbtrans *, int, 1760Sstevel@tonic-gate struct keyboard *); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * kbtrans_streams_has_reset(): 1800Sstevel@tonic-gate * 1810Sstevel@tonic-gate * At any time between kbtrans_streams_init and kbtrans_streams_fini, 1820Sstevel@tonic-gate * the hardware module can call this routine to report that the 1830Sstevel@tonic-gate * keyboard has been reset, e.g. by being unplugged and reattached. 1840Sstevel@tonic-gate * 1850Sstevel@tonic-gate * This function is for use by keyboard devices that do not formally 1860Sstevel@tonic-gate * support hotplug. If the keyboard hardware spontaneously resets 1870Sstevel@tonic-gate * itself in a case other than hotplug, this routine is called to 1880Sstevel@tonic-gate * report the rest. 1890Sstevel@tonic-gate * 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate extern void kbtrans_streams_has_reset(struct kbtrans *); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* 1940Sstevel@tonic-gate * kbtrans_ischar(): 1950Sstevel@tonic-gate * kbtrans_getchar(): 1960Sstevel@tonic-gate * 1970Sstevel@tonic-gate * These routines are used for polled input, e.g. for kmdb or PROM 1980Sstevel@tonic-gate * input. Note that, with suitable casting, these routines are usable 1990Sstevel@tonic-gate * as CONSOPENPOLLEDIO routines. 2000Sstevel@tonic-gate * 2010Sstevel@tonic-gate * May only be called from single-threaded code, e.g. kmdb. 2020Sstevel@tonic-gate */ 2030Sstevel@tonic-gate extern boolean_t kbtrans_ischar(struct kbtrans *); 2040Sstevel@tonic-gate extern int kbtrans_getchar(struct kbtrans *); 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * kbtrans_streams_enable(): 2080Sstevel@tonic-gate * Routine to be called from the hardware specific module when 2090Sstevel@tonic-gate * the stream is ready to take messages. 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate extern void kbtrans_streams_enable(struct kbtrans *); 2120Sstevel@tonic-gate 2131272Slq150181 /* 2141272Slq150181 * kbtrans_streams_setled(): 2151272Slq150181 * Routine to be called to only update the led state in kbtrans. 2161272Slq150181 */ 2171272Slq150181 extern void kbtrans_streams_setled(struct kbtrans *, int); 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* 2200Sstevel@tonic-gate * kbtrans_streams_releaseall(): 2210Sstevel@tonic-gate * Release all the keys that are held down. 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate extern void kbtrans_streams_releaseall(struct kbtrans *); 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * kbtrans_streams_set_queue(): 2270Sstevel@tonic-gate * Change the queue above the device, to support multiplexors. 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate extern void kbtrans_streams_set_queue(struct kbtrans *, queue_t *); 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* 2320Sstevel@tonic-gate * kbtrans_streams_get_queue(): 2330Sstevel@tonic-gate * Retrieve the current queue above the device. 2340Sstevel@tonic-gate */ 2350Sstevel@tonic-gate extern queue_t *kbtrans_streams_get_queue(struct kbtrans *); 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* 2380Sstevel@tonic-gate * kbtrans_streams_untimeout(): 2390Sstevel@tonic-gate * Clear timeout 2400Sstevel@tonic-gate */ 2410Sstevel@tonic-gate extern void kbtrans_streams_untimeout(struct kbtrans *); 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate #ifdef __cplusplus 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate #endif 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate #endif /* _SYS_KBTRANS_H */ 248