xref: /freebsd/sys/dev/hyperv/input/hv_kbdc.h (revision 926ce35a7e33457153b56be1ba51a31aea674000)
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 #define HVKBD_DRIVER_NAME	"hvkbd"
40 #define IS_UNICODE		(1)
41 #define IS_BREAK		(2)
42 #define IS_E0			(4)
43 #define IS_E1			(8)
44 
45 #define XTKBD_EMUL0		(0xe0)
46 #define XTKBD_EMUL1		(0xe1)
47 #define XTKBD_RELEASE		(0x80)
48 
49 #define DEBUG_HVSC(sc, ...) do {			\
50 	if (sc->debug > 0) {				\
51 		device_printf(sc->dev, __VA_ARGS__);	\
52 	}						\
53 } while (0)
54 #define DEBUG_HVKBD(kbd, ...) do {			\
55 	hv_kbd_sc *sc = (kbd)->kb_data;			\
56 	DEBUG_HVSC(sc, __VA_ARGS__);				\
57 } while (0)
58 
59 struct vmbus_channel;
60 struct vmbus_xact_ctx;
61 
62 typedef struct keystroke_t {
63 	uint16_t			makecode;
64 	uint32_t			info;
65 } keystroke;
66 
67 typedef struct keystroke_info {
68 	LIST_ENTRY(keystroke_info)	link;
69 	STAILQ_ENTRY(keystroke_info)	slink;
70 	keystroke			ks;
71 } keystroke_info;
72 
73 typedef struct hv_kbd_sc_t {
74 	struct vmbus_channel		*hs_chan;
75 	device_t			dev;
76 	struct vmbus_xact_ctx		*hs_xact_ctx;
77 	int32_t				buflen;
78 	uint8_t				*buf;
79 
80 	struct mtx			ks_mtx;
81 	LIST_HEAD(, keystroke_info)	ks_free_list;
82 	STAILQ_HEAD(, keystroke_info)	ks_queue;	/* keystroke info queue */
83 
84 	keyboard_t			sc_kbd;
85 	int				sc_mode;
86 	int				sc_state;
87 	int				sc_polling;	/* polling recursion count */
88 	uint32_t			sc_flags;
89 	int				debug;
90 } hv_kbd_sc;
91 
92 int	hv_kbd_produce_ks(hv_kbd_sc *sc, const keystroke *ks);
93 int	hv_kbd_fetch_top(hv_kbd_sc *sc, keystroke *top);
94 int	hv_kbd_modify_top(hv_kbd_sc *sc, keystroke *top);
95 int	hv_kbd_remove_top(hv_kbd_sc *sc);
96 int	hv_kbd_prod_is_ready(hv_kbd_sc *sc);
97 void	hv_kbd_read_channel(struct vmbus_channel *, void *);
98 
99 int	hv_kbd_drv_attach(device_t dev);
100 int	hv_kbd_drv_detach(device_t dev);
101 
102 int	hvkbd_driver_load(module_t, int, void *);
103 void	hv_kbd_intr(hv_kbd_sc *sc);
104 #endif
105