[PATCH v2 10/12] mac_via: make SCSI_DATA (DRQ) bit live rather than latched

Mark Cave-Ayland posted 12 patches 3 years, 11 months ago
Maintainers: "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
There is a newer version of this series
[PATCH v2 10/12] mac_via: make SCSI_DATA (DRQ) bit live rather than latched
Posted by Mark Cave-Ayland 3 years, 11 months ago
The VIA2 on the Q800 machine is not a separate chip as in older Macs but instead
is integrated into the on-board logic. From analysing the SCSI routines in the
MacOS toolbox ROM (and to a lesser extent NetBSD and Linux) the expectation seems
to be that the SCSI_DATA (DRQ) bit is live on the Q800 and not latched.

Fortunately we can use the recently introduced mos6522 last_irq_levels variable
which tracks the edge-triggered state to return the SCSI_DATA (DRQ) bit live to
the guest OS.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/misc/mac_via.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index 3f473c3fcf..d8b35e6ca6 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -906,9 +906,24 @@ static uint64_t mos6522_q800_via2_read(void *opaque, hwaddr addr, unsigned size)
 {
     MOS6522Q800VIA2State *s = MOS6522_Q800_VIA2(opaque);
     MOS6522State *ms = MOS6522(s);
+    uint64_t val;
 
     addr = (addr >> 9) & 0xf;
-    return mos6522_read(ms, addr, size);
+    val = mos6522_read(ms, addr, size);
+
+    switch (addr) {
+    case VIA_REG_IFR:
+        /*
+         * On a Q800 an emulated VIA2 is integrated into the onboard logic. The
+         * expectation of most OSs is that the DRQ bit is live, rather than
+         * latched as it would be on a real VIA so do the same here.
+         */
+        val &= ~VIA2_IRQ_SCSI_DATA;
+        val |= (ms->last_irq_levels & VIA2_IRQ_SCSI_DATA);
+        break;
+    }
+
+    return val;
 }
 
 static void mos6522_q800_via2_write(void *opaque, hwaddr addr, uint64_t val,
-- 
2.20.1


Re: [PATCH v2 10/12] mac_via: make SCSI_DATA (DRQ) bit live rather than latched
Posted by Philippe Mathieu-Daudé 3 years, 11 months ago
On 24/2/22 12:59, Mark Cave-Ayland wrote:
> The VIA2 on the Q800 machine is not a separate chip as in older Macs but instead
> is integrated into the on-board logic. From analysing the SCSI routines in the
> MacOS toolbox ROM (and to a lesser extent NetBSD and Linux) the expectation seems
> to be that the SCSI_DATA (DRQ) bit is live on the Q800 and not latched.
> 
> Fortunately we can use the recently introduced mos6522 last_irq_levels variable
> which tracks the edge-triggered state to return the SCSI_DATA (DRQ) bit live to
> the guest OS.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>   hw/misc/mac_via.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Re: [PATCH v2 10/12] mac_via: make SCSI_DATA (DRQ) bit live rather than latched
Posted by Laurent Vivier 3 years, 11 months ago
Le 24/02/2022 à 12:59, Mark Cave-Ayland a écrit :
> The VIA2 on the Q800 machine is not a separate chip as in older Macs but instead
> is integrated into the on-board logic. From analysing the SCSI routines in the
> MacOS toolbox ROM (and to a lesser extent NetBSD and Linux) the expectation seems
> to be that the SCSI_DATA (DRQ) bit is live on the Q800 and not latched.
> 
> Fortunately we can use the recently introduced mos6522 last_irq_levels variable
> which tracks the edge-triggered state to return the SCSI_DATA (DRQ) bit live to
> the guest OS.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>   hw/misc/mac_via.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)

Reviewed-by: Laurent Vivier <laurent@vivier.eu>