aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/input/virtio-input-hid.c119
-rw-r--r--hw/watchdog/watchdog.c65
-rw-r--r--hw/watchdog/wdt_diag288.c6
3 files changed, 150 insertions, 40 deletions
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index 4d3afc1b14..e78faec0b1 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -190,6 +190,7 @@ static void virtio_input_key_config(VirtIOInput *vinput,
static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
InputEvent *evt)
{
+ VirtIOInputHID *vhid = VIRTIO_INPUT_HID(dev);
VirtIOInput *vinput = VIRTIO_INPUT(dev);
virtio_input_event event;
int qcode;
@@ -215,7 +216,14 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
break;
case INPUT_EVENT_KIND_BTN:
btn = evt->u.btn.data;
- if (keymap_button[btn->button]) {
+ if (vhid->wheel_axis && (btn->button == INPUT_BUTTON_WHEEL_UP ||
+ btn->button == INPUT_BUTTON_WHEEL_DOWN)) {
+ event.type = cpu_to_le16(EV_REL);
+ event.code = cpu_to_le16(REL_WHEEL);
+ event.value = cpu_to_le32(btn->button == INPUT_BUTTON_WHEEL_UP
+ ? 1 : -1);
+ virtio_input_send(vinput, &event);
+ } else if (keymap_button[btn->button]) {
event.type = cpu_to_le16(EV_KEY);
event.code = cpu_to_le16(keymap_button[btn->button]);
event.value = cpu_to_le32(btn->down ? 1 : 0);
@@ -407,7 +415,7 @@ static QemuInputHandler virtio_mouse_handler = {
.sync = virtio_input_handle_sync,
};
-static struct virtio_input_config virtio_mouse_config[] = {
+static struct virtio_input_config virtio_mouse_config_v1[] = {
{
.select = VIRTIO_INPUT_CFG_ID_NAME,
.size = sizeof(VIRTIO_ID_NAME_MOUSE),
@@ -432,13 +440,53 @@ static struct virtio_input_config virtio_mouse_config[] = {
{ /* end of list */ },
};
+static struct virtio_input_config virtio_mouse_config_v2[] = {
+ {
+ .select = VIRTIO_INPUT_CFG_ID_NAME,
+ .size = sizeof(VIRTIO_ID_NAME_MOUSE),
+ .u.string = VIRTIO_ID_NAME_MOUSE,
+ },{
+ .select = VIRTIO_INPUT_CFG_ID_DEVIDS,
+ .size = sizeof(struct virtio_input_devids),
+ .u.ids = {
+ .bustype = const_le16(BUS_VIRTUAL),
+ .vendor = const_le16(0x0627), /* same we use for usb hid devices */
+ .product = const_le16(0x0002),
+ .version = const_le16(0x0002),
+ },
+ },{
+ .select = VIRTIO_INPUT_CFG_EV_BITS,
+ .subsel = EV_REL,
+ .size = 2,
+ .u.bitmap = {
+ (1 << REL_X) | (1 << REL_Y),
+ (1 << (REL_WHEEL - 8))
+ },
+ },
+ { /* end of list */ },
+};
+
+static Property virtio_mouse_properties[] = {
+ DEFINE_PROP_BOOL("wheel-axis", VirtIOInputHID, wheel_axis, true),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_mouse_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->props = virtio_mouse_properties;
+}
+
static void virtio_mouse_init(Object *obj)
{
VirtIOInputHID *vhid = VIRTIO_INPUT_HID(obj);
VirtIOInput *vinput = VIRTIO_INPUT(obj);
vhid->handler = &virtio_mouse_handler;
- virtio_input_init_config(vinput, virtio_mouse_config);
+ virtio_input_init_config(vinput, vhid->wheel_axis
+ ? virtio_mouse_config_v2
+ : virtio_mouse_config_v1);
virtio_input_key_config(vinput, keymap_button,
ARRAY_SIZE(keymap_button));
}
@@ -448,6 +496,7 @@ static const TypeInfo virtio_mouse_info = {
.parent = TYPE_VIRTIO_INPUT_HID,
.instance_size = sizeof(VirtIOInputHID),
.instance_init = virtio_mouse_init,
+ .class_init = virtio_mouse_class_init,
};
/* ----------------------------------------------------------------- */
@@ -459,7 +508,7 @@ static QemuInputHandler virtio_tablet_handler = {
.sync = virtio_input_handle_sync,
};
-static struct virtio_input_config virtio_tablet_config[] = {
+static struct virtio_input_config virtio_tablet_config_v1[] = {
{
.select = VIRTIO_INPUT_CFG_ID_NAME,
.size = sizeof(VIRTIO_ID_NAME_TABLET),
@@ -496,13 +545,72 @@ static struct virtio_input_config virtio_tablet_config[] = {
{ /* end of list */ },
};
+static struct virtio_input_config virtio_tablet_config_v2[] = {
+ {
+ .select = VIRTIO_INPUT_CFG_ID_NAME,
+ .size = sizeof(VIRTIO_ID_NAME_TABLET),
+ .u.string = VIRTIO_ID_NAME_TABLET,
+ },{
+ .select = VIRTIO_INPUT_CFG_ID_DEVIDS,
+ .size = sizeof(struct virtio_input_devids),
+ .u.ids = {
+ .bustype = const_le16(BUS_VIRTUAL),
+ .vendor = const_le16(0x0627), /* same we use for usb hid devices */
+ .product = const_le16(0x0003),
+ .version = const_le16(0x0002),
+ },
+ },{
+ .select = VIRTIO_INPUT_CFG_EV_BITS,
+ .subsel = EV_ABS,
+ .size = 1,
+ .u.bitmap = {
+ (1 << ABS_X) | (1 << ABS_Y),
+ },
+ },{
+ .select = VIRTIO_INPUT_CFG_EV_BITS,
+ .subsel = EV_REL,
+ .size = 2,
+ .u.bitmap = {
+ 0,
+ (1 << (REL_WHEEL - 8))
+ },
+ },{
+ .select = VIRTIO_INPUT_CFG_ABS_INFO,
+ .subsel = ABS_X,
+ .size = sizeof(virtio_input_absinfo),
+ .u.abs.min = const_le32(INPUT_EVENT_ABS_MIN),
+ .u.abs.max = const_le32(INPUT_EVENT_ABS_MAX),
+ },{
+ .select = VIRTIO_INPUT_CFG_ABS_INFO,
+ .subsel = ABS_Y,
+ .size = sizeof(virtio_input_absinfo),
+ .u.abs.min = const_le32(INPUT_EVENT_ABS_MIN),
+ .u.abs.max = const_le32(INPUT_EVENT_ABS_MAX),
+ },
+ { /* end of list */ },
+};
+
+static Property virtio_tablet_properties[] = {
+ DEFINE_PROP_BOOL("wheel-axis", VirtIOInputHID, wheel_axis, true),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_tablet_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->props = virtio_tablet_properties;
+}
+
static void virtio_tablet_init(Object *obj)
{
VirtIOInputHID *vhid = VIRTIO_INPUT_HID(obj);
VirtIOInput *vinput = VIRTIO_INPUT(obj);
vhid->handler = &virtio_tablet_handler;
- virtio_input_init_config(vinput, virtio_tablet_config);
+ virtio_input_init_config(vinput, vhid->wheel_axis
+ ? virtio_tablet_config_v2
+ : virtio_tablet_config_v1);
virtio_input_key_config(vinput, keymap_button,
ARRAY_SIZE(keymap_button));
}
@@ -512,6 +620,7 @@ static const TypeInfo virtio_tablet_info = {
.parent = TYPE_VIRTIO_INPUT_HID,
.instance_size = sizeof(VirtIOInputHID),
.instance_init = virtio_tablet_init,
+ .class_init = virtio_tablet_class_init,
};
/* ----------------------------------------------------------------- */
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index 0c5c9cde1c..670114ecfe 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -29,8 +29,9 @@
#include "qapi-event.h"
#include "hw/nmi.h"
#include "qemu/help_option.h"
+#include "qmp-commands.h"
-static int watchdog_action = WDT_RESET;
+static WatchdogAction watchdog_action = WATCHDOG_ACTION_RESET;
static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
void watchdog_add_model(WatchdogTimerModel *model)
@@ -77,27 +78,19 @@ int select_watchdog(const char *p)
int select_watchdog_action(const char *p)
{
- if (strcasecmp(p, "reset") == 0)
- watchdog_action = WDT_RESET;
- else if (strcasecmp(p, "shutdown") == 0)
- watchdog_action = WDT_SHUTDOWN;
- else if (strcasecmp(p, "poweroff") == 0)
- watchdog_action = WDT_POWEROFF;
- else if (strcasecmp(p, "pause") == 0)
- watchdog_action = WDT_PAUSE;
- else if (strcasecmp(p, "debug") == 0)
- watchdog_action = WDT_DEBUG;
- else if (strcasecmp(p, "none") == 0)
- watchdog_action = WDT_NONE;
- else if (strcasecmp(p, "inject-nmi") == 0)
- watchdog_action = WDT_NMI;
- else
- return -1;
+ int action;
+ char *qapi_value;
+ qapi_value = g_ascii_strdown(p, -1);
+ action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, NULL);
+ g_free(qapi_value);
+ if (action < 0)
+ return -1;
+ qmp_watchdog_set_action(action, &error_abort);
return 0;
}
-int get_watchdog_action(void)
+WatchdogAction get_watchdog_action(void)
{
return watchdog_action;
}
@@ -108,42 +101,50 @@ int get_watchdog_action(void)
void watchdog_perform_action(void)
{
switch (watchdog_action) {
- case WDT_RESET: /* same as 'system_reset' in monitor */
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_RESET, &error_abort);
+ case WATCHDOG_ACTION_RESET: /* same as 'system_reset' in monitor */
+ qapi_event_send_watchdog(WATCHDOG_ACTION_RESET, &error_abort);
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
break;
- case WDT_SHUTDOWN: /* same as 'system_powerdown' in monitor */
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_SHUTDOWN, &error_abort);
+ case WATCHDOG_ACTION_SHUTDOWN: /* same as 'system_powerdown' in monitor */
+ qapi_event_send_watchdog(WATCHDOG_ACTION_SHUTDOWN, &error_abort);
qemu_system_powerdown_request();
break;
- case WDT_POWEROFF: /* same as 'quit' command in monitor */
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_POWEROFF, &error_abort);
+ case WATCHDOG_ACTION_POWEROFF: /* same as 'quit' command in monitor */
+ qapi_event_send_watchdog(WATCHDOG_ACTION_POWEROFF, &error_abort);
exit(0);
- case WDT_PAUSE: /* same as 'stop' command in monitor */
+ case WATCHDOG_ACTION_PAUSE: /* same as 'stop' command in monitor */
/* In a timer callback, when vm_stop calls qemu_clock_enable
* you would get a deadlock. Bypass the problem.
*/
qemu_system_vmstop_request_prepare();
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_PAUSE, &error_abort);
+ qapi_event_send_watchdog(WATCHDOG_ACTION_PAUSE, &error_abort);
qemu_system_vmstop_request(RUN_STATE_WATCHDOG);
break;
- case WDT_DEBUG:
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_DEBUG, &error_abort);
+ case WATCHDOG_ACTION_DEBUG:
+ qapi_event_send_watchdog(WATCHDOG_ACTION_DEBUG, &error_abort);
fprintf(stderr, "watchdog: timer fired\n");
break;
- case WDT_NONE:
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_NONE, &error_abort);
+ case WATCHDOG_ACTION_NONE:
+ qapi_event_send_watchdog(WATCHDOG_ACTION_NONE, &error_abort);
break;
- case WDT_NMI:
- qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_INJECT_NMI,
+ case WATCHDOG_ACTION_INJECT_NMI:
+ qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI,
&error_abort);
nmi_monitor_handle(0, NULL);
break;
+
+ default:
+ assert(0);
}
}
+
+void qmp_watchdog_set_action(WatchdogAction action, Error **errp)
+{
+ watchdog_action = action;
+}
diff --git a/hw/watchdog/wdt_diag288.c b/hw/watchdog/wdt_diag288.c
index 47f289216a..1475743527 100644
--- a/hw/watchdog/wdt_diag288.c
+++ b/hw/watchdog/wdt_diag288.c
@@ -57,9 +57,9 @@ static void diag288_timer_expired(void *dev)
* the BQL; reset before triggering the action to avoid races with
* diag288 instructions. */
switch (get_watchdog_action()) {
- case WDT_DEBUG:
- case WDT_NONE:
- case WDT_PAUSE:
+ case WATCHDOG_ACTION_DEBUG:
+ case WATCHDOG_ACTION_NONE:
+ case WATCHDOG_ACTION_PAUSE:
break;
default:
wdt_diag288_reset(dev);