From patchwork Sun Oct 23 18:47:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 9391163 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 6A0DD6086B for ; Sun, 23 Oct 2016 18:48:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DA5A28B38 for ; Sun, 23 Oct 2016 18:48:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5257C28B40; Sun, 23 Oct 2016 18:48: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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 78D6828B3B for ; Sun, 23 Oct 2016 18:48:01 +0000 (UTC) Received: from localhost ([::1]:42040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNoN-00075v-Jh for patchwork-qemu-devel@patchwork.kernel.org; Sun, 23 Oct 2016 14:47:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNno-00075g-4S for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byNnn-000113-3Z for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:24 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:53637) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNnm-00010h-Tl for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:23 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A356C97A7; Sun, 23 Oct 2016 20:47:21 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iNWlvyFZyo1Z; Sun, 23 Oct 2016 20:47:20 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id AA6918E5D; Sun, 23 Oct 2016 20:47:20 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1byNnj-0001Xn-IW; Sun, 23 Oct 2016 20:47:19 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sun, 23 Oct 2016 20:47:17 +0200 Message-Id: <20161023184718.5892-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161023184718.5892-1-samuel.thibault@ens-lyon.org> References: <20161023184718.5892-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PATCH 2/3] Defer BrlAPI tty acquisition to when guest starts using device 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: Samuel Thibault , Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We do not want to catch the BrlAPI input/ouput immediately, but only when the guest has started discussing withour virtual device. This notably fixes input before the guest driver has started. Signed-off-by: Samuel Thibault --- backends/baum.c | 76 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index 9f9f7c0..2905404 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -92,6 +92,7 @@ typedef struct { brlapi_handle_t *brlapi; int brlapi_fd; unsigned int x, y; + bool deferred_init; uint8_t in_buf[BUF_SIZE]; uint8_t in_buf_used; @@ -223,6 +224,44 @@ static const uint8_t nabcc_translation[2][256] = { DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'), }; +/* The guest OS has started discussing with us, finish initializing BrlAPI */ +static int baum_deferred_init(BaumDriverState *baum) +{ +#if defined(CONFIG_SDL) +#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) + SDL_SysWMinfo info; +#endif +#endif + int tty; + + if (baum->deferred_init) { + return 1; + } + + if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) { + brlapi_perror("baum: brlapi__getDisplaySize"); + return 0; + } + +#if defined(CONFIG_SDL) +#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) + memset(&info, 0, sizeof(info)); + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) + tty = info.info.x11.wmwindow; + else +#endif +#endif + tty = BRLAPI_TTY_DEFAULT; + + if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) { + brlapi_perror("baum: brlapi__enterTtyMode"); + return 0; + } + baum->deferred_init = 1; + return 1; +} + /* The serial port can receive more of our data */ static void baum_accept_input(struct CharDriverState *chr) { @@ -449,6 +488,8 @@ static int baum_write(CharDriverState *chr, const uint8_t *buf, int len) return 0; if (!baum->brlapi) return len; + if (!baum_deferred_init(baum)) + return len; while (len) { /* Complete our buffer as much as possible */ @@ -500,6 +541,8 @@ static void baum_chr_read(void *opaque) int ret; if (!baum->brlapi) return; + if (!baum_deferred_init(baum)) + return; while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code); /* Emulate */ @@ -598,12 +641,6 @@ static CharDriverState *chr_baum_init(const char *id, BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - SDL_SysWMinfo info; -#endif -#endif - int tty; chr = qemu_chr_alloc(common, errp); if (!chr) { @@ -626,39 +663,14 @@ static CharDriverState *chr_baum_init(const char *id, brlapi_strerror(brlapi_error_location())); goto fail_handle; } + baum->deferred_init = 0; baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); - if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { - error_setg(errp, "brlapi__getDisplaySize: %s", - brlapi_strerror(brlapi_error_location())); - goto fail; - } - -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - memset(&info, 0, sizeof(info)); - SDL_VERSION(&info.version); - if (SDL_GetWMInfo(&info)) - tty = info.info.x11.wmwindow; - else -#endif -#endif - tty = BRLAPI_TTY_DEFAULT; - - if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { - error_setg(errp, "brlapi__enterTtyMode: %s", - brlapi_strerror(brlapi_error_location())); - goto fail; - } - qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); return chr; -fail: - timer_free(baum->cellCount_timer); - brlapi__closeConnection(handle); fail_handle: g_free(handle); g_free(chr);