qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/4] virtio-input: generalize virtio_input_key_config()


From: Marc-André Lureau
Subject: Re: [PATCH 1/4] virtio-input: generalize virtio_input_key_config()
Date: Sun, 19 Feb 2023 12:07:46 +0400

On Sat, Feb 18, 2023 at 8:23 PM Sergio Lopez <slp@redhat.com> wrote:
>
> 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>



> ---
>  hw/input/virtio-input-hid.c | 38 ++++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 17 deletions(-)
>
> diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
> index a7a244a95d..d28dab69ba 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 = {
> --
> 2.38.1
>
>


--
Marc-André Lureau



reply via email to

[Prev in Thread] Current Thread [Next in Thread]