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

« back to all changes in this revision

Viewing changes to hw/scsi/lsi53c895a.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:
184
184
} lsi_request;
185
185
 
186
186
typedef struct {
187
 
    PCIDevice dev;
 
187
    /*< private >*/
 
188
    PCIDevice parent_obj;
 
189
    /*< public >*/
 
190
 
188
191
    MemoryRegion mmio_io;
189
192
    MemoryRegion ram_io;
190
193
    MemoryRegion io_io;
275
278
    uint32_t script_ram[2048];
276
279
} LSIState;
277
280
 
 
281
#define TYPE_LSI53C895A "lsi53c895a"
 
282
 
 
283
#define LSI53C895A(obj) \
 
284
    OBJECT_CHECK(LSIState, (obj), TYPE_LSI53C895A)
 
285
 
278
286
static inline int lsi_irq_on_rsl(LSIState *s)
279
287
{
280
288
    return (s->sien0 & LSI_SIST0_RSL) && (s->scid & LSI_SCID_RRE);
382
390
{
383
391
    uint32_t buf;
384
392
 
385
 
    pci_dma_read(&s->dev, addr, &buf, 4);
 
393
    pci_dma_read(PCI_DEVICE(s), addr, &buf, 4);
386
394
    return cpu_to_le32(buf);
387
395
}
388
396
 
393
401
 
394
402
static void lsi_update_irq(LSIState *s)
395
403
{
 
404
    PCIDevice *d = PCI_DEVICE(s);
396
405
    int level;
397
406
    static int last_level;
398
407
    lsi_request *p;
424
433
                level, s->dstat, s->sist1, s->sist0);
425
434
        last_level = level;
426
435
    }
427
 
    qemu_set_irq(s->dev.irq[0], level);
 
436
    qemu_set_irq(d->irq[0], level);
428
437
 
