qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: agraf@suse.de, groug@kaod.org, mark.cave-ayland@ilande.co.uk,
	balaton@eik.bme.hu, qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 10/26] ppc/ide/macio: Add missing registers
Date: Wed, 27 Sep 2017 17:43:00 +1000	[thread overview]
Message-ID: <20170927074316.4454-11-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20170927074316.4454-1-david@gibson.dropbear.id.au>

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

The timing register exists on all variants of MacIO IDE, we just
store and return its value.

The interrupts register only exists on KeyLargo but it doesn't
hurt to have it. The lack of this register causes MacOS X to
hangs under some circumstances.

Both are 32-bit only. The HW might support smaller access sizes
but no known OS uses them.

Because the core IDE subsystem doesn't provide us with a way
to query the main (level) interrupt state, nor do we have a way
to know that DBDMA issued a (edge) interrupt, we reflect both
through a private pair of qirq's in order to maintain the
register state.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ide/macio.c | 44 +++++++++++++++++++++++++++++++++++++++++---
 hw/ppc/mac.h   |  6 +++++-
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 9742c005d1..db5db390e7 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -331,6 +331,12 @@ static void pmac_ide_writel (void *opaque,
     val = bswap32(val);
     if (addr == 0) {
         ide_data_writel(&d->bus, 0, val);
+    } else if (addr == 0x20) {
+        d->timing_reg = val;
+    } else if (addr == 0x30) {
+        if (val & 0x80000000u) {
+            d->irq_reg &= 0x7fffffff;
+        }
     }
 }
 
@@ -342,6 +348,17 @@ static uint32_t pmac_ide_readl (void *opaque,hwaddr addr)
     addr = (addr & 0xFFF) >> 4;
     if (addr == 0) {
         retval = ide_data_readl(&d->bus, 0);
+    } else if (addr == 0x20) {
+        retval = d->timing_reg;
+    } else if (addr == 0x30) {
+        /* This is an interrupt state register that only exists
+         * in the KeyLargo and later variants. Bit 0x8000_0000
+         * latches the DMA interrupt and has to be written to
+         * clear. Bit 0x4000_0000 is an image of the disk
+         * interrupt. MacOS X relies on this and will hang if
+         * we don't provide at least the disk interrupt
+         */
+        retval = d->irq_reg;
     } else {
         retval = 0xFFFFFFFF;
     }
@@ -426,13 +443,32 @@ static void macio_ide_realizefn(DeviceState *dev, Error **errp)
 {
     MACIOIDEState *s = MACIO_IDE(dev);
 
-    ide_init2(&s->bus, s->irq);
+    ide_init2(&s->bus, s->ide_irq);
 
     /* Register DMA callbacks */
     s->dma.ops = &dbdma_ops;
     s->bus.dma = &s->dma;
 }
 
+static void pmac_ide_irq(void *opaque, int n, int level)
+{
+    MACIOIDEState *s = opaque;
+    uint32_t mask = 0x80000000u >> n;
+
+    /* We need to reflect the IRQ state in the irq register */
+    if (level) {
+        s->irq_reg |= mask;
+    } else {
+        s->irq_reg &= ~mask;
+    }
+
+    if (n) {
+        qemu_set_irq(s->real_ide_irq, level);
+    } else {
+        qemu_set_irq(s->real_dma_irq, level);
+    }
+}
+
 static void macio_ide_initfn(Object *obj)
 {
     SysBusDevice *d = SYS_BUS_DEVICE(obj);
@@ -441,8 +477,10 @@ static void macio_ide_initfn(Object *obj)
     ide_bus_new(&s->bus, sizeof(s->bus), DEVICE(obj), 0, 2);
     memory_region_init_io(&s->mem, obj, &pmac_ide_ops, s, "pmac-ide", 0x1000);
     sysbus_init_mmio(d, &s->mem);
-    sysbus_init_irq(d, &s->irq);
-    sysbus_init_irq(d, &s->dma_irq);
+    sysbus_init_irq(d, &s->real_ide_irq);
+    sysbus_init_irq(d, &s->real_dma_irq);
+    s->dma_irq = qemu_allocate_irq(pmac_ide_irq, s, 0);
+    s->ide_irq = qemu_allocate_irq(pmac_ide_irq, s, 1);
 }
 
 static void macio_ide_class_init(ObjectClass *oc, void *data)
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 20cbddb4e4..300fc8ab68 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -132,7 +132,9 @@ typedef struct MACIOIDEState {
     SysBusDevice parent_obj;
     /*< public >*/
 
-    qemu_irq irq;
+    qemu_irq real_ide_irq;
+    qemu_irq real_dma_irq;
+    qemu_irq ide_irq;
     qemu_irq dma_irq;
 
     MemoryRegion mem;
@@ -140,6 +142,8 @@ typedef struct MACIOIDEState {
     IDEDMA dma;
     void *dbdma;
     bool dma_active;
+    uint32_t timing_reg;
+    uint32_t irq_reg;
 } MACIOIDEState;
 
 void macio_ide_init_drives(MACIOIDEState *ide, DriveInfo **hd_table);
-- 
2.13.5

  parent reply	other threads:[~2017-09-27  7:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27  7:42 [Qemu-devel] [PULL 00/26] ppc-for-2.11 queue 20170927 David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 01/26] ppc/kvm: check some capabilities with kvm_vm_check_extension() David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 02/26] ppc/kvm: drop kvmppc_has_cap_htab_fd() David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 03/26] ohci: Allow sysbus version to be used as a companion David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 04/26] ehci: Add ppc4xx-ehci for the USB 2.0 controller in embedded PPC SoCs David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 05/26] ppc: Add 460EX embedded CPU David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 06/26] ppc4xx: Add more PLB registers David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 07/26] ppc: QOMify g3beige machine David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 08/26] ppc/mac: Advertise a high clock frequency for NewWorld Macs David Gibson
2017-09-27  7:42 ` [Qemu-devel] [PULL 09/26] ppc/mac: More rework of the DBDMA emulation David Gibson
2017-09-27  7:43 ` David Gibson [this message]
2017-09-27  7:43 ` [Qemu-devel] [PULL 11/26] ppc: Fix OpenPIC model David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 12/26] ppc/kvm: change kvmppc_get_htab_fd() to return -errno on error David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 13/26] ppc/kvm: generalize the use of kvmppc_get_htab_fd() David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 14/26] spapr: introduce helpers to migrate HPT chunks and the end marker David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 15/26] ppc/pnv: Improve macro parenthesization David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 16/26] macio: convert pmac_ide_ops from old_mmio David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 17/26] spapr_pci: make index property mandatory David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 18/26] ppc: remove unused CPU definitions David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 19/26] ppc: remove all " David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 20/26] ppc/pnv: check for OPAL firmware file presence David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 21/26] spapr: fix the value of SDR1 in kvmppc_put_books_sregs() David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 22/26] mac_dbdma: remove unused IO fields from DBDMAState David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 23/26] mac_dbdma: QOMify David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 24/26] mac_dbdma: remove DBDMA_init() function David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 25/26] macio: pass channel into MACIOIDEState via qdev property David Gibson
2017-09-27  7:43 ` [Qemu-devel] [PULL 26/26] macio: use object link between MACIO_IDE and MAC_DBDMA object David Gibson
2017-09-27 21:43 ` [Qemu-devel] [PULL 00/26] ppc-for-2.11 queue 20170927 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170927074316.4454-11-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=balaton@eik.bme.hu \
    --cc=benh@kernel.crashing.org \
    --cc=groug@kaod.org \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).