2008-03-25 17:47:46 +00:00
|
|
|
/*
|
|
|
|
* kvm_virtio.c - virtio for kvm on s390
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License (version 2 only)
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/virtio.h>
|
|
|
|
#include <linux/virtio_config.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-06-20 13:24:18 +00:00
|
|
|
#include <linux/virtio_console.h>
|
2008-03-25 17:47:46 +00:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/virtio_ring.h>
|
2008-04-30 11:38:47 +00:00
|
|
|
#include <linux/pfn.h>
|
2008-03-25 17:47:46 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/kvm_para.h>
|
|
|
|
#include <asm/kvm_virtio.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/s390_ext.h>
|
|
|
|
|
|
|
|
#define VIRTIO_SUBCODE_64 0x0D00
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The pointer to our (page) of device descriptions.
|
|
|
|
*/
|
|
|
|
static void *kvm_devices;
|
2010-08-24 13:48:51 +00:00
|
|
|
struct work_struct hotplug_work;
|
2008-03-25 17:47:46 +00:00
|
|
|
|
|
|
|
struct kvm_device {
|
|
|
|
struct virtio_device vdev;
|
|
|
|
struct kvm_device_desc *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_kvmdev(vd) container_of(vd, struct kvm_device, vdev)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* memory layout:
|
|
|
|
* - kvm_device_descriptor
|
|
|
|
* struct kvm_device_desc
|
|
|
|
* - configuration
|
|
|
|
* struct kvm_vqconfig
|
|
|
|
* - feature bits
|
|
|
|
* - config space
|
|
|
|
*/
|
|
|
|
static struct kvm_vqconfig *kvm_vq_config(const struct kvm_device_desc *desc)
|
|
|
|
{
|
|
|
|
return (struct kvm_vqconfig *)(desc + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *kvm_vq_features(const struct kvm_device_desc *desc)
|
|
|
|
{
|
|
|
|
return (u8 *)(kvm_vq_config(desc) + desc->num_vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *kvm_vq_configspace(const struct kvm_device_desc *desc)
|
|
|
|
{
|
|
|
|
return kvm_vq_features(desc) + desc->feature_len * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The total size of the config page used by this device (incl. desc)
|
|
|
|
*/
|
|
|
|
static unsigned desc_size(const struct kvm_device_desc *desc)
|
|
|
|
{
|
|
|
|
return sizeof(*desc)
|
|
|
|
+ desc->num_vq * sizeof(struct kvm_vqconfig)
|
|
|
|
+ desc->feature_len * 2
|
|
|
|
+ desc->config_len;
|
|
|
|
}
|
|
|
|
|
2008-05-06 14:38:30 +00:00
|
|
|
/* This gets the device's feature bits. */
|
|
|
|
static u32 kvm_get_features(struct virtio_device *vdev)
|
2008-03-25 17:47:46 +00:00
|
|
|
{
|
2008-05-06 14:38:30 +00:00
|
|
|
unsigned int i;
|
|
|
|
u32 features = 0;
|
2008-03-25 17:47:46 +00:00
|
|
|
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
|
2008-05-06 14:38:30 +00:00
|
|
|
u8 *in_features = kvm_vq_features(desc);
|
2008-03-25 17:47:46 +00:00
|
|
|
|
2008-05-06 14:38:30 +00:00
|
|
|
for (i = 0; i < min(desc->feature_len * 8, 32); i++)
|
|
|
|
if (in_features[i / 8] & (1 << (i % 8)))
|
|
|
|
features |= (1 << i);
|
|
|
|
return features;
|
|
|
|
}
|
2008-03-25 17:47:46 +00:00
|
|
|
|
2008-07-25 17:06:07 +00:00
|
|
|
static void kvm_finalize_features(struct virtio_device *vdev)
|
2008-05-06 14:38:30 +00:00
|
|
|
{
|
2008-07-25 17:06:07 +00:00
|
|
|
unsigned int i, bits;
|
2008-05-06 14:38:30 +00:00
|
|
|
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
|
|
|
|
/* Second half of bitmap is features we accept. */
|
|
|
|
u8 *out_features = kvm_vq_features(desc) + desc->feature_len;
|
2008-03-25 17:47:46 +00:00
|
|
|
|
2008-07-25 17:06:13 +00:00
|
|
|
/* Give virtio_ring a chance to accept features. */
|
|
|
|
vring_transport_features(vdev);
|
|
|
|
|
2008-05-06 14:38:30 +00:00
|
|
|
memset(out_features, 0, desc->feature_len);
|
2008-07-25 17:06:07 +00:00
|
|
|
bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
|
|
|
|
for (i = 0; i < bits; i++) {
|
|
|
|
if (test_bit(i, vdev->features))
|
2008-05-06 14:38:30 +00:00
|
|
|
out_features[i / 8] |= (1 << (i % 8));
|
|
|
|
}
|
2008-03-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reading and writing elements in config space
|
|
|
|
*/
|
|
|
|
static void kvm_get(struct virtio_device *vdev, unsigned int offset,
|
|
|
|
void *buf, unsigned len)
|
|
|
|
{
|
|
|
|
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
|
|
|
|
|
|
|
|
BUG_ON(offset + len > desc->config_len);
|
|
|
|
memcpy(buf, kvm_vq_configspace(desc) + offset, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kvm_set(struct virtio_device *vdev, unsigned int offset,
|
|
|
|
const void *buf, unsigned len)
|
|
|
|
{
|
|
|
|
struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
|
|
|
|
|
|
|
|
BUG_ON(offset + len > desc->config_len);
|
|
|
|
memcpy(kvm_vq_configspace(desc) + offset, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The operations to get and set the status word just access
|
|
|
|
* the status field of the device descriptor. set_status will also
|
|
|
|
* make a hypercall to the host, to tell about status changes
|
|
|
|
*/
|
|
|
|
static u8 kvm_get_status(struct virtio_device *vdev)
|
|
|
|
{
|
|
|
|
return to_kvmdev(vdev)->desc->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kvm_set_status(struct virtio_device *vdev, u8 status)
|
|
|
|
{
|
|
|
|
BUG_ON(!status);
|
|
|
|
to_kvmdev(vdev)->desc->status = status;
|
|
|
|
kvm_hypercall1(KVM_S390_VIRTIO_SET_STATUS,
|
|
|
|
(unsigned long) to_kvmdev(vdev)->desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To reset the device, we use the KVM_VIRTIO_RESET hypercall, using the
|
|
|
|
* descriptor address. The Host will zero the status and all the
|
|
|
|
* features.
|
|
|
|
*/
|
|
|
|
static void kvm_reset(struct virtio_device *vdev)
|
|
|
|
{
|
|
|
|
kvm_hypercall1(KVM_S390_VIRTIO_RESET,
|
|
|
|
(unsigned long) to_kvmdev(vdev)->desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the virtio_ring code wants to notify the Host, it calls us here and we
|
|
|
|
* make a hypercall. We hand the address of the virtqueue so the Host
|
|
|
|
* knows which virtqueue we're talking about.
|
|
|
|
*/
|
|
|
|
static void kvm_notify(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
struct kvm_vqconfig *config = vq->priv;
|
|
|
|
|
|
|
|
kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, config->address);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine finds the first virtqueue described in the configuration of
|
|
|
|
* this device and sets it up.
|
|
|
|
*/
|
|
|
|
static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
|
2009-06-13 04:16:35 +00:00
|
|
|
unsigned index,
|
|
|
|
void (*callback)(struct virtqueue *vq),
|
|
|
|
const char *name)
|
2008-03-25 17:47:46 +00:00
|
|
|
{
|
|
|
|
struct kvm_device *kdev = to_kvmdev(vdev);
|
|
|
|
struct kvm_vqconfig *config;
|
|
|
|
struct virtqueue *vq;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (index >= kdev->desc->num_vq)
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
|
|
|
|
config = kvm_vq_config(kdev->desc)+index;
|
|
|
|
|
2008-04-30 11:38:47 +00:00
|
|
|
err = vmem_add_mapping(config->address,
|
2008-12-30 15:26:02 +00:00
|
|
|
vring_size(config->num,
|
|
|
|
KVM_S390_VIRTIO_RING_ALIGN));
|
2008-04-30 11:38:47 +00:00
|
|
|
if (err)
|
2008-03-25 17:47:46 +00:00
|
|
|
goto out;
|
|
|
|
|
2008-12-30 15:26:03 +00:00
|
|
|
vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN,
|
|
|
|
vdev, (void *) config->address,
|
2009-06-13 04:16:35 +00:00
|
|
|
kvm_notify, callback, name);
|
2008-03-25 17:47:46 +00:00
|
|
|
if (!vq) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register a callback token
|
|
|
|
* The host will sent this via the external interrupt parameter
|
|
|
|
*/
|
|
|
|
config->token = (u64) vq;
|
|
|
|
|
|
|
|
vq->priv = config;
|
|
|
|
return vq;
|
|
|
|
unmap:
|
2008-04-30 11:38:47 +00:00
|
|
|
vmem_remove_mapping(config->address,
|
2008-12-30 15:26:02 +00:00
|
|
|
vring_size(config->num,
|
|
|
|
KVM_S390_VIRTIO_RING_ALIGN));
|
2008-03-25 17:47:46 +00:00
|
|
|
out:
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kvm_del_vq(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
struct kvm_vqconfig *config = vq->priv;
|
|
|
|
|
|
|
|
vring_del_virtqueue(vq);
|
2008-04-30 11:38:47 +00:00
|
|
|
vmem_remove_mapping(config->address,
|
2008-12-30 15:26:02 +00:00
|
|
|
vring_size(config->num,
|
|
|
|
KVM_S390_VIRTIO_RING_ALIGN));
|
2008-03-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
2009-06-13 04:16:36 +00:00
|
|
|
static void kvm_del_vqs(struct virtio_device *vdev)
|
|
|
|
{
|
|
|
|
struct virtqueue *vq, *n;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(vq, n, &vdev->vqs, list)
|
|
|
|
kvm_del_vq(vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
|
|
|
|
struct virtqueue *vqs[],
|
|
|
|
vq_callback_t *callbacks[],
|
|
|
|
const char *names[])
|
|
|
|
{
|
|
|
|
struct kvm_device *kdev = to_kvmdev(vdev);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* We must have this many virtqueues. */
|
|
|
|
if (nvqs > kdev->desc->num_vq)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
for (i = 0; i < nvqs; ++i) {
|
|
|
|
vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i]);
|
|
|
|
if (IS_ERR(vqs[i]))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kvm_del_vqs(vdev);
|
|
|
|
return PTR_ERR(vqs[i]);
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:47:46 +00:00
|
|
|
/*
|
|
|
|
* The config ops structure as defined by virtio config
|
|
|
|
*/
|
|
|
|
static struct virtio_config_ops kvm_vq_configspace_ops = {
|
2008-05-06 14:38:30 +00:00
|
|
|
.get_features = kvm_get_features,
|
2008-07-25 17:06:07 +00:00
|
|
|
.finalize_features = kvm_finalize_features,
|
2008-03-25 17:47:46 +00:00
|
|
|
.get = kvm_get,
|
|
|
|
.set = kvm_set,
|
|
|
|
.get_status = kvm_get_status,
|
|
|
|
.set_status = kvm_set_status,
|
|
|
|
.reset = kvm_reset,
|
2009-06-13 04:16:36 +00:00
|
|
|
.find_vqs = kvm_find_vqs,
|
|
|
|
.del_vqs = kvm_del_vqs,
|
2008-03-25 17:47:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The root device for the kvm virtio devices.
|
|
|
|
* This makes them appear as /sys/devices/kvm_s390/0,1,2 not /sys/devices/0,1,2.
|
|
|
|
*/
|
2008-10-10 19:33:12 +00:00
|
|
|
static struct device *kvm_root;
|
2008-03-25 17:47:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* adds a new device and register it with virtio
|
|
|
|
* appropriate drivers are loaded by the device model
|
|
|
|
*/
|
2008-05-30 20:09:42 +00:00
|
|
|
static void add_kvm_device(struct kvm_device_desc *d, unsigned int offset)
|
2008-03-25 17:47:46 +00:00
|
|
|
{
|
|
|
|
struct kvm_device *kdev;
|
|
|
|
|
|
|
|
kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
|
|
|
|
if (!kdev) {
|
2008-05-30 20:09:42 +00:00
|
|
|
printk(KERN_EMERG "Cannot allocate kvm dev %u type %u\n",
|
|
|
|
offset, d->type);
|
2008-03-25 17:47:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:33:12 +00:00
|
|
|
kdev->vdev.dev.parent = kvm_root;
|
2008-03-25 17:47:46 +00:00
|
|
|
kdev->vdev.id.device = d->type;
|
|
|
|
kdev->vdev.config = &kvm_vq_configspace_ops;
|
|
|
|
kdev->desc = d;
|
|
|
|
|
|
|
|
if (register_virtio_device(&kdev->vdev) != 0) {
|
2008-05-30 20:09:42 +00:00
|
|
|
printk(KERN_ERR "Failed to register kvm device %u type %u\n",
|
|
|
|
offset, d->type);
|
2008-03-25 17:47:46 +00:00
|
|
|
kfree(kdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scan_devices() simply iterates through the device page.
|
|
|
|
* The type 0 is reserved to mean "end of devices".
|
|
|
|
*/
|
|
|
|
static void scan_devices(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct kvm_device_desc *d;
|
|
|
|
|
|
|
|
for (i = 0; i < PAGE_SIZE; i += desc_size(d)) {
|
|
|
|
d = kvm_devices + i;
|
|
|
|
|
|
|
|
if (d->type == 0)
|
|
|
|
break;
|
|
|
|
|
2008-05-30 20:09:42 +00:00
|
|
|
add_kvm_device(d, i);
|
2008-03-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 13:48:51 +00:00
|
|
|
/*
|
|
|
|
* match for a kvm device with a specific desc pointer
|
|
|
|
*/
|
|
|
|
static int match_desc(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
if ((ulong)to_kvmdev(dev_to_virtio(dev))->desc == (ulong)data)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hotplug_device tries to find changes in the device page.
|
|
|
|
*/
|
|
|
|
static void hotplug_devices(struct work_struct *dummy)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct kvm_device_desc *d;
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
for (i = 0; i < PAGE_SIZE; i += desc_size(d)) {
|
|
|
|
d = kvm_devices + i;
|
|
|
|
|
|
|
|
/* end of list */
|
|
|
|
if (d->type == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* device already exists */
|
|
|
|
dev = device_find_child(kvm_root, d, match_desc);
|
|
|
|
if (dev) {
|
|
|
|
/* XXX check for hotplug remove */
|
|
|
|
put_device(dev);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new device */
|
|
|
|
printk(KERN_INFO "Adding new virtio device %p\n", d);
|
|
|
|
add_kvm_device(d, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:47:46 +00:00
|
|
|
/*
|
|
|
|
* we emulate the request_irq behaviour on top of s390 extints
|
|
|
|
*/
|
|
|
|
static void kvm_extint_handler(u16 code)
|
|
|
|
{
|
2008-11-18 21:44:13 +00:00
|
|
|
struct virtqueue *vq;
|
|
|
|
u16 subcode;
|
2010-08-24 13:48:50 +00:00
|
|
|
u32 param;
|
2008-03-25 17:47:46 +00:00
|
|
|
|
2008-11-18 21:44:13 +00:00
|
|
|
subcode = S390_lowcore.cpu_addr;
|
2008-03-25 17:47:46 +00:00
|
|
|
if ((subcode & 0xff00) != VIRTIO_SUBCODE_64)
|
|
|
|
return;
|
|
|
|
|
2008-11-18 21:44:13 +00:00
|
|
|
/* The LSB might be overloaded, we have to mask it */
|
2010-02-26 21:37:43 +00:00
|
|
|
vq = (struct virtqueue *)(S390_lowcore.ext_params2 & ~1UL);
|
2008-11-18 21:44:13 +00:00
|
|
|
|
2010-08-24 13:48:50 +00:00
|
|
|
/* We use ext_params to decide what this interrupt means */
|
|
|
|
param = S390_lowcore.ext_params & VIRTIO_PARAM_MASK;
|
2008-11-18 21:44:13 +00:00
|
|
|
|
2010-08-24 13:48:50 +00:00
|
|
|
switch (param) {
|
|
|
|
case VIRTIO_PARAM_CONFIG_CHANGED:
|
|
|
|
{
|
2008-11-18 21:44:13 +00:00
|
|
|
struct virtio_driver *drv;
|
|
|
|
drv = container_of(vq->vdev->dev.driver,
|
|
|
|
struct virtio_driver, driver);
|
|
|
|
if (drv->config_changed)
|
|
|
|
drv->config_changed(vq->vdev);
|
2010-08-24 13:48:50 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2010-08-24 13:48:51 +00:00
|
|
|
case VIRTIO_PARAM_DEV_ADD:
|
|
|
|
schedule_work(&hotplug_work);
|
|
|
|
break;
|
2010-08-24 13:48:50 +00:00
|
|
|
case VIRTIO_PARAM_VRING_INTERRUPT:
|
|
|
|
default:
|
2008-11-18 21:44:13 +00:00
|
|
|
vring_interrupt(0, vq);
|
2010-08-24 13:48:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init function for virtio
|
|
|
|
* devices are in a single page above top of "normal" mem
|
|
|
|
*/
|
|
|
|
static int __init kvm_devices_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!MACHINE_IS_KVM)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2008-12-15 12:58:29 +00:00
|
|
|
kvm_root = root_device_register("kvm_s390");
|
2008-10-10 19:33:12 +00:00
|
|
|
if (IS_ERR(kvm_root)) {
|
|
|
|
rc = PTR_ERR(kvm_root);
|
2008-03-25 17:47:46 +00:00
|
|
|
printk(KERN_ERR "Could not register kvm_s390 root device");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-11-14 17:18:02 +00:00
|
|
|
rc = vmem_add_mapping(real_memory_size, PAGE_SIZE);
|
2008-04-30 11:38:47 +00:00
|
|
|
if (rc) {
|
2008-12-15 12:58:29 +00:00
|
|
|
root_device_unregister(kvm_root);
|
2008-04-30 11:38:47 +00:00
|
|
|
return rc;
|
2008-03-25 17:47:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 17:18:02 +00:00
|
|
|
kvm_devices = (void *) real_memory_size;
|
2008-03-25 17:47:46 +00:00
|
|
|
|
2010-08-24 13:48:51 +00:00
|
|
|
INIT_WORK(&hotplug_work, hotplug_devices);
|
|
|
|
|
2008-03-25 17:47:46 +00:00
|
|
|
ctl_set_bit(0, 9);
|
|
|
|
register_external_interrupt(0x2603, kvm_extint_handler);
|
|
|
|
|
|
|
|
scan_devices();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-20 13:24:18 +00:00
|
|
|
/* code for early console output with virtio_console */
|
|
|
|
static __init int early_put_chars(u32 vtermno, const char *buf, int count)
|
|
|
|
{
|
|
|
|
char scratch[17];
|
|
|
|
unsigned int len = count;
|
|
|
|
|
|
|
|
if (len > sizeof(scratch) - 1)
|
|
|
|
len = sizeof(scratch) - 1;
|
|
|
|
scratch[len] = '\0';
|
|
|
|
memcpy(scratch, buf, len);
|
|
|
|
kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-09-11 08:28:56 +00:00
|
|
|
static int __init s390_virtio_console_init(void)
|
2008-06-20 13:24:18 +00:00
|
|
|
{
|
2009-09-11 08:28:56 +00:00
|
|
|
if (!MACHINE_IS_KVM)
|
|
|
|
return -ENODEV;
|
|
|
|
return virtio_cons_early_init(early_put_chars);
|
2008-06-20 13:24:18 +00:00
|
|
|
}
|
2009-09-11 08:28:56 +00:00
|
|
|
console_initcall(s390_virtio_console_init);
|
|
|
|
|
2008-06-20 13:24:18 +00:00
|
|
|
|
2008-03-25 17:47:46 +00:00
|
|
|
/*
|
|
|
|
* We do this after core stuff, but before the drivers.
|
|
|
|
*/
|
|
|
|
postcore_initcall(kvm_devices_init);
|