xref: /openbmc/qemu/hw/virtio/virtio-net-pci.c (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
1cad3cd79SJuan Quintela /*
2cad3cd79SJuan Quintela  * Virtio net PCI Bindings
3cad3cd79SJuan Quintela  *
4cad3cd79SJuan Quintela  * Copyright IBM, Corp. 2007
5cad3cd79SJuan Quintela  * Copyright (c) 2009 CodeSourcery
6cad3cd79SJuan Quintela  *
7cad3cd79SJuan Quintela  * Authors:
8cad3cd79SJuan Quintela  *  Anthony Liguori   <aliguori@us.ibm.com>
9cad3cd79SJuan Quintela  *  Paul Brook        <paul@codesourcery.com>
10cad3cd79SJuan Quintela  *
11cad3cd79SJuan Quintela  * This work is licensed under the terms of the GNU GPL, version 2.  See
12cad3cd79SJuan Quintela  * the COPYING file in the top-level directory.
13cad3cd79SJuan Quintela  *
14cad3cd79SJuan Quintela  * Contributions after 2012-01-13 are licensed under the terms of the
15cad3cd79SJuan Quintela  * GNU GPL, version 2 or (at your option) any later version.
16cad3cd79SJuan Quintela  */
17cad3cd79SJuan Quintela 
18cad3cd79SJuan Quintela #include "qemu/osdep.h"
19cad3cd79SJuan Quintela 
20a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
21cad3cd79SJuan Quintela #include "hw/virtio/virtio-net.h"
22cad3cd79SJuan Quintela #include "virtio-pci.h"
23cad3cd79SJuan Quintela #include "qapi/error.h"
240b8fa32fSMarkus Armbruster #include "qemu/module.h"
25*db1015e9SEduardo Habkost #include "qom/object.h"
26cad3cd79SJuan Quintela 
27cad3cd79SJuan Quintela typedef struct VirtIONetPCI VirtIONetPCI;
28cad3cd79SJuan Quintela 
29cad3cd79SJuan Quintela /*
30cad3cd79SJuan Quintela  * virtio-net-pci: This extends VirtioPCIProxy.
31cad3cd79SJuan Quintela  */
32cad3cd79SJuan Quintela #define TYPE_VIRTIO_NET_PCI "virtio-net-pci-base"
33cad3cd79SJuan Quintela #define VIRTIO_NET_PCI(obj) \
34cad3cd79SJuan Quintela         OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
35cad3cd79SJuan Quintela 
36cad3cd79SJuan Quintela struct VirtIONetPCI {
37cad3cd79SJuan Quintela     VirtIOPCIProxy parent_obj;
38cad3cd79SJuan Quintela     VirtIONet vdev;
39cad3cd79SJuan Quintela };
40cad3cd79SJuan Quintela 
41cad3cd79SJuan Quintela static Property virtio_net_properties[] = {
42cad3cd79SJuan Quintela     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
43cad3cd79SJuan Quintela                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
44cad3cd79SJuan Quintela     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
45cad3cd79SJuan Quintela     DEFINE_PROP_END_OF_LIST(),
46cad3cd79SJuan Quintela };
47cad3cd79SJuan Quintela 
48cad3cd79SJuan Quintela static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
49cad3cd79SJuan Quintela {
50cad3cd79SJuan Quintela     DeviceState *qdev = DEVICE(vpci_dev);
51cad3cd79SJuan Quintela     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
52cad3cd79SJuan Quintela     DeviceState *vdev = DEVICE(&dev->vdev);
53cad3cd79SJuan Quintela 
54cad3cd79SJuan Quintela     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
55cad3cd79SJuan Quintela                                   object_get_typename(OBJECT(qdev)));
5699ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
57cad3cd79SJuan Quintela }
58cad3cd79SJuan Quintela 
59cad3cd79SJuan Quintela static void virtio_net_pci_class_init(ObjectClass *klass, void *data)
60cad3cd79SJuan Quintela {
61cad3cd79SJuan Quintela     DeviceClass *dc = DEVICE_CLASS(klass);
62cad3cd79SJuan Quintela     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
63cad3cd79SJuan Quintela     VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
64cad3cd79SJuan Quintela 
65cad3cd79SJuan Quintela     k->romfile = "efi-virtio.rom";
66cad3cd79SJuan Quintela     k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
67cad3cd79SJuan Quintela     k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
68cad3cd79SJuan Quintela     k->revision = VIRTIO_PCI_ABI_VERSION;
69cad3cd79SJuan Quintela     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
70cad3cd79SJuan Quintela     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
714f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_net_properties);
72cad3cd79SJuan Quintela     vpciklass->realize = virtio_net_pci_realize;
73cad3cd79SJuan Quintela }
74cad3cd79SJuan Quintela 
75cad3cd79SJuan Quintela static void virtio_net_pci_instance_init(Object *obj)
76cad3cd79SJuan Quintela {
77cad3cd79SJuan Quintela     VirtIONetPCI *dev = VIRTIO_NET_PCI(obj);
78cad3cd79SJuan Quintela 
79cad3cd79SJuan Quintela     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
80cad3cd79SJuan Quintela                                 TYPE_VIRTIO_NET);
81cad3cd79SJuan Quintela     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
82d2623129SMarkus Armbruster                               "bootindex");
83cad3cd79SJuan Quintela }
84cad3cd79SJuan Quintela 
85cad3cd79SJuan Quintela static const VirtioPCIDeviceTypeInfo virtio_net_pci_info = {
86cad3cd79SJuan Quintela     .base_name             = TYPE_VIRTIO_NET_PCI,
87cad3cd79SJuan Quintela     .generic_name          = "virtio-net-pci",
88cad3cd79SJuan Quintela     .transitional_name     = "virtio-net-pci-transitional",
89cad3cd79SJuan Quintela     .non_transitional_name = "virtio-net-pci-non-transitional",
90cad3cd79SJuan Quintela     .instance_size = sizeof(VirtIONetPCI),
91cad3cd79SJuan Quintela     .instance_init = virtio_net_pci_instance_init,
92cad3cd79SJuan Quintela     .class_init    = virtio_net_pci_class_init,
93cad3cd79SJuan Quintela };
94cad3cd79SJuan Quintela 
95cad3cd79SJuan Quintela static void virtio_net_pci_register(void)
96cad3cd79SJuan Quintela {
97cad3cd79SJuan Quintela     virtio_pci_types_register(&virtio_net_pci_info);
98cad3cd79SJuan Quintela }
99cad3cd79SJuan Quintela 
100cad3cd79SJuan Quintela type_init(virtio_net_pci_register)
101