Coverage Report

Created: 2026-10-31 08:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/hw/virtio/vdpa-dev-pci.c
Line
Count
Source
1
/*
2
 * Vhost Vdpa Device PCI Bindings
3
 *
4
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All Rights Reserved.
5
 *
6
 * Authors:
7
 *   Longpeng <longpeng2@huawei.com>
8
 *
9
 * Largely based on the "vhost-user-blk-pci.c" and "vhost-user-blk.c"
10
 * implemented by:
11
 *   Changpeng Liu <changpeng.liu@intel.com>
12
 *
13
 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
14
 * See the COPYING.LIB file in the top-level directory.
15
 */
16
#include "qemu/osdep.h"
17
#include <sys/ioctl.h>
18
#include <linux/vhost.h>
19
#include "hw/virtio/virtio.h"
20
#include "hw/virtio/vdpa-dev.h"
21
#include "hw/pci/pci.h"
22
#include "hw/core/qdev-properties.h"
23
#include "qapi/error.h"
24
#include "qemu/error-report.h"
25
#include "qemu/module.h"
26
#include "hw/virtio/virtio-pci.h"
27
#include "qom/object.h"
28
29
30
typedef struct VhostVdpaDevicePCI VhostVdpaDevicePCI;
31
32
#define TYPE_VHOST_VDPA_DEVICE_PCI "vhost-vdpa-device-pci-base"
33
DECLARE_INSTANCE_CHECKER(VhostVdpaDevicePCI, VHOST_VDPA_DEVICE_PCI,
34
                         TYPE_VHOST_VDPA_DEVICE_PCI)
35
36
struct VhostVdpaDevicePCI {
37
    VirtIOPCIProxy parent_obj;
38
    VhostVdpaDevice vdev;
39
};
40
41
static void vhost_vdpa_device_pci_instance_init(Object *obj)
42
0
{
43
0
    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(obj);
44
45
0
    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
46
0
                                TYPE_VHOST_VDPA_DEVICE);
47
0
    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
48
0
                              "bootindex");
49
0
}
50
51
static int vhost_vdpa_device_pci_post_init(VhostVdpaDevice *v, Error **errp)
52
0
{
53
0
    VhostVdpaDevicePCI *dev = container_of(v, VhostVdpaDevicePCI, vdev);
54
0
    VirtIOPCIProxy *vpci_dev = &dev->parent_obj;
55
56
0
    vpci_dev->class_code = virtio_pci_get_class_id(v->vdev_id);
57
0
    vpci_dev->trans_devid = virtio_pci_get_trans_devid(v->vdev_id);
58
    /* one for config vector */
59
0
    vpci_dev->nvectors = v->num_queues + 1;
60
61
0
    return 0;
62
0
}
63
64
static void
65
vhost_vdpa_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
66
0
{
67
0
    VhostVdpaDevicePCI *dev = VHOST_VDPA_DEVICE_PCI(vpci_dev);
68
69
0
    dev->vdev.post_init = vhost_vdpa_device_pci_post_init;
70
0
    qdev_realize(DEVICE(&dev->vdev), BUS(&vpci_dev->bus), errp);
71
0
}
72
73
static void vhost_vdpa_device_pci_class_init(ObjectClass *klass,
74
                                             const void *data)
75
61
{
76
61
    DeviceClass *dc = DEVICE_CLASS(klass);
77
61
    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
78
79
61
    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
80
61
    k->realize = vhost_vdpa_device_pci_realize;
81
61
}
82
83
static const VirtioPCIDeviceTypeInfo vhost_vdpa_device_pci_info = {
84
    .base_name               = TYPE_VHOST_VDPA_DEVICE_PCI,
85
    .generic_name            = "vhost-vdpa-device-pci",
86
    .transitional_name       = "vhost-vdpa-device-pci-transitional",
87
    .non_transitional_name   = "vhost-vdpa-device-pci-non-transitional",
88
    .instance_size  = sizeof(VhostVdpaDevicePCI),
89
    .instance_init  = vhost_vdpa_device_pci_instance_init,
90
    .class_init     = vhost_vdpa_device_pci_class_init,
91
};
92
93
static void vhost_vdpa_device_pci_register(void)
94
61
{
95
61
    virtio_pci_types_register(&vhost_vdpa_device_pci_info);
96
61
}
97
98
type_init(vhost_vdpa_device_pci_register);