Statistics
| Branch: | Revision:

root / hw / spapr_vio.c @ 0200db65

History | View | Annotate | Download (18.5 kB)

1
/*
2
 * QEMU sPAPR VIO code
3
 *
4
 * Copyright (c) 2010 David Gibson, IBM Corporation <dwg@au1.ibm.com>
5
 * Based on the s390 virtio bus code:
6
 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20
 */
21

    
22
#include "hw.h"
23
#include "sysemu.h"
24
#include "boards.h"
25
#include "monitor.h"
26
#include "loader.h"
27
#include "elf.h"
28
#include "hw/sysbus.h"
29
#include "kvm.h"
30
#include "device_tree.h"
31
#include "kvm_ppc.h"
32

    
33
#include "hw/spapr.h"
34
#include "hw/spapr_vio.h"
35
#include "hw/xics.h"
36

    
37
#ifdef CONFIG_FDT
38
#include <libfdt.h>
39
#endif /* CONFIG_FDT */
40

    
41
/* #define DEBUG_SPAPR */
42
/* #define DEBUG_TCE */
43

    
44
#ifdef DEBUG_SPAPR
45
#define dprintf(fmt, ...) \
46
    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
47
#else
48
#define dprintf(fmt, ...) \
49
    do { } while (0)
50
#endif
51

    
52
static struct BusInfo spapr_vio_bus_info = {
53
    .name       = "spapr-vio",
54
    .size       = sizeof(VIOsPAPRBus),
55
    .props = (Property[]) {
56
        DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0), \
57
        DEFINE_PROP_END_OF_LIST(),
58
    },
59
};
60

    
61
VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
62
{
63
    DeviceState *qdev;
64
    VIOsPAPRDevice *dev = NULL;
65

    
66
    QLIST_FOREACH(qdev, &bus->bus.children, sibling) {
67
        dev = (VIOsPAPRDevice *)qdev;
68
        if (dev->reg == reg) {
69
            break;
70
        }
71
    }
72

    
73
    return dev;
74
}
75

    
76
#ifdef CONFIG_FDT
77
static int vio_make_devnode(VIOsPAPRDevice *dev,
78
                            void *fdt)
79
{
80
    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
81
    int vdevice_off, node_off;
82
    int ret;
83

    
84
    vdevice_off = fdt_path_offset(fdt, "/vdevice");
85
    if (vdevice_off < 0) {
86
        return vdevice_off;
87
    }
88

    
89
    node_off = fdt_add_subnode(fdt, vdevice_off, dev->qdev.id);
90
    if (node_off < 0) {
91
        return node_off;
92
    }
93

    
94
    ret = fdt_setprop_cell(fdt, node_off, "reg", dev->reg);
95
    if (ret < 0) {
96
        return ret;
97
    }
98

    
99
    if (info->dt_type) {
100
        ret = fdt_setprop_string(fdt, node_off, "device_type",
101
                                 info->dt_type);
102
        if (ret < 0) {
103
            return ret;
104
        }
105
    }
106

    
107
    if (info->dt_compatible) {
108
        ret = fdt_setprop_string(fdt, node_off, "compatible",
109
                                 info->dt_compatible);
110
        if (ret < 0) {
111
            return ret;
112
        }
113
    }
114

    
115
    if (dev->qirq) {
116
        uint32_t ints_prop[] = {cpu_to_be32(dev->vio_irq_num), 0};
117

    
118
        ret = fdt_setprop(fdt, node_off, "interrupts", ints_prop,
119
                          sizeof(ints_prop));
120
        if (ret < 0) {
121
            return ret;
122
        }
123
    }
124

    
125
    if (dev->rtce_window_size) {
126
        uint32_t dma_prop[] = {cpu_to_be32(dev->reg),
127
                               0, 0,
128
                               0, cpu_to_be32(dev->rtce_window_size)};
129

    
130
        ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-address-cells", 2);
131
        if (ret < 0) {
132
            return ret;
133
        }
134

    
135
        ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-size-cells", 2);
136
        if (ret < 0) {
137
            return ret;
138
        }
139

    
140
        ret = fdt_setprop(fdt, node_off, "ibm,my-dma-window", dma_prop,
141
                          sizeof(dma_prop));
142
        if (ret < 0) {
143
            return ret;
144
        }
145
    }
146

    
147
    if (info->devnode) {
148
        ret = (info->devnode)(dev, fdt, node_off);
149
        if (ret < 0) {
150
            return ret;
151
        }
152
    }
153

    
154
    return node_off;
155
}
156
#endif /* CONFIG_FDT */
157

    
158
/*
159
 * RTCE handling
160
 */
