aboutsummaryrefslogtreecommitdiff
path: root/hw/input
diff options
context:
space:
mode:
authorSergio Lopez <slp@redhat.com>2023-05-26 13:29:20 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2023-05-28 13:08:25 +0400
commit944ae6d9f17c3c6609f8d0832311b7a050d6c4b6 (patch)
tree572df01f8b59c42c0e8e41a60a6bd1d8286375ed /hw/input
parent4c93ce54e7114aae33100d2ee4f2b36e451a1d06 (diff)
downloadqemu-944ae6d9f17c3c6609f8d0832311b7a050d6c4b6.zip
qemu-944ae6d9f17c3c6609f8d0832311b7a050d6c4b6.tar.gz
qemu-944ae6d9f17c3c6609f8d0832311b7a050d6c4b6.tar.bz2
virtio-input: generalize virtio_input_key_config()
As there are other bitmap-based config properties that need to be dealt in a similar fashion as VIRTIO_INPUT_CFG_EV_BITS, generalize the function to receive select and subsel as arguments, and rename it to virtio_input_extend_config() Signed-off-by: Sergio Lopez <slp@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20230526112925.38794-2-slp@redhat.com>
Diffstat (limited to 'hw/input')
-rw-r--r--hw/input/virtio-input-hid.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
index a7a244a..d28dab6 100644
--- a/hw/input/virtio-input-hid.c
+++ b/hw/input/virtio-input-hid.c
@@ -44,30 +44,31 @@ static const unsigned short axismap_abs[INPUT_AXIS__MAX] = {
/* ----------------------------------------------------------------- */
-static void virtio_input_key_config(VirtIOInput *vinput,
- const unsigned short *keymap,
- size_t mapsize)
+static void virtio_input_extend_config(VirtIOInput *vinput,
+ const unsigned short *map,
+ size_t mapsize,
+ uint8_t select, uint8_t subsel)
{
- virtio_input_config keys;
+ virtio_input_config ext;
int i, bit, byte, bmax = 0;
- memset(&keys, 0, sizeof(keys));
+ memset(&ext, 0, sizeof(ext));
for (i = 0; i < mapsize; i++) {
- bit = keymap[i];
+ bit = map[i];
if (!bit) {
continue;
}
byte = bit / 8;
bit = bit % 8;
- keys.u.bitmap[byte] |= (1 << bit);
+ ext.u.bitmap[byte] |= (1 << bit);
if (bmax < byte+1) {
bmax = byte+1;
}
}
- keys.select = VIRTIO_INPUT_CFG_EV_BITS;
- keys.subsel = EV_KEY;
- keys.size = bmax;
- virtio_input_add_config(vinput, &keys);
+ ext.select = select;
+ ext.subsel = subsel;
+ ext.size = bmax;
+ virtio_input_add_config(vinput, &ext);
}
static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,
@@ -281,8 +282,9 @@ static void virtio_keyboard_init(Object *obj)
vhid->handler = &virtio_keyboard_handler;
virtio_input_init_config(vinput, virtio_keyboard_config);
- virtio_input_key_config(vinput, qemu_input_map_qcode_to_linux,
- qemu_input_map_qcode_to_linux_len);
+ virtio_input_extend_config(vinput, qemu_input_map_qcode_to_linux,
+ qemu_input_map_qcode_to_linux_len,
+ VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
}
static const TypeInfo virtio_keyboard_info = {
@@ -373,8 +375,9 @@ static void virtio_mouse_init(Object *obj)
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));
+ virtio_input_extend_config(vinput, keymap_button,
+ ARRAY_SIZE(keymap_button),
+ VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
}
static const TypeInfo virtio_mouse_info = {
@@ -497,8 +500,9 @@ static void virtio_tablet_init(Object *obj)
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));
+ virtio_input_extend_config(vinput, keymap_button,
+ ARRAY_SIZE(keymap_button),
+ VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
}
static const TypeInfo virtio_tablet_info = {