Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * kvm_virtio.c - virtio for kvm on s390 |
| 3 | * |
| 4 | * Copyright IBM Corp. 2008 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License (version 2 only) |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * Author(s): Christian Borntraeger <borntraeger@de.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/bootmem.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/virtio.h> |
| 17 | #include <linux/virtio_config.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Christian Borntraeger | faeba830 | 2008-06-20 15:24:18 +0200 | [diff] [blame] | 19 | #include <linux/virtio_console.h> |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/virtio_ring.h> |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 22 | #include <linux/pfn.h> |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/kvm_para.h> |
| 25 | #include <asm/kvm_virtio.h> |
| 26 | #include <asm/setup.h> |
| 27 | #include <asm/s390_ext.h> |
| 28 | |
| 29 | #define VIRTIO_SUBCODE_64 0x0D00 |
| 30 | |
| 31 | /* |
| 32 | * The pointer to our (page) of device descriptions. |
| 33 | */ |
| 34 | static void *kvm_devices; |
Alexander Graf | cefa33e | 2010-08-24 15:48:51 +0200 | [diff] [blame] | 35 | struct work_struct hotplug_work; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 36 | |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 37 | struct kvm_device { |
| 38 | struct virtio_device vdev; |
| 39 | struct kvm_device_desc *desc; |
| 40 | }; |
| 41 | |
| 42 | #define to_kvmdev(vd) container_of(vd, struct kvm_device, vdev) |
| 43 | |
| 44 | /* |
| 45 | * memory layout: |
| 46 | * - kvm_device_descriptor |
| 47 | * struct kvm_device_desc |
| 48 | * - configuration |
| 49 | * struct kvm_vqconfig |
| 50 | * - feature bits |
| 51 | * - config space |
| 52 | */ |
| 53 | static struct kvm_vqconfig *kvm_vq_config(const struct kvm_device_desc *desc) |
| 54 | { |
| 55 | return (struct kvm_vqconfig *)(desc + 1); |
| 56 | } |
| 57 | |
| 58 | static u8 *kvm_vq_features(const struct kvm_device_desc *desc) |
| 59 | { |
| 60 | return (u8 *)(kvm_vq_config(desc) + desc->num_vq); |
| 61 | } |
| 62 | |
| 63 | static u8 *kvm_vq_configspace(const struct kvm_device_desc *desc) |
| 64 | { |
| 65 | return kvm_vq_features(desc) + desc->feature_len * 2; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * The total size of the config page used by this device (incl. desc) |
| 70 | */ |
| 71 | static unsigned desc_size(const struct kvm_device_desc *desc) |
| 72 | { |
| 73 | return sizeof(*desc) |
| 74 | + desc->num_vq * sizeof(struct kvm_vqconfig) |
| 75 | + desc->feature_len * 2 |
| 76 | + desc->config_len; |
| 77 | } |
| 78 | |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 79 | /* This gets the device's feature bits. */ |
| 80 | static u32 kvm_get_features(struct virtio_device *vdev) |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 81 | { |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 82 | unsigned int i; |
| 83 | u32 features = 0; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 84 | struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 85 | u8 *in_features = kvm_vq_features(desc); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 86 | |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 87 | for (i = 0; i < min(desc->feature_len * 8, 32); i++) |
| 88 | if (in_features[i / 8] & (1 << (i % 8))) |
| 89 | features |= (1 << i); |
| 90 | return features; |
| 91 | } |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 92 | |
Rusty Russell | c624896 | 2008-07-25 12:06:07 -0500 | [diff] [blame] | 93 | static void kvm_finalize_features(struct virtio_device *vdev) |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 94 | { |
Rusty Russell | c624896 | 2008-07-25 12:06:07 -0500 | [diff] [blame] | 95 | unsigned int i, bits; |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 96 | struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; |
| 97 | /* Second half of bitmap is features we accept. */ |
| 98 | u8 *out_features = kvm_vq_features(desc) + desc->feature_len; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 99 | |
Rusty Russell | e34f872 | 2008-07-25 12:06:13 -0500 | [diff] [blame] | 100 | /* Give virtio_ring a chance to accept features. */ |
| 101 | vring_transport_features(vdev); |
| 102 | |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 103 | memset(out_features, 0, desc->feature_len); |
Rusty Russell | c624896 | 2008-07-25 12:06:07 -0500 | [diff] [blame] | 104 | bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8; |
| 105 | for (i = 0; i < bits; i++) { |
| 106 | if (test_bit(i, vdev->features)) |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 107 | out_features[i / 8] |= (1 << (i % 8)); |
| 108 | } |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Reading and writing elements in config space |
| 113 | */ |
| 114 | static void kvm_get(struct virtio_device *vdev, unsigned int offset, |
| 115 | void *buf, unsigned len) |
| 116 | { |
| 117 | struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; |
| 118 | |
| 119 | BUG_ON(offset + len > desc->config_len); |
| 120 | memcpy(buf, kvm_vq_configspace(desc) + offset, len); |
| 121 | } |
| 122 | |
| 123 | static void kvm_set(struct virtio_device *vdev, unsigned int offset, |
| 124 | const void *buf, unsigned len) |
| 125 | { |
| 126 | struct kvm_device_desc *desc = to_kvmdev(vdev)->desc; |
| 127 | |
| 128 | BUG_ON(offset + len > desc->config_len); |
| 129 | memcpy(kvm_vq_configspace(desc) + offset, buf, len); |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * The operations to get and set the status word just access |
| 134 | * the status field of the device descriptor. set_status will also |
| 135 | * make a hypercall to the host, to tell about status changes |
| 136 | */ |
| 137 | static u8 kvm_get_status(struct virtio_device *vdev) |
| 138 | { |
| 139 | return to_kvmdev(vdev)->desc->status; |
| 140 | } |
| 141 | |
| 142 | static void kvm_set_status(struct virtio_device *vdev, u8 status) |
| 143 | { |
| 144 | BUG_ON(!status); |
| 145 | to_kvmdev(vdev)->desc->status = status; |
| 146 | kvm_hypercall1(KVM_S390_VIRTIO_SET_STATUS, |
| 147 | (unsigned long) to_kvmdev(vdev)->desc); |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * To reset the device, we use the KVM_VIRTIO_RESET hypercall, using the |
| 152 | * descriptor address. The Host will zero the status and all the |
| 153 | * features. |
| 154 | */ |
| 155 | static void kvm_reset(struct virtio_device *vdev) |
| 156 | { |
| 157 | kvm_hypercall1(KVM_S390_VIRTIO_RESET, |
| 158 | (unsigned long) to_kvmdev(vdev)->desc); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * When the virtio_ring code wants to notify the Host, it calls us here and we |
| 163 | * make a hypercall. We hand the address of the virtqueue so the Host |
| 164 | * knows which virtqueue we're talking about. |
| 165 | */ |
| 166 | static void kvm_notify(struct virtqueue *vq) |
| 167 | { |
| 168 | struct kvm_vqconfig *config = vq->priv; |
| 169 | |
| 170 | kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, config->address); |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * This routine finds the first virtqueue described in the configuration of |
| 175 | * this device and sets it up. |
| 176 | */ |
| 177 | static struct virtqueue *kvm_find_vq(struct virtio_device *vdev, |
Rusty Russell | 9499f5e | 2009-06-12 22:16:35 -0600 | [diff] [blame] | 178 | unsigned index, |
| 179 | void (*callback)(struct virtqueue *vq), |
| 180 | const char *name) |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 181 | { |
| 182 | struct kvm_device *kdev = to_kvmdev(vdev); |
| 183 | struct kvm_vqconfig *config; |
| 184 | struct virtqueue *vq; |
| 185 | int err; |
| 186 | |
| 187 | if (index >= kdev->desc->num_vq) |
| 188 | return ERR_PTR(-ENOENT); |
| 189 | |
| 190 | config = kvm_vq_config(kdev->desc)+index; |
| 191 | |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 192 | err = vmem_add_mapping(config->address, |
Rusty Russell | db40598 | 2008-12-30 09:26:02 -0600 | [diff] [blame] | 193 | vring_size(config->num, |
| 194 | KVM_S390_VIRTIO_RING_ALIGN)); |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 195 | if (err) |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 196 | goto out; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 197 | |
Rusty Russell | 87c7d57 | 2008-12-30 09:26:03 -0600 | [diff] [blame] | 198 | vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN, |
| 199 | vdev, (void *) config->address, |
Rusty Russell | 9499f5e | 2009-06-12 22:16:35 -0600 | [diff] [blame] | 200 | kvm_notify, callback, name); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 201 | if (!vq) { |
| 202 | err = -ENOMEM; |
| 203 | goto unmap; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * register a callback token |
| 208 | * The host will sent this via the external interrupt parameter |
| 209 | */ |
| 210 | config->token = (u64) vq; |
| 211 | |
| 212 | vq->priv = config; |
| 213 | return vq; |
| 214 | unmap: |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 215 | vmem_remove_mapping(config->address, |
Rusty Russell | db40598 | 2008-12-30 09:26:02 -0600 | [diff] [blame] | 216 | vring_size(config->num, |
| 217 | KVM_S390_VIRTIO_RING_ALIGN)); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 218 | out: |
| 219 | return ERR_PTR(err); |
| 220 | } |
| 221 | |
| 222 | static void kvm_del_vq(struct virtqueue *vq) |
| 223 | { |
| 224 | struct kvm_vqconfig *config = vq->priv; |
| 225 | |
| 226 | vring_del_virtqueue(vq); |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 227 | vmem_remove_mapping(config->address, |
Rusty Russell | db40598 | 2008-12-30 09:26:02 -0600 | [diff] [blame] | 228 | vring_size(config->num, |
| 229 | KVM_S390_VIRTIO_RING_ALIGN)); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 230 | } |
| 231 | |
Michael S. Tsirkin | d2a7ddd | 2009-06-12 22:16:36 -0600 | [diff] [blame] | 232 | static void kvm_del_vqs(struct virtio_device *vdev) |
| 233 | { |
| 234 | struct virtqueue *vq, *n; |
| 235 | |
| 236 | list_for_each_entry_safe(vq, n, &vdev->vqs, list) |
| 237 | kvm_del_vq(vq); |
| 238 | } |
| 239 | |
| 240 | static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs, |
| 241 | struct virtqueue *vqs[], |
| 242 | vq_callback_t *callbacks[], |
| 243 | const char *names[]) |
| 244 | { |
| 245 | struct kvm_device *kdev = to_kvmdev(vdev); |
| 246 | int i; |
| 247 | |
| 248 | /* We must have this many virtqueues. */ |
| 249 | if (nvqs > kdev->desc->num_vq) |
| 250 | return -ENOENT; |
| 251 | |
| 252 | for (i = 0; i < nvqs; ++i) { |
| 253 | vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i]); |
| 254 | if (IS_ERR(vqs[i])) |
| 255 | goto error; |
| 256 | } |
| 257 | return 0; |
| 258 | |
| 259 | error: |
| 260 | kvm_del_vqs(vdev); |
| 261 | return PTR_ERR(vqs[i]); |
| 262 | } |
| 263 | |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 264 | /* |
| 265 | * The config ops structure as defined by virtio config |
| 266 | */ |
| 267 | static struct virtio_config_ops kvm_vq_configspace_ops = { |
Heiko Carstens | 5ca9fd5 | 2008-05-06 17:38:30 +0300 | [diff] [blame] | 268 | .get_features = kvm_get_features, |
Rusty Russell | c624896 | 2008-07-25 12:06:07 -0500 | [diff] [blame] | 269 | .finalize_features = kvm_finalize_features, |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 270 | .get = kvm_get, |
| 271 | .set = kvm_set, |
| 272 | .get_status = kvm_get_status, |
| 273 | .set_status = kvm_set_status, |
| 274 | .reset = kvm_reset, |
Michael S. Tsirkin | d2a7ddd | 2009-06-12 22:16:36 -0600 | [diff] [blame] | 275 | .find_vqs = kvm_find_vqs, |
| 276 | .del_vqs = kvm_del_vqs, |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | /* |
| 280 | * The root device for the kvm virtio devices. |
| 281 | * This makes them appear as /sys/devices/kvm_s390/0,1,2 not /sys/devices/0,1,2. |
| 282 | */ |
Cornelia Huck | 37f1c01 | 2008-10-10 21:33:12 +0200 | [diff] [blame] | 283 | static struct device *kvm_root; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * adds a new device and register it with virtio |
| 287 | * appropriate drivers are loaded by the device model |
| 288 | */ |
Rusty Russell | b769f57 | 2008-05-30 15:09:42 -0500 | [diff] [blame] | 289 | static void add_kvm_device(struct kvm_device_desc *d, unsigned int offset) |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 290 | { |
| 291 | struct kvm_device *kdev; |
| 292 | |
| 293 | kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); |
| 294 | if (!kdev) { |
Rusty Russell | b769f57 | 2008-05-30 15:09:42 -0500 | [diff] [blame] | 295 | printk(KERN_EMERG "Cannot allocate kvm dev %u type %u\n", |
| 296 | offset, d->type); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 297 | return; |
| 298 | } |
| 299 | |
Cornelia Huck | 37f1c01 | 2008-10-10 21:33:12 +0200 | [diff] [blame] | 300 | kdev->vdev.dev.parent = kvm_root; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 301 | kdev->vdev.id.device = d->type; |
| 302 | kdev->vdev.config = &kvm_vq_configspace_ops; |
| 303 | kdev->desc = d; |
| 304 | |
| 305 | if (register_virtio_device(&kdev->vdev) != 0) { |
Rusty Russell | b769f57 | 2008-05-30 15:09:42 -0500 | [diff] [blame] | 306 | printk(KERN_ERR "Failed to register kvm device %u type %u\n", |
| 307 | offset, d->type); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 308 | kfree(kdev); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * scan_devices() simply iterates through the device page. |
| 314 | * The type 0 is reserved to mean "end of devices". |
| 315 | */ |
| 316 | static void scan_devices(void) |
| 317 | { |
| 318 | unsigned int i; |
| 319 | struct kvm_device_desc *d; |
| 320 | |
| 321 | for (i = 0; i < PAGE_SIZE; i += desc_size(d)) { |
| 322 | d = kvm_devices + i; |
| 323 | |
| 324 | if (d->type == 0) |
| 325 | break; |
| 326 | |
Rusty Russell | b769f57 | 2008-05-30 15:09:42 -0500 | [diff] [blame] | 327 | add_kvm_device(d, i); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| 331 | /* |
Alexander Graf | cefa33e | 2010-08-24 15:48:51 +0200 | [diff] [blame] | 332 | * match for a kvm device with a specific desc pointer |
| 333 | */ |
| 334 | static int match_desc(struct device *dev, void *data) |
| 335 | { |
| 336 | if ((ulong)to_kvmdev(dev_to_virtio(dev))->desc == (ulong)data) |
| 337 | return 1; |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | * hotplug_device tries to find changes in the device page. |
| 344 | */ |
| 345 | static void hotplug_devices(struct work_struct *dummy) |
| 346 | { |
| 347 | unsigned int i; |
| 348 | struct kvm_device_desc *d; |
| 349 | struct device *dev; |
| 350 | |
| 351 | for (i = 0; i < PAGE_SIZE; i += desc_size(d)) { |
| 352 | d = kvm_devices + i; |
| 353 | |
| 354 | /* end of list */ |
| 355 | if (d->type == 0) |
| 356 | break; |
| 357 | |
| 358 | /* device already exists */ |
| 359 | dev = device_find_child(kvm_root, d, match_desc); |
| 360 | if (dev) { |
| 361 | /* XXX check for hotplug remove */ |
| 362 | put_device(dev); |
| 363 | continue; |
| 364 | } |
| 365 | |
| 366 | /* new device */ |
| 367 | printk(KERN_INFO "Adding new virtio device %p\n", d); |
| 368 | add_kvm_device(d, i); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /* |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 373 | * we emulate the request_irq behaviour on top of s390 extints |
| 374 | */ |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 375 | static void kvm_extint_handler(unsigned int ext_int_code, |
| 376 | unsigned int param32, unsigned long param64) |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 377 | { |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 378 | struct virtqueue *vq; |
| 379 | u16 subcode; |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 380 | u32 param; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 381 | |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 382 | subcode = ext_int_code >> 16; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 383 | if ((subcode & 0xff00) != VIRTIO_SUBCODE_64) |
| 384 | return; |
| 385 | |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 386 | /* The LSB might be overloaded, we have to mask it */ |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 387 | vq = (struct virtqueue *)(param64 & ~1UL); |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 388 | |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 389 | /* We use ext_params to decide what this interrupt means */ |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 390 | param = param32 & VIRTIO_PARAM_MASK; |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 391 | |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 392 | switch (param) { |
| 393 | case VIRTIO_PARAM_CONFIG_CHANGED: |
| 394 | { |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 395 | struct virtio_driver *drv; |
| 396 | drv = container_of(vq->vdev->dev.driver, |
| 397 | struct virtio_driver, driver); |
| 398 | if (drv->config_changed) |
| 399 | drv->config_changed(vq->vdev); |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 400 | |
| 401 | break; |
| 402 | } |
Alexander Graf | cefa33e | 2010-08-24 15:48:51 +0200 | [diff] [blame] | 403 | case VIRTIO_PARAM_DEV_ADD: |
| 404 | schedule_work(&hotplug_work); |
| 405 | break; |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 406 | case VIRTIO_PARAM_VRING_INTERRUPT: |
| 407 | default: |
Christian Borntraeger | be3c583 | 2008-11-18 22:44:13 +0100 | [diff] [blame] | 408 | vring_interrupt(0, vq); |
Alexander Graf | fc678d6 | 2010-08-24 15:48:50 +0200 | [diff] [blame] | 409 | break; |
| 410 | } |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Init function for virtio |
| 415 | * devices are in a single page above top of "normal" mem |
| 416 | */ |
| 417 | static int __init kvm_devices_init(void) |
| 418 | { |
| 419 | int rc; |
| 420 | |
| 421 | if (!MACHINE_IS_KVM) |
| 422 | return -ENODEV; |
| 423 | |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 424 | kvm_root = root_device_register("kvm_s390"); |
Cornelia Huck | 37f1c01 | 2008-10-10 21:33:12 +0200 | [diff] [blame] | 425 | if (IS_ERR(kvm_root)) { |
| 426 | rc = PTR_ERR(kvm_root); |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 427 | printk(KERN_ERR "Could not register kvm_s390 root device"); |
| 428 | return rc; |
| 429 | } |
| 430 | |
Christian Borntraeger | cc835f78 | 2008-11-14 18:18:02 +0100 | [diff] [blame] | 431 | rc = vmem_add_mapping(real_memory_size, PAGE_SIZE); |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 432 | if (rc) { |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 433 | root_device_unregister(kvm_root); |
Heiko Carstens | 17f3458 | 2008-04-30 13:38:47 +0200 | [diff] [blame] | 434 | return rc; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Christian Borntraeger | cc835f78 | 2008-11-14 18:18:02 +0100 | [diff] [blame] | 437 | kvm_devices = (void *) real_memory_size; |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 438 | |
Alexander Graf | cefa33e | 2010-08-24 15:48:51 +0200 | [diff] [blame] | 439 | INIT_WORK(&hotplug_work, hotplug_devices); |
| 440 | |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 441 | ctl_set_bit(0, 9); |
| 442 | register_external_interrupt(0x2603, kvm_extint_handler); |
| 443 | |
| 444 | scan_devices(); |
| 445 | return 0; |
| 446 | } |
| 447 | |
Christian Borntraeger | faeba830 | 2008-06-20 15:24:18 +0200 | [diff] [blame] | 448 | /* code for early console output with virtio_console */ |
| 449 | static __init int early_put_chars(u32 vtermno, const char *buf, int count) |
| 450 | { |
| 451 | char scratch[17]; |
| 452 | unsigned int len = count; |
| 453 | |
| 454 | if (len > sizeof(scratch) - 1) |
| 455 | len = sizeof(scratch) - 1; |
| 456 | scratch[len] = '\0'; |
| 457 | memcpy(scratch, buf, len); |
| 458 | kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch)); |
| 459 | return len; |
| 460 | } |
| 461 | |
Hendrik Brueckner | c4de0c1 | 2009-09-11 10:28:56 +0200 | [diff] [blame] | 462 | static int __init s390_virtio_console_init(void) |
Christian Borntraeger | faeba830 | 2008-06-20 15:24:18 +0200 | [diff] [blame] | 463 | { |
Hendrik Brueckner | c4de0c1 | 2009-09-11 10:28:56 +0200 | [diff] [blame] | 464 | if (!MACHINE_IS_KVM) |
| 465 | return -ENODEV; |
| 466 | return virtio_cons_early_init(early_put_chars); |
Christian Borntraeger | faeba830 | 2008-06-20 15:24:18 +0200 | [diff] [blame] | 467 | } |
Hendrik Brueckner | c4de0c1 | 2009-09-11 10:28:56 +0200 | [diff] [blame] | 468 | console_initcall(s390_virtio_console_init); |
| 469 | |
Christian Borntraeger | faeba830 | 2008-06-20 15:24:18 +0200 | [diff] [blame] | 470 | |
Christian Borntraeger | e976a2b | 2008-03-25 18:47:46 +0100 | [diff] [blame] | 471 | /* |
| 472 | * We do this after core stuff, but before the drivers. |
| 473 | */ |
| 474 | postcore_initcall(kvm_devices_init); |