161

    
162
static void rtce_init(VIOsPAPRDevice *dev)
163
{
164
    size_t size = (dev->rtce_window_size >> SPAPR_VIO_TCE_PAGE_SHIFT)
165
        * sizeof(VIOsPAPR_RTCE);
166

    
167
    if (size) {
168
        dev->rtce_table = g_malloc0(size);
169
    }
170
}
171

    
172
static target_ulong h_put_tce(CPUState *env, sPAPREnvironment *spapr,
173
                              target_ulong opcode, target_ulong *args)
174
{
175
    target_ulong liobn = args[0];
176
    target_ulong ioba = args[1];
177
    target_ulong tce = args[2];
178
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, liobn);
179
    VIOsPAPR_RTCE *rtce;
180

    
181
    if (!dev) {
182
        hcall_dprintf("spapr_vio_put_tce on non-existent LIOBN "
183
                      TARGET_FMT_lx "\n", liobn);
184
        return H_PARAMETER;
185
    }
186

    
187
    ioba &= ~(SPAPR_VIO_TCE_PAGE_SIZE - 1);
188

    
189
#ifdef DEBUG_TCE
190
    fprintf(stderr, "spapr_vio_put_tce on %s  ioba 0x" TARGET_FMT_lx
191
            "  TCE 0x" TARGET_FMT_lx "\n", dev->qdev.id, ioba, tce);
192
#endif
193

    
194
    if (ioba >= dev->rtce_window_size) {
195
        hcall_dprintf("spapr_vio_put_tce on out-of-boards IOBA 0x"
196
                      TARGET_FMT_lx "\n", ioba);
197
        return H_PARAMETER;
198
    }
199

    
200
    rtce = dev->rtce_table + (ioba >> SPAPR_VIO_TCE_PAGE_SHIFT);
201
    rtce->tce = tce;
202

    
203
    return H_SUCCESS;
204
}
205

    
206
int spapr_vio_check_tces(VIOsPAPRDevice *dev, target_ulong ioba,
207
                         target_ulong len, enum VIOsPAPR_TCEAccess access)
208
{
209
    int start, end, i;
210

    
211
    start = ioba >> SPAPR_VIO_TCE_PAGE_SHIFT;
212
    end = (ioba + len - 1) >> SPAPR_VIO_TCE_PAGE_SHIFT;
213

    
214
    for (i = start; i <= end; i++) {
215
        if ((dev->rtce_table[i].tce & access) != access) {
216
#ifdef DEBUG_TCE
217
            fprintf(stderr, "FAIL on %d\n", i);
218
#endif
219
            return -1;
220
        }
221
    }
222

    
223
    return 0;
224
}
225

    
226
int spapr_tce_dma_write(VIOsPAPRDevice *dev, uint64_t taddr, const void *buf,
227
                        uint32_t size)
228
{
229
#ifdef DEBUG_TCE
230
    fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",
231
            (unsigned long long)taddr, size);
232
#endif
233

    
234
    /* Check for bypass */
235
    if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {
236
        cpu_physical_memory_write(taddr, buf, size);
237
        return 0;
238
    }
239

    
240
    while (size) {
241
        uint64_t tce;
242
        uint32_t lsize;
243
        uint64_t txaddr;
244

    
245
        /* Check if we are in bound */
246
        if (taddr >= dev->rtce_window_size) {
247
#ifdef DEBUG_TCE
248
            fprintf(stderr, "spapr_tce_dma_write out of bounds\n");
249
#endif
250
            return H_DEST_PARM;
251
        }
252
        tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;
253

    
254
        /* How much til end of page ? */
255
        lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);
