Coverage Report

Created: 2026-11-20 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/hw/virtio/virtio-blk-pci.c
Line
Count
Source
1
/*
2
 * Virtio blk PCI Bindings
3
 *
4
 * Copyright IBM, Corp. 2007
5
 * Copyright (c) 2009 CodeSourcery
6
 *
7
 * Authors:
8
 *  Anthony Liguori   <aliguori@us.ibm.com>
9
 *  Paul Brook        <paul@codesourcery.com>
10
 *
11
 * This work is licensed under the terms of the GNU GPL, version 2.  See
12
 * the COPYING file in the top-level directory.
13
 *
14
 * Contributions after 2012-01-13 are licensed under the terms of the
15
 * GNU GPL, version 2 or (at your option) any later version.
16
 */
17
18
#include "qemu/osdep.h"
19
20
#include "hw/core/qdev-properties.h"
21
#include "hw/virtio/virtio-blk.h"
22
#include "hw/virtio/virtio-pci.h"
23
#include "qapi/error.h"
24
#include "qemu/module.h"
25
#include "qom/object.h"
26
27
typedef struct VirtIOBlkPCI VirtIOBlkPCI;
28
29
/*
30
 * virtio-blk-pci: This extends VirtioPCIProxy.
31
 */
32
#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci-base"
33
DECLARE_INSTANCE_CHECKER(VirtIOBlkPCI, VIRTIO_BLK_PCI,
34
                         TYPE_VIRTIO_BLK_PCI)
35
36
struct VirtIOBlkPCI {
37
    VirtIOPCIProxy parent_obj;
38
    VirtIOBlock vdev;
39
};
40
41
static const Property virtio_blk_pci_properties[] = {
42
    DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
43
    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
44
                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
45
    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
46
                       DEV_NVECTORS_UNSPECIFIED),
47
};
48
49
static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
50
2
{
51
2
    VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
52
2
    DeviceState *vdev = DEVICE(&dev->vdev);
53
2
    VirtIOBlkConf *conf = &dev->vdev.conf;
54
55
2
    if (conf->num_queues == VIRTIO_BLK_AUTO_NUM_QUEUES) {
56
2
        conf->num_queues = virtio_pci_optimal_num_queues(0);
57
2
    }
58
59
2
    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
60
2
        vpci_dev->nvectors = conf->num_queues + 1;
61
2
    }
62
63
2
    qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
64
2
}
65
66
static void virtio_blk_pci_class_init(ObjectClass *klass, const void *data)
67
63
{
68
63
    DeviceClass *dc = DEVICE_CLASS(klass);
69
63
    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
70
63
    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
71
72
63
    set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
73
63
    device_class_set_props(dc, virtio_blk_pci_properties);
74
63
    pci_qdev_property_add_specifics(dc);
75
63
    k->realize = virtio_blk_pci_realize;
76
63
    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
77
63
    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
78
63
    pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
79
63
    pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
80
63
}
81
82
static void virtio_blk_pci_instance_init(Object *obj)
83
2
{
84
2
    VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj);
85
86
2
    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
87
2
                                TYPE_VIRTIO_BLK);
88
2
    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
89
2
                              "bootindex");
90
2
}
91
92
static const VirtioPCIDeviceTypeInfo virtio_blk_pci_info = {
93
    .base_name              = TYPE_VIRTIO_BLK_PCI,
94
    .generic_name           = "virtio-blk-pci",
95
    .transitional_name      = "virtio-blk-pci-transitional",
96
    .non_transitional_name  = "virtio-blk-pci-non-transitional",
97
    .instance_size = sizeof(VirtIOBlkPCI),
98
    .instance_init = virtio_blk_pci_instance_init,
99
    .class_init    = virtio_blk_pci_class_init,
100
};
101
102
static void virtio_blk_pci_register(void)
103
63
{
104
63
    virtio_pci_types_register(&virtio_blk_pci_info);
105
63
}
106
107
type_init(virtio_blk_pci_register)