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 51244Scg149915 * Common Development and Distribution License (the "License"). 61244Scg149915 * 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 */ 211244Scg149915 220Sstevel@tonic-gate /* 239432SPengcheng.Chen@Sun.COM * Copyright 2009 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_USB_HIDVAR_H 280Sstevel@tonic-gate #define _SYS_USB_HIDVAR_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate /* 380Sstevel@tonic-gate * HID : This header file contains the internal structures 390Sstevel@tonic-gate * and variable definitions used in hid driver. 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * HID USB device state management : 440Sstevel@tonic-gate * 450Sstevel@tonic-gate * ONLINE-----1--->SUSPENDED----2---->ONLINE 460Sstevel@tonic-gate * | 470Sstevel@tonic-gate * +-----3--->DISCONNECTED----4----->ONLINE 480Sstevel@tonic-gate * | 490Sstevel@tonic-gate * +-----7--->POWERED DOWN----8----->POWER CHANGE---9--->ONLINE 500Sstevel@tonic-gate * | 510Sstevel@tonic-gate * +---3--->DISCONNECTED 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * POWERED DOWN----1--->SUSPENDED------2----->POWERED DOWN 540Sstevel@tonic-gate * | | ^ 550Sstevel@tonic-gate * | 5 | 560Sstevel@tonic-gate * | | 6 570Sstevel@tonic-gate * | v | 580Sstevel@tonic-gate * +---------3----->DISCONNECTED-------4----->POWERED DOWN 590Sstevel@tonic-gate * 600Sstevel@tonic-gate * 1 = CPR SUSPEND 610Sstevel@tonic-gate * 2 = CPR RESUME (with original device) 620Sstevel@tonic-gate * 3 = Device Unplug 630Sstevel@tonic-gate * 4 = Original Device Plugged in 640Sstevel@tonic-gate * 5 = CPR RESUME (with device disconnected or with a wrong device) 650Sstevel@tonic-gate * 6 = CPR SUSPEND on a disconnected device 660Sstevel@tonic-gate * 7 = Device idles for time T & transitions to low power state 670Sstevel@tonic-gate * 8 = Remote wakeup by device OR Application kicking off IO to device 680Sstevel@tonic-gate * This results in a Transistion state till PM calls the power 690Sstevel@tonic-gate * entry point to raise the power level of the device 700Sstevel@tonic-gate * 9 = Device entry point called to raise power level of the device 710Sstevel@tonic-gate * 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate 740Sstevel@tonic-gate 751418Sqz150045 /* Boot Interface Subclass for HID devices */ 761418Sqz150045 #define BOOT_INTERFACE 0x01 771418Sqz150045 780Sstevel@tonic-gate /* Boot protocol values for keyboard and mouse */ 790Sstevel@tonic-gate #define KEYBOARD_PROTOCOL 0x01 /* legacy keyboard */ 800Sstevel@tonic-gate #define MOUSE_PROTOCOL 0x02 /* legacy mouse */ 811418Sqz150045 #define NONE_PROTOCOL 0 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * If the hid descriptor is not valid, the following values are 840Sstevel@tonic-gate * used. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate #define USBKPSZ 8 /* keyboard packet size */ 870Sstevel@tonic-gate #define USBMSSZ 3 /* mouse packet size */ 880Sstevel@tonic-gate #define USB_KB_HID_DESCR_LENGTH 0x3f /* keyboard Report descr length */ 890Sstevel@tonic-gate #define USB_MS_HID_DESCR_LENGTH 0x32 /* mouse Report descr length */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * Flags for the default pipe. 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate #define HID_DEFAULT_PIPE_BUSY 0x01 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Hid interrupt pipe states. Interrupt pipe 980Sstevel@tonic-gate * can be in only one of these states : 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * open--1-->data_transferring--1-->open 1010Sstevel@tonic-gate * | 1020Sstevel@tonic-gate * |----2---->closed 1030Sstevel@tonic-gate * 1040Sstevel@tonic-gate * 1 = interrupt pipe callback 1050Sstevel@tonic-gate * 2 = hid_close 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate #define HID_INTERRUPT_PIPE_CLOSED 0x00 /* Int. pipe is closed */ 1080Sstevel@tonic-gate #define HID_INTERRUPT_PIPE_OPEN 0x01 /* Int. pipe is opened */ 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate /* HID mctl processing return codes */ 1110Sstevel@tonic-gate #define HID_SUCCESS 0 /* mctl processed successfully */ 1120Sstevel@tonic-gate #define HID_INPROGRESS 1 /* mctl queued/deferred for execution */ 1130Sstevel@tonic-gate #define HID_ENQUEUE 2 /* mctl queued/deferred for execution */ 1140Sstevel@tonic-gate #define HID_FAILURE -1 /* mctl processing failed */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* Data is being sent up */ 1170Sstevel@tonic-gate #define HID_INTERRUPT_PIPE_DATA_TRANSFERRING 0x03 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* Attach/detach states */ 1200Sstevel@tonic-gate #define HID_LOCK_INIT 0x01 /* Initial attach state */ 1210Sstevel@tonic-gate #define HID_MINOR_NODES 0x02 /* Set after minor node is created */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* HID Protocol Requests */ 1240Sstevel@tonic-gate #define SET_IDLE 0x0a /* bRequest value to set idle request */ 1250Sstevel@tonic-gate #define DURATION (0<<8) /* no. of repeat reports (HID 7.2.4) */ 1260Sstevel@tonic-gate #define SET_PROTOCOL 0x0b /* bRequest value for boot protocol */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* Hid PM scheme */ 1290Sstevel@tonic-gate typedef enum { 1300Sstevel@tonic-gate HID_PM_ACTIVITY, /* device is power managed by idleness */ 1310Sstevel@tonic-gate HID_PM_OPEN_CLOSE, /* device is busy on open, idle on close */ 1320Sstevel@tonic-gate HID_PM_APPLICATION /* device is power managed by application */ 1330Sstevel@tonic-gate } hid_pm_scheme_t; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate typedef struct hid_power { 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate void *hid_state; /* points back to hid_state */ 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate int hid_pm_busy; /* device busy accounting */ 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate hid_pm_scheme_t hid_pm_strategy; /* device PM */ 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate uint8_t hid_wakeup_enabled; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* this is the bit mask of the power states that device has */ 1460Sstevel@tonic-gate uint8_t hid_pwr_states; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* wakeup and power transistion capabilites of an interface */ 1490Sstevel@tonic-gate uint8_t hid_pm_capabilities; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* flag to indicate if driver is about to raise power level */ 1520Sstevel@tonic-gate boolean_t hid_raise_power; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* current power level the device is in */ 1550Sstevel@tonic-gate uint8_t hid_current_power; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* mblk indicating that the device has powered up */ 1580Sstevel@tonic-gate mblk_t *hid_pm_pwrup; 1590Sstevel@tonic-gate } hid_power_t; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_power_t::hid_state)) 1620Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_power_t::hid_pm_strategy)) 1630Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_power_t::hid_wakeup_enabled)) 1640Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_power_t::hid_pwr_states)) 1650Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_power_t::hid_pm_capabilities)) 1660Sstevel@tonic-gate 1679432SPengcheng.Chen@Sun.COM 1680Sstevel@tonic-gate typedef struct hid_state { 1690Sstevel@tonic-gate dev_info_t *hid_dip; /* per-device info handle */ 1700Sstevel@tonic-gate kmutex_t hid_mutex; /* for general locking */ 1710Sstevel@tonic-gate int hid_instance; /* instance number */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* Attach/detach flags */ 1740Sstevel@tonic-gate int hid_attach_flags; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* device state flag */ 1770Sstevel@tonic-gate int hid_dev_state; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* outstanding requests on the default pipe */ 1800Sstevel@tonic-gate int hid_default_pipe_req; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate hid_power_t *hid_pm; /* ptr to power struct */ 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate usb_client_dev_data_t *hid_dev_data; /* ptr to usb reg struct */ 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate usb_dev_descr_t *hid_dev_descr; /* device descriptor. */ 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* hid driver is attached to this interface */ 1890Sstevel@tonic-gate int hid_interfaceno; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate usb_if_descr_t hid_if_descr; /* interface descr */ 1920Sstevel@tonic-gate usb_hid_descr_t hid_hid_descr; /* hid descriptor */ 1930Sstevel@tonic-gate usb_ep_descr_t hid_ep_intr_descr; 1940Sstevel@tonic-gate hidparser_handle_t hid_report_descr; /* report descr */ 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate usb_pipe_handle_t hid_default_pipe; /* default pipe */ 1970Sstevel@tonic-gate usb_pipe_handle_t hid_interrupt_pipe; /* intr pipe handle */ 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate int hid_packet_size; /* data packet size */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* Pipe policy for the interrupt pipe is saved here */ 2020Sstevel@tonic-gate usb_pipe_policy_t hid_intr_pipe_policy; 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * This field is only used if the device provides polled input 2060Sstevel@tonic-gate * This is state information for the usba layer. 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate usb_console_info_t hid_polled_console_info; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate /* 2110Sstevel@tonic-gate * This is the buffer that the raw characters are stored in. 2120Sstevel@tonic-gate * for polled mode. 2130Sstevel@tonic-gate */ 2140Sstevel@tonic-gate uchar_t *hid_polled_raw_buf; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate /* handle for outputting messages */ 2170Sstevel@tonic-gate usb_log_handle_t hid_log_handle; 2189432SPengcheng.Chen@Sun.COM 219*10153SAaron.Zang@Sun.COM queue_t *hid_internal_rq; 220*10153SAaron.Zang@Sun.COM queue_t *hid_external_rq; 221*10153SAaron.Zang@Sun.COM /* which one of the above 2 streams gets the input */ 222*10153SAaron.Zang@Sun.COM queue_t *hid_inuse_rq; 223*10153SAaron.Zang@Sun.COM int hid_internal_flag; /* see below */ 224*10153SAaron.Zang@Sun.COM int hid_external_flag; /* see below */ 2250Sstevel@tonic-gate } hid_state_t; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* warlock directives, stable data */ 2280Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(hid_state_t::hid_mutex, hid_state_t)) 2290Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(hid_state_t::hid_mutex, hid_power_t)) 2300Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_dip)) 2310Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_pm)) 2320Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_dev_data)) 2330Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_instance)) 2340Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_interrupt_pipe)) 2350Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_ep_intr_descr)) 2360Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_default_pipe)) 2370Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_log_handle)) 2380Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_if_descr)) 2390Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_dev_data)) 240978Sfrits _NOTE(DATA_READABLE_WITHOUT_LOCK(hid_state_t::hid_dev_descr)) 2410Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_ep_descr)) 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate /* 2450Sstevel@tonic-gate * The hid_polled_console_info field is a handle from usba. The 2460Sstevel@tonic-gate * handle is used when the kernel is in the single thread mode 2470Sstevel@tonic-gate * so the field is tagged with this note. 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", 2500Sstevel@tonic-gate hid_state_t::hid_polled_console_info)) 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate /* 2530Sstevel@tonic-gate * structure for argument for callback routine for async 2540Sstevel@tonic-gate * data transfer through default pipe. 2550Sstevel@tonic-gate */ 2560Sstevel@tonic-gate typedef struct hid_default_pipe_argument { 2579432SPengcheng.Chen@Sun.COM /* Pointer to the write queue from which the message comes from */ 2589432SPengcheng.Chen@Sun.COM queue_t *hid_default_pipe_arg_queue; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* Message to be sent up to the stream */ 2610Sstevel@tonic-gate struct iocblk hid_default_pipe_arg_mctlmsg; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate /* Pointer to the original mblk_t received from hid_wput() */ 2640Sstevel@tonic-gate mblk_t *hid_default_pipe_arg_mblk; 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* Request that caused this callback to happen */ 2670Sstevel@tonic-gate uchar_t hid_default_pipe_arg_bRequest; 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate } hid_default_pipe_arg_t; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * An instance of this structure is created per command down to the 2730Sstevel@tonic-gate * device. The control callback is not executed until the call is 2740Sstevel@tonic-gate * made into usba, so there is no danger of a callback happening when 2750Sstevel@tonic-gate * the fields of the structure are being set. 2760Sstevel@tonic-gate */ 2770Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", hid_default_pipe_arg_t)) 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2800Sstevel@tonic-gate * An instance of this structure is created per command down to the 2810Sstevel@tonic-gate * device. The callback is not executed until the call is 2820Sstevel@tonic-gate * made into usba, so there is no danger of a callback happening when 2830Sstevel@tonic-gate * the fields of the structure are being set. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate 286*10153SAaron.Zang@Sun.COM /* Value for hid_[internal|external]_flag */ 2870Sstevel@tonic-gate #define HID_STREAMS_OPEN 0x00000001 /* Streams are open */ 2880Sstevel@tonic-gate #define HID_STREAMS_DISMANTLING 0x00000002 /* In hid_close() */ 2890Sstevel@tonic-gate 290*10153SAaron.Zang@Sun.COM #define HID_STREAMS_FLAG(q, hidp) ((q) == (hidp)->hid_internal_rq ? \ 291*10153SAaron.Zang@Sun.COM (hidp)->hid_internal_flag : (hidp)->hid_external_flag) 292*10153SAaron.Zang@Sun.COM 293*10153SAaron.Zang@Sun.COM #define HID_IS_OPEN(hidp) (((hidp)->hid_internal_flag == \ 294*10153SAaron.Zang@Sun.COM HID_STREAMS_OPEN) || ((hidp)->hid_external_flag == HID_STREAMS_OPEN)) 295*10153SAaron.Zang@Sun.COM 2960Sstevel@tonic-gate #define HID_BAD_DESCR 0x01 /* Bad hid report descriptor */ 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate #define HID_MINOR_NAME_LEN 20 /* Max length of minor_name string */ 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate /* hid_close will wait 60 secons for callbacks to be over */ 3010Sstevel@tonic-gate #define HID_CLOSE_WAIT_TIMEOUT 10 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate /* define a timeout for draining requests on the default control pipe */ 3040Sstevel@tonic-gate #define HID_DEFAULT_PIPE_DRAIN_TIMEOUT 5 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate /* To support PM on SUN mice of later revisions */ 3070Sstevel@tonic-gate #define HID_SUN_MOUSE_VENDOR_ID 0x0430 3080Sstevel@tonic-gate #define HID_SUN_MOUSE_PROD_ID 0x0100 3090Sstevel@tonic-gate #define HID_SUN_MOUSE_BCDDEVICE 0x0105 /* and later revisions */ 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * Debug message Masks 3140Sstevel@tonic-gate */ 3150Sstevel@tonic-gate #define PRINT_MASK_ATTA 0x00000001 3160Sstevel@tonic-gate #define PRINT_MASK_OPEN 0x00000002 3170Sstevel@tonic-gate #define PRINT_MASK_CLOSE 0x00000004 3180Sstevel@tonic-gate #define PRINT_MASK_EVENTS 0x00000008 3190Sstevel@tonic-gate #define PRINT_MASK_PM 0x00000010 3200Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFF 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate /* 3230Sstevel@tonic-gate * Define states local to hid driver 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate #define USB_DEV_HID_POWER_CHANGE 0x80 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* define for retrying control requests */ 3280Sstevel@tonic-gate #define HID_RETRY 10 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate #ifdef __cplusplus 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate #endif 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate #endif /* _SYS_USB_HIDVAR_H */ 335