1 /* 2 * Virtio net 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/virtio/virtio-net.h" 21 #include "virtio-pci.h" 22 #include "qapi/error.h" 23 #include "qemu/module.h" 24 25 typedef struct VirtIONetPCI VirtIONetPCI; 26 27 /* 28 * virtio-net-pci: This extends VirtioPCIProxy. 29 */ 30 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci-base" 31 #define VIRTIO_NET_PCI(obj) \ 32 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI) 33 34 struct VirtIONetPCI { 35 VirtIOPCIProxy parent_obj; 36 VirtIONet vdev; 37 }; 38 39 static Property virtio_net_properties[] = { 40 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, 41 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), 42 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3), 43 DEFINE_PROP_END_OF_LIST(), 44 }; 45 46 static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 47 { 48 DeviceState *qdev = DEVICE(vpci_dev); 49 VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev); 50 DeviceState *vdev = DEVICE(&dev->vdev); 51 52 virtio_net_set_netclient_name(&dev->vdev, qdev->id, 53 object_get_typename(OBJECT(qdev))); 54 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 55 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 56 } 57 58 static void virtio_net_pci_class_init(ObjectClass *klass, void *data) 59 { 60 DeviceClass *dc = DEVICE_CLASS(klass); 61 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); 62 VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass); 63 64 k->romfile = "efi-virtio.rom"; 65 k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 66 k->device_id = PCI_DEVICE_ID_VIRTIO_NET; 67 k->revision = VIRTIO_PCI_ABI_VERSION; 68 k->class_id = PCI_CLASS_NETWORK_ETHERNET; 69 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 70 dc->props = virtio_net_properties; 71 vpciklass->realize = virtio_net_pci_realize; 72 } 73 74 static void virtio_net_pci_instance_init(Object *obj) 75 { 76 VirtIONetPCI *dev = VIRTIO_NET_PCI(obj); 77 78 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 79 TYPE_VIRTIO_NET); 80 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), 81 "bootindex", &error_abort); 82 } 83 84 static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = { 85 .base_name = TYPE_VIRTIO_NET_PCI, 86 .generic_name = "virtio-net-pci", 87 .transitional_name = "virtio-net-pci-transitional", 88 .non_transitional_name = "virtio-net-pci-non-transitional", 89 .instance_size = sizeof(VirtIONetPCI), 90 .instance_init = virtio_net_pci_instance_init, 91 .class_init = virtio_net_pci_class_init, 92 }; 93 94 static void virtio_net_pci_register(void) 95 { 96 virtio_pci_types_register(&virtio_net_pci_info); 97 } 98 99 type_init(virtio_net_pci_register) 100