virtio-rng-pci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "qemu/osdep.h"
  12. #include "virtio-pci.h"
  13. #include "hw/virtio/virtio-rng.h"
  14. #include "qapi/error.h"
  15. #include "qemu/module.h"
  16. typedef struct VirtIORngPCI VirtIORngPCI;
  17. /*
  18. * virtio-rng-pci: This extends VirtioPCIProxy.
  19. */
  20. #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci-base"
  21. #define VIRTIO_RNG_PCI(obj) \
  22. OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
  23. struct VirtIORngPCI {
  24. VirtIOPCIProxy parent_obj;
  25. VirtIORNG vdev;
  26. };
  27. static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
  28. {
  29. VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
  30. DeviceState *vdev = DEVICE(&vrng->vdev);
  31. if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
  32. return;
  33. }
  34. }
  35. static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
  36. {
  37. DeviceClass *dc = DEVICE_CLASS(klass);
  38. VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
  39. PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
  40. k->realize = virtio_rng_pci_realize;
  41. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  42. pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
  43. pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
  44. pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
  45. pcidev_k->class_id = PCI_CLASS_OTHERS;
  46. }
  47. static void virtio_rng_initfn(Object *obj)
  48. {
  49. VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
  50. virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
  51. TYPE_VIRTIO_RNG);
  52. }
  53. static const VirtioPCIDeviceTypeInfo virtio_rng_pci_info = {
  54. .base_name = TYPE_VIRTIO_RNG_PCI,
  55. .generic_name = "virtio-rng-pci",
  56. .transitional_name = "virtio-rng-pci-transitional",
  57. .non_transitional_name = "virtio-rng-pci-non-transitional",
  58. .instance_size = sizeof(VirtIORngPCI),
  59. .instance_init = virtio_rng_initfn,
  60. .class_init = virtio_rng_pci_class_init,
  61. };
  62. static void virtio_rng_pci_register(void)
  63. {
  64. virtio_pci_types_register(&virtio_rng_pci_info);
  65. }
  66. type_init(virtio_rng_pci_register)