From nobody Tue Feb 10 17:14:13 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163338298657383.1507955691327; Mon, 4 Oct 2021 14:29:46 -0700 (PDT) Received: from localhost ([::1]:35752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXVWr-0001oh-Bi for importer@patchew.org; Mon, 04 Oct 2021 17:29:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXVNq-0002Rr-W9 for qemu-devel@nongnu.org; Mon, 04 Oct 2021 17:20:30 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]:35892 helo=mail.default.ilande.bv.iomart.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXVNp-0002R0-8d for qemu-devel@nongnu.org; Mon, 04 Oct 2021 17:20:26 -0400 Received: from [2a00:23c4:8b9d:4100:5d98:71b5:90ca:dad1] (helo=kentang.home) by mail.default.ilande.bv.iomart.io with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXVNZ-0008kv-MA; Mon, 04 Oct 2021 22:20:13 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, laurent@vivier.eu Date: Mon, 4 Oct 2021 22:19:27 +0100 Message-Id: <20211004211928.15803-12-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211004211928.15803-1-mark.cave-ayland@ilande.co.uk> References: <20211004211928.15803-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a00:23c4:8b9d:4100:5d98:71b5:90ca:dad1 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH v2 11/12] macfb: add vertical blank interrupt X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.default.ilande.bv.iomart.io) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.default.ilande.bv.iomart.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633382988905100001 Content-Type: text/plain; charset="utf-8" The MacOS driver expects a 60.15Hz vertical blank interrupt to be generated= by the framebuffer which in turn schedules the mouse driver via the Vertical R= etrace Manager. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier --- hw/display/macfb.c | 83 ++++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 8 ++++ 2 files changed, 91 insertions(+) diff --git a/hw/display/macfb.c b/hw/display/macfb.c index ac5d46fa43..5b8812e9e7 100644 --- a/hw/display/macfb.c +++ b/hw/display/macfb.c @@ -33,9 +33,16 @@ #define DAFB_MODE_CTRL1 0x8 #define DAFB_MODE_CTRL2 0xc #define DAFB_MODE_SENSE 0x1c +#define DAFB_INTR_MASK 0x104 +#define DAFB_INTR_STAT 0x108 +#define DAFB_INTR_CLEAR 0x10c #define DAFB_RESET 0x200 #define DAFB_LUT 0x213 =20 +#define DAFB_INTR_VBL 0x4 + +/* Vertical Blank period (60.15Hz) */ +#define DAFB_INTR_VBL_PERIOD_NS 16625800 =20 /* * Quadra sense codes taken from Apple Technical Note HW26: @@ -450,6 +457,36 @@ static void macfb_update_display(void *opaque) macfb_draw_graphic(s); } =20 +static void macfb_update_irq(MacfbState *s) +{ + uint32_t irq_state =3D s->irq_state & s->irq_mask; + + if (irq_state) { + qemu_irq_raise(s->irq); + } else { + qemu_irq_lower(s->irq); + } +} + +static int64_t macfb_next_vbl(void) +{ + return (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + DAFB_INTR_VBL_PERIOD_N= S) / + DAFB_INTR_VBL_PERIOD_NS * DAFB_INTR_VBL_PERIOD_NS; +} + +static void macfb_vbl_timer(void *opaque) +{ + MacfbState *s =3D opaque; + int64_t next_vbl; + + s->irq_state |=3D DAFB_INTR_VBL; + macfb_update_irq(s); + + /* 60 Hz irq */ + next_vbl =3D macfb_next_vbl(); + timer_mod(s->vbl_timer, next_vbl); +} + static void macfb_reset(MacfbState *s) { int i; @@ -478,6 +515,9 @@ static uint64_t macfb_ctrl_read(void *opaque, case DAFB_MODE_CTRL2: val =3D s->regs[addr >> 2]; break; + case DAFB_INTR_STAT: + val =3D s->irq_state; + break; case DAFB_MODE_SENSE: val =3D macfb_sense_read(s); break; @@ -493,6 +533,8 @@ static void macfb_ctrl_write(void *opaque, unsigned int size) { MacfbState *s =3D opaque; + int64_t next_vbl; + switch (addr) { case DAFB_MODE_VADDR1: case DAFB_MODE_VADDR2: @@ -508,8 +550,23 @@ static void macfb_ctrl_write(void *opaque, case DAFB_MODE_SENSE: macfb_sense_write(s, val); break; + case DAFB_INTR_MASK: + s->irq_mask =3D val; + if (val & DAFB_INTR_VBL) { + next_vbl =3D macfb_next_vbl(); + timer_mod(s->vbl_timer, next_vbl); + } else { + timer_del(s->vbl_timer); + } + break; + case DAFB_INTR_CLEAR: + s->irq_state &=3D ~DAFB_INTR_VBL; + macfb_update_irq(s); + break; case DAFB_RESET: s->palette_current =3D 0; + s->irq_state &=3D ~DAFB_INTR_VBL; + macfb_update_irq(s); break; case DAFB_LUT: s->color_palette[s->palette_current] =3D val; @@ -586,6 +643,7 @@ static bool macfb_common_realize(DeviceState *dev, Macf= bState *s, Error **errp) s->vram_bit_mask =3D MACFB_VRAM_SIZE - 1; memory_region_set_coalescing(&s->mem_vram); =20 + s->vbl_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, macfb_vbl_timer, s); macfb_update_mode(s); return true; } @@ -601,6 +659,16 @@ static void macfb_sysbus_realize(DeviceState *dev, Err= or **errp) =20 sysbus_init_mmio(SYS_BUS_DEVICE(s), &ms->mem_ctrl); sysbus_init_mmio(SYS_BUS_DEVICE(s), &ms->mem_vram); + + qdev_init_gpio_out(dev, &ms->irq, 1); +} + +static void macfb_nubus_set_irq(void *opaque, int n, int level) +{ + MacfbNubusState *s =3D NUBUS_MACFB(opaque); + NubusDevice *nd =3D NUBUS_DEVICE(s); + + nubus_set_irq(nd, level); } =20 static void macfb_nubus_realize(DeviceState *dev, Error **errp) @@ -621,6 +689,19 @@ static void macfb_nubus_realize(DeviceState *dev, Erro= r **errp) =20 memory_region_add_subregion(&nd->slot_mem, DAFB_BASE, &ms->mem_ctrl); memory_region_add_subregion(&nd->slot_mem, VIDEO_BASE, &ms->mem_vram); + + ms->irq =3D qemu_allocate_irq(macfb_nubus_set_irq, s, 0); +} + +static void macfb_nubus_unrealize(DeviceState *dev) +{ + MacfbNubusState *s =3D NUBUS_MACFB(dev); + MacfbNubusDeviceClass *ndc =3D NUBUS_MACFB_GET_CLASS(dev); + MacfbState *ms =3D &s->macfb; + + ndc->parent_unrealize(dev); + + qemu_free_irq(ms->irq); } =20 static void macfb_sysbus_reset(DeviceState *d) @@ -671,6 +752,8 @@ static void macfb_nubus_class_init(ObjectClass *klass, = void *data) =20 device_class_set_parent_realize(dc, macfb_nubus_realize, &ndc->parent_realize); + device_class_set_parent_unrealize(dc, macfb_nubus_unrealize, + &ndc->parent_unrealize); dc->desc =3D "Nubus Macintosh framebuffer"; dc->reset =3D macfb_nubus_reset; dc->vmsd =3D &vmstate_macfb; diff --git a/include/hw/display/macfb.h b/include/hw/display/macfb.h index 0aff0d84d2..e52775aa21 100644 --- a/include/hw/display/macfb.h +++ b/include/hw/display/macfb.h @@ -14,7 +14,9 @@ #define MACFB_H =20 #include "exec/memory.h" +#include "hw/irq.h" #include "ui/console.h" +#include "qemu/timer.h" #include "qom/object.h" =20 typedef enum { @@ -63,6 +65,11 @@ typedef struct MacfbState { =20 uint32_t regs[MACFB_NUM_REGS]; MacFbMode *mode; + + uint32_t irq_state; + uint32_t irq_mask; + QEMUTimer *vbl_timer; + qemu_irq irq; } MacfbState; =20 #define TYPE_MACFB "sysbus-macfb" @@ -81,6 +88,7 @@ struct MacfbNubusDeviceClass { DeviceClass parent_class; =20 DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; }; =20 =20 --=20 2.20.1