256

    
257
        /* Check TCE */
258
        if (!(tce & 2)) {
259
            return H_DEST_PARM;
260
        }
261

    
262
        /* Translate */
263
        txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |
264
            (taddr & SPAPR_VIO_TCE_PAGE_MASK);
265

    
266
#ifdef DEBUG_TCE
267
        fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",
268
                (unsigned long long)txaddr, lsize);
269
#endif
270

    
271
        /* Do it */
272
        cpu_physical_memory_write(txaddr, buf, lsize);
273
        buf += lsize;
274
        taddr += lsize;
275
        size -= lsize;
276
    }
277
    return 0;
278
}
279

    
280
int spapr_tce_dma_zero(VIOsPAPRDevice *dev, uint64_t taddr, uint32_t size)
281
{
282
    /* FIXME: allocating a temp buffer is nasty, but just stepping
283
     * through writing zeroes is awkward.  This will do for now. */
284
    uint8_t zeroes[size];
285

    
286
#ifdef DEBUG_TCE
287
    fprintf(stderr, "spapr_tce_dma_zero taddr=0x%llx size=0x%x\n",
288
            (unsigned long long)taddr, size);
289
#endif
290

    
291
    memset(zeroes, 0, size);
292
    return spapr_tce_dma_write(dev, taddr, zeroes, size);
293
}
294

    
295
void stb_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint8_t val)
296
{
297
    spapr_tce_dma_write(dev, taddr, &val, sizeof(val));
298
}
299

    
300
void sth_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint16_t val)
301
{
302
    val = tswap16(val);
303
    spapr_tce_dma_write(dev, taddr, &val, sizeof(val));
304
}
305

    
306

    
307
void stw_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint32_t val)
308
{
309
    val = tswap32(val);
310
    spapr_tce_dma_write(dev, taddr, &val, sizeof(val));
311
}
312

    
313
void stq_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint64_t val)
314
{
315
    val = tswap64(val);
316
    spapr_tce_dma_write(dev, taddr, &val, sizeof(val));
317
}
318

    
319
int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf,
320
                       uint32_t size)
321
{
322
#ifdef DEBUG_TCE
323
    fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",
324
            (unsigned long long)taddr, size);
325
#endif
326

    
327
    /* Check for bypass */
328
    if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {
329
        cpu_physical_memory_read(taddr, buf, size);
330
        return 0;
331
    }
332

    
333
    while (size) {
334
        uint64_t tce;
335
        uint32_t lsize;
336
        uint64_t txaddr;
337

    
338
        /* Check if we are in bound */
339
        if (taddr >= dev->rtce_window_size) {
340
#ifdef DEBUG_TCE
341
            fprintf(stderr, "spapr_tce_dma_read out of bounds\n");
342
#endif
343
            return H_DEST_PARM;
344
        }
345
        tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;
346

    
347
        /* How much til end of page ? */
348
        lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);
349

    
350
        /* Check TCE */
351
        if (!(tce & 1)) {
352
            return H_DEST_PARM;
353
        }
354

    
355
        /* Translate */
356
        txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |
357
            (taddr & SPAPR_VIO_TCE_PAGE_MASK);
358

    
359
#ifdef DEBUG_TCE
360
        fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",
361
                (unsigned long long)txaddr, lsize);
362
#endif
363
        /* Do it */
364
        cpu_physical_memory_read(txaddr, buf, lsize);
365
        buf += lsize;
366
        taddr += lsize;
367
        size -= lsize;
368
    }
369
    return H_SUCCESS;
370
}
371

    
372
uint64_t ldq_tce(VIOsPAPRDevice *dev, uint64_t taddr)
373
{
374
    uint64_t val;
375

    
376
    spapr_tce_dma_read(dev, taddr, &val, sizeof(val));
377
    return tswap64(val);
378
}
379

    
380
/*
381
 * CRQ handling
382
 */
383
static target_ulong h_reg_crq(CPUState *env, sPAPREnvironment *spapr,
384
                              target_ulong opcode, target_ulong *args)
