From patchwork Tue Jun 7 15:23:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 857482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p57FNGM6019674 for ; Tue, 7 Jun 2011 15:23:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754244Ab1FGPXN (ORCPT ); Tue, 7 Jun 2011 11:23:13 -0400 Received: from filtteri5.pp.htv.fi ([213.243.153.188]:51766 "EHLO filtteri5.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753163Ab1FGPXM (ORCPT ); Tue, 7 Jun 2011 11:23:12 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri5.pp.htv.fi (Postfix) with ESMTP id 3EA355A6244; Tue, 7 Jun 2011 18:23:11 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp4.welho.com ([213.243.153.38]) by localhost (filtteri5.pp.htv.fi [213.243.153.188]) (amavisd-new, port 10024) with ESMTP id dhK6UAg37AiC; Tue, 7 Jun 2011 18:23:10 +0300 (EEST) Received: from localhost.localdomain (cs181148025.pp.htv.fi [82.181.148.25]) by smtp4.welho.com (Postfix) with ESMTP id BF8E85BC005; Tue, 7 Jun 2011 18:23:10 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Cyrill Gorcunov , Ingo Molnar , John Floren , Sasha Levin Subject: [PATCH] kvm tools, ui: Add simple keyboard support to SDL UI Date: Tue, 7 Jun 2011 18:23:09 +0300 Message-Id: <1307460189-8104-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Jun 2011 15:24:57 +0000 (UTC) This patch wires up hw/i8042.c to the SDL UI for simple guest keyboard support. Cc: Cyrill Gorcunov Cc: Ingo Molnar Cc: John Floren Cc: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/kvm-run.c | 1 + tools/kvm/ui/sdl.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 0 deletions(-) diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 8398287..b688ef7 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -643,6 +643,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) } if (sdl) { + kbd__init(kvm); if (fb) sdl__init(fb); } diff --git a/tools/kvm/ui/sdl.c b/tools/kvm/ui/sdl.c index bc69ed9..878df1d 100644 --- a/tools/kvm/ui/sdl.c +++ b/tools/kvm/ui/sdl.c @@ -1,6 +1,7 @@ #include "kvm/sdl.h" #include "kvm/framebuffer.h" +#include "kvm/i8042.h" #include "kvm/util.h" #include @@ -13,6 +14,63 @@ static void sdl__write(struct framebuffer *fb, u64 addr, u8 *data, u32 len) memcpy(&fb->mem[addr - fb->mem_addr], data, len); } +static u8 keymap[255] = { + [10] = 0x16, /* 1 */ + [11] = 0x1e, /* 2 */ + [12] = 0x26, /* 3 */ + [13] = 0x25, /* 4 */ + [14] = 0x27, /* 5 */ + [15] = 0x36, /* 6 */ + [16] = 0x3d, /* 7 */ + [17] = 0x3e, /* 8 */ + [18] = 0x46, /* 9 */ + [19] = 0x45, /* 9 */ + + [22] = 0x66, /* */ + + [24] = 0x15, /* q */ + [25] = 0x1d, /* w */ + [26] = 0x24, /* e */ + [27] = 0x2d, /* r */ + [28] = 0x2c, /* t */ + [29] = 0x35, /* y */ + [30] = 0x3c, /* u */ + [31] = 0x43, /* i */ + [32] = 0x44, /* o */ + [33] = 0x4d, /* p */ + + [36] = 0x5a, /* */ + + [38] = 0x1c, /* a */ + [39] = 0x1b, /* s */ + [40] = 0x23, /* d */ + [41] = 0x2b, /* f */ + [42] = 0x34, /* g */ + [43] = 0x33, /* h */ + [44] = 0x3b, /* j */ + [45] = 0x42, /* k */ + [46] = 0x4b, /* l */ + + [50] = 0x12, /* */ + + [52] = 0x1a, /* z */ + [53] = 0x22, /* x */ + [54] = 0x21, /* c */ + [55] = 0x2a, /* v */ + [56] = 0x32, /* b */ + [57] = 0x31, /* n */ + [58] = 0x3a, /* m */ + + [61] = 0x4e, /* - */ + [62] = 0x59, /* */ + [65] = 0x29, /* */ +}; + +static u8 to_code(u8 scancode) +{ + return keymap[scancode]; +} + static void *sdl__thread(void *p) { Uint32 rmask, gmask, bmask, amask; @@ -43,12 +101,30 @@ static void *sdl__thread(void *p) for (;;) { SDL_BlitSurface(guest_screen, NULL, screen, NULL); SDL_UpdateRect(screen, 0, 0, 0, 0); + while (SDL_PollEvent(&ev)) { switch (ev.type) { + case SDL_KEYDOWN: { + u8 code = to_code(ev.key.keysym.scancode); + if (code) + kbd_queue(code); + else + pr_warning("key '%d' not found in keymap", ev.key.keysym.scancode); + break; + } + case SDL_KEYUP: { + u8 code = to_code(ev.key.keysym.scancode); + if (code) { + kbd_queue(0xf0); + kbd_queue(code); + } + break; + } case SDL_QUIT: goto exit; } } + SDL_Delay(1000 / FRAME_RATE); } exit: