From patchwork Tue Jan 23 22:56:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10181133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 54DB46019D for ; Tue, 23 Jan 2018 23:02:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A287287E9 for ; Tue, 23 Jan 2018 23:02:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EA422880D; Tue, 23 Jan 2018 23:02:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81AA6287E9 for ; Tue, 23 Jan 2018 23:02:02 +0000 (UTC) Received: from localhost ([::1]:59592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee7Zp-0005FP-Ag for patchwork-qemu-devel@patchwork.kernel.org; Tue, 23 Jan 2018 18:02:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ee7X1-0003Ka-Ir for qemu-devel@nongnu.org; Tue, 23 Jan 2018 17:59:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ee7Wy-000430-22 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 17:59:07 -0500 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:44382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ee7Wx-00040q-J4 for qemu-devel@nongnu.org; Tue, 23 Jan 2018 17:59:03 -0500 Received: by mail-lf0-x243.google.com with SMTP id v188so2706573lfa.11 for ; Tue, 23 Jan 2018 14:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/QyF1Vwm+8svLryma+BP+Cu5HUfQ0Y0t6jE8PwDRlv4=; b=Zaq8L+l6RUnWShSpYClwuN3mQZKvOAq+jTqI3/ALM1h2CmJig6Mj5G3mYL1pQF7u7c V3FcO4NMcYR+KrKQCttZBobqxphSp3HoPZbHoU7mwNqALeiHpaBXwaXNq0ngJ40oNDry PMR4p09UEkHmufabz1itNIs/oy/MUaHOSA2tk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/QyF1Vwm+8svLryma+BP+Cu5HUfQ0Y0t6jE8PwDRlv4=; b=gXwqFRZ+md8vas1fyyZTvszTmQD0S4MYuR7Tk9uAfK0jO89LZxnDzdxocF+JCdX78C lx3HU6R4iLK/NnOyBhX2yUXH4A0IXr00fJErOALTACntJED9NwDt4EGo+fim8J3XNYEg MLn/cHSRPAboQ4vLsxKAF6iuXWS5P3U2KmXzMZwgltUMIj9FwfHBSTaZg1HnDaITEAo8 rL2oOD0ipgWup9WY8gCsKTaMmStIarSWi0I4TptFZErQDlrUPhGdUpfNrdvMLPb/9WdT OzZyzGn277+cI+XIWLC9v4+8jYUJ13cfjIyKu7CnsAsjJrmt/tybLYns+2QD7U8cyfgy eWuA== X-Gm-Message-State: AKwxytc2c9rqPDwdWtLLLmQWuYmNvUzB+ZX5Hvq8zq4yebfKhdLqDjPF lnsfua5Lp1p+b7iegwFAWzHZA2xXWpY= X-Google-Smtp-Source: AH8x225xiEKntxadi2dFIMzArJdhGcqg5sBPeAqSaPqQtzYFIaJLnKOjZEgO3JaKFaxqIuiDhBXvPA== X-Received: by 10.25.56.13 with SMTP id f13mr2118489lfa.16.1516748341815; Tue, 23 Jan 2018 14:59:01 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id m25sm245424lfc.38.2018.01.23.14.59.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 14:59:01 -0800 (PST) From: Linus Walleij To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 23:56:54 +0100 Message-Id: <20180123225654.5764-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::243 Subject: [Qemu-devel] [PATCH] pl110: Implement vertical compare/next base interrupts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Linus Walleij , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This implements rudimentary support for interrupt generation on the PL110. I am working on a new DRI/KMS driver for Linux and since that uses the blanking interrupt, we need something to fire here. Without any interrupt support Linux waits for a while and then gives ugly messages about the vblank not working in the console (it does not hang perpetually or anything though, DRI is pretty forgiving). I solved it for now by setting up a timer to fire at 60Hz and pull the interrupts for "vertical compare" and "next memory base" at this interval. This works fine and fires roughly the same number of IRQs on QEMU as on the hardware and leaves the console clean and nice. People who want to create more accurate emulation can probably work on top of this if need be. It is certainly closer to the hardware behaviour than what we have today anyway. Cc: Peter Maydell Signed-off-by: Linus Walleij --- hw/display/pl110.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hw/display/pl110.c b/hw/display/pl110.c index 8c7dcc6f0a69..777bb3f44503 100644 --- a/hw/display/pl110.c +++ b/hw/display/pl110.c @@ -12,6 +12,7 @@ #include "ui/console.h" #include "framebuffer.h" #include "ui/pixel_ops.h" +#include "qemu/timer.h" #include "qemu/log.h" #define PL110_CR_EN 0x001 @@ -19,6 +20,8 @@ #define PL110_CR_BEBO 0x200 #define PL110_CR_BEPO 0x400 #define PL110_CR_PWR 0x800 +#define PL110_IE_NB 0x004 +#define PL110_IE_VC 0x008 enum pl110_bppmode { @@ -50,6 +53,7 @@ typedef struct PL110State { MemoryRegion iomem; MemoryRegionSection fbsection; QemuConsole *con; + QEMUTimer *vblank_timer; int version; uint32_t timing[4]; @@ -320,7 +324,23 @@ static void pl110_resize(PL110State *s, int width, int height) /* Update interrupts. */ static void pl110_update(PL110State *s) { - /* TODO: Implement interrupts. */ + /* Raise IRQ if enabled and any status bit is 1 */ + if (s->int_status & s->int_mask) { + qemu_irq_raise(s->irq); + } else { + qemu_irq_lower(s->irq); + } +} + +static void pl110_vblank_interrupt(void *opaque) +{ + PL110State *s = opaque; + + /* Fire the vertical compare and next base IRQs and re-arm */ + s->int_status |= (PL110_IE_NB | PL110_IE_VC); + timer_mod(s->vblank_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 60); + pl110_update(s); } static uint64_t pl110_read(void *opaque, hwaddr offset, @@ -429,6 +449,10 @@ static void pl110_write(void *opaque, hwaddr offset, s->bpp = (val >> 1) & 7; if (pl110_enabled(s)) { qemu_console_resize(s->con, s->cols, s->rows); + timer_mod(s->vblank_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 60); + } else { + timer_del(s->vblank_timer); } break; case 10: /* LCDICR */ @@ -474,6 +498,7 @@ static void pl110_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->iomem, OBJECT(s), &pl110_ops, s, "pl110", 0x1000); sysbus_init_mmio(sbd, &s->iomem); sysbus_init_irq(sbd, &s->irq); + s->vblank_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, pl110_vblank_interrupt, s); qdev_init_gpio_in(dev, pl110_mux_ctrl_set, 1); s->con = graphic_console_init(dev, 0, &pl110_gfx_ops, s); }