2013-01-24 14:08:55 +08:00
|
|
|
/*
|
|
|
|
* virtio ccw target implementation
|
|
|
|
*
|
2015-05-27 19:11:59 +08:00
|
|
|
* Copyright 2012,2015 IBM Corp.
|
2013-01-24 14:08:55 +08:00
|
|
|
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
2015-05-27 19:11:59 +08:00
|
|
|
* Pierre Morel <pmorel@linux.vnet.ibm.com>
|
2013-01-24 14:08:55 +08:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at
|
|
|
|
* your option) any later version. See the COPYING file in the top-level
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw/hw.h"
|
2014-10-07 19:59:18 +08:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-01-24 14:08:55 +08:00
|
|
|
#include "sysemu/blockdev.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "net/net.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
#include "hw/virtio/virtio-serial.h"
|
|
|
|
#include "hw/virtio/virtio-net.h"
|
2013-01-24 14:08:55 +08:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "qemu/bitops.h"
|
2015-03-18 01:29:20 +08:00
|
|
|
#include "qemu/error-report.h"
|
2014-12-11 21:25:12 +08:00
|
|
|
#include "hw/virtio/virtio-access.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2013-07-15 23:45:03 +08:00
|
|
|
#include "hw/s390x/adapter.h"
|
|
|
|
#include "hw/s390x/s390_flic.h"
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
#include "ioinst.h"
|
|
|
|
#include "css.h"
|
|
|
|
#include "virtio-ccw.h"
|
|
|
|
#include "trace.h"
|
|
|
|
|
2013-08-01 23:27:00 +08:00
|
|
|
static QTAILQ_HEAD(, IndAddr) indicator_addresses =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(indicator_addresses);
|
|
|
|
|
|
|
|
static IndAddr *get_indicator(hwaddr ind_addr, int len)
|
|
|
|
{
|
|
|
|
IndAddr *indicator;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(indicator, &indicator_addresses, sibling) {
|
|
|
|
if (indicator->addr == ind_addr) {
|
|
|
|
indicator->refcnt++;
|
|
|
|
return indicator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
indicator = g_new0(IndAddr, 1);
|
|
|
|
indicator->addr = ind_addr;
|
|
|
|
indicator->len = len;
|
|
|
|
indicator->refcnt = 1;
|
|
|
|
QTAILQ_INSERT_TAIL(&indicator_addresses, indicator, sibling);
|
|
|
|
return indicator;
|
|
|
|
}
|
|
|
|
|
2013-07-15 23:45:03 +08:00
|
|
|
static int s390_io_adapter_map(AdapterInfo *adapter, uint64_t map_addr,
|
|
|
|
bool do_map)
|
|
|
|
{
|
|
|
|
S390FLICState *fs = s390_get_flic();
|
|
|
|
S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
|
|
|
|
|
|
|
|
return fsc->io_adapter_map(fs, adapter->adapter_id, map_addr, do_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_indicator(AdapterInfo *adapter, IndAddr *indicator)
|
2013-08-01 23:27:00 +08:00
|
|
|
{
|
|
|
|
assert(indicator->refcnt > 0);
|
|
|
|
indicator->refcnt--;
|
|
|
|
if (indicator->refcnt > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTAILQ_REMOVE(&indicator_addresses, indicator, sibling);
|
2013-07-15 23:45:03 +08:00
|
|
|
if (indicator->map) {
|
|
|
|
s390_io_adapter_map(adapter, indicator->map, false);
|
|
|
|
}
|
2013-08-01 23:27:00 +08:00
|
|
|
g_free(indicator);
|
|
|
|
}
|
|
|
|
|
2013-07-15 23:45:03 +08:00
|
|
|
static int map_indicator(AdapterInfo *adapter, IndAddr *indicator)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (indicator->map) {
|
|
|
|
return 0; /* already mapped is not an error */
|
|
|
|
}
|
|
|
|
indicator->map = indicator->addr;
|
|
|
|
ret = s390_io_adapter_map(adapter, indicator->map, true);
|
|
|
|
if ((ret != 0) && (ret != -ENOSYS)) {
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
indicator->map = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-24 02:27:30 +08:00
|
|
|
static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
|
|
|
|
VirtioCcwDevice *dev);
|
2013-04-24 16:21:18 +08:00
|
|
|
|
2013-12-07 00:54:27 +08:00
|
|
|
static void virtual_css_bus_reset(BusState *qbus)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
/* This should actually be modelled via the generic css */
|
|
|
|
css_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
BusClass *k = BUS_CLASS(klass);
|
|
|
|
|
|
|
|
k->reset = virtual_css_bus_reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtual_css_bus_info = {
|
|
|
|
.name = TYPE_VIRTUAL_CSS_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(VirtualCssBus),
|
|
|
|
.class_init = virtual_css_bus_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
|
|
|
|
{
|
|
|
|
VirtIODevice *vdev = NULL;
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtioCcwDevice *dev = sch->driver_data;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-09-20 19:51:52 +08:00
|
|
|
if (dev) {
|
|
|
|
vdev = virtio_bus_get_device(&dev->bus);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
return vdev;
|
|
|
|
}
|
|
|
|
|
2013-02-15 17:18:43 +08:00
|
|
|
static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
|
|
|
|
bool assign, bool set_handler)
|
|
|
|
{
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, n);
|
2013-02-15 17:18:43 +08:00
|
|
|
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
|
|
|
|
int r = 0;
|
|
|
|
SubchDev *sch = dev->sch;
|
|
|
|
uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;
|
|
|
|
|
|
|
|
if (assign) {
|
|
|
|
r = event_notifier_init(notifier, 1);
|
|
|
|
if (r < 0) {
|
|
|
|
error_report("%s: unable to init event notifier: %d", __func__, r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
|
2013-06-28 15:28:06 +08:00
|
|
|
r = s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
|
2013-02-15 17:18:43 +08:00
|
|
|
if (r < 0) {
|
|
|
|
error_report("%s: unable to assign ioeventfd: %d", __func__, r);
|
|
|
|
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
|
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
virtio_queue_set_host_notifier_fd_handler(vq, false, false);
|
2013-06-28 15:28:06 +08:00
|
|
|
s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
|
2013-02-15 17:18:43 +08:00
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
|
|
|
|
{
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev;
|
2013-02-15 17:18:43 +08:00
|
|
|
int n, r;
|
|
|
|
|
|
|
|
if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
|
2013-02-19 20:48:17 +08:00
|
|
|
dev->ioeventfd_disabled ||
|
2013-02-15 17:18:43 +08:00
|
|
|
dev->ioeventfd_started) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
vdev = virtio_bus_get_device(&dev->bus);
|
2015-05-29 14:15:27 +08:00
|
|
|
for (n = 0; n < VIRTIO_CCW_QUEUE_MAX; n++) {
|
2013-09-20 19:51:52 +08:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2013-02-15 17:18:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
|
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dev->ioeventfd_started = true;
|
|
|
|
return;
|
|
|
|
|
|
|
|
assign_error:
|
|
|
|
while (--n >= 0) {
|
2013-09-20 19:51:52 +08:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2013-02-15 17:18:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
|
|
|
|
assert(r >= 0);
|
|
|
|
}
|
|
|
|
dev->ioeventfd_started = false;
|
|
|
|
/* Disable ioeventfd for this device. */
|
|
|
|
dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
|
|
|
|
error_report("%s: failed. Fallback to userspace (slower).", __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
|
|
|
|
{
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev;
|
2013-02-15 17:18:43 +08:00
|
|
|
int n, r;
|
|
|
|
|
|
|
|
if (!dev->ioeventfd_started) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
vdev = virtio_bus_get_device(&dev->bus);
|
2015-05-29 14:15:27 +08:00
|
|
|
for (n = 0; n < VIRTIO_CCW_QUEUE_MAX; n++) {
|
2013-09-20 19:51:52 +08:00
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
2013-02-15 17:18:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
|
|
|
|
assert(r >= 0);
|
|
|
|
}
|
|
|
|
dev->ioeventfd_started = false;
|
|
|
|
}
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
VirtualCssBus *virtual_css_bus_init(void)
|
|
|
|
{
|
|
|
|
VirtualCssBus *cbus;
|
|
|
|
BusState *bus;
|
|
|
|
DeviceState *dev;
|
|
|
|
|
|
|
|
/* Create bridge device */
|
|
|
|
dev = qdev_create(NULL, "virtual-css-bridge");
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
|
|
|
|
/* Create bus on bridge device */
|
|
|
|
bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
|
|
|
|
cbus = VIRTUAL_CSS_BUS(bus);
|
|
|
|
|
|
|
|
/* Enable hotplugging */
|
2014-09-26 17:28:30 +08:00
|
|
|
qbus_set_hotplug_handler(bus, dev, &error_abort);
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
return cbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Communication blocks used by several channel commands. */
|
2014-12-11 21:25:13 +08:00
|
|
|
typedef struct VqInfoBlockLegacy {
|
2013-01-24 14:08:55 +08:00
|
|
|
uint64_t queue;
|
|
|
|
uint32_t align;
|
|
|
|
uint16_t index;
|
|
|
|
uint16_t num;
|
2014-12-11 21:25:13 +08:00
|
|
|
} QEMU_PACKED VqInfoBlockLegacy;
|
|
|
|
|
|
|
|
typedef struct VqInfoBlock {
|
|
|
|
uint64_t desc;
|
|
|
|
uint32_t res0;
|
|
|
|
uint16_t index;
|
|
|
|
uint16_t num;
|
|
|
|
uint64_t avail;
|
|
|
|
uint64_t used;
|
2013-01-24 14:08:55 +08:00
|
|
|
} QEMU_PACKED VqInfoBlock;
|
|
|
|
|
|
|
|
typedef struct VqConfigBlock {
|
|
|
|
uint16_t index;
|
|
|
|
uint16_t num_max;
|
|
|
|
} QEMU_PACKED VqConfigBlock;
|
|
|
|
|
|
|
|
typedef struct VirtioFeatDesc {
|
|
|
|
uint32_t features;
|
|
|
|
uint8_t index;
|
|
|
|
} QEMU_PACKED VirtioFeatDesc;
|
|
|
|
|
2013-02-06 17:31:37 +08:00
|
|
|
typedef struct VirtioThinintInfo {
|
|
|
|
hwaddr summary_indicator;
|
|
|
|
hwaddr device_indicator;
|
|
|
|
uint64_t ind_bit;
|
|
|
|
uint8_t isc;
|
|
|
|
} QEMU_PACKED VirtioThinintInfo;
|
|
|
|
|
2014-12-11 21:25:12 +08:00
|
|
|
typedef struct VirtioRevInfo {
|
|
|
|
uint16_t revision;
|
|
|
|
uint16_t length;
|
|
|
|
uint8_t data[0];
|
|
|
|
} QEMU_PACKED VirtioRevInfo;
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
/* Specify where the virtqueues for the subchannel are in guest memory. */
|
2014-12-11 21:25:13 +08:00
|
|
|
static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock *info,
|
|
|
|
VqInfoBlockLegacy *linfo)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
|
2014-12-11 21:25:13 +08:00
|
|
|
uint16_t index = info ? info->index : linfo->index;
|
|
|
|
uint16_t num = info ? info->num : linfo->num;
|
|
|
|
uint64_t desc = info ? info->desc : linfo->queue;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2015-05-29 14:15:27 +08:00
|
|
|
if (index >= VIRTIO_CCW_QUEUE_MAX) {
|
2013-01-24 14:08:55 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Current code in virtio.c relies on 4K alignment. */
|
2014-12-11 21:25:13 +08:00
|
|
|
if (linfo && desc && (linfo->align != 4096)) {
|
2013-01-24 14:08:55 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-09-20 19:51:52 +08:00
|
|
|
if (!vdev) {
|
2013-01-24 14:08:55 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:25:13 +08:00
|
|
|
if (info) {
|
|
|
|
virtio_queue_set_rings(vdev, index, desc, info->avail, info->used);
|
|
|
|
} else {
|
|
|
|
virtio_queue_set_addr(vdev, index, desc);
|
|
|
|
}
|
|
|
|
if (!desc) {
|
2015-04-23 14:21:40 +08:00
|
|
|
virtio_queue_set_vector(vdev, index, VIRTIO_NO_VECTOR);
|
2013-01-24 14:08:55 +08:00
|
|
|
} else {
|
|
|
|
/* Fail if we don't have a big enough queue. */
|
|
|
|
/* TODO: Add interface to handle vring.num changing */
|
2013-09-20 19:51:52 +08:00
|
|
|
if (virtio_queue_get_num(vdev, index) > num) {
|
2013-01-24 14:08:55 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
virtio_queue_set_vector(vdev, index, index);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
/* tell notify handler in case of config change */
|
2015-05-29 14:15:27 +08:00
|
|
|
vdev->config_vector = VIRTIO_CCW_QUEUE_MAX;
|
2013-01-24 14:08:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-23 21:46:31 +08:00
|
|
|
static void virtio_ccw_reset_virtio(VirtioCcwDevice *dev, VirtIODevice *vdev)
|
|
|
|
{
|
|
|
|
virtio_ccw_stop_ioeventfd(dev);
|
|
|
|
virtio_reset(vdev);
|
|
|
|
if (dev->indicators) {
|
|
|
|
release_indicator(&dev->routes.adapter, dev->indicators);
|
|
|
|
dev->indicators = NULL;
|
|
|
|
}
|
|
|
|
if (dev->indicators2) {
|
|
|
|
release_indicator(&dev->routes.adapter, dev->indicators2);
|
|
|
|
dev->indicators2 = NULL;
|
|
|
|
}
|
|
|
|
if (dev->summary_indicator) {
|
|
|
|
release_indicator(&dev->routes.adapter, dev->summary_indicator);
|
|
|
|
dev->summary_indicator = NULL;
|
|
|
|
}
|
|
|
|
dev->sch->thinint_active = false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:25:13 +08:00
|
|
|
static int virtio_ccw_handle_set_vq(SubchDev *sch, CCW1 ccw, bool check_len,
|
|
|
|
bool is_legacy)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VqInfoBlock info;
|
2014-12-11 21:25:13 +08:00
|
|
|
VqInfoBlockLegacy linfo;
|
|
|
|
size_t info_len = is_legacy ? sizeof(linfo) : sizeof(info);
|
|
|
|
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != info_len) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < info_len) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
if (is_legacy) {
|
|
|
|
linfo.queue = address_space_ldq_be(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
linfo.align = address_space_ldl_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(linfo.queue),
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
|
|
|
linfo.index = address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(linfo.queue)
|
|
|
|
+ sizeof(linfo.align),
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
|
|
|
linfo.num = address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(linfo.queue)
|
|
|
|
+ sizeof(linfo.align)
|
|
|
|
+ sizeof(linfo.index),
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
|
|
|
ret = virtio_ccw_set_vqs(sch, NULL, &linfo);
|
|
|
|
} else {
|
|
|
|
info.desc = address_space_ldq_be(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
info.index = address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(info.desc)
|
|
|
|
+ sizeof(info.res0),
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
info.num = address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(info.desc)
|
|
|
|
+ sizeof(info.res0)
|
|
|
|
+ sizeof(info.index),
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
info.avail = address_space_ldq_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(info.desc)
|
|
|
|
+ sizeof(info.res0)
|
|
|
|
+ sizeof(info.index)
|
|
|
|
+ sizeof(info.num),
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
info.used = address_space_ldq_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(info.desc)
|
|
|
|
+ sizeof(info.res0)
|
|
|
|
+ sizeof(info.index)
|
|
|
|
+ sizeof(info.num)
|
|
|
|
+ sizeof(info.avail),
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
ret = virtio_ccw_set_vqs(sch, &info, NULL);
|
|
|
|
}
|
|
|
|
sch->curr_status.scsw.count = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
|
|
|
|
{
|
|
|
|
int ret;
|
2014-12-11 21:25:12 +08:00
|
|
|
VirtioRevInfo revinfo;
|
2013-01-24 14:08:55 +08:00
|
|
|
uint8_t status;
|
|
|
|
VirtioFeatDesc features;
|
|
|
|
void *config;
|
|
|
|
hwaddr indicators;
|
|
|
|
VqConfigBlock vq_config;
|
|
|
|
VirtioCcwDevice *dev = sch->driver_data;
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
|
2013-01-24 14:08:55 +08:00
|
|
|
bool check_len;
|
|
|
|
int len;
|
|
|
|
hwaddr hw_len;
|
2013-02-06 17:31:37 +08:00
|
|
|
VirtioThinintInfo *thinint;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
if (!dev) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
|
|
|
|
ccw.cmd_code);
|
|
|
|
check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
|
|
|
|
|
|
|
|
/* Look at the command. */
|
|
|
|
switch (ccw.cmd_code) {
|
|
|
|
case CCW_CMD_SET_VQ:
|
2014-12-11 21:25:13 +08:00
|
|
|
ret = virtio_ccw_handle_set_vq(sch, ccw, check_len, dev->revision < 1);
|
2013-01-24 14:08:55 +08:00
|
|
|
break;
|
|
|
|
case CCW_CMD_VDEV_RESET:
|
2015-06-23 21:46:31 +08:00
|
|
|
virtio_ccw_reset_virtio(dev, vdev);
|
2013-01-24 14:08:55 +08:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case CCW_CMD_READ_FEAT:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(features)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(features)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
features.index = address_space_ldub(&address_space_memory,
|
|
|
|
ccw.cda
|
|
|
|
+ sizeof(features.features),
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2015-05-26 22:34:47 +08:00
|
|
|
if (features.index == 0) {
|
2014-12-11 21:25:12 +08:00
|
|
|
features.features = (uint32_t)vdev->host_features;
|
|
|
|
} else if (features.index == 1) {
|
|
|
|
features.features = (uint32_t)(vdev->host_features >> 32);
|
|
|
|
/*
|
|
|
|
* Don't offer version 1 to the guest if it did not
|
|
|
|
* negotiate at least revision 1.
|
|
|
|
*/
|
|
|
|
if (dev->revision <= 0) {
|
|
|
|
features.features &= ~(1 << (VIRTIO_F_VERSION_1 - 32));
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
} else {
|
|
|
|
/* Return zeroes if the guest supports more feature bits. */
|
|
|
|
features.features = 0;
|
|
|
|
}
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
address_space_stl_le(&address_space_memory, ccw.cda,
|
|
|
|
features.features, MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(features);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_WRITE_FEAT:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(features)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(features)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
features.index = address_space_ldub(&address_space_memory,
|
|
|
|
ccw.cda
|
|
|
|
+ sizeof(features.features),
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
|
|
|
features.features = address_space_ldl_le(&address_space_memory,
|
|
|
|
ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2015-05-26 22:34:47 +08:00
|
|
|
if (features.index == 0) {
|
2014-12-11 21:25:12 +08:00
|
|
|
virtio_set_features(vdev,
|
|
|
|
(vdev->guest_features & 0xffffffff00000000ULL) |
|
|
|
|
features.features);
|
|
|
|
} else if (features.index == 1) {
|
|
|
|
/*
|
|
|
|
* The guest should not set version 1 if it didn't
|
|
|
|
* negotiate a revision >= 1.
|
|
|
|
*/
|
|
|
|
if (dev->revision <= 0) {
|
|
|
|
features.features &= ~(1 << (VIRTIO_F_VERSION_1 - 32));
|
|
|
|
}
|
|
|
|
virtio_set_features(vdev,
|
|
|
|
(vdev->guest_features & 0x00000000ffffffffULL) |
|
|
|
|
((uint64_t)features.features << 32));
|
2013-01-24 14:08:55 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the guest supports more feature bits, assert that it
|
|
|
|
* passes us zeroes for those we don't support.
|
|
|
|
*/
|
|
|
|
if (features.features) {
|
|
|
|
fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
|
|
|
|
features.index, features.features);
|
|
|
|
/* XXX: do a unit check here? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(features);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_READ_CONF:
|
|
|
|
if (check_len) {
|
2013-09-20 19:51:52 +08:00
|
|
|
if (ccw.count > vdev->config_len) {
|
2013-01-24 14:08:55 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
len = MIN(ccw.count, vdev->config_len);
|
2013-01-24 14:08:55 +08:00
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
2013-09-20 19:51:52 +08:00
|
|
|
virtio_bus_get_vdev_config(&dev->bus, vdev->config);
|
2013-01-24 14:08:55 +08:00
|
|
|
/* XXX config space endianness */
|
2013-09-20 19:51:52 +08:00
|
|
|
cpu_physical_memory_write(ccw.cda, vdev->config, len);
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - len;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_WRITE_CONF:
|
|
|
|
if (check_len) {
|
2013-09-20 19:51:52 +08:00
|
|
|
if (ccw.count > vdev->config_len) {
|
2013-01-24 14:08:55 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
len = MIN(ccw.count, vdev->config_len);
|
2013-01-24 14:08:55 +08:00
|
|
|
hw_len = len;
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
|
|
|
config = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
|
|
|
|
if (!config) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
|
|
|
len = hw_len;
|
|
|
|
/* XXX config space endianness */
|
2013-09-20 19:51:52 +08:00
|
|
|
memcpy(vdev->config, config, len);
|
2013-01-24 14:08:55 +08:00
|
|
|
cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
|
2013-09-20 19:51:52 +08:00
|
|
|
virtio_bus_set_vdev_config(&dev->bus, vdev->config);
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - len;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_WRITE_STATUS:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(status)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(status)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
status = address_space_ldub(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
2013-02-15 17:18:43 +08:00
|
|
|
if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
|
|
|
virtio_ccw_stop_ioeventfd(dev);
|
|
|
|
}
|
2015-06-04 18:34:15 +08:00
|
|
|
if (virtio_set_status(vdev, status) == 0) {
|
|
|
|
if (vdev->status == 0) {
|
2015-06-23 21:46:31 +08:00
|
|
|
virtio_ccw_reset_virtio(dev, vdev);
|
2015-06-04 18:34:15 +08:00
|
|
|
}
|
|
|
|
if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
|
|
|
|
virtio_ccw_start_ioeventfd(dev);
|
|
|
|
}
|
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(status);
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
/* Trigger a command reject. */
|
|
|
|
ret = -ENOSYS;
|
2013-02-15 17:18:43 +08:00
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_SET_IND:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(indicators)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(indicators)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-06 17:31:37 +08:00
|
|
|
if (sch->thinint_active) {
|
|
|
|
/* Trigger a command reject. */
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-05 23:13:05 +08:00
|
|
|
if (!ccw.cda) {
|
2013-01-24 14:08:55 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
indicators = address_space_ldq_be(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
2013-08-01 23:27:00 +08:00
|
|
|
dev->indicators = get_indicator(indicators, sizeof(uint64_t));
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_SET_CONF_IND:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(indicators)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(indicators)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-05 23:13:05 +08:00
|
|
|
if (!ccw.cda) {
|
2013-01-24 14:08:55 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
indicators = address_space_ldq_be(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
2013-08-01 23:27:00 +08:00
|
|
|
dev->indicators2 = get_indicator(indicators, sizeof(uint64_t));
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CCW_CMD_READ_VQ_CONF:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(vq_config)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(vq_config)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
vq_config.index = address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2015-05-29 14:15:27 +08:00
|
|
|
if (vq_config.index >= VIRTIO_CCW_QUEUE_MAX) {
|
2015-03-20 20:16:20 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2013-09-20 19:51:52 +08:00
|
|
|
vq_config.num_max = virtio_queue_get_num(vdev,
|
2013-01-24 14:08:55 +08:00
|
|
|
vq_config.index);
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
address_space_stw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(vq_config.index),
|
|
|
|
vq_config.num_max,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2013-01-24 14:08:55 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-02-06 17:31:37 +08:00
|
|
|
case CCW_CMD_SET_IND_ADAPTER:
|
|
|
|
if (check_len) {
|
|
|
|
if (ccw.count != sizeof(*thinint)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ccw.count < sizeof(*thinint)) {
|
|
|
|
/* Can't execute command. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
len = sizeof(*thinint);
|
|
|
|
hw_len = len;
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else if (dev->indicators && !sch->thinint_active) {
|
|
|
|
/* Trigger a command reject. */
|
|
|
|
ret = -ENOSYS;
|
|
|
|
} else {
|
|
|
|
thinint = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
|
|
|
|
if (!thinint) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else {
|
2015-03-11 17:57:50 +08:00
|
|
|
uint64_t ind_bit = ldq_be_p(&thinint->ind_bit);
|
|
|
|
|
2013-02-06 17:31:37 +08:00
|
|
|
len = hw_len;
|
2013-08-01 23:27:00 +08:00
|
|
|
dev->summary_indicator =
|
2015-03-11 17:57:50 +08:00
|
|
|
get_indicator(ldq_be_p(&thinint->summary_indicator),
|
|
|
|
sizeof(uint8_t));
|
|
|
|
dev->indicators =
|
|
|
|
get_indicator(ldq_be_p(&thinint->device_indicator),
|
|
|
|
ind_bit / 8 + 1);
|
2013-02-06 17:31:37 +08:00
|
|
|
dev->thinint_isc = thinint->isc;
|
2015-03-11 17:57:50 +08:00
|
|
|
dev->routes.adapter.ind_offset = ind_bit;
|
2013-07-15 23:45:03 +08:00
|
|
|
dev->routes.adapter.summary_offset = 7;
|
2013-02-06 17:31:37 +08:00
|
|
|
cpu_physical_memory_unmap(thinint, hw_len, 0, hw_len);
|
2013-07-15 23:45:03 +08:00
|
|
|
ret = css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
|
|
|
|
dev->thinint_isc, true, false,
|
2013-07-15 23:45:03 +08:00
|
|
|
&dev->routes.adapter.adapter_id);
|
2013-07-15 23:45:03 +08:00
|
|
|
assert(ret == 0);
|
2013-08-01 23:27:00 +08:00
|
|
|
sch->thinint_active = ((dev->indicators != NULL) &&
|
|
|
|
(dev->summary_indicator != NULL));
|
2013-02-06 17:31:37 +08:00
|
|
|
sch->curr_status.scsw.count = ccw.count - len;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-12-11 21:25:12 +08:00
|
|
|
case CCW_CMD_SET_VIRTIO_REV:
|
|
|
|
len = sizeof(revinfo);
|
|
|
|
if (ccw.count < len) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ccw.cda) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
revinfo.revision =
|
|
|
|
address_space_lduw_be(&address_space_memory, ccw.cda,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
revinfo.length =
|
|
|
|
address_space_lduw_be(&address_space_memory,
|
|
|
|
ccw.cda + sizeof(revinfo.revision),
|
|
|
|
MEMTXATTRS_UNSPECIFIED, NULL);
|
|
|
|
if (ccw.count < len + revinfo.length ||
|
|
|
|
(check_len && ccw.count > len + revinfo.length)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Once we start to support revisions with additional data, we'll
|
|
|
|
* need to fetch it here. Nothing to do for now, though.
|
|
|
|
*/
|
|
|
|
if (dev->revision >= 0 ||
|
|
|
|
revinfo.revision > virtio_ccw_rev_max(vdev)) {
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
dev->revision = revinfo.revision;
|
|
|
|
break;
|
2013-01-24 14:08:55 +08:00
|
|
|
default:
|
2013-01-29 00:01:30 +08:00
|
|
|
ret = -ENOSYS;
|
2013-01-24 14:08:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-11 21:25:12 +08:00
|
|
|
static void virtio_sch_disable_cb(SubchDev *sch)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = sch->driver_data;
|
|
|
|
|
|
|
|
dev->revision = -1;
|
|
|
|
}
|
|
|
|
|
2015-04-21 22:36:55 +08:00
|
|
|
static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
unsigned int cssid = 0;
|
|
|
|
unsigned int ssid = 0;
|
|
|
|
unsigned int schid;
|
|
|
|
unsigned int devno;
|
|
|
|
bool have_devno = false;
|
|
|
|
bool found = false;
|
|
|
|
SubchDev *sch;
|
|
|
|
int num;
|
2015-04-21 22:36:55 +08:00
|
|
|
Error *err = NULL;
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
sch = g_malloc0(sizeof(SubchDev));
|
|
|
|
|
|
|
|
sch->driver_data = dev;
|
|
|
|
dev->sch = sch;
|
|
|
|
|
2013-08-01 23:27:00 +08:00
|
|
|
dev->indicators = NULL;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
/* Initialize subchannel structure. */
|
|
|
|
sch->channel_prog = 0x0;
|
|
|
|
sch->last_cmd_valid = false;
|
2013-02-06 17:31:37 +08:00
|
|
|
sch->thinint_active = false;
|
2013-01-24 14:08:55 +08:00
|
|
|
/*
|
|
|
|
* Use a device number if provided. Otherwise, fall back to subchannel
|
|
|
|
* number.
|
|
|
|
*/
|
|
|
|
if (dev->bus_id) {
|
|
|
|
num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno);
|
|
|
|
if (num == 3) {
|
|
|
|
if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "Invalid cssid or ssid: cssid %x, ssid %x",
|
|
|
|
cssid, ssid);
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
/* Enforce use of virtual cssid. */
|
|
|
|
if (cssid != VIRTUAL_CSSID) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "cssid %x not valid for virtio devices",
|
|
|
|
cssid);
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
if (css_devno_used(cssid, ssid, devno)) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "Device %x.%x.%04x already exists",
|
|
|
|
cssid, ssid, devno);
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
sch->cssid = cssid;
|
|
|
|
sch->ssid = ssid;
|
|
|
|
sch->devno = devno;
|
|
|
|
have_devno = true;
|
|
|
|
} else {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "Malformed devno parameter '%s'", dev->bus_id);
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the next free id. */
|
|
|
|
if (have_devno) {
|
|
|
|
for (schid = 0; schid <= MAX_SCHID; schid++) {
|
|
|
|
if (!css_find_subch(1, cssid, ssid, schid)) {
|
|
|
|
sch->schid = schid;
|
|
|
|
css_subch_assign(cssid, ssid, schid, devno, sch);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "No free subchannel found for %x.%x.%04x",
|
|
|
|
cssid, ssid, devno);
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
|
|
|
|
"user-configured");
|
|
|
|
} else {
|
|
|
|
cssid = VIRTUAL_CSSID;
|
|
|
|
for (ssid = 0; ssid <= MAX_SSID; ssid++) {
|
|
|
|
for (schid = 0; schid <= MAX_SCHID; schid++) {
|
|
|
|
if (!css_find_subch(1, cssid, ssid, schid)) {
|
|
|
|
sch->cssid = cssid;
|
|
|
|
sch->ssid = ssid;
|
|
|
|
sch->schid = schid;
|
|
|
|
devno = schid;
|
|
|
|
/*
|
|
|
|
* If the devno is already taken, look further in this
|
|
|
|
* subchannel set.
|
|
|
|
*/
|
|
|
|
while (css_devno_used(cssid, ssid, devno)) {
|
|
|
|
if (devno == MAX_SCHID) {
|
|
|
|
devno = 0;
|
|
|
|
} else if (devno == schid - 1) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "No free devno found");
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
} else {
|
|
|
|
devno++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sch->devno = devno;
|
|
|
|
css_subch_assign(cssid, ssid, schid, devno, sch);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2015-02-27 21:53:39 +08:00
|
|
|
error_setg(errp, "Virtual channel subsystem is full!");
|
2013-01-24 14:08:55 +08:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
|
|
|
|
"auto-configured");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build initial schib. */
|
|
|
|
css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);
|
|
|
|
|
|
|
|
sch->ccw_cb = virtio_ccw_cb;
|
2014-12-11 21:25:12 +08:00
|
|
|
sch->disable_cb = virtio_sch_disable_cb;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
/* Build senseid data. */
|
|
|
|
memset(&sch->id, 0, sizeof(SenseId));
|
|
|
|
sch->id.reserved = 0xff;
|
|
|
|
sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
|
2015-04-21 22:36:55 +08:00
|
|
|
|
2014-12-11 21:25:12 +08:00
|
|
|
dev->revision = -1;
|
|
|
|
|
2015-04-21 22:36:55 +08:00
|
|
|
if (k->realize) {
|
|
|
|
k->realize(dev, &err);
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
css_subch_assign(cssid, ssid, schid, devno, NULL);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
return;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
out_err:
|
|
|
|
dev->sch = NULL;
|
|
|
|
g_free(sch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_exit(VirtioCcwDevice *dev)
|
|
|
|
{
|
|
|
|
SubchDev *sch = dev->sch;
|
|
|
|
|
|
|
|
if (sch) {
|
|
|
|
css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
|
|
|
|
g_free(sch);
|
|
|
|
}
|
2013-08-01 23:27:00 +08:00
|
|
|
if (dev->indicators) {
|
2013-07-15 23:45:03 +08:00
|
|
|
release_indicator(&dev->routes.adapter, dev->indicators);
|
2013-08-01 23:27:00 +08:00
|
|
|
dev->indicators = NULL;
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-05-15 20:12:50 +08:00
|
|
|
DeviceState *qdev = DEVICE(ccw_dev);
|
2013-04-11 22:30:00 +08:00
|
|
|
VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-05-15 20:12:50 +08:00
|
|
|
virtio_net_set_netclient_name(&dev->vdev, qdev->id,
|
|
|
|
object_get_typename(OBJECT(qdev)));
|
2013-04-11 22:30:00 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 22:30:00 +08:00
|
|
|
static void virtio_ccw_net_instance_init(Object *obj)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-04-11 22:30:00 +08:00
|
|
|
VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_NET);
|
2014-10-07 16:00:22 +08:00
|
|
|
object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
|
|
|
|
"bootindex", &error_abort);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-19 00:37:25 +08:00
|
|
|
VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
|
|
|
|
2013-03-19 00:37:25 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 00:37:25 +08:00
|
|
|
static void virtio_ccw_blk_instance_init(Object *obj)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-19 00:37:25 +08:00
|
|
|
VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_BLK);
|
2014-06-10 15:03:20 +08:00
|
|
|
object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
|
|
|
|
&error_abort);
|
2014-10-07 16:00:32 +08:00
|
|
|
object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
|
|
|
|
"bootindex", &error_abort);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-04-09 20:53:33 +08:00
|
|
|
VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2013-04-30 22:08:50 +08:00
|
|
|
DeviceState *proxy = DEVICE(ccw_dev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-04-30 22:08:50 +08:00
|
|
|
char *bus_name;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For command line compatibility, this sets the virtio-serial-device bus
|
|
|
|
* name as before.
|
|
|
|
*/
|
|
|
|
if (proxy->id) {
|
|
|
|
bus_name = g_strdup_printf("%s.0", proxy->id);
|
|
|
|
virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
|
|
|
|
g_free(bus_name);
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-04-09 20:53:33 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 20:53:33 +08:00
|
|
|
|
|
|
|
static void virtio_ccw_serial_instance_init(Object *obj)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-04-09 20:53:33 +08:00
|
|
|
VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_SERIAL);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-27 17:49:12 +08:00
|
|
|
VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-03-27 17:49:12 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-27 17:49:12 +08:00
|
|
|
static void virtio_ccw_balloon_instance_init(Object *obj)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-27 17:49:12 +08:00
|
|
|
VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
|
2015-05-11 17:34:07 +08:00
|
|
|
|
2015-01-29 22:24:41 +08:00
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_BALLOON);
|
2015-05-11 17:34:07 +08:00
|
|
|
object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
|
|
|
|
"guest-stats", &error_abort);
|
|
|
|
object_property_add_alias(obj, "guest-stats-polling-interval",
|
|
|
|
OBJECT(&dev->vdev),
|
|
|
|
"guest-stats-polling-interval", &error_abort);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-21 22:15:17 +08:00
|
|
|
VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2013-04-30 22:08:51 +08:00
|
|
|
DeviceState *qdev = DEVICE(ccw_dev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-04-30 22:08:51 +08:00
|
|
|
char *bus_name;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For command line compatibility, this sets the virtio-scsi-device bus
|
|
|
|
* name as before.
|
|
|
|
*/
|
|
|
|
if (qdev->id) {
|
|
|
|
bus_name = g_strdup_printf("%s.0", qdev->id);
|
|
|
|
virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
|
|
|
|
g_free(bus_name);
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-03-21 22:15:17 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 22:15:17 +08:00
|
|
|
static void virtio_ccw_scsi_instance_init(Object *obj)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
2013-03-21 22:15:17 +08:00
|
|
|
VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_SCSI);
|
2014-08-06 13:35:06 +08:00
|
|
|
object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
|
|
|
|
&error_abort);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
2013-04-19 22:16:50 +08:00
|
|
|
#ifdef CONFIG_VHOST_SCSI
|
2015-02-27 21:53:39 +08:00
|
|
|
static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-04-19 22:16:50 +08:00
|
|
|
{
|
|
|
|
VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-04-19 22:16:50 +08:00
|
|
|
|
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
2013-04-19 22:16:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vhost_ccw_scsi_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VHOST_SCSI);
|
2013-04-19 22:16:50 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
2013-03-04 20:06:56 +08:00
|
|
|
{
|
2013-04-24 16:07:58 +08:00
|
|
|
VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
2015-02-27 21:53:39 +08:00
|
|
|
Error *err = NULL;
|
2013-03-04 20:06:56 +08:00
|
|
|
|
2013-04-24 16:07:58 +08:00
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
2015-02-27 21:53:39 +08:00
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
2013-03-04 20:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-04-24 16:07:58 +08:00
|
|
|
object_property_set_link(OBJECT(dev),
|
2013-06-01 02:12:48 +08:00
|
|
|
OBJECT(dev->vdev.conf.rng), "rng",
|
2013-04-24 16:07:58 +08:00
|
|
|
NULL);
|
2013-03-04 20:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
/* DeviceState to VirtioCcwDevice. Note: used on datapath,
|
|
|
|
* be careful and test performance if you change this.
|
|
|
|
*/
|
|
|
|
static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
|
|
|
|
{
|
|
|
|
return container_of(d, VirtioCcwDevice, parent_obj);
|
|
|
|
}
|
|
|
|
|
2013-02-06 17:31:37 +08:00
|
|
|
static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc,
|
|
|
|
uint8_t to_be_set)
|
|
|
|
{
|
|
|
|
uint8_t ind_old, ind_new;
|
|
|
|
hwaddr len = 1;
|
|
|
|
uint8_t *ind_addr;
|
|
|
|
|
|
|
|
ind_addr = cpu_physical_memory_map(ind_loc, &len, 1);
|
|
|
|
if (!ind_addr) {
|
|
|
|
error_report("%s(%x.%x.%04x): unable to access indicator",
|
|
|
|
__func__, sch->cssid, sch->ssid, sch->schid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
ind_old = *ind_addr;
|
|
|
|
ind_new = ind_old | to_be_set;
|
|
|
|
} while (atomic_cmpxchg(ind_addr, ind_old, ind_new) != ind_old);
|
|
|
|
cpu_physical_memory_unmap(ind_addr, len, 1, len);
|
|
|
|
|
|
|
|
return ind_old;
|
|
|
|
}
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
|
|
|
|
SubchDev *sch = dev->sch;
|
|
|
|
uint64_t indicators;
|
|
|
|
|
|
|
|
if (vector >= 128) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:15:27 +08:00
|
|
|
if (vector < VIRTIO_CCW_QUEUE_MAX) {
|
2013-04-23 23:15:19 +08:00
|
|
|
if (!dev->indicators) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-06 17:31:37 +08:00
|
|
|
if (sch->thinint_active) {
|
|
|
|
/*
|
|
|
|
* In the adapter interrupt case, indicators points to a
|
|
|
|
* memory area that may be (way) larger than 64 bit and
|
|
|
|
* ind_bit indicates the start of the indicators in a big
|
|
|
|
* endian notation.
|
|
|
|
*/
|
2013-07-15 23:45:03 +08:00
|
|
|
uint64_t ind_bit = dev->routes.adapter.ind_offset;
|
|
|
|
|
2013-08-01 23:27:00 +08:00
|
|
|
virtio_set_ind_atomic(sch, dev->indicators->addr +
|
2013-07-15 23:45:03 +08:00
|
|
|
(ind_bit + vector) / 8,
|
|
|
|
0x80 >> ((ind_bit + vector) % 8));
|
2013-08-01 23:27:00 +08:00
|
|
|
if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr,
|
2013-02-06 17:31:37 +08:00
|
|
|
0x01)) {
|
|
|
|
css_adapter_interrupt(dev->thinint_isc);
|
|
|
|
}
|
|
|
|
} else {
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
indicators = address_space_ldq(&address_space_memory,
|
|
|
|
dev->indicators->addr,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2013-02-06 17:31:37 +08:00
|
|
|
indicators |= 1ULL << vector;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
address_space_stq(&address_space_memory, dev->indicators->addr,
|
|
|
|
indicators, MEMTXATTRS_UNSPECIFIED, NULL);
|
2013-02-06 17:31:37 +08:00
|
|
|
css_conditional_io_interrupt(sch);
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
} else {
|
2013-04-23 23:15:19 +08:00
|
|
|
if (!dev->indicators2) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
vector = 0;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
indicators = address_space_ldq(&address_space_memory,
|
|
|
|
dev->indicators2->addr,
|
|
|
|
MEMTXATTRS_UNSPECIFIED,
|
|
|
|
NULL);
|
2013-01-29 23:33:04 +08:00
|
|
|
indicators |= 1ULL << vector;
|
Switch non-CPU callers from ld/st*_phys to address_space_ld/st*
Switch all the uses of ld/st*_phys to address_space_ld/st*,
except for those cases where the address space is the CPU's
(ie cs->as). This was done with the following script which
generates a Coccinelle patch.
A few over-80-columns lines in the result were rewrapped by
hand where Coccinelle failed to do the wrapping automatically,
as well as one location where it didn't put a line-continuation
'\' when wrapping lines on a change made to a match inside
a macro definition.
===begin===
#!/bin/sh -e
# Usage:
# ./ldst-phys.spatch.sh > ldst-phys.spatch
# spatch -sp_file ldst-phys.spatch -dir . | sed -e '/^+/s/\t/ /g' > out.patch
# patch -p1 < out.patch
for FN in ub uw_le uw_be l_le l_be q_le q_be uw l q; do
cat <<EOF
@ cpu_matches_ld_${FN} @
expression E1,E2;
identifier as;
@@
ld${FN}_phys(E1->as,E2)
@ other_matches_ld_${FN} depends on !cpu_matches_ld_${FN} @
expression E1,E2;
@@
-ld${FN}_phys(E1,E2)
+address_space_ld${FN}(E1,E2, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
for FN in b w_le w_be l_le l_be q_le q_be w l q; do
cat <<EOF
@ cpu_matches_st_${FN} @
expression E1,E2,E3;
identifier as;
@@
st${FN}_phys(E1->as,E2,E3)
@ other_matches_st_${FN} depends on !cpu_matches_st_${FN} @
expression E1,E2,E3;
@@
-st${FN}_phys(E1,E2,E3)
+address_space_st${FN}(E1,E2,E3, MEMTXATTRS_UNSPECIFIED, NULL)
EOF
done
===endit===
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2015-04-26 23:49:24 +08:00
|
|
|
address_space_stq(&address_space_memory, dev->indicators2->addr,
|
|
|
|
indicators, MEMTXATTRS_UNSPECIFIED, NULL);
|
2013-02-06 17:31:37 +08:00
|
|
|
css_conditional_io_interrupt(sch);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_reset(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2015-06-23 21:46:31 +08:00
|
|
|
virtio_ccw_reset_virtio(dev, vdev);
|
2013-01-24 14:08:55 +08:00
|
|
|
css_reset_sch(dev->sch);
|
|
|
|
}
|
|
|
|
|
2013-02-15 17:18:43 +08:00
|
|
|
static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
|
|
|
|
if (running) {
|
|
|
|
virtio_ccw_start_ioeventfd(dev);
|
|
|
|
} else {
|
|
|
|
virtio_ccw_stop_ioeventfd(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-19 20:48:17 +08:00
|
|
|
static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
|
|
|
|
return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
|
|
|
|
/* Stop using the generic ioeventfd, we are doing eventfd handling
|
|
|
|
* ourselves below */
|
|
|
|
dev->ioeventfd_disabled = assign;
|
|
|
|
if (assign) {
|
|
|
|
virtio_ccw_stop_ioeventfd(dev);
|
|
|
|
}
|
|
|
|
return virtio_ccw_set_guest2host_notifier(dev, n, assign, false);
|
|
|
|
}
|
|
|
|
|
2013-07-15 23:45:03 +08:00
|
|
|
static int virtio_ccw_get_mappings(VirtioCcwDevice *dev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (!dev->sch->thinint_active) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = map_indicator(&dev->routes.adapter, dev->summary_indicator);
|
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = map_indicator(&dev->routes.adapter, dev->indicators);
|
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
dev->routes.adapter.summary_addr = dev->summary_indicator->map;
|
|
|
|
dev->routes.adapter.ind_addr = dev->indicators->map;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_setup_irqroutes(VirtioCcwDevice *dev, int nvqs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
int ret;
|
|
|
|
S390FLICState *fs = s390_get_flic();
|
|
|
|
S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
|
|
|
|
|
|
|
|
ret = virtio_ccw_get_mappings(dev);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
for (i = 0; i < nvqs; i++) {
|
|
|
|
if (!virtio_queue_get_num(vdev, i)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dev->routes.num_routes = i;
|
|
|
|
return fsc->add_adapter_routes(fs, &dev->routes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_release_irqroutes(VirtioCcwDevice *dev, int nvqs)
|
|
|
|
{
|
|
|
|
S390FLICState *fs = s390_get_flic();
|
|
|
|
S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
|
|
|
|
|
|
|
|
fsc->release_adapter_routes(fs, &dev->routes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_add_irqfd(VirtioCcwDevice *dev, int n)
|
|
|
|
{
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, n);
|
|
|
|
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
|
|
|
|
|
|
|
|
return kvm_irqchip_add_irqfd_notifier(kvm_state, notifier, NULL,
|
|
|
|
dev->routes.gsi[n]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_remove_irqfd(VirtioCcwDevice *dev, int n)
|
|
|
|
{
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, n);
|
|
|
|
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kvm_irqchip_remove_irqfd_notifier(kvm_state, notifier,
|
|
|
|
dev->routes.gsi[n]);
|
|
|
|
assert(ret == 0);
|
|
|
|
}
|
|
|
|
|
2013-02-19 20:48:17 +08:00
|
|
|
static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
|
|
|
|
bool assign, bool with_irqfd)
|
|
|
|
{
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
VirtQueue *vq = virtio_get_queue(vdev, n);
|
2013-02-19 20:48:17 +08:00
|
|
|
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
2013-02-19 20:48:17 +08:00
|
|
|
|
|
|
|
if (assign) {
|
|
|
|
int r = event_notifier_init(notifier, 0);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
|
2013-07-15 23:45:03 +08:00
|
|
|
if (with_irqfd) {
|
|
|
|
r = virtio_ccw_add_irqfd(dev, n);
|
|
|
|
if (r) {
|
|
|
|
virtio_queue_set_guest_notifier_fd_handler(vq, false,
|
|
|
|
with_irqfd);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We do not support individual masking for channel devices, so we
|
|
|
|
* need to manually trigger any guest masking callbacks here.
|
2013-02-19 20:48:17 +08:00
|
|
|
*/
|
|
|
|
if (k->guest_notifier_mask) {
|
2013-09-20 19:51:52 +08:00
|
|
|
k->guest_notifier_mask(vdev, n, false);
|
2013-02-19 20:48:17 +08:00
|
|
|
}
|
|
|
|
/* get lost events and re-inject */
|
|
|
|
if (k->guest_notifier_pending &&
|
2013-09-20 19:51:52 +08:00
|
|
|
k->guest_notifier_pending(vdev, n)) {
|
2013-02-19 20:48:17 +08:00
|
|
|
event_notifier_set(notifier);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (k->guest_notifier_mask) {
|
2013-09-20 19:51:52 +08:00
|
|
|
k->guest_notifier_mask(vdev, n, true);
|
2013-02-19 20:48:17 +08:00
|
|
|
}
|
2013-07-15 23:45:03 +08:00
|
|
|
if (with_irqfd) {
|
|
|
|
virtio_ccw_remove_irqfd(dev, n);
|
|
|
|
}
|
2013-02-19 20:48:17 +08:00
|
|
|
virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
|
|
|
|
event_notifier_cleanup(notifier);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
|
|
|
|
bool assigned)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
2013-09-20 19:51:52 +08:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
2013-07-15 23:45:03 +08:00
|
|
|
bool with_irqfd = dev->sch->thinint_active && kvm_irqfds_enabled();
|
2013-02-19 20:48:17 +08:00
|
|
|
int r, n;
|
|
|
|
|
2013-07-15 23:45:03 +08:00
|
|
|
if (with_irqfd && assigned) {
|
|
|
|
/* irq routes need to be set up before assigning irqfds */
|
|
|
|
r = virtio_ccw_setup_irqroutes(dev, nvqs);
|
|
|
|
if (r < 0) {
|
|
|
|
goto irqroute_error;
|
|
|
|
}
|
|
|
|
}
|
2013-02-19 20:48:17 +08:00
|
|
|
for (n = 0; n < nvqs; n++) {
|
|
|
|
if (!virtio_queue_get_num(vdev, n)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-07-15 23:45:03 +08:00
|
|
|
r = virtio_ccw_set_guest_notifier(dev, n, assigned, with_irqfd);
|
2013-02-19 20:48:17 +08:00
|
|
|
if (r < 0) {
|
|
|
|
goto assign_error;
|
|
|
|
}
|
|
|
|
}
|
2013-07-15 23:45:03 +08:00
|
|
|
if (with_irqfd && !assigned) {
|
|
|
|
/* release irq routes after irqfds have been released */
|
|
|
|
virtio_ccw_release_irqroutes(dev, nvqs);
|
|
|
|
}
|
2013-02-19 20:48:17 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
assign_error:
|
|
|
|
while (--n >= 0) {
|
|
|
|
virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
|
|
|
|
}
|
2013-07-15 23:45:03 +08:00
|
|
|
irqroute_error:
|
|
|
|
if (with_irqfd && assigned) {
|
|
|
|
virtio_ccw_release_irqroutes(dev, nvqs);
|
|
|
|
}
|
2013-02-19 20:48:17 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-02-11 20:29:44 +08:00
|
|
|
static void virtio_ccw_save_queue(DeviceState *d, int n, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
|
|
|
|
qemu_put_be16(f, virtio_queue_vector(vdev, n));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_load_queue(DeviceState *d, int n, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
|
|
|
uint16_t vector;
|
|
|
|
|
|
|
|
qemu_get_be16s(f, &vector);
|
|
|
|
virtio_queue_set_vector(vdev, n , vector);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
SubchDev *s = dev->sch;
|
2015-06-03 23:04:03 +08:00
|
|
|
VirtIODevice *vdev = virtio_ccw_get_vdev(s);
|
2014-02-11 20:29:44 +08:00
|
|
|
|
|
|
|
subch_device_save(s, f);
|
|
|
|
if (dev->indicators != NULL) {
|
|
|
|
qemu_put_be32(f, dev->indicators->len);
|
|
|
|
qemu_put_be64(f, dev->indicators->addr);
|
|
|
|
} else {
|
|
|
|
qemu_put_be32(f, 0);
|
|
|
|
qemu_put_be64(f, 0UL);
|
|
|
|
}
|
|
|
|
if (dev->indicators2 != NULL) {
|
|
|
|
qemu_put_be32(f, dev->indicators2->len);
|
|
|
|
qemu_put_be64(f, dev->indicators2->addr);
|
|
|
|
} else {
|
|
|
|
qemu_put_be32(f, 0);
|
|
|
|
qemu_put_be64(f, 0UL);
|
|
|
|
}
|
|
|
|
if (dev->summary_indicator != NULL) {
|
|
|
|
qemu_put_be32(f, dev->summary_indicator->len);
|
|
|
|
qemu_put_be64(f, dev->summary_indicator->addr);
|
|
|
|
} else {
|
|
|
|
qemu_put_be32(f, 0);
|
|
|
|
qemu_put_be64(f, 0UL);
|
|
|
|
}
|
2015-06-03 23:04:03 +08:00
|
|
|
qemu_put_be16(f, vdev->config_vector);
|
2014-02-11 20:29:44 +08:00
|
|
|
qemu_put_be64(f, dev->routes.adapter.ind_offset);
|
|
|
|
qemu_put_byte(f, dev->thinint_isc);
|
2015-06-25 18:20:08 +08:00
|
|
|
qemu_put_be32(f, dev->revision);
|
2014-02-11 20:29:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
SubchDev *s = dev->sch;
|
2015-06-03 23:04:03 +08:00
|
|
|
VirtIODevice *vdev = virtio_ccw_get_vdev(s);
|
2014-02-11 20:29:44 +08:00
|
|
|
int len;
|
|
|
|
|
|
|
|
s->driver_data = dev;
|
|
|
|
subch_device_load(s, f);
|
|
|
|
len = qemu_get_be32(f);
|
|
|
|
if (len != 0) {
|
|
|
|
dev->indicators = get_indicator(qemu_get_be64(f), len);
|
|
|
|
} else {
|
|
|
|
qemu_get_be64(f);
|
|
|
|
dev->indicators = NULL;
|
|
|
|
}
|
|
|
|
len = qemu_get_be32(f);
|
|
|
|
if (len != 0) {
|
|
|
|
dev->indicators2 = get_indicator(qemu_get_be64(f), len);
|
|
|
|
} else {
|
|
|
|
qemu_get_be64(f);
|
|
|
|
dev->indicators2 = NULL;
|
|
|
|
}
|
|
|
|
len = qemu_get_be32(f);
|
|
|
|
if (len != 0) {
|
|
|
|
dev->summary_indicator = get_indicator(qemu_get_be64(f), len);
|
|
|
|
} else {
|
|
|
|
qemu_get_be64(f);
|
|
|
|
dev->summary_indicator = NULL;
|
|
|
|
}
|
2015-06-03 23:04:03 +08:00
|
|
|
qemu_get_be16s(f, &vdev->config_vector);
|
2014-02-11 20:29:44 +08:00
|
|
|
dev->routes.adapter.ind_offset = qemu_get_be64(f);
|
|
|
|
dev->thinint_isc = qemu_get_byte(f);
|
|
|
|
if (s->thinint_active) {
|
|
|
|
return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
|
|
|
|
dev->thinint_isc, true, false,
|
|
|
|
&dev->routes.adapter.adapter_id);
|
|
|
|
}
|
2015-06-25 18:20:08 +08:00
|
|
|
dev->revision = qemu_get_be32(f);
|
2014-02-11 20:29:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 22:36:56 +08:00
|
|
|
/* This is called by virtio-bus just after the device is plugged. */
|
2015-05-29 14:15:25 +08:00
|
|
|
static void virtio_ccw_device_plugged(DeviceState *d, Error **errp)
|
2015-04-21 22:36:56 +08:00
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
2015-05-29 14:15:28 +08:00
|
|
|
VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
|
2015-04-21 22:36:56 +08:00
|
|
|
SubchDev *sch = dev->sch;
|
2015-05-29 14:15:28 +08:00
|
|
|
int n = virtio_get_num_queues(vdev);
|
|
|
|
|
|
|
|
if (virtio_get_num_queues(vdev) > VIRTIO_CCW_QUEUE_MAX) {
|
|
|
|
error_setg(errp, "The nubmer of virtqueues %d "
|
|
|
|
"exceeds ccw limit %d", n,
|
|
|
|
VIRTIO_CCW_QUEUE_MAX);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-21 22:36:56 +08:00
|
|
|
|
2015-06-15 23:57:02 +08:00
|
|
|
if (!kvm_eventfds_enabled()) {
|
|
|
|
dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
|
|
|
|
}
|
|
|
|
|
2015-04-21 22:36:56 +08:00
|
|
|
sch->id.cu_model = virtio_bus_get_vdev_id(&dev->bus);
|
|
|
|
|
|
|
|
css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
|
|
|
|
d->hotplugged, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_device_unplugged(DeviceState *d)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
|
|
|
|
|
|
|
|
virtio_ccw_stop_ioeventfd(dev);
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
/**************** Virtio-ccw Bus Device Descriptions *******************/
|
|
|
|
|
|
|
|
static Property virtio_ccw_net_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-01-24 14:08:55 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_net_realize;
|
2013-04-11 22:30:00 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_net_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_net = {
|
2013-04-11 22:30:00 +08:00
|
|
|
.name = TYPE_VIRTIO_NET_CCW,
|
2013-01-24 14:08:55 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-04-11 22:30:00 +08:00
|
|
|
.instance_size = sizeof(VirtIONetCcw),
|
|
|
|
.instance_init = virtio_ccw_net_instance_init,
|
2013-01-24 14:08:55 +08:00
|
|
|
.class_init = virtio_ccw_net_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property virtio_ccw_blk_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-01-24 14:08:55 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_blk_realize;
|
2013-03-19 00:37:25 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_blk_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_blk = {
|
2013-03-19 00:37:25 +08:00
|
|
|
.name = TYPE_VIRTIO_BLK_CCW,
|
2013-01-24 14:08:55 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-03-19 00:37:25 +08:00
|
|
|
.instance_size = sizeof(VirtIOBlkCcw),
|
|
|
|
.instance_init = virtio_ccw_blk_instance_init,
|
2013-01-24 14:08:55 +08:00
|
|
|
.class_init = virtio_ccw_blk_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property virtio_ccw_serial_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-01-24 14:08:55 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_serial_realize;
|
2013-04-09 20:53:33 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_serial_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_serial = {
|
2013-04-09 20:53:33 +08:00
|
|
|
.name = TYPE_VIRTIO_SERIAL_CCW,
|
2013-01-24 14:08:55 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-04-09 20:53:33 +08:00
|
|
|
.instance_size = sizeof(VirtioSerialCcw),
|
|
|
|
.instance_init = virtio_ccw_serial_instance_init,
|
2013-01-24 14:08:55 +08:00
|
|
|
.class_init = virtio_ccw_serial_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property virtio_ccw_balloon_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-01-24 14:08:55 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_balloon_realize;
|
2013-03-27 17:49:12 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_balloon_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_balloon = {
|
2013-03-27 17:49:12 +08:00
|
|
|
.name = TYPE_VIRTIO_BALLOON_CCW,
|
2013-01-24 14:08:55 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-03-27 17:49:12 +08:00
|
|
|
.instance_size = sizeof(VirtIOBalloonCcw),
|
|
|
|
.instance_init = virtio_ccw_balloon_instance_init,
|
2013-01-24 14:08:55 +08:00
|
|
|
.class_init = virtio_ccw_balloon_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property virtio_ccw_scsi_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-01-24 14:08:55 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_scsi_realize;
|
2013-03-21 22:15:17 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_scsi_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_scsi = {
|
2013-03-21 22:15:17 +08:00
|
|
|
.name = TYPE_VIRTIO_SCSI_CCW,
|
2013-01-24 14:08:55 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-03-21 22:15:17 +08:00
|
|
|
.instance_size = sizeof(VirtIOSCSICcw),
|
|
|
|
.instance_init = virtio_ccw_scsi_instance_init,
|
2013-01-24 14:08:55 +08:00
|
|
|
.class_init = virtio_ccw_scsi_class_init,
|
|
|
|
};
|
|
|
|
|
2013-04-19 22:16:50 +08:00
|
|
|
#ifdef CONFIG_VHOST_SCSI
|
|
|
|
static Property vhost_ccw_scsi_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = vhost_ccw_scsi_realize;
|
2013-04-19 22:16:50 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = vhost_ccw_scsi_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2013-04-19 22:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo vhost_ccw_scsi = {
|
|
|
|
.name = TYPE_VHOST_SCSI_CCW,
|
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2014-09-30 19:55:04 +08:00
|
|
|
.instance_size = sizeof(VHostSCSICcw),
|
2013-04-19 22:16:50 +08:00
|
|
|
.instance_init = vhost_ccw_scsi_instance_init,
|
|
|
|
.class_init = vhost_ccw_scsi_class_init,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-04-24 16:07:58 +08:00
|
|
|
static void virtio_ccw_rng_instance_init(Object *obj)
|
2013-03-04 20:06:56 +08:00
|
|
|
{
|
2013-04-24 16:07:58 +08:00
|
|
|
VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
|
2014-09-30 14:10:38 +08:00
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_RNG);
|
2014-10-29 18:17:19 +08:00
|
|
|
object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
|
|
|
|
"rng", &error_abort);
|
2013-03-04 20:06:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Property virtio_ccw_rng_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
2013-02-15 17:18:43 +08:00
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
2013-03-04 20:06:56 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
k->realize = virtio_ccw_rng_realize;
|
2013-04-24 16:07:58 +08:00
|
|
|
k->exit = virtio_ccw_exit;
|
2013-03-04 20:06:56 +08:00
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_rng_properties;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2013-03-04 20:06:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_rng = {
|
2013-04-24 16:07:58 +08:00
|
|
|
.name = TYPE_VIRTIO_RNG_CCW,
|
2013-03-04 20:06:56 +08:00
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
2013-04-24 16:07:58 +08:00
|
|
|
.instance_size = sizeof(VirtIORNGCcw),
|
|
|
|
.instance_init = virtio_ccw_rng_instance_init,
|
2013-03-04 20:06:56 +08:00
|
|
|
.class_init = virtio_ccw_rng_class_init,
|
|
|
|
};
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
|
|
|
|
|
2013-08-24 02:27:30 +08:00
|
|
|
virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
|
2015-04-21 22:36:55 +08:00
|
|
|
virtio_ccw_device_realize(_dev, errp);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int virtio_ccw_busdev_exit(DeviceState *dev)
|
|
|
|
{
|
|
|
|
VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
|
|
|
|
VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
|
|
|
|
|
|
|
|
return _info->exit(_dev);
|
|
|
|
}
|
|
|
|
|
2014-09-26 17:28:30 +08:00
|
|
|
static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
|
|
|
|
SubchDev *sch = _dev->sch;
|
|
|
|
|
2013-10-15 22:47:16 +08:00
|
|
|
virtio_ccw_stop_ioeventfd(_dev);
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
/*
|
|
|
|
* We should arrive here only for device_del, since we don't support
|
|
|
|
* direct hot(un)plug of channels, but only through virtio.
|
|
|
|
*/
|
|
|
|
assert(sch != NULL);
|
|
|
|
/* Subchannel is now disabled and no longer valid. */
|
|
|
|
sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
|
|
|
|
PMCW_FLAGS_MASK_DNV);
|
|
|
|
|
|
|
|
css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
|
|
|
|
|
2013-09-11 20:54:09 +08:00
|
|
|
object_unparent(OBJECT(dev));
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
2015-02-27 21:53:39 +08:00
|
|
|
dc->realize = virtio_ccw_busdev_realize;
|
2013-01-24 14:08:55 +08:00
|
|
|
dc->exit = virtio_ccw_busdev_exit;
|
|
|
|
dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_device_info = {
|
|
|
|
.name = TYPE_VIRTIO_CCW_DEVICE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(VirtioCcwDevice),
|
|
|
|
.class_init = virtio_ccw_device_class_init,
|
|
|
|
.class_size = sizeof(VirtIOCCWDeviceClass),
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************** Virtual-css Bus Bridge Device ********************/
|
|
|
|
/* Only required to have the virtio bus as child in the system bus */
|
|
|
|
|
|
|
|
static int virtual_css_bridge_init(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
/* nothing */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
2014-09-26 17:28:30 +08:00
|
|
|
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
|
2015-03-17 20:42:03 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2013-01-24 14:08:55 +08:00
|
|
|
|
|
|
|
k->init = virtual_css_bridge_init;
|
2014-09-26 17:28:30 +08:00
|
|
|
hc->unplug = virtio_ccw_busdev_unplug;
|
2015-03-17 20:42:03 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtual_css_bridge_info = {
|
|
|
|
.name = "virtual-css-bridge",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(SysBusDevice),
|
|
|
|
.class_init = virtual_css_bridge_class_init,
|
2014-09-26 17:28:30 +08:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_HOTPLUG_HANDLER },
|
|
|
|
{ }
|
|
|
|
}
|
2013-01-24 14:08:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* virtio-ccw-bus */
|
|
|
|
|
2013-08-24 02:27:30 +08:00
|
|
|
static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
|
|
|
|
VirtioCcwDevice *dev)
|
2013-01-24 14:08:55 +08:00
|
|
|
{
|
|
|
|
DeviceState *qdev = DEVICE(dev);
|
2013-04-30 22:08:47 +08:00
|
|
|
char virtio_bus_name[] = "virtio-bus";
|
2013-01-24 14:08:55 +08:00
|
|
|
|
2013-08-24 06:02:27 +08:00
|
|
|
qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
|
|
|
|
qdev, virtio_bus_name);
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
|
|
|
|
BusClass *bus_class = BUS_CLASS(klass);
|
|
|
|
|
|
|
|
bus_class->max_dev = 1;
|
|
|
|
k->notify = virtio_ccw_notify;
|
2013-02-15 17:18:43 +08:00
|
|
|
k->vmstate_change = virtio_ccw_vmstate_change;
|
2013-02-19 20:48:17 +08:00
|
|
|
k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
|
|
|
|
k->set_host_notifier = virtio_ccw_set_host_notifier;
|
|
|
|
k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
|
2014-02-11 20:29:44 +08:00
|
|
|
k->save_queue = virtio_ccw_save_queue;
|
|
|
|
k->load_queue = virtio_ccw_load_queue;
|
|
|
|
k->save_config = virtio_ccw_save_config;
|
|
|
|
k->load_config = virtio_ccw_load_config;
|
2015-04-21 22:36:56 +08:00
|
|
|
k->device_plugged = virtio_ccw_device_plugged;
|
|
|
|
k->device_unplugged = virtio_ccw_device_unplugged;
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_bus_info = {
|
|
|
|
.name = TYPE_VIRTIO_CCW_BUS,
|
|
|
|
.parent = TYPE_VIRTIO_BUS,
|
|
|
|
.instance_size = sizeof(VirtioCcwBusState),
|
|
|
|
.class_init = virtio_ccw_bus_class_init,
|
|
|
|
};
|
|
|
|
|
2015-05-27 19:11:59 +08:00
|
|
|
#ifdef CONFIG_VIRTFS
|
|
|
|
static Property virtio_ccw_9p_properties[] = {
|
|
|
|
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
|
|
|
|
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
|
|
|
|
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp)
|
|
|
|
{
|
|
|
|
V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev);
|
|
|
|
DeviceState *vdev = DEVICE(&dev->vdev);
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
|
|
|
|
object_property_set_bool(OBJECT(vdev), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->exit = virtio_ccw_exit;
|
|
|
|
k->realize = virtio_ccw_9p_realize;
|
|
|
|
dc->reset = virtio_ccw_reset;
|
|
|
|
dc->props = virtio_ccw_9p_properties;
|
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_ccw_9p_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
V9fsCCWState *dev = VIRTIO_9P_CCW(obj);
|
|
|
|
|
|
|
|
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
|
|
|
|
TYPE_VIRTIO_9P);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtio_ccw_9p_info = {
|
|
|
|
.name = TYPE_VIRTIO_9P_CCW,
|
|
|
|
.parent = TYPE_VIRTIO_CCW_DEVICE,
|
|
|
|
.instance_size = sizeof(V9fsCCWState),
|
|
|
|
.instance_init = virtio_ccw_9p_instance_init,
|
|
|
|
.class_init = virtio_ccw_9p_class_init,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-01-24 14:08:55 +08:00
|
|
|
static void virtio_ccw_register(void)
|
|
|
|
{
|
|
|
|
type_register_static(&virtio_ccw_bus_info);
|
|
|
|
type_register_static(&virtual_css_bus_info);
|
|
|
|
type_register_static(&virtio_ccw_device_info);
|
|
|
|
type_register_static(&virtio_ccw_serial);
|
|
|
|
type_register_static(&virtio_ccw_blk);
|
|
|
|
type_register_static(&virtio_ccw_net);
|
|
|
|
type_register_static(&virtio_ccw_balloon);
|
|
|
|
type_register_static(&virtio_ccw_scsi);
|
2013-04-26 01:38:28 +08:00
|
|
|
#ifdef CONFIG_VHOST_SCSI
|
2013-04-19 22:16:50 +08:00
|
|
|
type_register_static(&vhost_ccw_scsi);
|
2013-04-26 01:38:28 +08:00
|
|
|
#endif
|
2013-03-04 20:06:56 +08:00
|
|
|
type_register_static(&virtio_ccw_rng);
|
2013-01-24 14:08:55 +08:00
|
|
|
type_register_static(&virtual_css_bridge_info);
|
2015-05-27 19:11:59 +08:00
|
|
|
#ifdef CONFIG_VIRTFS
|
|
|
|
type_register_static(&virtio_ccw_9p_info);
|
|
|
|
#endif
|
2013-01-24 14:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(virtio_ccw_register)
|