xref: /freebsd/sys/dev/hyperv/input/hv_kbdc.h (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
1 /*-
2  * Copyright (c) 2017 Microsoft Corp.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _HV_KBD_H
30 #define _HV_KBD_H
31 #include <sys/param.h>
32 #include <sys/lock.h>
33 #include <sys/mutex.h>
34 #include <sys/queue.h>
35 #include <sys/systm.h>
36 
37 #include <dev/kbd/kbdreg.h>
38 
39 #include "opt_evdev.h"
40 #ifdef EVDEV_SUPPORT
41 #include <dev/evdev/evdev.h>
42 #include <dev/evdev/input.h>
43 #endif
44 
45 #define HVKBD_DRIVER_NAME	"hvkbd"
46 #define IS_UNICODE		(1)
47 #define IS_BREAK		(2)
48 #define IS_E0			(4)
49 #define IS_E1			(8)
50 
51 #define XTKBD_EMUL0		(0xe0)
52 #define XTKBD_EMUL1		(0xe1)
53 #define XTKBD_RELEASE		(0x80)
54 
55 #define DEBUG_HVSC(sc, ...) do {			\
56 	if (sc->debug > 0) {				\
57 		device_printf(sc->dev, __VA_ARGS__);	\
58 	}						\
59 } while (0)
60 #define DEBUG_HVKBD(kbd, ...) do {			\
61 	hv_kbd_sc *sc = (kbd)->kb_data;			\
62 	DEBUG_HVSC(sc, __VA_ARGS__);				\
63 } while (0)
64 
65 struct vmbus_channel;
66 struct vmbus_xact_ctx;
67 
68 typedef struct keystroke_t {
69 	uint16_t			makecode;
70 	uint32_t			info;
71 } keystroke;
72 
73 typedef struct keystroke_info {
74 	LIST_ENTRY(keystroke_info)	link;
75 	STAILQ_ENTRY(keystroke_info)	slink;
76 	keystroke			ks;
77 } keystroke_info;
78 
79 typedef struct hv_kbd_sc_t {
80 	struct vmbus_channel		*hs_chan;
81 	device_t			dev;
82 	struct vmbus_xact_ctx		*hs_xact_ctx;
83 	int32_t				buflen;
84 	uint8_t				*buf;
85 
86 	struct mtx			ks_mtx;
87 	LIST_HEAD(, keystroke_info)	ks_free_list;
88 	STAILQ_HEAD(, keystroke_info)	ks_queue;	/* keystroke info queue */
89 
90 	keyboard_t			sc_kbd;
91 	int				sc_mode;
92 	int				sc_state;
93 	uint32_t			sc_accents;	/* accent key index (> 0) */
94 	uint32_t			sc_composed_char; /* composed char code */
95 	uint8_t				sc_prefix;	/* AT scan code prefix */
96 	int				sc_polling;	/* polling recursion count */
97 	uint32_t			sc_flags;
98 	int				debug;
99 
100 #ifdef EVDEV_SUPPORT
101 	struct evdev_dev		*ks_evdev;
102 	int				ks_evdev_state;
103 #endif
104 } hv_kbd_sc;
105 
106 int	hv_kbd_produce_ks(hv_kbd_sc *sc, const keystroke *ks);
107 int	hv_kbd_fetch_top(hv_kbd_sc *sc, keystroke *top);
108 int	hv_kbd_modify_top(hv_kbd_sc *sc, keystroke *top);
109 int	hv_kbd_remove_top(hv_kbd_sc *sc);
110 int	hv_kbd_prod_is_ready(hv_kbd_sc *sc);
111 void	hv_kbd_read_channel(struct vmbus_channel *, void *);
112 
113 int	hv_kbd_drv_attach(device_t dev);
114 int	hv_kbd_drv_detach(device_t dev);
115 
116 int	hvkbd_driver_load(module_t, int, void *);
117 void	hv_kbd_intr(hv_kbd_sc *sc);
118 #endif
119