2 * Vhost-user GPIO virtio device
4 * Copyright (c) 2022 Viresh Kumar <viresh.kumar@linaro.org>
6 * SPDX-License-Identifier: GPL-2.0-or-later
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"
17 static Property vgpio_properties
[] = {
18 DEFINE_PROP_CHR("chardev", VHostUserBase
, chardev
),
19 DEFINE_PROP_END_OF_LIST(),
22 static void vgpio_realize(DeviceState
*dev
, Error
**errp
)
24 VHostUserBase
*vub
= VHOST_USER_BASE(dev
);
25 VHostUserBaseClass
*vubc
= VHOST_USER_BASE_GET_CLASS(dev
);
28 vub
->virtio_id
= VIRTIO_ID_GPIO
;
30 vub
->config_size
= sizeof(struct virtio_gpio_config
);
32 vubc
->parent_realize(dev
, errp
);
35 static const VMStateDescription vu_gpio_vmstate
= {
36 .name
= "vhost-user-gpio",
40 static void vu_gpio_class_init(ObjectClass
*klass
, void *data
)
42 DeviceClass
*dc
= DEVICE_CLASS(klass
);
43 VHostUserBaseClass
*vubc
= VHOST_USER_BASE_CLASS(klass
);
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
);
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
,
59 static void vu_gpio_register_types(void)
61 type_register_static(&vu_gpio_info
);
64 type_init(vu_gpio_register_types
)