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 const Property vgpio_properties[] = { 18 DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), 19 }; 20 21 static void vgpio_realize(DeviceState *dev, Error **errp) 22 { 23 VHostUserBase *vub = VHOST_USER_BASE(dev); 24 VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); 25 26 /* Fixed for GPIO */ 27 vub->virtio_id = VIRTIO_ID_GPIO; 28 vub->num_vqs = 2; 29 vub->config_size = sizeof(struct virtio_gpio_config); 30 31 vubc->parent_realize(dev, errp); 32 } 33 34 static const VMStateDescription vu_gpio_vmstate = { 35 .name = "vhost-user-gpio", 36 .unmigratable = 1, 37 }; 38 39 static void vu_gpio_class_init(ObjectClass *klass, void *data) 40 { 41 DeviceClass *dc = DEVICE_CLASS(klass); 42 VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); 43 44 dc->vmsd = &vu_gpio_vmstate; 45 device_class_set_props(dc, vgpio_properties); 46 device_class_set_parent_realize(dc, vgpio_realize, 47 &vubc->parent_realize); 48 set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 49 } 50 51 static const TypeInfo vu_gpio_info = { 52 .name = TYPE_VHOST_USER_GPIO, 53 .parent = TYPE_VHOST_USER_BASE, 54 .instance_size = sizeof(VHostUserGPIO), 55 .class_init = vu_gpio_class_init, 56 }; 57 58 static void vu_gpio_register_types(void) 59 { 60 type_register_static(&vu_gpio_info); 61 } 62 63 type_init(vu_gpio_register_types) 64