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

« back to all changes in this revision

Viewing changes to hw/ppc/spapr_pci.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:
119
119
    rtas_st(rets, 1, val);
120
120
}
121
121
 
122
 
static void rtas_ibm_read_pci_config(sPAPREnvironment *spapr,
 
122
static void rtas_ibm_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
123
123
                                     uint32_t token, uint32_t nargs,
124
124
                                     target_ulong args,
125
125
                                     uint32_t nret, target_ulong rets)
139
139
    finish_read_pci_config(spapr, buid, addr, size, rets);
140
140
}
141
141
 
142
 
static void rtas_read_pci_config(sPAPREnvironment *spapr,
 
142
static void rtas_read_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
143
143
                                 uint32_t token, uint32_t nargs,
144
144
                                 target_ulong args,
145
145
                                 uint32_t nret, target_ulong rets)
185
185
    rtas_st(rets, 0, 0);
186
186
}
187
187
 
188
 
static void rtas_ibm_write_pci_config(sPAPREnvironment *spapr,
 
188
static void rtas_ibm_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
189
189
                                      uint32_t token, uint32_t nargs,
190
190
                                      target_ulong args,
191
191
                                      uint32_t nret, target_ulong rets)
206
206
    finish_write_pci_config(spapr, buid, addr, size, val, rets);
207
207
}
208
208
 
209
 
static void rtas_write_pci_config(sPAPREnvironment *spapr,
 
209
static void rtas_write_pci_config(PowerPCCPU *cpu, sPAPREnvironment *spapr,
210
210
                                  uint32_t token, uint32_t nargs,
211
211
                                  target_ulong args,
212
212
                                  uint32_t nret, target_ulong rets)
277
277
    }
278
278
}
279
279
 
280
 
static void rtas_ibm_change_msi(sPAPREnvironment *spapr,
 
280
static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,
281
281
                                uint32_t token, uint32_t nargs,
282
282
                                target_ulong args, uint32_t nret,
283
283
                                target_ulong rets)
374
374
    trace_spapr_pci_rtas_ibm_change_msi(func, req_num);
375
375
}
376
376
 
377
 
