2 * Virtio net PCI Bindings
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
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.
18 #include "qemu/osdep.h"
20 #include "hw/qdev-properties.h"
21 #include "hw/virtio/virtio-net.h"
22 #include "virtio-pci.h"
23 #include "qapi/error.h"
24 #include "qemu/module.h"
26 typedef struct VirtIONetPCI VirtIONetPCI
;
29 * virtio-net-pci: This extends VirtioPCIProxy.
31 #define TYPE_VIRTIO_NET_PCI "virtio-net-pci-base"
32 #define VIRTIO_NET_PCI(obj) \
33 OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
36 VirtIOPCIProxy parent_obj
;
40 static Property virtio_net_properties
[] = {
41 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy
, flags
,
42 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT
, true),
43 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 3),
44 DEFINE_PROP_END_OF_LIST(),
47 static void virtio_net_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
49 DeviceState
*qdev
= DEVICE(vpci_dev
);
50 VirtIONetPCI
*dev
= VIRTIO_NET_PCI(vpci_dev
);
51 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
53 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
54 object_get_typename(OBJECT(qdev
)));
55 qdev_set_parent_bus(vdev
, BUS(&vpci_dev
->bus
));
56 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
59 static void virtio_net_pci_class_init(ObjectClass
*klass
, void *data
)
61 DeviceClass
*dc
= DEVICE_CLASS(klass
);
62 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
63 VirtioPCIClass
*vpciklass
= VIRTIO_PCI_CLASS(klass
);
65 k
->romfile
= "efi-virtio.rom";
66 k
->vendor_id
= PCI_VENDOR_ID_REDHAT_QUMRANET
;
67 k
->device_id
= PCI_DEVICE_ID_VIRTIO_NET
;
68 k
->revision
= VIRTIO_PCI_ABI_VERSION
;
69 k
->class_id
= PCI_CLASS_NETWORK_ETHERNET
;
70 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
71 dc
->props
= virtio_net_properties
;
72 vpciklass
->realize
= virtio_net_pci_realize
;
75 static void virtio_net_pci_instance_init(Object
*obj
)
77 VirtIONetPCI
*dev
= VIRTIO_NET_PCI(obj
);
79 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
81 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
82 "bootindex", &error_abort
);
85 static const VirtioPCIDeviceTypeInfo virtio_net_pci_info
= {
86 .base_name
= TYPE_VIRTIO_NET_PCI
,
87 .generic_name
= "virtio-net-pci",
88 .transitional_name
= "virtio-net-pci-transitional",
89 .non_transitional_name
= "virtio-net-pci-non-transitional",
90 .instance_size
= sizeof(VirtIONetPCI
),
91 .instance_init
= virtio_net_pci_instance_init
,
92 .class_init
= virtio_net_pci_class_init
,
95 static void virtio_net_pci_register(void)
97 virtio_pci_types_register(&virtio_net_pci_info
);
100 type_init(virtio_net_pci_register
)