429
438
    if (!level && lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON)) {
430
439
        DPRINTF("Handled IRQs & disconnected, looking for pending "
520
529
/* Initiate a SCSI layer data transfer.  */
521
530
static void lsi_do_dma(LSIState *s, int out)
522
531
{
 
532
    PCIDevice *pci_dev;
523
533
    uint32_t count;
524
534
    dma_addr_t addr;
525
535
    SCSIDevice *dev;
531
541
        return;
532
542
    }
533
543
 
 
544
    pci_dev = PCI_DEVICE(s);
534
545
    dev = s->current->req->dev;
535
546
    assert(dev);
536
547
 
556
567
    }
557
568
    /* ??? Set SFBR to first data byte.  */
558
569
    if (out) {
559
 
        pci_dma_read(&s->dev, addr, s->current->dma_buf, count);
 
570
        pci_dma_read(pci_dev, addr, s->current->dma_buf, count);
560
571
    } else {
561
 
        pci_dma_write(&s->dev, addr, s->current->dma_buf, count);
 
572
        pci_dma_write(pci_dev, addr, s->current->dma_buf, count);
562
573
    }
563
574
    s->current->dma_len -= count;
564
575
    if (s->current->dma_len == 0) {
653
664
 
654
665
static void lsi_request_cancelled(SCSIRequest *req)
655
666
{
656
 
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
 
667
    LSIState *s = LSI53C895A(req->bus->qbus.parent);
657
668
    lsi_request *p = req->hba_private;
658
669
 
659
670
    req->hba_private = NULL;
692
703
 /* Callback to indicate that the SCSI layer has completed a command.  */
693
704
static void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid)
694
705
{
695
 
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
 
706
    LSIState *s = LSI53C895A(req->bus->qbus.parent);
696
707
    int out;
697
708
 
698
709
    out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
717
728
 /* Callback to indicate that the SCSI layer has completed a transfer.  */
718
729
static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
719
730
{
720
 
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
 
731
    LSIState *s = LSI53C895A(req->bus->qbus.parent);
721
732
    int out;
722
733
 
723
734
    assert(req->hba_private);
753
764
    DPRINTF("Send command len=%d\n", s->dbc);
754
765
    if (s->dbc > 16)
755
766
        s->dbc = 16;
756
 
    pci_dma_read(&s->dev, s->dnad, buf, s->dbc);
 
767
    pci_dma_read(PCI_DEVICE(s), s->dnad, buf, s->dbc);
757
768
    s->sfbr = buf[0];
758
769
    s->command_complete = 0;
759
770
 
804
815
    s->dbc = 1;
805
816
    status = s->status;
806
817
    s->sfbr = status;
807
 
    pci_dma_write(&s->dev, s->dnad, &status, 1);
 
818
    pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
808
819
    lsi_set_phase(s, PHASE_MI);
809
820
    s->msg_action = 1;
810
821
    lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
818
829
    len = s->msg_len;
819
830
    if (len > s->dbc)
820
831
        len = s->dbc;
821
 
    pci_dma_write(&s->dev, s->dnad, s->msg, len);
 
832
    pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len);
822
833
    /* Linux drivers rely on the last byte being in the SIDL.  */
823
834
    s->sidl = s->msg[len - 1];
824
835
    s->msg_len -= len;
850
861
static uint8_t lsi_get_msgbyte(LSIState *s)
851
862
{
852
863
    uint8_t data;
853
 
    pci_dma_read(&s->dev, s->dnad, &data, 1);
 
864
    pci_dma_read(PCI_DEVICE(s), s->dnad, &data, 1);
854
865
    s->dnad++;
855
866
    s->dbc--;
856
867
    return data;
996
1007
#define LSI_BUF_SIZE 4096
997
1008
static void lsi_memcpy(LSIState *s, uint32_t dest, uint32_t src, int count)
998
1009
{
 
1010
    PCIDevice *d = PCI_DEVICE(s);
999
1011
    int n;
1000
1012
    uint8_t buf[LSI_BUF_SIZE];
1001
1013
 
1002
1014
    DPRINTF("memcpy dest 0x%08x src 0x%08x count %d\n", dest, src, count);
1003
1015
    while (count) {
1004
1016
        n = (count > LSI_BUF_SIZE) ? LSI_BUF_SIZE : count;
1005
 
        pci_dma_read(&s->dev, src, buf, n);
1006
 
        pci_dma_write(&s->dev, dest, buf, n);
 
1017
        pci_dma_read(d, src, buf, n);
 
1018
        pci_dma_write(d, dest, buf, n);
1007
1019
        src += n;
1008
1020
        dest += n;
1009
1021
        count -= n;
1029
1041
 
1030
1042
static void lsi_execute_script(LSIState *s)
1031
1043
{
 
1044
    PCIDevice *pci_dev = PCI_DEVICE(s);
1032
1045
    uint32_t insn;
1033
1046
    uint32_t addr, addr_high;
1034
1047
    int opcode;
1071
1084
 
1072
1085
            /* 32-bit Table indirect */
1073
1086
            offset = sxt24(addr);
1074
 
            pci_dma_read(&s->dev, s->dsa + offset, buf, 8);
 
1087
            pci_dma_read(pci_dev, s->dsa + offset, buf, 8);
1075
1088
            /* byte count is stored in bits 0:23 only */
1076
1089
            s->dbc = cpu_to_le32(buf[0]) & 0xffffff;
1077
1090
            s->rbc = s->dbc;
1430
1443
            n = (insn & 7);
1431
1444
            reg = (insn >> 16) & 0xff;
1432
1445
            if (insn & (1 << 24)) {
1433
 
                pci_dma_read(&s->dev, addr, data, n);
 
1446
                pci_dma_read(pci_dev, addr, data, n);
1434
1447
                DPRINTF("Load reg 0x%x size %d addr 0x%08x = %08x\n", reg, n,
1435
1448
                        addr, *(int *)data);
1436
1449
                for (i = 0; i < n; i++) {
1441
1454
                for (i = 0; i < n; i++) {
1442
1455
                    data[i] = lsi_reg_readb(s, reg + i);
1443
1456
                }
1444
 
                pci_dma_write(&s->dev, addr, data, n);
 
1457
                pci_dma_write(pci_dev, addr, data, n);
1445
1458
            }
1446
1459
        }
1447
1460
    }
1726
1739
            lsi_execute_script(s);
1727
1740
        }
1728
1741
        if (val & LSI_ISTAT0_SRST) {
1729
 
            qdev_reset_all(&s->dev.qdev);
 
1742
            qdev_reset_all(DEVICE(s));
1730
1743
        }
1731
1744
        break;
1732
1745
    case 0x16: /* MBOX0 */
1960
1973
 
1961
1974
static void lsi_scsi_reset(DeviceState *dev)
1962
1975
{
1963
 
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, dev);
 
1976
    LSIState *s = LSI53C895A(dev);
1964
1977
 
1965
1978
    lsi_soft_reset(s);
1966
1979
}
1983
1996
    .minimum_version_id_old = 0,
1984
1997
    .pre_save = lsi_pre_save,
1985
1998
    .fields      = (VMStateField []) {
1986
 
        VMSTATE_PCI_DEVICE(dev, LSIState),
 
1999
        VMSTATE_PCI_DEVICE(parent_obj, LSIState),
1987
2000
 
1988
2001
        VMSTATE_INT32(carry, LSIState),
1989
2002
        VMSTATE_INT32(status, LSIState),
2061
2074
 
2062
2075
static void lsi_scsi_uninit(PCIDevice *d)
2063
2076
{
2064
 
    LSIState *s = DO_UPCAST(LSIState, dev, d);
 
2077
    LSIState *s = LSI53C895A(d);
2065
2078
 
2066
2079
    memory_region_destroy(&s->mmio_io);
2067
2080
    memory_region_destroy(&s->ram_io);
2080
2093
 
2081
2094
static int lsi_scsi_init(PCIDevice *dev)
2082
2095
{
2083
 
    LSIState *s = DO_UPCAST(LSIState, dev, dev);
 
2096
    LSIState *s = LSI53C895A(dev);
 
2097
    DeviceState *d = DEVICE(dev);
2084
2098
    uint8_t *pci_conf;
 
2099
    Error *err = NULL;
2085
2100
 
2086
 
    pci_conf = s->dev.config;
 
2101
    pci_conf = dev->config;
2087
2102
 
2088
2103
    /* PCI latency timer = 255 */
2089
2104
    pci_conf[PCI_LATENCY_TIMER] = 0xff;
2090
2105
    /* Interrupt pin A */
2091
2106
    pci_conf[PCI_INTERRUPT_PIN] = 0x01;
2092
2107
 
2093
 
    memory_region_init_io(&s->mmio_io, &lsi_mmio_ops, s, "lsi-mmio", 0x400);
2094
 
    memory_region_init_io(&s->ram_io, &lsi_ram_ops, s, "lsi-ram", 0x2000);
2095
 
    memory_region_init_io(&s->io_io, &lsi_io_ops, s, "lsi-io", 256);
 
2108
    memory_region_init_io(&s->mmio_io, OBJECT(s), &lsi_mmio_ops, s,
 
2109
                          "lsi-mmio", 0x400);
 
2110
    memory_region_init_io(&s->ram_io, OBJECT(s), &lsi_ram_ops, s,
 
2111
                          "lsi-ram", 0x2000);
 
2112
    memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s,
 
2113
                          "lsi-io", 256);
2096
2114
 
2097
 
    pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_io);
2098
 
    pci_register_bar(&s->dev, 1, 0, &s->mmio_io);
2099
 
    pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io);
 
2115
    pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_io);
 
2116
    pci_register_bar(dev, 1, 0, &s->mmio_io);
 
2117
    pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io);
2100
2118
    QTAILQ_INIT(&s->queue);
2101
2119
 
2102
 
    scsi_bus_new(&s->bus, &dev->qdev, &lsi_scsi_info, NULL);
2103
 
    if (!dev->qdev.hotplugged) {
2104
 
        return scsi_bus_legacy_handle_cmdline(&s->bus);
 
2120
    scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL);
 
2121
    if (!d->hotplugged) {
 
2122
        scsi_bus_legacy_handle_cmdline(&s->bus, &err);
 
2123
        if (err != NULL) {
 
2124
            error_free(err);
 
2125
            return -1;
 
2126
        }
2105
2127
    }
2106
2128
    return 0;
2107
2129
}
2119
2141
    k->subsystem_id = 0x1000;
2120
2142
    dc->reset = lsi_scsi_reset;
2121
2143
    dc->vmsd = &vmstate_lsi_scsi;
 
2144
    set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
2122
2145
}
2123
2146
 
2124
2147
static const TypeInfo lsi_info = {
2125
 
    .name          = "lsi53c895a",
 
2148
    .name          = TYPE_LSI53C895A,
2126
2149
    .parent        = TYPE_PCI_DEVICE,
2127
2150
    .instance_size = sizeof(LSIState),
2128
2151
    .class_init    = lsi_class_init,