xref: /openbmc/qemu/hw/virtio/vhost-user-i2c.c (revision a158c63b)
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 Property vi2c_properties[] = {
18     DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
19     DEFINE_PROP_END_OF_LIST(),
20 };
21 
22 static void vi2c_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 I2C */
28     vub->virtio_id = VIRTIO_ID_I2C_ADAPTER;
29     vub->num_vqs = 1;
30     vub->vq_size = 4;
31 
32     vubc->parent_realize(dev, errp);
33 }
34 
35 static const VMStateDescription vu_i2c_vmstate = {
36     .name = "vhost-user-i2c",
37     .unmigratable = 1,
38 };
39 
40 static void vu_i2c_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_i2c_vmstate;
46     device_class_set_props(dc, vi2c_properties);
47     device_class_set_parent_realize(dc, vi2c_realize,
48                                     &vubc->parent_realize);
49     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
50 }
51 
52 static const TypeInfo vu_i2c_info = {
53     .name = TYPE_VHOST_USER_I2C,
54     .parent = TYPE_VHOST_USER_BASE,
55     .instance_size = sizeof(VHostUserI2C),
56     .class_init = vu_i2c_class_init,
57 };
58 
59 static void vu_i2c_register_types(void)
60 {
61     type_register_static(&vu_i2c_info);
62 }
63 
64 type_init(vu_i2c_register_types)
65