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>
This commit is contained in:
Sergio Lopez 2023-05-26 13:29:20 +02:00 committed by Marc-André Lureau
parent 4c93ce54e7
commit 944ae6d9f1

View File

@ -44,30 +44,31 @@ static const unsigned short axismap_abs[INPUT_AXIS__MAX] = {
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
static void virtio_input_key_config(VirtIOInput *vinput, static void virtio_input_extend_config(VirtIOInput *vinput,
const unsigned short *keymap, const unsigned short *map,
size_t mapsize) size_t mapsize,
uint8_t select, uint8_t subsel)
{ {
virtio_input_config keys; virtio_input_config ext;
int i, bit, byte, bmax = 0; int i, bit, byte, bmax = 0;
memset(&keys, 0, sizeof(keys)); memset(&ext, 0, sizeof(ext));
for (i = 0; i < mapsize; i++) { for (i = 0; i < mapsize; i++) {
bit = keymap[i]; bit = map[i];
if (!bit) { if (!bit) {
continue; continue;
} }
byte = bit / 8; byte = bit / 8;
bit = bit % 8; bit = bit % 8;
keys.u.bitmap[byte] |= (1 << bit); ext.u.bitmap[byte] |= (1 << bit);
if (bmax < byte+1) { if (bmax < byte+1) {
bmax = byte+1; bmax = byte+1;
} }
} }
keys.select = VIRTIO_INPUT_CFG_EV_BITS; ext.select = select;
keys.subsel = EV_KEY; ext.subsel = subsel;
keys.size = bmax; ext.size = bmax;
virtio_input_add_config(vinput, &keys); virtio_input_add_config(vinput, &ext);
} }
static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, 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; vhid->handler = &virtio_keyboard_handler;
virtio_input_init_config(vinput, virtio_keyboard_config); virtio_input_init_config(vinput, virtio_keyboard_config);
virtio_input_key_config(vinput, qemu_input_map_qcode_to_linux, virtio_input_extend_config(vinput, qemu_input_map_qcode_to_linux,
qemu_input_map_qcode_to_linux_len); qemu_input_map_qcode_to_linux_len,
VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
} }
static const TypeInfo virtio_keyboard_info = { 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_input_init_config(vinput, vhid->wheel_axis
? virtio_mouse_config_v2 ? virtio_mouse_config_v2
: virtio_mouse_config_v1); : virtio_mouse_config_v1);
virtio_input_key_config(vinput, keymap_button, virtio_input_extend_config(vinput, keymap_button,
ARRAY_SIZE(keymap_button)); ARRAY_SIZE(keymap_button),
VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
} }
static const TypeInfo virtio_mouse_info = { 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_input_init_config(vinput, vhid->wheel_axis
? virtio_tablet_config_v2 ? virtio_tablet_config_v2
: virtio_tablet_config_v1); : virtio_tablet_config_v1);
virtio_input_key_config(vinput, keymap_button, virtio_input_extend_config(vinput, keymap_button,
ARRAY_SIZE(keymap_button)); ARRAY_SIZE(keymap_button),
VIRTIO_INPUT_CFG_EV_BITS, EV_KEY);
} }
static const TypeInfo virtio_tablet_info = { static const TypeInfo virtio_tablet_info = {