2 * Copyright (c) 2017 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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.
31 #include <sys/param.h>
33 #include <sys/mutex.h>
34 #include <sys/queue.h>
35 #include <sys/systm.h>
37 #include <dev/kbd/kbdreg.h>
39 #define HVKBD_DRIVER_NAME "hvkbd"
40 #define IS_UNICODE (1)
45 #define XTKBD_EMUL0 (0xe0)
46 #define XTKBD_EMUL1 (0xe1)
47 #define XTKBD_RELEASE (0x80)
49 #define DEBUG_HVSC(sc, ...) do { \
50 if (sc->debug > 0) { \
51 device_printf(sc->dev, __VA_ARGS__); \
54 #define DEBUG_HVKBD(kbd, ...) do { \
55 hv_kbd_sc *sc = (kbd)->kb_data; \
56 DEBUG_HVSC(sc, __VA_ARGS__); \
60 struct vmbus_xact_ctx;
62 typedef struct keystroke_t {
67 typedef struct keystroke_info {
68 LIST_ENTRY(keystroke_info) link;
69 STAILQ_ENTRY(keystroke_info) slink;
73 typedef struct hv_kbd_sc_t {
74 struct vmbus_channel *hs_chan;
76 struct vmbus_xact_ctx *hs_xact_ctx;
81 LIST_HEAD(, keystroke_info) ks_free_list;
82 STAILQ_HEAD(, keystroke_info) ks_queue; /* keystroke info queue */
87 int sc_polling; /* polling recursion count */
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 *);
99 int hv_kbd_drv_attach(device_t dev);
100 int hv_kbd_drv_detach(device_t dev);
102 int hvkbd_driver_load(module_t, int, void *);
103 void hv_kbd_intr(hv_kbd_sc *sc);