~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/intc/openpic.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "hw/ppc/mac.h"
38
38
#include "hw/pci/pci.h"
39
39
#include "hw/ppc/openpic.h"
 
40
#include "hw/ppc/ppc_e500.h"
40
41
#include "hw/sysbus.h"
41
42
#include "hw/pci/msi.h"
42
43
#include "qemu/bitops.h"
43
 
#include "hw/ppc/ppc.h"
44
44
 
45
45
//#define DEBUG_OPENPIC
46
46
 
57
57
    } while (0)
58
58
 
59
59
#define MAX_CPU     32
60
 
#define MAX_SRC     256
61
 
#define MAX_TMR     4
62
 
#define MAX_IPI     4
63
60
#define MAX_MSI     8
64
 
#define MAX_IRQ     (MAX_SRC + MAX_IPI + MAX_TMR)
65
61
#define VID         0x03 /* MPIC version ID */
66
62
 
67
63
/* OpenPIC capability flags */
78
74
#define OPENPIC_SUMMARY_REG_START   0x3800
79
75
#define OPENPIC_SUMMARY_REG_SIZE    0x800
80
76
#define OPENPIC_SRC_REG_START        0x10000
81
 
#define OPENPIC_SRC_REG_SIZE         (MAX_SRC * 0x20)
 
77
#define OPENPIC_SRC_REG_SIZE         (OPENPIC_MAX_SRC * 0x20)
82
78
#define OPENPIC_CPU_REG_START        0x20000
83
79
#define OPENPIC_CPU_REG_SIZE         0x100 + ((MAX_CPU - 1) * 0x1000)
84
80
 
86
82
#define RAVEN_MAX_CPU      2
87
83
#define RAVEN_MAX_EXT     48
88
84
#define RAVEN_MAX_IRQ     64
89
 
#define RAVEN_MAX_TMR      MAX_TMR
90
 
#define RAVEN_MAX_IPI      MAX_IPI
 
85
#define RAVEN_MAX_TMR      OPENPIC_MAX_TMR
 
86
#define RAVEN_MAX_IPI      OPENPIC_MAX_IPI
91
87
 
92
88
/* Interrupt definitions */
93
89
#define RAVEN_FE_IRQ     (RAVEN_MAX_EXT)     /* Internal functional IRQ */
184
180
 
185
181
static int get_current_cpu(void)
186
182
{
187
 
    CPUState *cpu_single_cpu;
188
 
 
189
 
    if (!cpu_single_env) {
 
183
    if (!current_cpu) {
190
184
        return -1;
191
185
    }
192
186
 
193
 
    cpu_single_cpu = ENV_GET_CPU(cpu_single_env);
194
 
    return cpu_single_cpu->cpu_index;
 
187
    return current_cpu->cpu_index;
195
188
}
196
189
 
197
190
static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr,
209
202
    /* Round up to the nearest 64 IRQs so that the queue length
210
203
     * won't change when moving between 32 and 64 bit hosts.
211
204
     */
212
 
    unsigned long queue[BITS_TO_LONGS((MAX_IRQ + 63) & ~63)];
 
205
    unsigned long queue[BITS_TO_LONGS((OPENPIC_MAX_IRQ + 63) & ~63)];
213
206
    int next;
214
207
    int priority;
215
208
} IRQQueue;
255
248
    uint32_t outputs_active[OPENPIC_OUTPUT_NB];
256
249
} IRQDest;
257
250
 
 
251
#define OPENPIC(obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC)
 
252
 
258
253
typedef struct OpenPICState {
259
 
    SysBusDevice busdev;
 
254
    /*< private >*/
 
255
    SysBusDevice parent_obj;
 
256
    /*< public >*/
 
257
 
260
258
    MemoryRegion mem;
261
259
 
262
260
    /* Behavior control */
283
281
    uint32_t spve; /* Spurious vector register */
284
282
    uint32_t tfrr; /* Timer frequency reporting register */
285
283
    /* Source registers */
286
 
    IRQSource src[MAX_IRQ];
 
284
    IRQSource src[OPENPIC_MAX_IRQ];
287
285
    /* Local registers per output pin */
288
286
    IRQDest dst[MAX_CPU];
289
287
    uint32_t nb_cpus;
291
289
    struct {
292
290
        uint32_t tccr;  /* Global timer current count register */
293
291
        uint32_t tbcr;  /* Global timer base count register */
294
 
    } timers[MAX_TMR];
 
292
    } timers[OPENPIC_MAX_TMR];
295
293
    /* Shared MSI registers */
