xref: /openbmc/qemu/hw/virtio/vhost-user-gpio.c (revision 6fdc5bc1)
1 /*
2  * Vhost-user GPIO virtio device
3  *
4  * Copyright (c) 2022 Viresh Kumar <viresh.kumar@linaro.org>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
11 #include "hw/qdev-properties.h"
12 #include "hw/virtio/virtio-bus.h"
13 #include "hw/virtio/vhost-user-gpio.h"
14 #include "standard-headers/linux/virtio_ids.h"
15 #include "standard-headers/linux/virtio_gpio.h"
16 
17 static Property vgpio_properties[] = {
18     DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
19     DEFINE_PROP_END_OF_LIST(),
20 };
21 
22 static void vgpio_realize(DeviceState *dev, Error **errp)
23 {
24     VHostUserBase *vub = VHOST_USER_BASE(dev);
25     VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev);
26 
27     /* Fixed for GPIO */
28     vub->virtio_id = VIRTIO_ID_GPIO;
29     vub->num_vqs = 2;
30     vub->config_size = sizeof(struct virtio_gpio_config);
31 
32     vubc->parent_realize(dev, errp);
33 }
34 
35 static const VMStateDescription vu_gpio_vmstate = {
36     .name = "vhost-user-gpio",
37     .unmigratable = 1,
38 };
39 
40 static void vu_gpio_class_init(ObjectClass *klass, void *data)
41 {
42     DeviceClass *dc = DEVICE_CLASS(klass);
43     VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
44 
45     dc->vmsd = &vu_gpio_vmstate;
46     device_class_set_props(dc, vgpio_properties);
47     device_class_set_parent_realize(dc, vgpio_realize,
48                                     &vubc->parent_realize);
49     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
50 }
51 
52 static const TypeInfo vu_gpio_info = {
53     .name = TYPE_VHOST_USER_GPIO,
54     .parent = TYPE_VHOST_USER_BASE,
55     .instance_size = sizeof(VHostUserGPIO),
56     .class_init = vu_gpio_class_init,
57 };
58 
59 static void vu_gpio_register_types(void)
60 {
61     type_register_static(&vu_gpio_info);
62 }
63 
64 type_init(vu_gpio_register_types)
65