xref: /freebsd/sys/dev/hyperv/input/hv_kbdc.h (revision 8d13bc63c0e1d50bc9e47ac1f26329c999bfecf0)
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 
27 #ifndef _HV_KBD_H
28 #define _HV_KBD_H
29 #include <sys/param.h>
30 #include <sys/lock.h>
31 #include <sys/mutex.h>
32 #include <sys/queue.h>
33 #include <sys/systm.h>
34 
35 #include <dev/kbd/kbdreg.h>
36 
37 #include "opt_evdev.h"
38 #ifdef EVDEV_SUPPORT
39 #include <dev/evdev/evdev.h>
40 #include <dev/evdev/input.h>
41 #endif
42 
43 #define HVKBD_DRIVER_NAME	"hvkbd"
44 #define IS_UNICODE		(1)
45 #define IS_BREAK		(2)
46 #define IS_E0			(4)
47 #define IS_E1			(8)
48 
49 #define XTKBD_EMUL0		(0xe0)
50 #define XTKBD_EMUL1		(0xe1)
51 #define XTKBD_RELEASE		(0x80)
52 
53 #define DEBUG_HVSC(sc, ...) do {			\
54 	if (sc->debug > 0) {				\
55 		device_printf(sc->dev, __VA_ARGS__);	\
56 	}						\
57 } while (0)
58 #define DEBUG_HVKBD(kbd, ...) do {			\
59 	hv_kbd_sc *sc = (kbd)->kb_data;			\
60 	DEBUG_HVSC(sc, __VA_ARGS__);				\
61 } while (0)
62 
63 struct vmbus_channel;
64 struct vmbus_xact_ctx;
65 
66 typedef struct keystroke_t {
67 	uint16_t			makecode;
68 	uint32_t			info;
69 } keystroke;
70 
71 typedef struct keystroke_info {
72 	LIST_ENTRY(keystroke_info)	link;
73 	STAILQ_ENTRY(keystroke_info)	slink;
74 	keystroke			ks;
75 } keystroke_info;
76 
77 typedef struct hv_kbd_sc_t {
78 	struct vmbus_channel		*hs_chan;
79 	device_t			dev;
80 	struct vmbus_xact_ctx		*hs_xact_ctx;
81 	int32_t				buflen;
82 	uint8_t				*buf;
83 
84 	struct mtx			ks_mtx;
85 	LIST_HEAD(, keystroke_info)	ks_free_list;
86 	STAILQ_HEAD(, keystroke_info)	ks_queue;	/* keystroke info queue */
87 
88 	keyboard_t			sc_kbd;
89 	int				sc_mode;
90 	int				sc_state;
91 	uint32_t			sc_accents;	/* accent key index (> 0) */
92 	uint32_t			sc_composed_char; /* composed char code */
93 	uint8_t				sc_prefix;	/* AT scan code prefix */
94 	int				sc_polling;	/* polling recursion count */
95 	uint32_t			sc_flags;
96 	int				debug;
97 
98 #ifdef EVDEV_SUPPORT
99 	struct evdev_dev		*ks_evdev;
100 	int				ks_evdev_state;
101 #endif
102 } hv_kbd_sc;
103 
104 int	hv_kbd_produce_ks(hv_kbd_sc *sc, const keystroke *ks);
105 int	hv_kbd_fetch_top(hv_kbd_sc *sc, keystroke *top);
106 int	hv_kbd_modify_top(hv_kbd_sc *sc, keystroke *top);
107 int	hv_kbd_remove_top(hv_kbd_sc *sc);
108 int	hv_kbd_prod_is_ready(hv_kbd_sc *sc);
109 void	hv_kbd_read_channel(struct vmbus_channel *, void *);
110 
111 int	hv_kbd_drv_attach(device_t dev);
112 int	hv_kbd_drv_detach(device_t dev);
113 
114 int	hvkbd_driver_load(module_t, int, void *);
115 void	hv_kbd_intr(hv_kbd_sc *sc);
116 #endif
117