385
{
386
    target_ulong reg = args[0];
387
    target_ulong queue_addr = args[1];
388
    target_ulong queue_len = args[2];
389
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
390

    
391
    if (!dev) {
392
        hcall_dprintf("h_reg_crq on non-existent unit 0x"
393
                      TARGET_FMT_lx "\n", reg);
394
        return H_PARAMETER;
395
    }
396

    
397
    /* We can't grok a queue size bigger than 256M for now */
398
    if (queue_len < 0x1000 || queue_len > 0x10000000) {
399
        hcall_dprintf("h_reg_crq, queue size too small or too big (0x%llx)\n",
400
                      (unsigned long long)queue_len);
401
        return H_PARAMETER;
402
    }
403

    
404
    /* Check queue alignment */
405
    if (queue_addr & 0xfff) {
406
        hcall_dprintf("h_reg_crq, queue not aligned (0x%llx)\n",
407
                      (unsigned long long)queue_addr);
408
        return H_PARAMETER;
409
    }
410

    
411
    /* Check if device supports CRQs */
412
    if (!dev->crq.SendFunc) {
413
        return H_NOT_FOUND;
414
    }
415

    
416

    
417
    /* Already a queue ? */
418
    if (dev->crq.qsize) {
419
        return H_RESOURCE;
420
    }
421
    dev->crq.qladdr = queue_addr;
422
    dev->crq.qsize = queue_len;
423
    dev->crq.qnext = 0;
424

    
425
    dprintf("CRQ for dev 0x" TARGET_FMT_lx " registered at 0x"
426
            TARGET_FMT_lx "/0x" TARGET_FMT_lx "\n",
427
            reg, queue_addr, queue_len);
428
    return H_SUCCESS;
429
}
430

    
431
static target_ulong h_free_crq(CPUState *env, sPAPREnvironment *spapr,
432
                               target_ulong opcode, target_ulong *args)
433
{
434
    target_ulong reg = args[0];
435
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
436

    
437
    if (!dev) {
438
        hcall_dprintf("h_free_crq on non-existent unit 0x"
439
                      TARGET_FMT_lx "\n", reg);
440
        return H_PARAMETER;
441
    }
442

    
443
    dev->crq.qladdr = 0;
444
    dev->crq.qsize = 0;
445
    dev->crq.qnext = 0;
446

    
447
    dprintf("CRQ for dev 0x" TARGET_FMT_lx " freed\n", reg);
448

    
449
    return H_SUCCESS;
450
}
451

    
452
static target_ulong h_send_crq(CPUState *env, sPAPREnvironment *spapr,
453
                               target_ulong opcode, target_ulong *args)
454
{
455
    target_ulong reg = args[0];
456
    target_ulong msg_hi = args[1];
457
    target_ulong msg_lo = args[2];
458
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
459
    uint64_t crq_mangle[2];
460

    
461
    if (!dev) {
462
        hcall_dprintf("h_send_crq on non-existent unit 0x"
463
                      TARGET_FMT_lx "\n", reg);
464
        return H_PARAMETER;
465
    }
466
    crq_mangle[0] = cpu_to_be64(msg_hi);
467
    crq_mangle[1] = cpu_to_be64(msg_lo);
468

    
469
    if (dev->crq.SendFunc) {
470
        return dev->crq.SendFunc(dev, (uint8_t *)crq_mangle);
471
    }
472

    
473
    return H_HARDWARE;
474
}
475

    
476
static target_ulong h_enable_crq(CPUState *env, sPAPREnvironment *spapr,
477
                                 target_ulong opcode, target_ulong *args)
