17221d3b6SViresh Kumar /*
27221d3b6SViresh Kumar * Vhost-user i2c virtio device
37221d3b6SViresh Kumar *
47221d3b6SViresh Kumar * Copyright (c) 2021 Viresh Kumar <viresh.kumar@linaro.org>
57221d3b6SViresh Kumar *
67221d3b6SViresh Kumar * SPDX-License-Identifier: GPL-2.0-or-later
77221d3b6SViresh Kumar */
87221d3b6SViresh Kumar
97221d3b6SViresh Kumar #include "qemu/osdep.h"
107221d3b6SViresh Kumar #include "qapi/error.h"
117221d3b6SViresh Kumar #include "hw/qdev-properties.h"
127221d3b6SViresh Kumar #include "hw/virtio/virtio-bus.h"
137221d3b6SViresh Kumar #include "hw/virtio/vhost-user-i2c.h"
147221d3b6SViresh Kumar #include "qemu/error-report.h"
157221d3b6SViresh Kumar #include "standard-headers/linux/virtio_ids.h"
167221d3b6SViresh Kumar
17*a50616b5SAlex Bennée static Property vi2c_properties[] = {
18*a50616b5SAlex Bennée DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
19*a50616b5SAlex Bennée DEFINE_PROP_END_OF_LIST(),
200a24dd1fSViresh Kumar };
210a24dd1fSViresh Kumar
vi2c_realize(DeviceState * dev,Error ** errp)22*a50616b5SAlex Bennée static void vi2c_realize(DeviceState *dev, Error **errp)
237221d3b6SViresh Kumar {
24*a50616b5SAlex Bennée VHostUserBase *vub = VHOST_USER_BASE(dev);
25*a50616b5SAlex Bennée VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev);
267221d3b6SViresh Kumar
27*a50616b5SAlex Bennée /* Fixed for I2C */
28*a50616b5SAlex Bennée vub->virtio_id = VIRTIO_ID_I2C_ADAPTER;
29*a50616b5SAlex Bennée vub->num_vqs = 1;
30*a50616b5SAlex Bennée vub->vq_size = 4;
317221d3b6SViresh Kumar
32*a50616b5SAlex Bennée vubc->parent_realize(dev, errp);
337221d3b6SViresh Kumar }
347221d3b6SViresh Kumar
357221d3b6SViresh Kumar static const VMStateDescription vu_i2c_vmstate = {
367221d3b6SViresh Kumar .name = "vhost-user-i2c",
377221d3b6SViresh Kumar .unmigratable = 1,
387221d3b6SViresh Kumar };
397221d3b6SViresh Kumar
vu_i2c_class_init(ObjectClass * klass,void * data)407221d3b6SViresh Kumar static void vu_i2c_class_init(ObjectClass *klass, void *data)
417221d3b6SViresh Kumar {
427221d3b6SViresh Kumar DeviceClass *dc = DEVICE_CLASS(klass);
43*a50616b5SAlex Bennée VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
447221d3b6SViresh Kumar
457221d3b6SViresh Kumar dc->vmsd = &vu_i2c_vmstate;
46*a50616b5SAlex Bennée device_class_set_props(dc, vi2c_properties);
47*a50616b5SAlex Bennée device_class_set_parent_realize(dc, vi2c_realize,
48*a50616b5SAlex Bennée &vubc->parent_realize);
497221d3b6SViresh Kumar set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
507221d3b6SViresh Kumar }
517221d3b6SViresh Kumar
527221d3b6SViresh Kumar static const TypeInfo vu_i2c_info = {
537221d3b6SViresh Kumar .name = TYPE_VHOST_USER_I2C,
54*a50616b5SAlex Bennée .parent = TYPE_VHOST_USER_BASE,
557221d3b6SViresh Kumar .instance_size = sizeof(VHostUserI2C),
567221d3b6SViresh Kumar .class_init = vu_i2c_class_init,
577221d3b6SViresh Kumar };
587221d3b6SViresh Kumar
vu_i2c_register_types(void)597221d3b6SViresh Kumar static void vu_i2c_register_types(void)
607221d3b6SViresh Kumar {
617221d3b6SViresh Kumar type_register_static(&vu_i2c_info);
627221d3b6SViresh Kumar }
637221d3b6SViresh Kumar
647221d3b6SViresh Kumar type_init(vu_i2c_register_types)
65