From nobody Tue Feb 10 15:03:07 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 163317314133221.91616506185312; Sat, 2 Oct 2021 04:12:21 -0700 (PDT) Received: from localhost ([::1]:55234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWcwF-0003PM-Vm for importer@patchew.org; Sat, 02 Oct 2021 07:12:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWclC-0004zt-OC for qemu-devel@nongnu.org; Sat, 02 Oct 2021 07:00:56 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]:33210 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 1mWclB-00057t-1O for qemu-devel@nongnu.org; Sat, 02 Oct 2021 07:00:54 -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 1mWckx-00020j-HJ; Sat, 02 Oct 2021 12:00:43 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, laurent@vivier.eu Date: Sat, 2 Oct 2021 12:00:06 +0100 Message-Id: <20211002110007.30825-12-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211002110007.30825-1-mark.cave-ayland@ilande.co.uk> References: <20211002110007.30825-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 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: 1633173142201100003 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 | 81 ++++++++++++++++++++++++++++++++++++++ include/hw/display/macfb.h | 8 ++++ 2 files changed, 89 insertions(+) diff --git a/hw/display/macfb.c b/hw/display/macfb.c index 29f6ad8eba..60a203e67b 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: @@ -449,6 +456,32 @@ 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 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 (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + DAFB_INTR_VBL_PERIOD_NS) / + DAFB_INTR_VBL_PERIOD_NS * DAFB_INTR_VBL_PERIOD_NS; + timer_mod(s->vbl_timer, next_vbl); +} + static void macfb_reset(MacfbState *s) { int i; @@ -477,6 +510,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; @@ -492,6 +528,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: @@ -507,8 +545,25 @@ 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 (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + DAFB_INTR_VBL_PERIOD_NS) / + DAFB_INTR_VBL_PERIOD_NS * DAFB_INTR_VBL_PERIOD_NS; + 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 +641,7 @@ static void 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); } =20 @@ -601,6 +657,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) @@ -622,6 +688,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) @@ -672,6 +751,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