xref: /qemu/include/hw/virtio/virtio-bus.h (revision 5d448f9dac460d0adf7d7549a9c324f50f1dd1e2)
1ff8eca55SKONRAD Frederic /*
2ff8eca55SKONRAD Frederic  * VirtioBus
3ff8eca55SKONRAD Frederic  *
4ff8eca55SKONRAD Frederic  *  Copyright (C) 2012 : GreenSocs Ltd
5ff8eca55SKONRAD Frederic  *      http://www.greensocs.com/ , email: info@greensocs.com
6ff8eca55SKONRAD Frederic  *
7ff8eca55SKONRAD Frederic  *  Developed by :
8ff8eca55SKONRAD Frederic  *  Frederic Konrad   <fred.konrad@greensocs.com>
9ff8eca55SKONRAD Frederic  *
10ff8eca55SKONRAD Frederic  * This program is free software; you can redistribute it and/or modify
11ff8eca55SKONRAD Frederic  * it under the terms of the GNU General Public License as published by
12ff8eca55SKONRAD Frederic  * the Free Software Foundation, either version 2 of the License, or
13ff8eca55SKONRAD Frederic  * (at your option) any later version.
14ff8eca55SKONRAD Frederic  *
15ff8eca55SKONRAD Frederic  * This program is distributed in the hope that it will be useful,
16ff8eca55SKONRAD Frederic  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17ff8eca55SKONRAD Frederic  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18ff8eca55SKONRAD Frederic  * GNU General Public License for more details.
19ff8eca55SKONRAD Frederic  *
20ff8eca55SKONRAD Frederic  * You should have received a copy of the GNU General Public License along
21ff8eca55SKONRAD Frederic  * with this program; if not, see <http://www.gnu.org/licenses/>.
22ff8eca55SKONRAD Frederic  *
23ff8eca55SKONRAD Frederic  */
24ff8eca55SKONRAD Frederic 
25ff8eca55SKONRAD Frederic #ifndef VIRTIO_BUS_H
26ff8eca55SKONRAD Frederic #define VIRTIO_BUS_H
27ff8eca55SKONRAD Frederic 
2883c9f4caSPaolo Bonzini #include "hw/qdev.h"
29ff8eca55SKONRAD Frederic #include "sysemu/sysemu.h"
300d09e41aSPaolo Bonzini #include "hw/virtio/virtio.h"
31ff8eca55SKONRAD Frederic 
32ff8eca55SKONRAD Frederic #define TYPE_VIRTIO_BUS "virtio-bus"
33ff8eca55SKONRAD Frederic #define VIRTIO_BUS_GET_CLASS(obj) \
34ff8eca55SKONRAD Frederic         OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
35ff8eca55SKONRAD Frederic #define VIRTIO_BUS_CLASS(klass) \
36ff8eca55SKONRAD Frederic         OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
37ff8eca55SKONRAD Frederic #define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
38ff8eca55SKONRAD Frederic 
39ff8eca55SKONRAD Frederic typedef struct VirtioBusState VirtioBusState;
40ff8eca55SKONRAD Frederic 
41ff8eca55SKONRAD Frederic typedef struct VirtioBusClass {
42ff8eca55SKONRAD Frederic     /* This is what a VirtioBus must implement */
43ff8eca55SKONRAD Frederic     BusClass parent;
44ff8eca55SKONRAD Frederic     void (*notify)(DeviceState *d, uint16_t vector);
45ff8eca55SKONRAD Frederic     void (*save_config)(DeviceState *d, QEMUFile *f);
46ff8eca55SKONRAD Frederic     void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
47ff8eca55SKONRAD Frederic     int (*load_config)(DeviceState *d, QEMUFile *f);
48ff8eca55SKONRAD Frederic     int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
49ff8eca55SKONRAD Frederic     int (*load_done)(DeviceState *d, QEMUFile *f);
50ff8eca55SKONRAD Frederic     unsigned (*get_features)(DeviceState *d);
51ff8eca55SKONRAD Frederic     bool (*query_guest_notifiers)(DeviceState *d);
52ff8eca55SKONRAD Frederic     int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
53ff8eca55SKONRAD Frederic     int (*set_host_notifier)(DeviceState *d, int n, bool assigned);
54ff8eca55SKONRAD Frederic     void (*vmstate_change)(DeviceState *d, bool running);
55ff8eca55SKONRAD Frederic     /*
56ff8eca55SKONRAD Frederic      * transport independent init function.
57ff8eca55SKONRAD Frederic      * This is called by virtio-bus just after the device is plugged.
58ff8eca55SKONRAD Frederic      */
59ff8eca55SKONRAD Frederic     void (*device_plugged)(DeviceState *d);
60ff8eca55SKONRAD Frederic     /*
61ff8eca55SKONRAD Frederic      * transport independent exit function.
62ff8eca55SKONRAD Frederic      * This is called by virtio-bus just before the device is unplugged.
63ff8eca55SKONRAD Frederic      */
64ff8eca55SKONRAD Frederic     void (*device_unplug)(DeviceState *d);
65ff8eca55SKONRAD Frederic } VirtioBusClass;
66ff8eca55SKONRAD Frederic 
67ff8eca55SKONRAD Frederic struct VirtioBusState {
68ff8eca55SKONRAD Frederic     BusState parent_obj;
69ff8eca55SKONRAD Frederic     /*
70ff8eca55SKONRAD Frederic      * Only one VirtIODevice can be plugged on the bus.
71ff8eca55SKONRAD Frederic      */
72ff8eca55SKONRAD Frederic     VirtIODevice *vdev;
73ff8eca55SKONRAD Frederic     /*
74ff8eca55SKONRAD Frederic      * This will be removed at the end of the series.
75ff8eca55SKONRAD Frederic      */
76ff8eca55SKONRAD Frederic     VirtIOBindings bindings;
77ff8eca55SKONRAD Frederic };
78ff8eca55SKONRAD Frederic 
79ff8eca55SKONRAD Frederic int virtio_bus_plug_device(VirtIODevice *vdev);
80ff8eca55SKONRAD Frederic void virtio_bus_reset(VirtioBusState *bus);
81ff8eca55SKONRAD Frederic void virtio_bus_destroy_device(VirtioBusState *bus);
82ff8eca55SKONRAD Frederic /* Get the device id of the plugged device. */
83ff8eca55SKONRAD Frederic uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
84ff8eca55SKONRAD Frederic /* Get the config_len field of the plugged device. */
85ff8eca55SKONRAD Frederic size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
868e05db92SKONRAD Frederic /* Get the features of the plugged device. */
878e05db92SKONRAD Frederic uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
888e05db92SKONRAD Frederic                                     uint32_t requested_features);
89*5d448f9dSKONRAD Frederic /* Set the features of the plugged device. */
90*5d448f9dSKONRAD Frederic void virtio_bus_set_vdev_features(VirtioBusState *bus,
91*5d448f9dSKONRAD Frederic                                   uint32_t requested_features);
928e05db92SKONRAD Frederic /* Get bad features of the plugged device. */
938e05db92SKONRAD Frederic uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
948e05db92SKONRAD Frederic /* Get config of the plugged device. */
958e05db92SKONRAD Frederic void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
96*5d448f9dSKONRAD Frederic /* Set config of the plugged device. */
97*5d448f9dSKONRAD Frederic void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
98ff8eca55SKONRAD Frederic 
99ff8eca55SKONRAD Frederic #endif /* VIRTIO_BUS_H */
100