From patchwork Sun Sep 9 02:21:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10593253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A4A813AC for ; Sun, 9 Sep 2018 02:22:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83E0B29E35 for ; Sun, 9 Sep 2018 02:22:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 773C429F0B; Sun, 9 Sep 2018 02:22:32 +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=-7.3 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI, 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 1466F29E35 for ; Sun, 9 Sep 2018 02:22:31 +0000 (UTC) Received: from localhost ([::1]:45820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fypMt-0007BM-0l for patchwork-qemu-devel@patchwork.kernel.org; Sat, 08 Sep 2018 22:22:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fypM4-0005go-Pt for qemu-devel@nongnu.org; Sat, 08 Sep 2018 22:21:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fypM3-0005cb-KI for qemu-devel@nongnu.org; Sat, 08 Sep 2018 22:21:40 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:33227) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fypM3-0005aP-B8 for qemu-devel@nongnu.org; Sat, 08 Sep 2018 22:21:39 -0400 Received: by mail-lj1-x243.google.com with SMTP id s12-v6so15133500ljj.0 for ; Sat, 08 Sep 2018 19:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=S4oDXR2vTrrsXvKcEqD3nC9dmh+8WGePTEoQG8s1PW0=; b=XJkLnv3CrIruR9ho9N1pxX2Aye4f7ragBw3alpHQxKVxmiAR9juyIsN98g7boXsMC8 HulQ0wLD/IfXyIBdTM2Xe8wAtwMc5FGyZ6bA246I2/V0LGE1s3WQJDaAzDuj9nsU5oDb M0Ws5gMNb71YqikwJ2MREZ/+ryTliDGmaz2dJhPZXGks5gB+2F5dD0xY5CV82h3OJjgb sXp34HS+R5/WApjFbXC+ihBqxeGugA0FaepYoSLYRsl9f0eJhRJM+LHSKXZlaVdeDhd3 jjzcr/OO/QGGhOWZ2PU2CDnpiM6Ey9YlOx8pGn4Dn/yfHwy4Xk6+QSDS1V5w3BJqkvsv rBYg== 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=S4oDXR2vTrrsXvKcEqD3nC9dmh+8WGePTEoQG8s1PW0=; b=qna6mKN1IVBmElpyf61vAQFN7rsfZS6GaciNFnebCcuRPgSlGIVtNDgcgOVDjqtQZY pK+FO+AEySVcQlD/nMOhMigeeCDdnBOyUKl9lQIzWpHQqwRxGRumJZFxpkB6oR1hq2dC wjr6wh3E/WXplFvWQ/VlNACyfz+5WUVzrpRK/OiTy4lNweydXNPvYYGFLozfO7CRLEKZ V/iT8j8g42OstJlO75QnoEZwPvEFJDQjDHYsrB+ez3u/C/ClwqB7fPr2dvWkz4rl3Nuh yBnAqmE9SL0IoLSmmOyRtlbqxDH/+QvU8pIUT85Z0f7e8A9C+PBHPDMeURcDaqQOhKGm gVlw== X-Gm-Message-State: APzg51Bwk7sPkTCi/xKssMnyV8NZ2FStZT/zNeXKOSBqF5yA5OmJpDxc p/+sOaASXGfRX3xk44tNDqvJMNmi X-Google-Smtp-Source: ANB0Vda8bOFpwGMcRsLbJALJYAeJojYdczLwUqEqA7IE+PmYxsB7qhoCIKzBq48eih8kdNV1c1wGVw== X-Received: by 2002:a2e:534e:: with SMTP id t14-v6mr9128574ljd.26.1536459697615; Sat, 08 Sep 2018 19:21:37 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net. (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id b10-v6sm2004228lfa.6.2018.09.08.19.21.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Sep 2018 19:21:36 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Sat, 8 Sep 2018 19:21:04 -0700 Message-Id: <20180909022104.5939-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH] target/xtensa: support input from chardev console 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: Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Complete xtensa-semi chardev console implementation: allow reading input characters from file descriptor 0 and call sys_select_one simcall on it. Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 55 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 7aa1d1357bda..f3c23f8625c2 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -34,8 +34,6 @@ #include "qemu/log.h" #include "sysemu/sysemu.h" -static CharBackend *xtensa_sim_console; - enum { TARGET_SYS_exit = 1, TARGET_SYS_read = 3, @@ -153,12 +151,45 @@ static uint32_t errno_h2g(int host_errno) } } +typedef struct SimInputBuffer { + char buffer[16]; + size_t offset; +} SimInputBuffer; + +static CharBackend *xtensa_sim_console; +static SimInputBuffer sim_input_buffer; + +static IOCanReadHandler xtensa_sim_console_can_read; +static int xtensa_sim_console_can_read(void *opaque) +{ + SimInputBuffer *p = opaque; + + return sizeof(p->buffer) - p->offset; +} + +static IOReadHandler xtensa_sim_console_read; +static void xtensa_sim_console_read(void *opaque, const uint8_t *buf, int size) +{ + SimInputBuffer *p = opaque; + size_t copy = sizeof(p->buffer) - p->offset; + + if (size < copy) { + copy = size; + } + memcpy(p->buffer + p->offset, buf, copy); + p->offset += copy; +} + void xtensa_sim_open_console(Chardev *chr) { static CharBackend console; qemu_chr_fe_init(&console, chr, &error_abort); - qemu_chr_fe_set_handlers(&console, NULL, NULL, NULL, NULL, NULL, NULL, true); + qemu_chr_fe_set_handlers(&console, + xtensa_sim_console_can_read, + xtensa_sim_console_read, + NULL, NULL, &sim_input_buffer, + NULL, true); xtensa_sim_console = &console; } @@ -200,6 +231,22 @@ void HELPER(simcall)(CPUXtensaState *env) io_done = qemu_chr_fe_write_all(xtensa_sim_console, buf, io_sz); regs[3] = errno_h2g(errno); + } else if (!is_write && fd == 0) { + if (sim_input_buffer.offset) { + io_done = sim_input_buffer.offset; + if (io_sz < io_done) { + io_done = io_sz; + } + memcpy(buf, sim_input_buffer.buffer, io_done); + memmove(sim_input_buffer.buffer, + sim_input_buffer.buffer + io_done, + sim_input_buffer.offset - io_done); + sim_input_buffer.offset -= io_done; + qemu_chr_fe_accept_input(xtensa_sim_console); + } else { + io_done = -1; + regs[3] = TARGET_EAGAIN; + } } else { qemu_log_mask(LOG_GUEST_ERROR, "%s fd %d is not supported with chardev console\n", @@ -295,6 +342,8 @@ void HELPER(simcall)(CPUXtensaState *env) if (fd < 3 && xtensa_sim_console) { if ((fd == 1 || fd == 2) && rq == SELECT_ONE_WRITE) { regs[2] = 1; + } else if (fd == 0 && rq == SELECT_ONE_READ) { + regs[2] = sim_input_buffer.offset > 0; } else { regs[2] = 0; }