]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/virtio/virtio-bus.h
virtio: add start_ioeventfd and stop_ioeventfd to VirtioDeviceClass
[mirror_qemu.git] / include / hw / virtio / virtio-bus.h
CommitLineData
ff8eca55
FK
1/*
2 * VirtioBus
3 *
4 * Copyright (C) 2012 : GreenSocs Ltd
5 * http://www.greensocs.com/ , email: info@greensocs.com
6 *
7 * Developed by :
8 * Frederic Konrad <fred.konrad@greensocs.com>
9 *
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.
14 *
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.
19 *
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/>.
22 *
23 */
24
25#ifndef VIRTIO_BUS_H
26#define VIRTIO_BUS_H
27
83c9f4ca 28#include "hw/qdev.h"
ff8eca55 29#include "sysemu/sysemu.h"
0d09e41a 30#include "hw/virtio/virtio.h"
ff8eca55
FK
31
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)
38
39typedef struct VirtioBusState VirtioBusState;
40
41typedef 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);
a6df8adf 47 void (*save_extra_state)(DeviceState *d, QEMUFile *f);
ff8eca55
FK
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);
a6df8adf
JW
51 int (*load_extra_state)(DeviceState *d, QEMUFile *f);
52 bool (*has_extra_state)(DeviceState *d);
ff8eca55
FK
53 bool (*query_guest_notifiers)(DeviceState *d);
54 int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
ff8eca55 55 void (*vmstate_change)(DeviceState *d, bool running);
d1b4259f
MC
56 /*
57 * Expose the features the transport layer supports before
58 * the negotiation takes place.
59 */
60 void (*pre_plugged)(DeviceState *d, Error **errp);
ff8eca55
FK
61 /*
62 * transport independent init function.
63 * This is called by virtio-bus just after the device is plugged.
64 */
e8398045 65 void (*device_plugged)(DeviceState *d, Error **errp);
ff8eca55
FK
66 /*
67 * transport independent exit function.
68 * This is called by virtio-bus just before the device is unplugged.
69 */
5e96f5d2 70 void (*device_unplugged)(DeviceState *d);
e0d686bf 71 int (*query_nvectors)(DeviceState *d);
6798e245 72 /*
b13d3962
PB
73 * ioeventfd handling: if the transport implements ioeventfd_assign,
74 * it must implement ioeventfd_disabled as well.
6798e245 75 */
6798e245
CH
76 /* Returns true if the ioeventfd has been disabled for the device. */
77 bool (*ioeventfd_disabled)(DeviceState *d);
6798e245
CH
78 /*
79 * Assigns/deassigns the ioeventfd backing for the transport on
80 * the device for queue number n. Returns an error value on
81 * failure.
82 */
83 int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier,
84 int n, bool assign);
6ce69d1c
PM
85 /*
86 * Does the transport have variable vring alignment?
87 * (ie can it ever call virtio_queue_set_align()?)
88 * Note that changing this will break migration for this transport.
89 */
90 bool has_variable_vring_alignment;
ff8eca55
FK
91} VirtioBusClass;
92
93struct VirtioBusState {
94 BusState parent_obj;
4ddcc2d5
PB
95
96 /*
97 * Set if the default ioeventfd handlers are disabled by vhost
98 * or dataplane.
99 */
100 bool ioeventfd_disabled;
b13d3962
PB
101
102 /*
103 * Set if ioeventfd has been started.
104 */
105 bool ioeventfd_started;
ff8eca55
FK
106};
107
e8398045 108void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp);
ff8eca55 109void virtio_bus_reset(VirtioBusState *bus);
5e96f5d2 110void virtio_bus_device_unplugged(VirtIODevice *bus);
ff8eca55
FK
111/* Get the device id of the plugged device. */
112uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
113/* Get the config_len field of the plugged device. */
114size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
8e05db92
FK
115/* Get bad features of the plugged device. */
116uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
117/* Get config of the plugged device. */
118void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
5d448f9d
FK
119/* Set config of the plugged device. */
120void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
ff8eca55 121
06d3dff0
PB
122static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
123{
124 BusState *qbus = &bus->parent_obj;
125 BusChild *kid = QTAILQ_FIRST(&qbus->children);
126 DeviceState *qdev = kid ? kid->child : NULL;
127
128 /* This is used on the data path, the cast is guaranteed
129 * to succeed by the qdev machinery.
130 */
131 return (VirtIODevice *)qdev;
132}
133
6798e245 134/* Start the ioeventfd. */
ff4c07df 135int virtio_bus_start_ioeventfd(VirtioBusState *bus);
6798e245
CH
136/* Stop the ioeventfd. */
137void virtio_bus_stop_ioeventfd(VirtioBusState *bus);
138/* Switch from/to the generic ioeventfd handler */
139int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign);
140
ff4c07df
PB
141/* This is temporary. It is only needed because virtio_bus_set_host_notifier
142 * sets ioeventfd_disabled but we will shortly get rid of it. */
143int set_host_notifier_internal(DeviceState *proxy, VirtioBusState *bus,
144 int n, bool assign, bool set_handler);
145
ff8eca55 146#endif /* VIRTIO_BUS_H */