478
{
479
    target_ulong reg = args[0];
480
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
481

    
482
    if (!dev) {
483
        hcall_dprintf("h_enable_crq on non-existent unit 0x"
484
                      TARGET_FMT_lx "\n", reg);
485
        return H_PARAMETER;
486
    }
487

    
488
    return 0;
489
}
490

    
491
/* Returns negative error, 0 success, or positive: queue full */
492
int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)
493
{
494
    int rc;
495
    uint8_t byte;
496

    
497
    if (!dev->crq.qsize) {
498
        fprintf(stderr, "spapr_vio_send_creq on uninitialized queue\n");
499
        return -1;
500
    }
501

    
502
    /* Maybe do a fast path for KVM just writing to the pages */
503
    rc = spapr_tce_dma_read(dev, dev->crq.qladdr + dev->crq.qnext, &byte, 1);
504
    if (rc) {
505
        return rc;
506
    }
507
    if (byte != 0) {
508
        return 1;
509
    }
510

    
511
    rc = spapr_tce_dma_write(dev, dev->crq.qladdr + dev->crq.qnext + 8,
512
                             &crq[8], 8);
513
    if (rc) {
514
        return rc;
515
    }
516

    
517
    kvmppc_eieio();
518

    
519
    rc = spapr_tce_dma_write(dev, dev->crq.qladdr + dev->crq.qnext, crq, 8);
520
    if (rc) {
521
        return rc;
522
    }
523

    
524
    dev->crq.qnext = (dev->crq.qnext + 16) % dev->crq.qsize;
525

    
526
    if (dev->signal_state & 1) {
527
        qemu_irq_pulse(dev->qirq);
528
    }
529

    
530
    return 0;
531
}
532

    
533
/* "quiesce" handling */
534

    
535
static void spapr_vio_quiesce_one(VIOsPAPRDevice *dev)
536
{
537
    dev->flags &= ~VIO_PAPR_FLAG_DMA_BYPASS;
538

    
539
    if (dev->rtce_table) {
540
        size_t size = (dev->rtce_window_size >> SPAPR_VIO_TCE_PAGE_SHIFT)
541
            * sizeof(VIOsPAPR_RTCE);
542
        memset(dev->rtce_table, 0, size);
543
    }
544

    
545
    dev->crq.qladdr = 0;
546
    dev->crq.qsize = 0;
547
    dev->crq.qnext = 0;
548
}
549

    
550
static void rtas_set_tce_bypass(sPAPREnvironment *spapr, uint32_t token,
551
                                uint32_t nargs, target_ulong args,
552
                                uint32_t nret, target_ulong rets)
553
{
554
    VIOsPAPRBus *bus = spapr->vio_bus;
555
    VIOsPAPRDevice *dev;
556
    uint32_t unit, enable;
557

    
558
    if (nargs != 2) {
559
        rtas_st(rets, 0, -3);
560
        return;
561
    }
562
    unit = rtas_ld(args, 0);
563
    enable = rtas_ld(args, 1);
564
    dev = spapr_vio_find_by_reg(bus, unit);
565
    if (!dev) {
566
        rtas_st(rets, 0, -3);
567
        return;
568
    }
569
    if (enable) {
570
        dev->flags |= VIO_PAPR_FLAG_DMA_BYPASS;
571
    } else {
572
        dev->flags &= ~VIO_PAPR_FLAG_DMA_BYPASS;
573
    }
574

    
575
    rtas_st(rets, 0, 0);
576
}
577

    
578
static void rtas_quiesce(sPAPREnvironment *spapr, uint32_t token,
579
                         uint32_t nargs, target_ulong args,
580
                         uint32_t nret, target_ulong rets)
581
{
582
    VIOsPAPRBus *bus = spapr->vio_bus;
583
    DeviceState *qdev;
584
    VIOsPAPRDevice *dev = NULL;
585

    
586
    if (nargs != 0) {
587
        rtas_st(rets, 0, -3);
588
        return;
589
    }
590

    
591
    QLIST_FOREACH(qdev, &bus->bus.children, sibling) {
592
        dev = (VIOsPAPRDevice *)qdev;
593
        spapr_vio_quiesce_one(dev);
594
    }
595

    
596
    rtas_st(rets, 0, 0);
597
}
598

    
599
static int spapr_vio_busdev_init(DeviceState *qdev, DeviceInfo *qinfo)
600
{
601
    VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
602
    VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
603
    char *id;
604

    
605
    if (asprintf(&id, "%s@%x", info->dt_name, dev->reg) < 0) {
606
        return -1;
607
    }
608

    
609
    dev->qdev.id = id;
610

    
611
    dev->qirq = spapr_allocate_irq(dev->vio_irq_num, &dev->vio_irq_num);
612
    if (!dev->qirq) {
613
        return -1;
614
    }
615

    
616
    rtce_init(dev);
617

    
618
    return info->init(dev);
619
}
620

    
621
void spapr_vio_bus_register_withprop(VIOsPAPRDeviceInfo *info)
622
{
623
    info->qdev.init = spapr_vio_busdev_init;
624
    info->qdev.bus_info = &spapr_vio_bus_info;
625

    
626
    assert(info->qdev.size >= sizeof(VIOsPAPRDevice));
627
    qdev_register(&info->qdev);
628
}
629

    
630
static target_ulong h_vio_signal(CPUState *env, sPAPREnvironment *spapr,
631
                                 target_ulong opcode,
632
                                 target_ulong *args)
633
{
634
    target_ulong reg = args[0];
635
    target_ulong mode = args[1];
636
    VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
637
    VIOsPAPRDeviceInfo *info;
638

    
639
    if (!dev) {
640
        return H_PARAMETER;
641
    }
642

    
643
    info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
644

    
645
    if (mode & ~info->signal_mask) {
646
        return H_PARAMETER;
647
    }
648

    
649
    dev->signal_state = mode;
650

    
651
    return H_SUCCESS;
652
}
653

    
654
VIOsPAPRBus *spapr_vio_bus_init(void)
655
{
656
    VIOsPAPRBus *bus;
657
    BusState *qbus;
658
    DeviceState *dev;
659
    DeviceInfo *qinfo;
660

    
661
    /* Create bridge device */
662
    dev = qdev_create(NULL, "spapr-vio-bridge");
663
    qdev_init_nofail(dev);
664

    
665
    /* Create bus on bridge device */
666

    
667
    qbus = qbus_create(&spapr_vio_bus_info, dev, "spapr-vio");
668
    bus = DO_UPCAST(VIOsPAPRBus, bus, qbus);
669

    
670
    /* hcall-vio */
671
    spapr_register_hypercall(H_VIO_SIGNAL, h_vio_signal);
672

    
673
    /* hcall-tce */
674
    spapr_register_hypercall(H_PUT_TCE, h_put_tce);
675

    
676
    /* hcall-crq */
677
    spapr_register_hypercall(H_REG_CRQ, h_reg_crq);
678
    spapr_register_hypercall(H_FREE_CRQ, h_free_crq);
679
    spapr_register_hypercall(H_SEND_CRQ, h_send_crq);
680
    spapr_register_hypercall(H_ENABLE_CRQ, h_enable_crq);
681

    
682
    /* RTAS calls */
683
    spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
684
    spapr_rtas_register("quiesce", rtas_quiesce);
685

    
686
    for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
687
        VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
688

    
689
        if (qinfo->bus_info != &spapr_vio_bus_info) {
690
            continue;
691
        }
692

    
693
        if (info->hcalls) {
694
            info->hcalls(bus);
695
        }
696
    }
697

    
698
    return bus;
699
}
700

    
701
/* Represents sPAPR hcall VIO devices */
702

    
703
static int spapr_vio_bridge_init(SysBusDevice *dev)
704
{
705
    /* nothing */
706
    return 0;
707
}
708

    
709
static SysBusDeviceInfo spapr_vio_bridge_info = {
710
    .init = spapr_vio_bridge_init,
711
    .qdev.name  = "spapr-vio-bridge",
712
    .qdev.size  = sizeof(SysBusDevice),
713
    .qdev.no_user = 1,
714
};
715

    
716
static void spapr_vio_register_devices(void)
717
{
718
    sysbus_register_withprop(&spapr_vio_bridge_info);
719
}
720

    
721
device_init(spapr_vio_register_devices)
722

    
723
#ifdef CONFIG_FDT
724
int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)
725
{
726
    DeviceState *qdev;
727
    int ret = 0;
728

    
729
    QLIST_FOREACH(qdev, &bus->bus.children, sibling) {
730
        VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
731

    
732
        ret = vio_make_devnode(dev, fdt);
733

    
734
        if (ret < 0) {
735
            return ret;
736
        }
737
    }
738

    
739
    return 0;
740
}
741
#endif /* CONFIG_FDT */