* [Qemu-devel] [PATCH 0/2] macio patches
@ 2017-09-20 6:19 Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 1/2] ppc/ide/macio: Add missing registers Mark Cave-Ayland
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2017-09-20 6:19 UTC (permalink / raw)
To: qemu-devel, qemu-ppc, david
Here are the macio patches taken from my previous "ppc: more Mac-related fixups"
patchset with the v2 pmac_ide_ops conversion changes as requested.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Benjamin Herrenschmidt (1):
ppc/ide/macio: Add missing registers
Mark Cave-Ayland (1):
macio: convert pmac_ide_ops from old_mmio
hw/ide/macio.c | 191 +++++++++++++++++++++++++++++---------------------------
hw/ppc/mac.h | 6 +-
2 files changed, 104 insertions(+), 93 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 1/2] ppc/ide/macio: Add missing registers
2017-09-20 6:19 [Qemu-devel] [PATCH 0/2] macio patches Mark Cave-Ayland
@ 2017-09-20 6:20 ` Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 2/2] macio: convert pmac_ide_ops from old_mmio Mark Cave-Ayland
2017-09-20 6:31 ` [Qemu-devel] [PATCH 0/2] macio patches David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2017-09-20 6:20 UTC (permalink / raw)
To: qemu-devel, qemu-ppc, david
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>
---
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 9742c00..db5db39 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 20cbddb..300fc8a 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);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] macio: convert pmac_ide_ops from old_mmio
2017-09-20 6:19 [Qemu-devel] [PATCH 0/2] macio patches Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 1/2] ppc/ide/macio: Add missing registers Mark Cave-Ayland
@ 2017-09-20 6:20 ` Mark Cave-Ayland
2017-09-20 6:31 ` [Qemu-devel] [PATCH 0/2] macio patches David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: Mark Cave-Ayland @ 2017-09-20 6:20 UTC (permalink / raw)
To: qemu-devel, qemu-ppc, david
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/ide/macio.c | 181 +++++++++++++++++++++++---------------------------------
1 file changed, 75 insertions(+), 106 deletions(-)
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index db5db39..18ae952 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -255,131 +255,100 @@ static void pmac_ide_flush(DBDMA_io *io)
}
/* PowerMac IDE memory IO */
-static void pmac_ide_writeb (void *opaque,
- hwaddr addr, uint32_t val)
+static uint64_t pmac_ide_read(void *opaque, hwaddr addr, unsigned size)
{
MACIOIDEState *d = opaque;
-
- addr = (addr & 0xFFF) >> 4;
- switch (addr) {
- case 1 ... 7:
- ide_ioport_write(&d->bus, addr, val);
- break;
- case 8:
- case 22:
- ide_cmd_write(&d->bus, 0, val);
+ uint64_t retval = 0xffffffff;
+ int reg = addr >> 4;
+
+ switch (reg) {
+ case 0x0:
+ if (size == 2) {
+ retval = ide_data_readw(&d->bus, 0);
+ } else if (size == 4) {
+ retval = ide_data_readl(&d->bus, 0);
+ }
break;
- default:
+ case 0x1 ... 0x7:
+ if (size == 1) {
+ retval = ide_ioport_read(&d->bus, reg);
+ }
break;
- }
-}
-
-static uint32_t pmac_ide_readb (void *opaque,hwaddr addr)
-{
- uint8_t retval;
- MACIOIDEState *d = opaque;
-
- addr = (addr & 0xFFF) >> 4;
- switch (addr) {
- case 1 ... 7:
- retval = ide_ioport_read(&d->bus, addr);
+ case 0x8:
+ case 0x16:
+ if (size == 1) {
+ retval = ide_status_read(&d->bus, 0);
+ }
break;
- case 8:
- case 22:
- retval = ide_status_read(&d->bus, 0);
+ case 0x20:
+ if (size == 4) {
+ retval = d->timing_reg;
+ }
break;
- default:
- retval = 0xFF;
+ case 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
+ */
+ if (size == 4) {
+ retval = d->irq_reg;
+ }
break;
}
- return retval;
-}
-static void pmac_ide_writew (void *opaque,
- hwaddr addr, uint32_t val)
-{
- MACIOIDEState *d = opaque;
-
- addr = (addr & 0xFFF) >> 4;
- val = bswap16(val);
- if (addr == 0) {
- ide_data_writew(&d->bus, 0, val);
- }
-}
-
-static uint32_t pmac_ide_readw (void *opaque,hwaddr addr)
-{
- uint16_t retval;
- MACIOIDEState *d = opaque;
-
- addr = (addr & 0xFFF) >> 4;
- if (addr == 0) {
- retval = ide_data_readw(&d->bus, 0);
- } else {
- retval = 0xFFFF;
- }
- retval = bswap16(retval);
return retval;
}
-static void pmac_ide_writel (void *opaque,
- hwaddr addr, uint32_t val)
-{
- MACIOIDEState *d = opaque;
- addr = (addr & 0xFFF) >> 4;
- 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;
- }
- }
-}
-
-static uint32_t pmac_ide_readl (void *opaque,hwaddr addr)
+static void pmac_ide_write(void *opaque, hwaddr addr, uint64_t val,
+ unsigned size)
{
- uint32_t retval;
MACIOIDEState *d = opaque;
-
- 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;
+ int reg = addr >> 4;
+
+ switch (reg) {
+ case 0x0:
+ if (size == 2) {
+ ide_data_writew(&d->bus, 0, val);
+ } else if (size == 4) {
+ ide_data_writel(&d->bus, 0, val);
+ }
+ break;
+ case 0x1 ... 0x7:
+ if (size == 1) {
+ ide_ioport_write(&d->bus, reg, val);
+ }
+ break;
+ case 0x8:
+ case 0x16:
+ if (size == 1) {
+ ide_cmd_write(&d->bus, 0, val);
+ }
+ break;
+ case 0x20:
+ if (size == 4) {
+ d->timing_reg = val;
+ }
+ break;
+ case 0x30:
+ if (size == 4) {
+ if (val & 0x80000000u) {
+ d->irq_reg &= 0x7fffffff;
+ }
+ }
+ break;
}
- retval = bswap32(retval);
- return retval;
}
static const MemoryRegionOps pmac_ide_ops = {
- .old_mmio = {
- .write = {
- pmac_ide_writeb,
- pmac_ide_writew,
- pmac_ide_writel,
- },
- .read = {
- pmac_ide_readb,
- pmac_ide_readw,
- pmac_ide_readl,
- },
- },
- .endianness = DEVICE_NATIVE_ENDIAN,
+ .read = pmac_ide_read,
+ .write = pmac_ide_write,
+ .valid.min_access_size = 1,
+ .valid.max_access_size = 4,
+ .endianness = DEVICE_LITTLE_ENDIAN,
};
static const VMStateDescription vmstate_pmac = {
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] macio patches
2017-09-20 6:19 [Qemu-devel] [PATCH 0/2] macio patches Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 1/2] ppc/ide/macio: Add missing registers Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 2/2] macio: convert pmac_ide_ops from old_mmio Mark Cave-Ayland
@ 2017-09-20 6:31 ` David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2017-09-20 6:31 UTC (permalink / raw)
To: Mark Cave-Ayland; +Cc: qemu-devel, qemu-ppc
[-- Attachment #1: Type: text/plain, Size: 859 bytes --]
On Wed, Sep 20, 2017 at 07:19:59AM +0100, Mark Cave-Ayland wrote:
> Here are the macio patches taken from my previous "ppc: more Mac-related fixups"
> patchset with the v2 pmac_ide_ops conversion changes as requested.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Applied to ppc-for-2.11, thanks.
>
>
> Benjamin Herrenschmidt (1):
> ppc/ide/macio: Add missing registers
>
> Mark Cave-Ayland (1):
> macio: convert pmac_ide_ops from old_mmio
>
> hw/ide/macio.c | 191 +++++++++++++++++++++++++++++---------------------------
> hw/ppc/mac.h | 6 +-
> 2 files changed, 104 insertions(+), 93 deletions(-)
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-09-20 6:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-20 6:19 [Qemu-devel] [PATCH 0/2] macio patches Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 1/2] ppc/ide/macio: Add missing registers Mark Cave-Ayland
2017-09-20 6:20 ` [Qemu-devel] [PATCH 2/2] macio: convert pmac_ide_ops from old_mmio Mark Cave-Ayland
2017-09-20 6:31 ` [Qemu-devel] [PATCH 0/2] macio patches David Gibson
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).