Coverage Report

Created: 2026-10-31 08:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/hw/virtio/vhost-user-rng-pci.c
Line
Count
Source
1
/*
2
 * Vhost-user RNG virtio device PCI glue
3
 *
4
 * Copyright (c) 2021 Mathieu Poirier <mathieu.poirier@linaro.org>
5
 *
6
 * SPDX-License-Identifier: GPL-2.0-or-later
7
 */
8
9
#include "qemu/osdep.h"
10
#include "hw/core/qdev-properties.h"
11
#include "hw/virtio/vhost-user-rng.h"
12
#include "hw/virtio/virtio-pci.h"
13
14
struct VHostUserRNGPCI {
15
    VirtIOPCIProxy parent_obj;
16
    VHostUserRNG vdev;
17
};
18
19
typedef struct VHostUserRNGPCI VHostUserRNGPCI;
20
21
#define TYPE_VHOST_USER_RNG_PCI "vhost-user-rng-pci-base"
22
23
DECLARE_INSTANCE_CHECKER(VHostUserRNGPCI, VHOST_USER_RNG_PCI,
24
                         TYPE_VHOST_USER_RNG_PCI)
25
26
static const Property vhost_user_rng_pci_properties[] = {
27
    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
28
                       DEV_NVECTORS_UNSPECIFIED),
29
};
30
31
static void vhost_user_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
32
0
{
33
0
    VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(vpci_dev);
34
0
    DeviceState *vdev = DEVICE(&dev->vdev);
35
36
0
    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
37
0
        vpci_dev->nvectors = 1;
38
0
    }
39
40
0
    qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
41
0
}
42
43
static void vhost_user_rng_pci_class_init(ObjectClass *klass, const void *data)
44
61
{
45
61
    DeviceClass *dc = DEVICE_CLASS(klass);
46
61
    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
47
61
    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
48
61
    k->realize = vhost_user_rng_pci_realize;
49
61
    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
50
61
    device_class_set_props(dc, vhost_user_rng_pci_properties);
51
61
    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
52
61
    pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
53
61
    pcidev_k->revision = 0x00;
54
61
    pcidev_k->class_id = PCI_CLASS_OTHERS;
55
61
}
56
57
static void vhost_user_rng_pci_instance_init(Object *obj)
58
0
{
59
0
    VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(obj);
60
61
0
    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
62
0
                                TYPE_VHOST_USER_RNG);
63
0
}
64
65
static const VirtioPCIDeviceTypeInfo vhost_user_rng_pci_info = {
66
    .base_name = TYPE_VHOST_USER_RNG_PCI,
67
    .non_transitional_name = "vhost-user-rng-pci",
68
    .instance_size = sizeof(VHostUserRNGPCI),
69
    .instance_init = vhost_user_rng_pci_instance_init,
70
    .class_init = vhost_user_rng_pci_class_init,
71
};
72
73
static void vhost_user_rng_pci_register(void)
74
61
{
75
61
    virtio_pci_types_register(&vhost_user_rng_pci_info);
76
61
}
77
78
type_init(vhost_user_rng_pci_register);