pci: Allow PCI bus subtypes to support extended config space accesses
[qemu/ar7.git] / include / hw / virtio / virtio-bus.h
blob7fec9dc929f9b801094e2b368ffc734260ba926a
1 /*
2 * VirtioBus
4 * Copyright (C) 2012 : GreenSocs Ltd
5 * http://www.greensocs.com/ , email: info@greensocs.com
7 * Developed by :
8 * Frederic Konrad <fred.konrad@greensocs.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, see <http://www.gnu.org/licenses/>.
25 #ifndef VIRTIO_BUS_H
26 #define VIRTIO_BUS_H
28 #include "hw/qdev.h"
29 #include "sysemu/sysemu.h"
30 #include "hw/virtio/virtio.h"
32 #define TYPE_VIRTIO_BUS "virtio-bus"
33 #define VIRTIO_BUS_GET_CLASS(obj) \
34 OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
35 #define VIRTIO_BUS_CLASS(klass) \
36 OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
37 #define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
39 typedef struct VirtioBusState VirtioBusState;
41 typedef struct VirtioBusClass {
42 /* This is what a VirtioBus must implement */
43 BusClass parent;
44 void (*notify)(DeviceState *d, uint16_t vector);
45 void (*save_config)(DeviceState *d, QEMUFile *f);
46 void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
47 void (*save_extra_state)(DeviceState *d, QEMUFile *f);
48 int (*load_config)(DeviceState *d, QEMUFile *f);
49 int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
50 int (*load_done)(DeviceState *d, QEMUFile *f);
51 int (*load_extra_state)(DeviceState *d, QEMUFile *f);
52 bool (*has_extra_state)(DeviceState *d);
53 bool (*query_guest_notifiers)(DeviceState *d);
54 int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
55 int (*set_host_notifier_mr)(DeviceState *d, int n,
56 MemoryRegion *mr, bool assign);
57 void (*vmstate_change)(DeviceState *d, bool running);
59 * Expose the features the transport layer supports before
60 * the negotiation takes place.
62 void (*pre_plugged)(DeviceState *d, Error **errp);
64 * transport independent init function.
65 * This is called by virtio-bus just after the device is plugged.
67 void (*device_plugged)(DeviceState *d, Error **errp);
69 * transport independent exit function.
70 * This is called by virtio-bus just before the device is unplugged.
72 void (*device_unplugged)(DeviceState *d);
73 int (*query_nvectors)(DeviceState *d);
75 * ioeventfd handling: if the transport implements ioeventfd_assign,
76 * it must implement ioeventfd_enabled as well.
78 /* Returns true if the ioeventfd is enabled for the device. */
79 bool (*ioeventfd_enabled)(DeviceState *d);
81 * Assigns/deassigns the ioeventfd backing for the transport on
82 * the device for queue number n. Returns an error value on
83 * failure.
85 int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier,
86 int n, bool assign);
88 * Does the transport have variable vring alignment?
89 * (ie can it ever call virtio_queue_set_align()?)
90 * Note that changing this will break migration for this transport.
92 bool has_variable_vring_alignment;
93 AddressSpace *(*get_dma_as)(DeviceState *d);
94 } VirtioBusClass;
96 struct VirtioBusState {
97 BusState parent_obj;
100 * Set if ioeventfd has been started.
102 bool ioeventfd_started;
105 * Set if ioeventfd has been grabbed by vhost. When ioeventfd
106 * is grabbed by vhost, we track its started/stopped state (which
107 * depends in turn on the virtio status register), but do not
108 * register a handler for the ioeventfd. When ioeventfd is
109 * released, if ioeventfd_started is true we finally register
110 * the handler so that QEMU's device model can use ioeventfd.
112 int ioeventfd_grabbed;
115 void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp);
116 void virtio_bus_reset(VirtioBusState *bus);
117 void virtio_bus_device_unplugged(VirtIODevice *bus);
118 /* Get the device id of the plugged device. */
119 uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
120 /* Get the config_len field of the plugged device. */
121 size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
122 /* Get bad features of the plugged device. */
123 uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
124 /* Get config of the plugged device. */
125 void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
126 /* Set config of the plugged device. */
127 void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
129 static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
131 BusState *qbus = &bus->parent_obj;
132 BusChild *kid = QTAILQ_FIRST(&qbus->children);
133 DeviceState *qdev = kid ? kid->child : NULL;
135 /* This is used on the data path, the cast is guaranteed
136 * to succeed by the qdev machinery.
138 return (VirtIODevice *)qdev;
141 /* Return whether the proxy allows ioeventfd. */
142 bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus);
143 /* Start the ioeventfd. */
144 int virtio_bus_start_ioeventfd(VirtioBusState *bus);
145 /* Stop the ioeventfd. */
146 void virtio_bus_stop_ioeventfd(VirtioBusState *bus);
147 /* Tell the bus that vhost is grabbing the ioeventfd. */
148 int virtio_bus_grab_ioeventfd(VirtioBusState *bus);
149 /* bus that vhost is not using the ioeventfd anymore. */
150 void virtio_bus_release_ioeventfd(VirtioBusState *bus);
151 /* Switch from/to the generic ioeventfd handler */
152 int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign);
153 /* Tell the bus that the ioeventfd handler is no longer required. */
154 void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n);
156 #endif /* VIRTIO_BUS_H */