1 /* 2 * Vhost-user i2c virtio device 3 * 4 * Copyright (c) 2021 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-i2c.h" 14 #include "qemu/error-report.h" 15 #include "standard-headers/linux/virtio_ids.h" 16 17 static const Property vi2c_properties[] = { 18 DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), 19 }; 20 21 static void vi2c_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 I2C */ 27 vub->virtio_id = VIRTIO_ID_I2C_ADAPTER; 28 vub->num_vqs = 1; 29 vub->vq_size = 4; 30 31 vubc->parent_realize(dev, errp); 32 } 33 34 static const VMStateDescription vu_i2c_vmstate = { 35 .name = "vhost-user-i2c", 36 .unmigratable = 1, 37 }; 38 39 static void vu_i2c_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_i2c_vmstate; 45 device_class_set_props(dc, vi2c_properties); 46 device_class_set_parent_realize(dc, vi2c_realize, 47 &vubc->parent_realize); 48 set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 49 } 50 51 static const TypeInfo vu_i2c_info = { 52 .name = TYPE_VHOST_USER_I2C, 53 .parent = TYPE_VHOST_USER_BASE, 54 .instance_size = sizeof(VHostUserI2C), 55 .class_init = vu_i2c_class_init, 56 }; 57 58 static void vu_i2c_register_types(void) 59 { 60 type_register_static(&vu_i2c_info); 61 } 62 63 type_init(vu_i2c_register_types) 64