blob: a99d09a11f05eed1e317de5e8f06c549ab760b8b [file] [log] [blame]
Christian Borntraegere976a2b2008-03-25 18:47:46 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * virtio for kvm on s390
Christian Borntraegere976a2b2008-03-25 18:47:46 +01003 *
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
Heiko Carstens052ff462011-01-05 12:47:28 +010013#include <linux/kernel_stat.h>
Christian Borntraegere976a2b2008-03-25 18:47:46 +010014#include <linux/init.h>
15#include <linux/bootmem.h>
16#include <linux/err.h>
17#include <linux/virtio.h>
18#include <linux/virtio_config.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Christian Borntraegerfaeba8302008-06-20 15:24:18 +020020#include <linux/virtio_console.h>
Christian Borntraegere976a2b2008-03-25 18:47:46 +010021#include <linux/interrupt.h>
22#include <linux/virtio_ring.h>
Heiko Carstens3a4c5d52011-07-30 09:25:15 +020023#include <linux/export.h>
Heiko Carstens17f34582008-04-30 13:38:47 +020024#include <linux/pfn.h>
Christian Borntraegere976a2b2008-03-25 18:47:46 +010025#include <asm/io.h>
26#include <asm/kvm_para.h>
27#include <asm/kvm_virtio.h>
Heinz Graalfscd183452012-06-11 16:06:59 +020028#include <asm/sclp.h>
Christian Borntraegere976a2b2008-03-25 18:47:46 +010029#include <asm/setup.h>
Heiko Carstens052ff462011-01-05 12:47:28 +010030#include <asm/irq.h>
Christian Borntraegere976a2b2008-03-25 18:47:46 +010031
32#define VIRTIO_SUBCODE_64 0x0D00
33
34/*
35 * The pointer to our (page) of device descriptions.
36 */
37static void *kvm_devices;
Martin Schwidefskyc4736d92011-10-30 15:17:11 +010038static struct work_struct hotplug_work;
Christian Borntraegere976a2b2008-03-25 18:47:46 +010039
Christian Borntraegere976a2b2008-03-25 18:47:46 +010040struct kvm_device {
41 struct virtio_device vdev;
42 struct kvm_device_desc *desc;
43};
44
45#define to_kvmdev(vd) container_of(vd, struct kvm_device, vdev)
46
47/*
48 * memory layout:
49 * - kvm_device_descriptor
50 * struct kvm_device_desc
51 * - configuration
52 * struct kvm_vqconfig
53 * - feature bits
54 * - config space
55 */
56static struct kvm_vqconfig *kvm_vq_config(const struct kvm_device_desc *desc)
57{
58 return (struct kvm_vqconfig *)(desc + 1);
59}
60
61static u8 *kvm_vq_features(const struct kvm_device_desc *desc)
62{
63 return (u8 *)(kvm_vq_config(desc) + desc->num_vq);
64}
65
66static u8 *kvm_vq_configspace(const struct kvm_device_desc *desc)
67{
68 return kvm_vq_features(desc) + desc->feature_len * 2;
69}
70
71/*
72 * The total size of the config page used by this device (incl. desc)
73 */
74static unsigned desc_size(const struct kvm_device_desc *desc)
75{
76 return sizeof(*desc)
77 + desc->num_vq * sizeof(struct kvm_vqconfig)
78 + desc->feature_len * 2
79 + desc->config_len;
80}
81
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030082/* This gets the device's feature bits. */
Michael S. Tsirkind0254772014-10-07 16:39:43 +020083static u64 kvm_get_features(struct virtio_device *vdev)
Christian Borntraegere976a2b2008-03-25 18:47:46 +010084{
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030085 unsigned int i;
86 u32 features = 0;
Christian Borntraegere976a2b2008-03-25 18:47:46 +010087 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030088 u8 *in_features = kvm_vq_features(desc);
Christian Borntraegere976a2b2008-03-25 18:47:46 +010089
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030090 for (i = 0; i < min(desc->feature_len * 8, 32); i++)
91 if (in_features[i / 8] & (1 << (i % 8)))
92 features |= (1 << i);
93 return features;
94}
Christian Borntraegere976a2b2008-03-25 18:47:46 +010095
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +020096static int kvm_finalize_features(struct virtio_device *vdev)
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030097{
Rusty Russellc6248962008-07-25 12:06:07 -050098 unsigned int i, bits;
Heiko Carstens5ca9fd52008-05-06 17:38:30 +030099 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
100 /* Second half of bitmap is features we accept. */
101 u8 *out_features = kvm_vq_features(desc) + desc->feature_len;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100102
Rusty Russelle34f8722008-07-25 12:06:13 -0500103 /* Give virtio_ring a chance to accept features. */
104 vring_transport_features(vdev);
105
Michael S. Tsirkin93d389f2014-11-27 13:45:58 +0200106 /* Make sure we don't have any features > 32 bits! */
107 BUG_ON((u32)vdev->features != vdev->features);
108
Heiko Carstens5ca9fd52008-05-06 17:38:30 +0300109 memset(out_features, 0, desc->feature_len);
Rusty Russellc6248962008-07-25 12:06:07 -0500110 bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
111 for (i = 0; i < bits; i++) {
Michael S. Tsirkine16e12b2014-10-07 16:39:42 +0200112 if (__virtio_test_bit(vdev, i))
Heiko Carstens5ca9fd52008-05-06 17:38:30 +0300113 out_features[i / 8] |= (1 << (i % 8));
114 }
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200115
116 return 0;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100117}
118
119/*
120 * Reading and writing elements in config space
121 */
122static void kvm_get(struct virtio_device *vdev, unsigned int offset,
123 void *buf, unsigned len)
124{
125 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
126
127 BUG_ON(offset + len > desc->config_len);
128 memcpy(buf, kvm_vq_configspace(desc) + offset, len);
129}
130
131static void kvm_set(struct virtio_device *vdev, unsigned int offset,
132 const void *buf, unsigned len)
133{
134 struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
135
136 BUG_ON(offset + len > desc->config_len);
137 memcpy(kvm_vq_configspace(desc) + offset, buf, len);
138}
139
140/*
141 * The operations to get and set the status word just access
142 * the status field of the device descriptor. set_status will also
143 * make a hypercall to the host, to tell about status changes
144 */
145static u8 kvm_get_status(struct virtio_device *vdev)
146{
147 return to_kvmdev(vdev)->desc->status;
148}
149
150static void kvm_set_status(struct virtio_device *vdev, u8 status)
151{
152 BUG_ON(!status);
153 to_kvmdev(vdev)->desc->status = status;
154 kvm_hypercall1(KVM_S390_VIRTIO_SET_STATUS,
155 (unsigned long) to_kvmdev(vdev)->desc);
156}
157
158/*
159 * To reset the device, we use the KVM_VIRTIO_RESET hypercall, using the
160 * descriptor address. The Host will zero the status and all the
161 * features.
162 */
163static void kvm_reset(struct virtio_device *vdev)
164{
165 kvm_hypercall1(KVM_S390_VIRTIO_RESET,
166 (unsigned long) to_kvmdev(vdev)->desc);
167}
168
169/*
170 * When the virtio_ring code wants to notify the Host, it calls us here and we
171 * make a hypercall. We hand the address of the virtqueue so the Host
172 * knows which virtqueue we're talking about.
173 */
Heinz Graalfs46f9c2b2013-10-29 09:38:50 +1030174static bool kvm_notify(struct virtqueue *vq)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100175{
Heinz Graalfs46f9c2b2013-10-29 09:38:50 +1030176 long rc;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100177 struct kvm_vqconfig *config = vq->priv;
178
Heinz Graalfs46f9c2b2013-10-29 09:38:50 +1030179 rc = kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, config->address);
180 if (rc < 0)
181 return false;
182 return true;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100183}
184
185/*
186 * This routine finds the first virtqueue described in the configuration of
187 * this device and sets it up.
188 */
189static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
Rusty Russell9499f5e2009-06-12 22:16:35 -0600190 unsigned index,
191 void (*callback)(struct virtqueue *vq),
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200192 const char *name, bool ctx)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100193{
194 struct kvm_device *kdev = to_kvmdev(vdev);
195 struct kvm_vqconfig *config;
196 struct virtqueue *vq;
197 int err;
198
199 if (index >= kdev->desc->num_vq)
200 return ERR_PTR(-ENOENT);
201
Michael S. Tsirkin6457f1262012-09-05 21:47:45 +0300202 if (!name)
203 return NULL;
204
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100205 config = kvm_vq_config(kdev->desc)+index;
206
Heiko Carstens17f34582008-04-30 13:38:47 +0200207 err = vmem_add_mapping(config->address,
Rusty Russelldb405982008-12-30 09:26:02 -0600208 vring_size(config->num,
209 KVM_S390_VIRTIO_RING_ALIGN));
Heiko Carstens17f34582008-04-30 13:38:47 +0200210 if (err)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100211 goto out;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100212
Jason Wang17bb6d42012-08-28 13:54:13 +0200213 vq = vring_new_virtqueue(index, config->num, KVM_S390_VIRTIO_RING_ALIGN,
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200214 vdev, true, ctx, (void *) config->address,
Rusty Russell9499f5e2009-06-12 22:16:35 -0600215 kvm_notify, callback, name);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100216 if (!vq) {
217 err = -ENOMEM;
218 goto unmap;
219 }
220
221 /*
222 * register a callback token
223 * The host will sent this via the external interrupt parameter
224 */
225 config->token = (u64) vq;
226
227 vq->priv = config;
228 return vq;
229unmap:
Heiko Carstens17f34582008-04-30 13:38:47 +0200230 vmem_remove_mapping(config->address,
Rusty Russelldb405982008-12-30 09:26:02 -0600231 vring_size(config->num,
232 KVM_S390_VIRTIO_RING_ALIGN));
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100233out:
234 return ERR_PTR(err);
235}
236
237static void kvm_del_vq(struct virtqueue *vq)
238{
239 struct kvm_vqconfig *config = vq->priv;
240
241 vring_del_virtqueue(vq);
Heiko Carstens17f34582008-04-30 13:38:47 +0200242 vmem_remove_mapping(config->address,
Rusty Russelldb405982008-12-30 09:26:02 -0600243 vring_size(config->num,
244 KVM_S390_VIRTIO_RING_ALIGN));
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100245}
246
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600247static void kvm_del_vqs(struct virtio_device *vdev)
248{
249 struct virtqueue *vq, *n;
250
251 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
252 kvm_del_vq(vq);
253}
254
255static int kvm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
256 struct virtqueue *vqs[],
257 vq_callback_t *callbacks[],
Christoph Hellwigfb5e31d2017-02-05 18:15:22 +0100258 const char * const names[],
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200259 const bool *ctx,
Christoph Hellwigfb5e31d2017-02-05 18:15:22 +0100260 struct irq_affinity *desc)
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600261{
262 struct kvm_device *kdev = to_kvmdev(vdev);
263 int i;
264
265 /* We must have this many virtqueues. */
266 if (nvqs > kdev->desc->num_vq)
267 return -ENOENT;
268
269 for (i = 0; i < nvqs; ++i) {
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200270 vqs[i] = kvm_find_vq(vdev, i, callbacks[i], names[i],
271 ctx ? ctx[i] : false);
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600272 if (IS_ERR(vqs[i]))
273 goto error;
274 }
275 return 0;
276
277error:
278 kvm_del_vqs(vdev);
279 return PTR_ERR(vqs[i]);
280}
281
Rick Jones66846042011-11-14 14:17:08 +0000282static const char *kvm_bus_name(struct virtio_device *vdev)
283{
284 return "";
285}
286
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100287/*
288 * The config ops structure as defined by virtio config
289 */
Stephen Hemminger93503932013-02-10 15:57:38 +1030290static const struct virtio_config_ops kvm_vq_configspace_ops = {
Heiko Carstens5ca9fd52008-05-06 17:38:30 +0300291 .get_features = kvm_get_features,
Rusty Russellc6248962008-07-25 12:06:07 -0500292 .finalize_features = kvm_finalize_features,
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100293 .get = kvm_get,
294 .set = kvm_set,
295 .get_status = kvm_get_status,
296 .set_status = kvm_set_status,
297 .reset = kvm_reset,
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600298 .find_vqs = kvm_find_vqs,
299 .del_vqs = kvm_del_vqs,
Rick Jones66846042011-11-14 14:17:08 +0000300 .bus_name = kvm_bus_name,
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100301};
302
303/*
304 * The root device for the kvm virtio devices.
305 * This makes them appear as /sys/devices/kvm_s390/0,1,2 not /sys/devices/0,1,2.
306 */
Cornelia Huck37f1c012008-10-10 21:33:12 +0200307static struct device *kvm_root;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100308
309/*
310 * adds a new device and register it with virtio
311 * appropriate drivers are loaded by the device model
312 */
Rusty Russellb769f572008-05-30 15:09:42 -0500313static void add_kvm_device(struct kvm_device_desc *d, unsigned int offset)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100314{
315 struct kvm_device *kdev;
316
317 kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
318 if (!kdev) {
Rusty Russellb769f572008-05-30 15:09:42 -0500319 printk(KERN_EMERG "Cannot allocate kvm dev %u type %u\n",
320 offset, d->type);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100321 return;
322 }
323
Cornelia Huck37f1c012008-10-10 21:33:12 +0200324 kdev->vdev.dev.parent = kvm_root;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100325 kdev->vdev.id.device = d->type;
326 kdev->vdev.config = &kvm_vq_configspace_ops;
327 kdev->desc = d;
328
329 if (register_virtio_device(&kdev->vdev) != 0) {
Rusty Russellb769f572008-05-30 15:09:42 -0500330 printk(KERN_ERR "Failed to register kvm device %u type %u\n",
331 offset, d->type);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100332 kfree(kdev);
333 }
334}
335
336/*
337 * scan_devices() simply iterates through the device page.
338 * The type 0 is reserved to mean "end of devices".
339 */
340static void scan_devices(void)
341{
342 unsigned int i;
343 struct kvm_device_desc *d;
344
345 for (i = 0; i < PAGE_SIZE; i += desc_size(d)) {
346 d = kvm_devices + i;
347
348 if (d->type == 0)
349 break;
350
Rusty Russellb769f572008-05-30 15:09:42 -0500351 add_kvm_device(d, i);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100352 }
353}
354
355/*
Alexander Grafcefa33e2010-08-24 15:48:51 +0200356 * match for a kvm device with a specific desc pointer
357 */
358static int match_desc(struct device *dev, void *data)
359{
Martin Schwidefsky7bf40742011-10-30 15:17:17 +0100360 struct virtio_device *vdev = dev_to_virtio(dev);
361 struct kvm_device *kdev = to_kvmdev(vdev);
Alexander Grafcefa33e2010-08-24 15:48:51 +0200362
Martin Schwidefsky7bf40742011-10-30 15:17:17 +0100363 return kdev->desc == data;
Alexander Grafcefa33e2010-08-24 15:48:51 +0200364}
365
366/*
367 * hotplug_device tries to find changes in the device page.
368 */
369static void hotplug_devices(struct work_struct *dummy)
370{
371 unsigned int i;
372 struct kvm_device_desc *d;
373 struct device *dev;
374
375 for (i = 0; i < PAGE_SIZE; i += desc_size(d)) {
376 d = kvm_devices + i;
377
378 /* end of list */
379 if (d->type == 0)
380 break;
381
382 /* device already exists */
383 dev = device_find_child(kvm_root, d, match_desc);
384 if (dev) {
385 /* XXX check for hotplug remove */
386 put_device(dev);
387 continue;
388 }
389
390 /* new device */
391 printk(KERN_INFO "Adding new virtio device %p\n", d);
392 add_kvm_device(d, i);
393 }
394}
395
396/*
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100397 * we emulate the request_irq behaviour on top of s390 extints
398 */
Heiko Carstensfde15c32012-03-11 11:59:31 -0400399static void kvm_extint_handler(struct ext_code ext_code,
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200400 unsigned int param32, unsigned long param64)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100401{
Christian Borntraegerbe3c5832008-11-18 22:44:13 +0100402 struct virtqueue *vq;
Alexander Graffc678d62010-08-24 15:48:50 +0200403 u32 param;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100404
Heiko Carstensfde15c32012-03-11 11:59:31 -0400405 if ((ext_code.subcode & 0xff00) != VIRTIO_SUBCODE_64)
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100406 return;
Heiko Carstens420f42e2013-01-02 15:18:18 +0100407 inc_irq_stat(IRQEXT_VRT);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100408
Christian Borntraegerbe3c5832008-11-18 22:44:13 +0100409 /* The LSB might be overloaded, we have to mask it */
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200410 vq = (struct virtqueue *)(param64 & ~1UL);
Christian Borntraegerbe3c5832008-11-18 22:44:13 +0100411
Alexander Graffc678d62010-08-24 15:48:50 +0200412 /* We use ext_params to decide what this interrupt means */
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200413 param = param32 & VIRTIO_PARAM_MASK;
Christian Borntraegerbe3c5832008-11-18 22:44:13 +0100414
Alexander Graffc678d62010-08-24 15:48:50 +0200415 switch (param) {
416 case VIRTIO_PARAM_CONFIG_CHANGED:
Michael S. Tsirkin016c98c2014-10-14 10:40:34 +1030417 virtio_config_changed(vq->vdev);
Alexander Graffc678d62010-08-24 15:48:50 +0200418 break;
Alexander Grafcefa33e2010-08-24 15:48:51 +0200419 case VIRTIO_PARAM_DEV_ADD:
420 schedule_work(&hotplug_work);
421 break;
Alexander Graffc678d62010-08-24 15:48:50 +0200422 case VIRTIO_PARAM_VRING_INTERRUPT:
423 default:
Christian Borntraegerbe3c5832008-11-18 22:44:13 +0100424 vring_interrupt(0, vq);
Alexander Graffc678d62010-08-24 15:48:50 +0200425 break;
426 }
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100427}
428
429/*
Cornelia Huck55c171a2012-12-14 17:02:16 +0100430 * For s390-virtio, we expect a page above main storage containing
431 * the virtio configuration. Try to actually load from this area
432 * in order to figure out if the host provides this page.
433 */
434static int __init test_devices_support(unsigned long addr)
435{
436 int ret = -EIO;
437
438 asm volatile(
439 "0: lura 0,%1\n"
440 "1: xgr %0,%0\n"
441 "2:\n"
442 EX_TABLE(0b,2b)
443 EX_TABLE(1b,2b)
444 : "+d" (ret)
445 : "a" (addr)
446 : "0", "cc");
447 return ret;
448}
449/*
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100450 * Init function for virtio
Nick Wang3188bf62013-03-25 17:22:56 +0100451 * devices are in a single page above top of "normal" + standby mem
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100452 */
453static int __init kvm_devices_init(void)
454{
455 int rc;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200456 unsigned long total_memory_size = sclp.rzm * sclp.rnmax;
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100457
458 if (!MACHINE_IS_KVM)
459 return -ENODEV;
460
Nick Wang3188bf62013-03-25 17:22:56 +0100461 if (test_devices_support(total_memory_size) < 0)
Cornelia Huck55c171a2012-12-14 17:02:16 +0100462 return -ENODEV;
463
Cornelia Huck3b2fbb32016-07-07 17:07:57 +0200464 pr_warn("The s390-virtio transport is deprecated. Please switch to a modern host providing virtio-ccw.\n");
465
Nick Wang3188bf62013-03-25 17:22:56 +0100466 rc = vmem_add_mapping(total_memory_size, PAGE_SIZE);
Cornelia Huck55c171a2012-12-14 17:02:16 +0100467 if (rc)
468 return rc;
469
Nick Wang3188bf62013-03-25 17:22:56 +0100470 kvm_devices = (void *) total_memory_size;
Cornelia Huck55c171a2012-12-14 17:02:16 +0100471
Mark McLoughlin035da162008-12-15 12:58:29 +0000472 kvm_root = root_device_register("kvm_s390");
Cornelia Huck37f1c012008-10-10 21:33:12 +0200473 if (IS_ERR(kvm_root)) {
474 rc = PTR_ERR(kvm_root);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100475 printk(KERN_ERR "Could not register kvm_s390 root device");
Nick Wang3188bf62013-03-25 17:22:56 +0100476 vmem_remove_mapping(total_memory_size, PAGE_SIZE);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100477 return rc;
478 }
479
Alexander Grafcefa33e2010-08-24 15:48:51 +0200480 INIT_WORK(&hotplug_work, hotplug_devices);
481
Heiko Carstens82003c32013-09-04 13:35:45 +0200482 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
Thomas Huth1dad0932014-03-31 15:24:08 +0200483 register_external_irq(EXT_IRQ_CP_SERVICE, kvm_extint_handler);
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100484
485 scan_devices();
486 return 0;
487}
488
Christian Borntraegerfaeba8302008-06-20 15:24:18 +0200489/* code for early console output with virtio_console */
Christian Borntraeger2ab0d562016-07-07 17:07:56 +0200490static int early_put_chars(u32 vtermno, const char *buf, int count)
Christian Borntraegerfaeba8302008-06-20 15:24:18 +0200491{
492 char scratch[17];
493 unsigned int len = count;
494
495 if (len > sizeof(scratch) - 1)
496 len = sizeof(scratch) - 1;
497 scratch[len] = '\0';
498 memcpy(scratch, buf, len);
499 kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, __pa(scratch));
500 return len;
501}
502
Hendrik Bruecknerc4de0c12009-09-11 10:28:56 +0200503static int __init s390_virtio_console_init(void)
Christian Borntraegerfaeba8302008-06-20 15:24:18 +0200504{
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200505 if (sclp.has_vt220 || sclp.has_linemode)
Hendrik Bruecknerc4de0c12009-09-11 10:28:56 +0200506 return -ENODEV;
507 return virtio_cons_early_init(early_put_chars);
Christian Borntraegerfaeba8302008-06-20 15:24:18 +0200508}
Hendrik Bruecknerc4de0c12009-09-11 10:28:56 +0200509console_initcall(s390_virtio_console_init);
510
Christian Borntraegerfaeba8302008-06-20 15:24:18 +0200511
Christian Borntraegere976a2b2008-03-25 18:47:46 +0100512/*
513 * We do this after core stuff, but before the drivers.
514 */
515postcore_initcall(kvm_devices_init);