qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: BALATON Zoltan <balaton@eik.bme.hu>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Bernhard Beschow <shentey@gmail.com>,
	qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	Gerd Hoffmann <kraxel@redhat.com>,
	Daniel Henrique Barboza <danielhb413@gmail.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	philmd@linaro.org, ReneEngel80@emailn.de
Subject: [PATCH] hw/intc/i8259: Implement legacy LTIM Edge/Level Bank Select
Date: Thu,  2 Mar 2023 09:06:26 +0000	[thread overview]
Message-ID: <20230302090626.1085437-1-dwmw2@infradead.org> (raw)
In-Reply-To: <81f53c106bf9584828402ab92e94ac4331c58c7a.camel@infradead.org>

Back in the mists of time, before IBM PS/2 came along with MCA and added
per-pin level control in the ELCR register, the i8259 had a chip-wide
level-mode control in bit 3 of ICW1.

Even in the PIIX3 datasheet from 1996 this is documented as 'This bit is
disabled', but apparently MorphOS is using it in the version of the
i8259 which is in the Pegasos2 board as part of the vt82c686 chipset.

It's easy enough to implement, and I think it's harmless enough to do so
unconditionally.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
---
 hw/intc/i8259.c                 | 10 ++++------
 hw/intc/i8259_common.c          | 24 +++++++++++++++++++++++-
 include/hw/isa/i8259_internal.h |  1 +
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c
index 17910f3bcb..bbae2d87f4 100644
--- a/hw/intc/i8259.c
+++ b/hw/intc/i8259.c
@@ -133,7 +133,7 @@ static void pic_set_irq(void *opaque, int irq, int level)
     }
 #endif
 