296
294
    struct {
297
295
        uint32_t msir;   /* Shared Message Signaled Interrupt Register */
503
501
    OpenPICState *opp = opaque;
504
502
    IRQSource *src;
505
503
 
506
 
    if (n_IRQ >= MAX_IRQ) {
 
504
    if (n_IRQ >= OPENPIC_MAX_IRQ) {
507
505
        fprintf(stderr, "%s: IRQ %d out of range\n", __func__, n_IRQ);
508
506
        abort();
509
507
    }
537
535
 
538
536
static void openpic_reset(DeviceState *d)
539
537
{
540
 
    OpenPICState *opp = FROM_SYSBUS(typeof(*opp), SYS_BUS_DEVICE(d));
 
538
    OpenPICState *opp = OPENPIC(d);
541
539
    int i;
542
540
 
543
541
    opp->gcr = GCR_RESET;
576
574
        opp->dst[i].servicing.next = -1;
577
575
    }
578
576
    /* Initialise timers */
579
 
    for (i = 0; i < MAX_TMR; i++) {
 
577
    for (i = 0; i < OPENPIC_MAX_TMR; i++) {
580
578
        opp->timers[i].tccr = 0;
581
579
        opp->timers[i].tbcr = TBCR_CI;
582
580
    }
703
701
    bool mpic_proxy = false;
704
702
 
705
703
    if (val & GCR_RESET) {
706
 
        openpic_reset(&opp->busdev.qdev);
 
704
        openpic_reset(DEVICE(opp));
707
705
        return;
708
706
    }
709
707
 
1182
1180
        IRQ_resetbit(&dst->raised, irq);
1183
1181
    }
1184
1182
 
1185
 
    if ((irq >= opp->irq_ipi0) &&  (irq < (opp->irq_ipi0 + MAX_IPI))) {
 
1183
    if ((irq >= opp->irq_ipi0) &&  (irq < (opp->irq_ipi0 + OPENPIC_MAX_IPI))) {
1186
1184
        src->destmask &= ~(1 << cpu);
1187
1185
        if (src->destmask && !src->level) {
1188
1186
            /* trigger on CPUs that didn't know about it yet */
1381
1379
                        sizeof(opp->dst[i].outputs_active));
1382
1380
    }
1383
1381
 
1384
 
    for (i = 0; i < MAX_TMR; i++) {
 
1382
    for (i = 0; i < OPENPIC_MAX_TMR; i++) {
1385
1383
        qemu_put_be32s(f, &opp->timers[i].tccr);
1386
1384
        qemu_put_be32s(f, &opp->timers[i].tbcr);
1387
1385
    }
1440
1438
                        sizeof(opp->dst[i].outputs_active));
1441
1439
    }
1442
1440
 
1443
 
    for (i = 0; i < MAX_TMR; i++) {
 
1441
    for (i = 0; i < OPENPIC_MAX_TMR; i++) {
1444
1442
        qemu_get_be32s(f, &opp->timers[i].tccr);
1445
1443
        qemu_get_be32s(f, &opp->timers[i].tbcr);
1446
1444
    }
1473
1471
static void fsl_common_init(OpenPICState *opp)
1474
1472
{
1475
1473
    int i;
1476
 
    int virq = MAX_SRC;
 
1474
    int virq = OPENPIC_MAX_SRC;
1477
1475
 
1478
1476
    opp->vid = VID_REVISION_1_2;
1479
1477
    opp->vir = VIR_GENERIC;
1481
1479
    opp->tfrr_reset = 0;
1482
1480
    opp->ivpr_reset = IVPR_MASK_MASK;
1483
1481
    opp->idr_reset = 1 << 0;
1484
 
    opp->max_irq = MAX_IRQ;
 
1482
    opp->max_irq = OPENPIC_MAX_IRQ;
1485
1483
 
1486
1484
    opp->irq_ipi0 = virq;
1487
 
    virq += MAX_IPI;
 
1485
    virq += OPENPIC_MAX_IPI;
1488
1486
    opp->irq_tim0 = virq;
1489
 
    virq += MAX_TMR;
 
1487
    virq += OPENPIC_MAX_TMR;
1490
1488
 
1491
 
    assert(virq <= MAX_IRQ);
 
1489
    assert(virq <= OPENPIC_MAX_IRQ);
1492
1490
 
1493
1491
    opp->irq_msi = 224;
1494
1492
 
1498
1496
    }
1499
1497
 
1500
1498
    /* Internal interrupts, including message and MSI */
1501
 
    for (i = 16; i < MAX_SRC; i++) {
 
1499
    for (i = 16; i < OPENPIC_MAX_SRC; i++) {
1502
1500
        opp->src[i].type = IRQ_TYPE_FSLINT;
1503
1501
        opp->src[i].level = true;
1504
1502
    }
1505
1503
 
1506
1504
    /* timers and IPIs */
1507
 
    for (i = MAX_SRC; i < virq; i++) {
 
1505
    for (i = OPENPIC_MAX_SRC; i < virq; i++) {
1508
1506
        opp->src[i].type = IRQ_TYPE_FSLSPECIAL;
1509
1507
        opp->src[i].level = false;
1510
1508
    }
1515
1513
    while (list->name) {
1516
1514
        assert(*count < ARRAY_SIZE(opp->sub_io_mem));
1517
1515
 
1518
 
        memory_region_init_io(&opp->sub_io_mem[*count], list->ops, opp,
1519
 
                              list->name, list->size);
 
1516
        memory_region_init_io(&opp->sub_io_mem[*count], OBJECT(opp), list->ops,
 
1517
                              opp, list->name, list->size);
1520
1518
 
1521
1519
        memory_region_add_subregion(&opp->mem, list->start_addr,
1522
1520
                                    &opp->sub_io_mem[*count]);
1526
1524
    }
1527
1525
}
1528
1526
 
1529
 
static int openpic_init(SysBusDevice *dev)
1530
 
{
1531
 
    OpenPICState *opp = FROM_SYSBUS(typeof (*opp), dev);
 
1527
static void openpic_init(Object *obj)
 
1528
{
 
1529
    OpenPICState *opp = OPENPIC(obj);
 
1530
 
 
1531
    memory_region_init(&opp->mem, obj, "openpic", 0x40000);
 
1532
}
 
1533
 
 
1534
static void openpic_realize(DeviceState *dev, Error **errp)
 
1535
{
 
1536
    SysBusDevice *d = SYS_BUS_DEVICE(dev);
 
1537
    OpenPICState *opp = OPENPIC(dev);
1532
1538
    int i, j;
1533
1539
    int list_count = 0;
1534
1540
    static const MemReg list_le[] = {
1561
1567
        {NULL}
1562
1568
    };
1563
1569
 
1564
 
    memory_region_init(&opp->mem, "openpic", 0x40000);
1565
 
 
1566
1570
    switch (opp->model) {
1567
1571
    case OPENPIC_MODEL_FSL_MPIC_20:
1568
1572
    default:
1605
1609
        opp->brr1 = -1;
1606
1610
        opp->mpic_mode_mask = GCR_MODE_MIXED;
1607
1611
 
1608
 
        /* Only UP supported today */
1609
1612
        if (opp->nb_cpus != 1) {
1610
 
            return -EINVAL;
 
1613
            error_setg(errp, "Only UP supported today");
 
1614
            return;
1611
1615
        }
1612
1616
 
1613
1617
        map_list(opp, list_le, &list_count);
1617
1621
    for (i = 0; i < opp->nb_cpus; i++) {
1618
1622
        opp->dst[i].irqs = g_new(qemu_irq, OPENPIC_OUTPUT_NB);
1619
1623
        for (j = 0; j < OPENPIC_OUTPUT_NB; j++) {
1620
 
            sysbus_init_irq(dev, &opp->dst[i].irqs[j]);
 
1624
            sysbus_init_irq(d, &opp->dst[i].irqs[j]);
1621
1625
        }
1622
1626
    }
1623
1627
 
1624
 
    register_savevm(&opp->busdev.qdev, "openpic", 0, 2,
 
1628
    register_savevm(dev, "openpic", 0, 2,
1625
1629
                    openpic_save, openpic_load, opp);
1626
1630
 
1627
 
    sysbus_init_mmio(dev, &opp->mem);
1628
 
    qdev_init_gpio_in(&dev->qdev, openpic_set_irq, opp->max_irq);
1629
 
 
1630
 
    return 0;
 
1631
    sysbus_init_mmio(d, &opp->mem);
 
1632
    qdev_init_gpio_in(dev, openpic_set_irq, opp->max_irq);
1631
1633
}
1632
1634
 
1633
1635
static Property openpic_properties[] = {
1636
1638
    DEFINE_PROP_END_OF_LIST(),
1637
1639
};
1638
1640
 
1639
 
static void openpic_class_init(ObjectClass *klass, void *data)
 
1641
static void openpic_class_init(ObjectClass *oc, void *data)
1640
1642
{
1641
 
    DeviceClass *dc = DEVICE_CLASS(klass);
1642
 
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
1643
    DeviceClass *dc = DEVICE_CLASS(oc);
1643
1644
 
1644
 
    k->init = openpic_init;
 
1645
    dc->realize = openpic_realize;
1645
1646
    dc->props = openpic_properties;
1646
1647
    dc->reset = openpic_reset;
1647
1648
}
1648
1649
 
1649
1650
static const TypeInfo openpic_info = {
1650
 
    .name          = "openpic",
 
1651
    .name          = TYPE_OPENPIC,
1651
1652
    .parent        = TYPE_SYS_BUS_DEVICE,
1652
1653
    .instance_size = sizeof(OpenPICState),
 
1654
    .instance_init = openpic_init,
1653
1655
    .class_init    = openpic_class_init,
1654
1656
};
1655
1657