xref: /freebsd/sys/dev/hyperv/input/hv_kbdc.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
13f1b91c5SSepherosa Ziehau /*-
23f1b91c5SSepherosa Ziehau  * Copyright (c) 2017 Microsoft Corp.
33f1b91c5SSepherosa Ziehau  * All rights reserved.
43f1b91c5SSepherosa Ziehau  *
53f1b91c5SSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
63f1b91c5SSepherosa Ziehau  * modification, are permitted provided that the following conditions
73f1b91c5SSepherosa Ziehau  * are met:
83f1b91c5SSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
93f1b91c5SSepherosa Ziehau  *    notice unmodified, this list of conditions, and the following
103f1b91c5SSepherosa Ziehau  *    disclaimer.
113f1b91c5SSepherosa Ziehau  * 2. Redistributions in binary form must reproduce the above copyright
123f1b91c5SSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer in the
133f1b91c5SSepherosa Ziehau  *    documentation and/or other materials provided with the distribution.
143f1b91c5SSepherosa Ziehau  *
153f1b91c5SSepherosa Ziehau  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
163f1b91c5SSepherosa Ziehau  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173f1b91c5SSepherosa Ziehau  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183f1b91c5SSepherosa Ziehau  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
193f1b91c5SSepherosa Ziehau  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
203f1b91c5SSepherosa Ziehau  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
213f1b91c5SSepherosa Ziehau  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223f1b91c5SSepherosa Ziehau  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
233f1b91c5SSepherosa Ziehau  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
243f1b91c5SSepherosa Ziehau  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253f1b91c5SSepherosa Ziehau  */
263f1b91c5SSepherosa Ziehau 
273f1b91c5SSepherosa Ziehau #ifndef _HV_KBD_H
283f1b91c5SSepherosa Ziehau #define _HV_KBD_H
293f1b91c5SSepherosa Ziehau #include <sys/param.h>
303f1b91c5SSepherosa Ziehau #include <sys/lock.h>
313f1b91c5SSepherosa Ziehau #include <sys/mutex.h>
323f1b91c5SSepherosa Ziehau #include <sys/queue.h>
333f1b91c5SSepherosa Ziehau #include <sys/systm.h>
343f1b91c5SSepherosa Ziehau 
353f1b91c5SSepherosa Ziehau #include <dev/kbd/kbdreg.h>
363f1b91c5SSepherosa Ziehau 
37c2a15928SVladimir Kondratyev #include "opt_evdev.h"
38c2a15928SVladimir Kondratyev #ifdef EVDEV_SUPPORT
39c2a15928SVladimir Kondratyev #include <dev/evdev/evdev.h>
40c2a15928SVladimir Kondratyev #include <dev/evdev/input.h>
41c2a15928SVladimir Kondratyev #endif
42c2a15928SVladimir Kondratyev 
433f1b91c5SSepherosa Ziehau #define HVKBD_DRIVER_NAME	"hvkbd"
443f1b91c5SSepherosa Ziehau #define IS_UNICODE		(1)
453f1b91c5SSepherosa Ziehau #define IS_BREAK		(2)
463f1b91c5SSepherosa Ziehau #define IS_E0			(4)
473f1b91c5SSepherosa Ziehau #define IS_E1			(8)
483f1b91c5SSepherosa Ziehau 
493f1b91c5SSepherosa Ziehau #define XTKBD_EMUL0		(0xe0)
503f1b91c5SSepherosa Ziehau #define XTKBD_EMUL1		(0xe1)
513f1b91c5SSepherosa Ziehau #define XTKBD_RELEASE		(0x80)
523f1b91c5SSepherosa Ziehau 
533f1b91c5SSepherosa Ziehau #define DEBUG_HVSC(sc, ...) do {			\
543f1b91c5SSepherosa Ziehau 	if (sc->debug > 0) {				\
553f1b91c5SSepherosa Ziehau 		device_printf(sc->dev, __VA_ARGS__);	\
563f1b91c5SSepherosa Ziehau 	}						\
573f1b91c5SSepherosa Ziehau } while (0)
583f1b91c5SSepherosa Ziehau #define DEBUG_HVKBD(kbd, ...) do {			\
593f1b91c5SSepherosa Ziehau 	hv_kbd_sc *sc = (kbd)->kb_data;			\
603f1b91c5SSepherosa Ziehau 	DEBUG_HVSC(sc, __VA_ARGS__);				\
613f1b91c5SSepherosa Ziehau } while (0)
623f1b91c5SSepherosa Ziehau 
633f1b91c5SSepherosa Ziehau struct vmbus_channel;
643f1b91c5SSepherosa Ziehau struct vmbus_xact_ctx;
653f1b91c5SSepherosa Ziehau 
663f1b91c5SSepherosa Ziehau typedef struct keystroke_t {
673f1b91c5SSepherosa Ziehau 	uint16_t			makecode;
683f1b91c5SSepherosa Ziehau 	uint32_t			info;
693f1b91c5SSepherosa Ziehau } keystroke;
703f1b91c5SSepherosa Ziehau 
713f1b91c5SSepherosa Ziehau typedef struct keystroke_info {
723f1b91c5SSepherosa Ziehau 	LIST_ENTRY(keystroke_info)	link;
733f1b91c5SSepherosa Ziehau 	STAILQ_ENTRY(keystroke_info)	slink;
743f1b91c5SSepherosa Ziehau 	keystroke			ks;
753f1b91c5SSepherosa Ziehau } keystroke_info;
763f1b91c5SSepherosa Ziehau 
773f1b91c5SSepherosa Ziehau typedef struct hv_kbd_sc_t {
783f1b91c5SSepherosa Ziehau 	struct vmbus_channel		*hs_chan;
793f1b91c5SSepherosa Ziehau 	device_t			dev;
803f1b91c5SSepherosa Ziehau 	struct vmbus_xact_ctx		*hs_xact_ctx;
813f1b91c5SSepherosa Ziehau 	int32_t				buflen;
823f1b91c5SSepherosa Ziehau 	uint8_t				*buf;
833f1b91c5SSepherosa Ziehau 
843f1b91c5SSepherosa Ziehau 	struct mtx			ks_mtx;
853f1b91c5SSepherosa Ziehau 	LIST_HEAD(, keystroke_info)	ks_free_list;
863f1b91c5SSepherosa Ziehau 	STAILQ_HEAD(, keystroke_info)	ks_queue;	/* keystroke info queue */
873f1b91c5SSepherosa Ziehau 
883f1b91c5SSepherosa Ziehau 	keyboard_t			sc_kbd;
893f1b91c5SSepherosa Ziehau 	int				sc_mode;
903f1b91c5SSepherosa Ziehau 	int				sc_state;
91*e4643aa4SVladimir Kondratyev 	uint32_t			sc_accents;	/* accent key index (> 0) */
92*e4643aa4SVladimir Kondratyev 	uint32_t			sc_composed_char; /* composed char code */
93*e4643aa4SVladimir Kondratyev 	uint8_t				sc_prefix;	/* AT scan code prefix */
943f1b91c5SSepherosa Ziehau 	int				sc_polling;	/* polling recursion count */
953f1b91c5SSepherosa Ziehau 	uint32_t			sc_flags;
963f1b91c5SSepherosa Ziehau 	int				debug;
97c2a15928SVladimir Kondratyev 
98c2a15928SVladimir Kondratyev #ifdef EVDEV_SUPPORT
99c2a15928SVladimir Kondratyev 	struct evdev_dev		*ks_evdev;
100c2a15928SVladimir Kondratyev 	int				ks_evdev_state;
101c2a15928SVladimir Kondratyev #endif
1023f1b91c5SSepherosa Ziehau } hv_kbd_sc;
1033f1b91c5SSepherosa Ziehau 
1043f1b91c5SSepherosa Ziehau int	hv_kbd_produce_ks(hv_kbd_sc *sc, const keystroke *ks);
1053f1b91c5SSepherosa Ziehau int	hv_kbd_fetch_top(hv_kbd_sc *sc, keystroke *top);
1063f1b91c5SSepherosa Ziehau int	hv_kbd_modify_top(hv_kbd_sc *sc, keystroke *top);
1073f1b91c5SSepherosa Ziehau int	hv_kbd_remove_top(hv_kbd_sc *sc);
1083f1b91c5SSepherosa Ziehau int	hv_kbd_prod_is_ready(hv_kbd_sc *sc);
1093f1b91c5SSepherosa Ziehau void	hv_kbd_read_channel(struct vmbus_channel *, void *);
1103f1b91c5SSepherosa Ziehau 
1113f1b91c5SSepherosa Ziehau int	hv_kbd_drv_attach(device_t dev);
1123f1b91c5SSepherosa Ziehau int	hv_kbd_drv_detach(device_t dev);
1133f1b91c5SSepherosa Ziehau 
1143f1b91c5SSepherosa Ziehau int	hvkbd_driver_load(module_t, int, void *);
1153f1b91c5SSepherosa Ziehau void	hv_kbd_intr(hv_kbd_sc *sc);
1163f1b91c5SSepherosa Ziehau #endif
117