cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

hid.h (2559B)


      1#ifndef QEMU_HID_H
      2#define QEMU_HID_H
      3
      4#include "ui/input.h"
      5
      6#define HID_MOUSE     1
      7#define HID_TABLET    2
      8#define HID_KEYBOARD  3
      9
     10typedef struct HIDPointerEvent {
     11    int32_t xdx, ydy; /* relative iff it's a mouse, otherwise absolute */
     12    int32_t dz, buttons_state;
     13} HIDPointerEvent;
     14
     15#define QUEUE_LENGTH    16 /* should be enough for a triple-click */
     16#define QUEUE_MASK      (QUEUE_LENGTH-1u)
     17#define QUEUE_INCR(v)   ((v)++, (v) &= QUEUE_MASK)
     18
     19typedef struct HIDState HIDState;
     20typedef void (*HIDEventFunc)(HIDState *s);
     21
     22typedef struct HIDMouseState {
     23    HIDPointerEvent queue[QUEUE_LENGTH];
     24    int mouse_grabbed;
     25} HIDMouseState;
     26
     27typedef struct HIDKeyboardState {
     28    uint32_t keycodes[QUEUE_LENGTH];
     29    uint16_t modifiers;
     30    uint8_t leds;
     31    uint8_t key[16];
     32    int32_t keys;
     33} HIDKeyboardState;
     34
     35struct HIDState {
     36    union {
     37        HIDMouseState ptr;
     38        HIDKeyboardState kbd;
     39    };
     40    uint32_t head; /* index into circular queue */
     41    uint32_t n;
     42    int kind;
     43    int32_t protocol;
     44    uint8_t idle;
     45    bool idle_pending;
     46    QEMUTimer *idle_timer;
     47    HIDEventFunc event;
     48    QemuInputHandlerState *s;
     49};
     50
     51void hid_init(HIDState *hs, int kind, HIDEventFunc event);
     52void hid_reset(HIDState *hs);
     53void hid_free(HIDState *hs);
     54
     55bool hid_has_events(HIDState *hs);
     56void hid_set_next_idle(HIDState *hs);
     57void hid_pointer_activate(HIDState *hs);
     58int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
     59int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
     60int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
     61
     62extern const VMStateDescription vmstate_hid_keyboard_device;
     63
     64#define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) {                \
     65    .name       = (stringify(_field)),                               \
     66    .size       = sizeof(HIDState),                                  \
     67    .vmsd       = &vmstate_hid_keyboard_device,                      \
     68    .flags      = VMS_STRUCT,                                        \
     69    .offset     = vmstate_offset_value(_state, _field, HIDState),    \
     70}
     71
     72extern const VMStateDescription vmstate_hid_ptr_device;
     73
     74#define VMSTATE_HID_POINTER_DEVICE(_field, _state) {                 \
     75    .name       = (stringify(_field)),                               \
     76    .size       = sizeof(HIDState),                                  \
     77    .vmsd       = &vmstate_hid_ptr_device,                           \
     78    .flags      = VMS_STRUCT,                                        \
     79    .offset     = vmstate_offset_value(_state, _field, HIDState),    \
     80}
     81
     82
     83#endif /* QEMU_HID_H */