static void rtas_ibm_query_interrupt_source_number(sPAPREnvironment *spapr,
 
377
static void rtas_ibm_query_interrupt_source_number(PowerPCCPU *cpu,
 
378
                                                   sPAPREnvironment *spapr,
378
379
                                                   uint32_t token,
379
380
                                                   uint32_t nargs,
380
381
                                                   target_ulong args,
439
440
    qemu_set_irq(spapr_phb_lsi_qirq(phb, irq_num), level);
440
441
}
441
442
 
442
 
static uint64_t spapr_io_read(void *opaque, hwaddr addr,
443
 
                              unsigned size)
444
 
{
445
 
    switch (size) {
446
 
    case 1:
447
 
        return cpu_inb(addr);
448
 
    case 2:
449
 
        return cpu_inw(addr);
450
 
    case 4:
451
 
        return cpu_inl(addr);
452
 
    }
453
 
    assert(0);
454
 
}
455
 
 
456
 
static void spapr_io_write(void *opaque, hwaddr addr,
457
 
                           uint64_t data, unsigned size)
458
 
{
459
 
    switch (size) {
460
 
    case 1:
461
 
        cpu_outb(addr, data);
462
 
        return;
463
 
    case 2:
464
 
        cpu_outw(addr, data);
465
 
        return;
466
 
    case 4:
467
 
        cpu_outl(addr, data);
468
 
        return;
469
 
    }
470
 
    assert(0);
471
 
}
472
 
 
473
 
static const MemoryRegionOps spapr_io_ops = {
474
 
    .endianness = DEVICE_LITTLE_ENDIAN,
475
 
    .read = spapr_io_read,
476
 
    .write = spapr_io_write
477
 
};
478
 
 
479
443
/*
480
444
 * MSI/MSIX memory region implementation.
481
445
 * The handler handles both MSI and MSIX.
506
470
/*
507
471
 * PHB PCI device
508
472
 */
509
 
static DMAContext *spapr_pci_dma_context_fn(PCIBus *bus, void *opaque,
510
 
                                            int devfn)
 
473
static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
511
474
{
512
475
    sPAPRPHBState *phb = opaque;
513
476
 
514
 
    return phb->dma;
 
477
    return &phb->iommu_as;
515
478
}
516
479
 
517
480
static int spapr_phb_init(SysBusDevice *s)
518
481
{
 
482
    DeviceState *dev = DEVICE(s);
519
483
    sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
520
484
    PCIHostState *phb = PCI_HOST_BRIDGE(s);
521
485
    const char *busname;
581
545
 
582
546
    /* Initialize memory regions */
583
547
    sprintf(namebuf, "%s.mmio", sphb->dtbusname);
584
 
    memory_region_init(&sphb->memspace, namebuf, INT64_MAX);
 
548
    memory_region_init(&sphb->memspace, OBJECT(sphb), namebuf, INT64_MAX);
585
549
 
586
550
    sprintf(namebuf, "%s.mmio-alias", sphb->dtbusname);
587
 
    memory_region_init_alias(&sphb->memwindow, namebuf, &sphb->memspace,
 
551
    memory_region_init_alias(&sphb->memwindow, OBJECT(sphb),
 
552
                             namebuf, &sphb->memspace,
588
553
                             SPAPR_PCI_MEM_WIN_BUS_OFFSET, sphb->mem_win_size);
589
554
    memory_region_add_subregion(get_system_memory(), sphb->mem_win_addr,
590
555
                                &sphb->memwindow);
598
563
     * system_io works around the problem until all the users of
599
564
     * old_portion are updated */
600
565
    sprintf(namebuf, "%s.io", sphb->dtbusname);
601
 
    memory_region_init(&sphb->iospace, namebuf, SPAPR_PCI_IO_WIN_SIZE);
 
566
    memory_region_init(&sphb->iospace, OBJECT(sphb),
 
567
                       namebuf, SPAPR_PCI_IO_WIN_SIZE);
602
568
    /* FIXME: fix to support multiple PHBs */
603
569
    memory_region_add_subregion(get_system_io(), 0, &sphb->iospace);
604
570
 
605
571
    sprintf(namebuf, "%s.io-alias", sphb->dtbusname);
606
 
    memory_region_init_io(&sphb->iowindow, &spapr_io_ops, sphb,
607
 
                          namebuf, SPAPR_PCI_IO_WIN_SIZE);
 
572
    memory_region_init_alias(&sphb->iowindow, OBJECT(sphb), namebuf,
 
573
                             get_system_io(), 0, SPAPR_PCI_IO_WIN_SIZE);
608
574
    memory_region_add_subregion(get_system_memory(), sphb->io_win_addr,
609
575
                                &sphb->iowindow);
610
576
 
613
579
     * from msi_notify()/msix_notify() */
614
580
    if (msi_supported) {
615
581
        sprintf(namebuf, "%s.msi", sphb->dtbusname);
616
 
        memory_region_init_io(&sphb->msiwindow, &spapr_msi_ops, sphb,
 
582
        memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, sphb,
617
583
                              namebuf, SPAPR_MSIX_MAX_DEVS * 0x10000);
618
584
        memory_region_add_subregion(get_system_memory(), sphb->msi_win_addr,
619
585
                                    &sphb->msiwindow);
631
597
     * since it's unique by construction, and makes the guest visible
632
598
     * BUID clear.
633
599
     */
634
 
    if (s->qdev.id) {
 
600
    if (dev->id) {
635
601
        busname = NULL;
636
602
    } else if (sphb->index == 0) {
637
603
        busname = "pci";
638
604
    } else {
639
605
        busname = sphb->dtbusname;
640
606
    }
641
 
    bus = pci_register_bus(DEVICE(s), busname,
 
607
    bus = pci_register_bus(dev, busname,
642
608
                           pci_spapr_set_irq, pci_spapr_map_irq, sphb,
643
609
                           &sphb->memspace, &sphb->iospace,
644
610
                           PCI_DEVFN(0, 0), PCI_NUM_PINS, TYPE_PCI_BUS);
646
612
 
647
613
    sphb->dma_window_start = 0;
648
614
    sphb->dma_window_size = 0x40000000;
649
 
    sphb->dma = spapr_tce_new_dma_context(sphb->dma_liobn, sphb->dma_window_size);
650
 
    if (!sphb->dma) {
 
615
    sphb->tcet = spapr_tce_new_table(dev, sphb->dma_liobn,
 
616
                                     sphb->dma_window_size);
 
617
    if (!sphb->tcet) {
651
618
        fprintf(stderr, "Unable to create TCE table for %s\n", sphb->dtbusname);
652
619
        return -1;
653
620
    }
654
 
    pci_setup_iommu(bus, spapr_pci_dma_context_fn, sphb);
 
621
    address_space_init(&sphb->iommu_as, spapr_tce_get_iommu(sphb->tcet),
 
622
                       sphb->dtbusname);
 
623
 
 
624
    pci_setup_iommu(bus, spapr_pci_dma_iommu, sphb);
655
625
 
656
626
    QLIST_INSERT_HEAD(&spapr->phbs, sphb, list);
657
627
 
676
646
    sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
677
647
 
678
648
    /* Reset the IOMMU state */
679
 
    spapr_tce_reset(sphb->dma);
 
649
    device_reset(DEVICE(sphb->tcet));
680
650
}
681
651
 
682
652
static Property spapr_phb_properties[] = {
693
663
    DEFINE_PROP_END_OF_LIST(),
694
664
};
695
665
 
 
666
static const VMStateDescription vmstate_spapr_pci_lsi = {
 
667
    .name = "spapr_pci/lsi",
 
668
    .version_id = 1,
 
669
    .minimum_version_id = 1,
 
670
    .minimum_version_id_old = 1,
 
671
    .fields      = (VMStateField []) {
 
672
        VMSTATE_UINT32_EQUAL(irq, struct spapr_pci_lsi),
 
673
 
 
674
        VMSTATE_END_OF_LIST()
 
675
    },
 
676
};
 
677
 
 
678
static const VMStateDescription vmstate_spapr_pci_msi = {
 
679
    .name = "spapr_pci/lsi",
 
680
    .version_id = 1,
 
681
    .minimum_version_id = 1,
 
682
    .minimum_version_id_old = 1,
 
683
    .fields      = (VMStateField []) {
 
684
        VMSTATE_UINT32(config_addr, struct spapr_pci_msi),
 
685
        VMSTATE_UINT32(irq, struct spapr_pci_msi),
 
686
        VMSTATE_UINT32(nvec, struct spapr_pci_msi),
 
687
 
 
688
        VMSTATE_END_OF_LIST()
 
689
    },
 
690
};
 
691
 
 
692
static const VMStateDescription vmstate_spapr_pci = {
 
693
    .name = "spapr_pci",
 
694
    .version_id = 1,
 
695
    .minimum_version_id = 1,
 
696
    .minimum_version_id_old = 1,
 
697
    .fields      = (VMStateField []) {
 
698
        VMSTATE_UINT64_EQUAL(buid, sPAPRPHBState),
 
699
        VMSTATE_UINT32_EQUAL(dma_liobn, sPAPRPHBState),
 
700
        VMSTATE_UINT64_EQUAL(mem_win_addr, sPAPRPHBState),
 
701
        VMSTATE_UINT64_EQUAL(mem_win_size, sPAPRPHBState),
 
702
        VMSTATE_UINT64_EQUAL(io_win_addr, sPAPRPHBState),
 
703
        VMSTATE_UINT64_EQUAL(io_win_size, sPAPRPHBState),
 
704
        VMSTATE_UINT64_EQUAL(msi_win_addr, sPAPRPHBState),
 
705
        VMSTATE_STRUCT_ARRAY(lsi_table, sPAPRPHBState, PCI_NUM_PINS, 0,
 
706
                             vmstate_spapr_pci_lsi, struct spapr_pci_lsi),
 
707
        VMSTATE_STRUCT_ARRAY(msi_table, sPAPRPHBState, SPAPR_MSIX_MAX_DEVS, 0,
 
708
                             vmstate_spapr_pci_msi, struct spapr_pci_msi),
 
709
 
 
710
        VMSTATE_END_OF_LIST()
 
711
    },
 
712
};
 
713
 
 
714
static const char *spapr_phb_root_bus_path(PCIHostState *host_bridge,
 
715
                                           PCIBus *rootbus)
 
716
{
 
717
    sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(host_bridge);
 
718
 
 
719
    return sphb->dtbusname;
 
720
}
 
721
 
696
722
static void spapr_phb_class_init(ObjectClass *klass, void *data)
697
723
{
 
724
    PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
698
725
    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
699
726
    DeviceClass *dc = DEVICE_CLASS(klass);
700
727
 
 
728
    hc->root_bus_path = spapr_phb_root_bus_path;
701
729
    sdc->init = spapr_phb_init;
702
730
    dc->props = spapr_phb_properties;
703
731
    dc->reset = spapr_phb_reset;
 
732
    dc->vmsd = &vmstate_spapr_pci;
704
733
}
705
734
 
706
735
static const TypeInfo spapr_phb_info = {