master
c 65 lines 1.73 KB
Raw
1 /*
2 * Vhost-user spi virtio device
3 *
4 * Copyright (C) 2025 Qualcomm Innovation Center, Inc. All Rights Reserved.
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/core/qdev-properties.h"
12 #include "hw/virtio/virtio-bus.h"
13 #include "hw/virtio/vhost-user-spi.h"
14 #include "qemu/error-report.h"
15 #include "standard-headers/linux/virtio_ids.h"
16 #include "standard-headers/linux/virtio_spi.h"
17
18 static const Property vspi_properties[] = {
19 DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
20 };
21
22 static void vspi_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 SPI */
28 vub->virtio_id = VIRTIO_ID_SPI;
29 vub->num_vqs = 1;
30 vub->vq_size = 4;
31 vub->config_size = sizeof(struct virtio_spi_config);
32
33 vubc->parent_realize(dev, errp);
34 }
35
36 static const VMStateDescription vu_spi_vmstate = {
37 .name = "vhost-user-spi",
38 .unmigratable = 1,
39 };
40
41 static void vu_spi_class_init(ObjectClass *klass, const void *data)
42 {
43 DeviceClass *dc = DEVICE_CLASS(klass);
44 VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
45
46 dc->vmsd = &vu_spi_vmstate;
47 device_class_set_props(dc, vspi_properties);
48 device_class_set_parent_realize(dc, vspi_realize,
49 &vubc->parent_realize);
50 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
51 }
52
53 static const TypeInfo vu_spi_info = {
54 .name = TYPE_VHOST_USER_SPI,
55 .parent = TYPE_VHOST_USER_BASE,
56 .instance_size = sizeof(VHostUserSPI),
57 .class_init = vu_spi_class_init,
58 };
59
60 static void vu_spi_register_types(void)
61 {
62 type_register_static(&vu_spi_info);
63 }
64
65 type_init(vu_spi_register_types)