cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

virtio-rng-pci.c (2309B)


      1/*
      2 * Virtio rng PCI Bindings
      3 *
      4 * Copyright 2012 Red Hat, Inc.
      5 * Copyright 2012 Amit Shah <amit.shah@redhat.com>
      6 *
      7 * This work is licensed under the terms of the GNU GPL, version 2 or
      8 * (at your option) any later version.  See the COPYING file in the
      9 * top-level directory.
     10 */
     11
     12#include "qemu/osdep.h"
     13
     14#include "virtio-pci.h"
     15#include "hw/virtio/virtio-rng.h"
     16#include "qapi/error.h"
     17#include "qemu/module.h"
     18#include "qom/object.h"
     19
     20typedef struct VirtIORngPCI VirtIORngPCI;
     21
     22/*
     23 * virtio-rng-pci: This extends VirtioPCIProxy.
     24 */
     25#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci-base"
     26DECLARE_INSTANCE_CHECKER(VirtIORngPCI, VIRTIO_RNG_PCI,
     27                         TYPE_VIRTIO_RNG_PCI)
     28
     29struct VirtIORngPCI {
     30    VirtIOPCIProxy parent_obj;
     31    VirtIORNG vdev;
     32};
     33
     34static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     35{
     36    VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
     37    DeviceState *vdev = DEVICE(&vrng->vdev);
     38
     39    if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
     40        return;
     41    }
     42}
     43
     44static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
     45{
     46    DeviceClass *dc = DEVICE_CLASS(klass);
     47    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
     48    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
     49
     50    k->realize = virtio_rng_pci_realize;
     51    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     52
     53    pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
     54    pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
     55    pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     56    pcidev_k->class_id = PCI_CLASS_OTHERS;
     57}
     58
     59static void virtio_rng_initfn(Object *obj)
     60{
     61    VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
     62
     63    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
     64                                TYPE_VIRTIO_RNG);
     65}
     66
     67static const VirtioPCIDeviceTypeInfo virtio_rng_pci_info = {
     68    .base_name             = TYPE_VIRTIO_RNG_PCI,
     69    .generic_name          = "virtio-rng-pci",
     70    .transitional_name     = "virtio-rng-pci-transitional",
     71    .non_transitional_name = "virtio-rng-pci-non-transitional",
     72    .instance_size = sizeof(VirtIORngPCI),
     73    .instance_init = virtio_rng_initfn,
     74    .class_init    = virtio_rng_pci_class_init,
     75};
     76
     77static void virtio_rng_pci_register(void)
     78{
     79    virtio_pci_types_register(&virtio_rng_pci_info);
     80}
     81
     82type_init(virtio_rng_pci_register)