2013-01-15 07:08:01 +08:00
|
|
|
/*
|
|
|
|
* VirtioBus
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 : GreenSocs Ltd
|
|
|
|
* http://www.greensocs.com/ , email: info@greensocs.com
|
|
|
|
*
|
|
|
|
* Developed by :
|
|
|
|
* Frederic Konrad <fred.konrad@greensocs.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VIRTIO_BUS_H
|
|
|
|
#define VIRTIO_BUS_H
|
|
|
|
|
2019-08-12 13:23:51 +08:00
|
|
|
#include "hw/qdev-core.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/virtio/virtio.h"
|
2013-01-15 07:08:01 +08:00
|
|
|
|
|
|
|
#define TYPE_VIRTIO_BUS "virtio-bus"
|
|
|
|
#define VIRTIO_BUS_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
|
|
|
|
#define VIRTIO_BUS_CLASS(klass) \
|
|
|
|
OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
|
|
|
|
#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
|
|
|
|
|
|
|
|
typedef struct VirtioBusState VirtioBusState;
|
|
|
|
|
|
|
|
typedef struct VirtioBusClass {
|
|
|
|
/* This is what a VirtioBus must implement */
|
|
|
|
BusClass parent;
|
|
|
|
void (*notify)(DeviceState *d, uint16_t vector);
|
|
|
|
void (*save_config)(DeviceState *d, QEMUFile *f);
|
|
|
|
void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
|
2015-11-06 16:02:44 +08:00
|
|
|
void (*save_extra_state)(DeviceState *d, QEMUFile *f);
|
2013-01-15 07:08:01 +08:00
|
|
|
int (*load_config)(DeviceState *d, QEMUFile *f);
|
|
|
|
int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
|
|
|
|
int (*load_done)(DeviceState *d, QEMUFile *f);
|
2015-11-06 16:02:44 +08:00
|
|
|
int (*load_extra_state)(DeviceState *d, QEMUFile *f);
|
|
|
|
bool (*has_extra_state)(DeviceState *d);
|
2013-01-15 07:08:01 +08:00
|
|
|
bool (*query_guest_notifiers)(DeviceState *d);
|
|
|
|
int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
|
2018-04-12 23:12:30 +08:00
|
|
|
int (*set_host_notifier_mr)(DeviceState *d, int n,
|
|
|
|
MemoryRegion *mr, bool assign);
|
2013-01-15 07:08:01 +08:00
|
|
|
void (*vmstate_change)(DeviceState *d, bool running);
|
2016-09-13 21:30:30 +08:00
|
|
|
/*
|
|
|
|
* Expose the features the transport layer supports before
|
|
|
|
* the negotiation takes place.
|
|
|
|
*/
|
|
|
|
void (*pre_plugged)(DeviceState *d, Error **errp);
|
2013-01-15 07:08:01 +08:00
|
|
|
/*
|
|
|
|
* transport independent init function.
|
|
|
|
* This is called by virtio-bus just after the device is plugged.
|
|
|
|
*/
|
2015-05-29 14:15:25 +08:00
|
|
|
void (*device_plugged)(DeviceState *d, Error **errp);
|
2013-01-15 07:08:01 +08:00
|
|
|
/*
|
|
|
|
* transport independent exit function.
|
|
|
|
* This is called by virtio-bus just before the device is unplugged.
|
|
|
|
*/
|
2013-09-20 19:59:08 +08:00
|
|
|
void (*device_unplugged)(DeviceState *d);
|
2015-04-23 14:21:46 +08:00
|
|
|
int (*query_nvectors)(DeviceState *d);
|
2016-06-10 17:04:09 +08:00
|
|
|
/*
|
2016-10-22 04:48:06 +08:00
|
|
|
* ioeventfd handling: if the transport implements ioeventfd_assign,
|
2016-10-22 04:48:08 +08:00
|
|
|
* it must implement ioeventfd_enabled as well.
|
2016-06-10 17:04:09 +08:00
|
|
|
*/
|
2016-10-22 04:48:08 +08:00
|
|
|
/* Returns true if the ioeventfd is enabled for the device. */
|
|
|
|
bool (*ioeventfd_enabled)(DeviceState *d);
|
2016-06-10 17:04:09 +08:00
|
|
|
/*
|
|
|
|
* Assigns/deassigns the ioeventfd backing for the transport on
|
|
|
|
* the device for queue number n. Returns an error value on
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier,
|
|
|
|
int n, bool assign);
|
2013-07-16 20:25:08 +08:00
|
|
|
/*
|
|
|
|
* Does the transport have variable vring alignment?
|
|
|
|
* (ie can it ever call virtio_queue_set_align()?)
|
|
|
|
* Note that changing this will break migration for this transport.
|
|
|
|
*/
|
|
|
|
bool has_variable_vring_alignment;
|
2016-12-30 18:09:10 +08:00
|
|
|
AddressSpace *(*get_dma_as)(DeviceState *d);
|
2013-01-15 07:08:01 +08:00
|
|
|
} VirtioBusClass;
|
|
|
|
|
|
|
|
struct VirtioBusState {
|
|
|
|
BusState parent_obj;
|
2016-10-22 04:48:05 +08:00
|
|
|
|
2016-10-22 04:48:06 +08:00
|
|
|
/*
|
|
|
|
* Set if ioeventfd has been started.
|
|
|
|
*/
|
|
|
|
bool ioeventfd_started;
|
2016-11-18 23:07:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set if ioeventfd has been grabbed by vhost. When ioeventfd
|
|
|
|
* is grabbed by vhost, we track its started/stopped state (which
|
|
|
|
* depends in turn on the virtio status register), but do not
|
|
|
|
* register a handler for the ioeventfd. When ioeventfd is
|
|
|
|
* released, if ioeventfd_started is true we finally register
|
|
|
|
* the handler so that QEMU's device model can use ioeventfd.
|
|
|
|
*/
|
|
|
|
int ioeventfd_grabbed;
|
2013-01-15 07:08:01 +08:00
|
|
|
};
|
|
|
|
|
2015-05-29 14:15:25 +08:00
|
|
|
void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp);
|
2013-01-15 07:08:01 +08:00
|
|
|
void virtio_bus_reset(VirtioBusState *bus);
|
2013-09-20 19:59:08 +08:00
|
|
|
void virtio_bus_device_unplugged(VirtIODevice *bus);
|
2013-01-15 07:08:01 +08:00
|
|
|
/* Get the device id of the plugged device. */
|
|
|
|
uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
|
|
|
|
/* Get the config_len field of the plugged device. */
|
|
|
|
size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
|
2013-01-15 07:08:02 +08:00
|
|
|
/* Get bad features of the plugged device. */
|
|
|
|
uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
|
|
|
|
/* Get config of the plugged device. */
|
|
|
|
void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
|
2013-04-24 16:21:17 +08:00
|
|
|
/* Set config of the plugged device. */
|
|
|
|
void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
|
2013-01-15 07:08:01 +08:00
|
|
|
|
2013-09-20 19:31:39 +08:00
|
|
|
static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
|
|
|
|
{
|
|
|
|
BusState *qbus = &bus->parent_obj;
|
|
|
|
BusChild *kid = QTAILQ_FIRST(&qbus->children);
|
|
|
|
DeviceState *qdev = kid ? kid->child : NULL;
|
|
|
|
|
|
|
|
/* This is used on the data path, the cast is guaranteed
|
|
|
|
* to succeed by the qdev machinery.
|
|
|
|
*/
|
|
|
|
return (VirtIODevice *)qdev;
|
|
|
|
}
|
|
|
|
|
2016-10-22 04:48:08 +08:00
|
|
|
/* Return whether the proxy allows ioeventfd. */
|
|
|
|
bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus);
|
2016-06-10 17:04:09 +08:00
|
|
|
/* Start the ioeventfd. */
|
2016-10-22 04:48:07 +08:00
|
|
|
int virtio_bus_start_ioeventfd(VirtioBusState *bus);
|
2016-06-10 17:04:09 +08:00
|
|
|
/* Stop the ioeventfd. */
|
|
|
|
void virtio_bus_stop_ioeventfd(VirtioBusState *bus);
|
2016-11-18 23:07:00 +08:00
|
|
|
/* Tell the bus that vhost is grabbing the ioeventfd. */
|
|
|
|
int virtio_bus_grab_ioeventfd(VirtioBusState *bus);
|
|
|
|
/* bus that vhost is not using the ioeventfd anymore. */
|
|
|
|
void virtio_bus_release_ioeventfd(VirtioBusState *bus);
|
2016-06-10 17:04:09 +08:00
|
|
|
/* Switch from/to the generic ioeventfd handler */
|
|
|
|
int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign);
|
2018-01-29 22:20:56 +08:00
|
|
|
/* Tell the bus that the ioeventfd handler is no longer required. */
|
|
|
|
void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n);
|
2016-06-10 17:04:09 +08:00
|
|
|
|
2013-01-15 07:08:01 +08:00
|
|
|
#endif /* VIRTIO_BUS_H */
|