-    if (s->elcr & mask) {
+    if (s->ltim || (s->elcr & mask)) {
         /* level triggered */
         if (level) {
             s->irr |= mask;
@@ -167,7 +167,7 @@ static void pic_intack(PICCommonState *s, int irq)
         s->isr |= (1 << irq);
     }
     /* We don't clear a level sensitive interrupt here */
-    if (!(s->elcr & (1 << irq))) {
+    if (!s->ltim && !(s->elcr & (1 << irq))) {
         s->irr &= ~(1 << irq);
     }
     pic_update_irq(s);
@@ -224,6 +224,7 @@ static void pic_reset(DeviceState *dev)
     PICCommonState *s = PIC_COMMON(dev);
 
     s->elcr = 0;
+    s->ltim = 0;
     pic_init_reset(s);
 }
 
@@ -243,10 +244,7 @@ static void pic_ioport_write(void *opaque, hwaddr addr64,
             s->init_state = 1;
             s->init4 = val & 1;
             s->single_mode = val & 2;
-            if (val & 0x08) {
-                qemu_log_mask(LOG_UNIMP,
-                              "i8259: level sensitive irq not supported\n");
-            }
+            s->ltim = val & 8;
         } else if (val & 0x08) {
             if (val & 0x04) {
                 s->poll = 1;
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index af2e4a2241..c931dc2d07 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -51,7 +51,7 @@ void pic_reset_common(PICCommonState *s)
     s->special_fully_nested_mode = 0;
     s->init4 = 0;
     s->single_mode = 0;
-    /* Note: ELCR is not reset */
+    /* Note: ELCR and LTIM are not reset */
 }
 
 static int pic_dispatch_pre_save(void *opaque)
@@ -144,6 +144,24 @@ static void pic_print_info(InterruptStatsProvider *obj, Monitor *mon)
                    s->special_fully_nested_mode);
 }
 
+static bool ltim_state_needed(void *opaque)
+{
+    PICCommonState *s = PIC_COMMON(opaque);
+
+    return !!s->ltim;
+}
+
+static const VMStateDescription vmstate_pic_ltim = {
+    .name = "i8259/ltim",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = ltim_state_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT8(ltim, PICCommonState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const VMStateDescription vmstate_pic_common = {
     .name = "i8259",
     .version_id = 1,
@@ -168,6 +186,10 @@ static const VMStateDescription vmstate_pic_common = {
         VMSTATE_UINT8(single_mode, PICCommonState),
         VMSTATE_UINT8(elcr, PICCommonState),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (const VMStateDescription*[]) {
+        &vmstate_pic_ltim,
+        NULL
     }
 };
 
diff --git a/include/hw/isa/i8259_internal.h b/include/hw/isa/i8259_internal.h
index 155b098452..f9dcc4163e 100644
--- a/include/hw/isa/i8259_internal.h
+++ b/include/hw/isa/i8259_internal.h
@@ -61,6 +61,7 @@ struct PICCommonState {
     uint8_t single_mode; /* true if slave pic is not initialized */
     uint8_t elcr; /* PIIX edge/trigger selection*/
     uint8_t elcr_mask;
+    uint8_t ltim; /* Edge/Level Bank Select (pre-PIIX, chip-wide) */
     qemu_irq int_out[1];
     uint32_t master; /* reflects /SP input pin */
     uint32_t iobase;
-- 
2.39.0



  reply	other threads:[~2023-03-02  9:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01  0:17 [PATCH v5 0/7] Pegasos2 fixes and audio output support BALATON Zoltan
2023-03-01  0:17 ` [PATCH v5 1/7] hw/display/sm501: Add debug property to control pixman usage BALATON Zoltan
2023-03-02 21:51   ` BALATON Zoltan
2023-03-01  0:17 ` [PATCH v5 2/7] Revert "hw/isa/vt82c686: Remove intermediate IRQ forwarder" BALATON Zoltan
2023-03-01  0:33   ` BALATON Zoltan
2023-03-01  6:43     ` Bernhard Beschow
2023-03-01 11:17       ` BALATON Zoltan
2023-03-02 10:41     ` Philippe Mathieu-Daudé
2023-03-02 10:44       ` Philippe Mathieu-Daudé
2023-03-02 12:37       ` BALATON Zoltan
2023-03-02 12:46         ` Philippe Mathieu-Daudé
2023-03-01  0:17 ` [PATCH v5 3/7] hw/isa/vt82c686: Implement PCI IRQ routing BALATON Zoltan
2023-03-01  6:38   ` Bernhard Beschow
2023-03-01 11:15     ` BALATON Zoltan
2023-03-01 21:08       ` Bernhard Beschow
2023-03-01 21:27         ` BALATON Zoltan
2023-03-01  0:17 ` [PATCH v5 4/7] hw/ppc/pegasos2: Fix PCI interrupt routing BALATON Zoltan
2023-03-03  9:17   ` Daniel Henrique Barboza
2023-03-01  0:17 ` [PATCH v5 5/7] hw/isa/vt82c686: Work around missing level sensitive irq in i8259 model BALATON Zoltan
2023-03-01  6:49   ` Bernhard Beschow
2023-03-01 11:27     ` BALATON Zoltan
2023-03-01 11:52       ` David Woodhouse
2023-03-01 13:18         ` BALATON Zoltan
2023-03-01 14:05           ` David Woodhouse
2023-03-01 18:01             ` BALATON Zoltan
2023-03-01 21:53               ` David Woodhouse
2023-03-01 22:47                 ` BALATON Zoltan
2023-03-02  8:59                   ` David Woodhouse
2023-03-02  9:06                     ` David Woodhouse [this message]
2023-03-02  9:58                       ` [PATCH] hw/intc/i8259: Implement legacy LTIM Edge/Level Bank Select David Woodhouse
2023-03-02 12:35                       ` BALATON Zoltan
2023-03-02 21:46                     ` [PATCH v5 5/7] hw/isa/vt82c686: Work around missing level sensitive irq in i8259 model BALATON Zoltan
2023-03-01 20:58             ` Bernhard Beschow
2023-03-01  0:17 ` [PATCH v5 6/7] hw/usb/vt82c686-uhci-pci: Use PCI IRQ routing BALATON Zoltan
2023-03-01  0:17 ` [PATCH v5 7/7] hw/audio/via-ac97: Basic implementation of audio playback BALATON Zoltan
2023-03-02 21:59   ` BALATON Zoltan
2023-03-03  6:57   ` Volker Rümelin

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=20230302090626.1085437-1-dwmw2@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=ReneEngel80@emailn.de \
    --cc=balaton@eik.bme.hu \
    --cc=danielhb413@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=shentey@gmail.com \
    /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).