From patchwork Tue May 25 08:36:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 53515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB63FB7D61 for ; Tue, 25 May 2010 19:08:49 +1000 (EST) Received: from localhost ([127.0.0.1]:55253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGq7x-0007YS-VN for incoming@patchwork.ozlabs.org; Tue, 25 May 2010 05:08:46 -0400 Received: from [140.186.70.92] (port=48373 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGpgh-0003C2-WD for qemu-devel@nongnu.org; Tue, 25 May 2010 04:40:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGpgY-0003ej-SB for qemu-devel@nongnu.org; Tue, 25 May 2010 04:40:35 -0400 Received: from sh.osrg.net ([192.16.179.4]:51699) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGpgX-0003eF-TB for qemu-devel@nongnu.org; Tue, 25 May 2010 04:40:26 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o4P8eJYs010223; Tue, 25 May 2010 17:40:19 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id D2F513E0304; Tue, 25 May 2010 17:40:17 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Date: Tue, 25 May 2010 17:36:54 +0900 Message-Id: <1274776624-16435-15-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1274776624-16435-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1274776624-16435-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 255 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 25 May 2010 17:40:19 +0900 (JST) X-Virus-Scanned: clamav-milter 0.96 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: aliguori@us.ibm.com, mtosatti@redhat.com, avi@redhat.com, Yoshiaki Tamura , ohmura.kei@lab.ntt.co.jp Subject: [Qemu-devel] [RFC PATCH 13/23] Introduce event-tap. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org event-tap controls when to start ft transaction, and inserts callbacks to the net/block. Signed-off-by: Yoshiaki Tamura --- Makefile.target | 1 + event-tap.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ event-tap.h | 32 ++++++++++ 3 files changed, 217 insertions(+), 0 deletions(-) create mode 100644 event-tap.c create mode 100644 event-tap.h diff --git a/Makefile.target b/Makefile.target index 82caf20..a49b21f 100644 --- a/Makefile.target +++ b/Makefile.target @@ -188,6 +188,7 @@ obj-$(CONFIG_KVM) += kvm.o kvm-all.o # MSI-X depends on kvm for interrupt injection, # so moved it from Makefile.objs to Makefile.target for now obj-y += msix.o +obj-y += event-tap.o obj-$(CONFIG_ISA_MMIO) += isa_mmio.o LIBS+=-lz diff --git a/event-tap.c b/event-tap.c new file mode 100644 index 0000000..5d3a338 --- /dev/null +++ b/event-tap.c @@ -0,0 +1,184 @@ +/* + * Event Tap functions for QEMU + * + * Copyright (c) 2010 Nippon Telegraph and Telephone Corporation. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "block.h" +#include "ioport.h" +#include "osdep.h" +#include "hw/hw.h" +#include "net/queue.h" +#include "event-tap.h" + +static enum EVENT_TAP_STATE event_tap_state = EVENT_TAP_OFF; + +typedef struct EventTapIOport { + uint32_t address; + uint32_t data; + int index; +} EventTapIOport; + +#define MMIO_BUF_SIZE 8 + +typedef struct EventTapMMIO { + uint64_t address; + uint8_t buf[MMIO_BUF_SIZE]; + int len; +} EventTapMMIO; + +#define EVENT_TAP_IOPORT 1 +#define EVENT_TAP_MMIO 2 + +typedef struct EventTapLog { + int mode; + union { + EventTapIOport ioport ; + EventTapMMIO mmio; + }; +} EventTapLog; + +static EventTapLog last_event_tap; + +int event_tap_register(int (*cb)(void)) +{ + if (cb == NULL || event_tap_state != EVENT_TAP_OFF) + return -1; + + bdrv_event_tap_register(cb); + qemu_net_event_tap_register(cb); + event_tap_state = EVENT_TAP_ON; + + return 0; +} + +int event_tap_unregister(void) +{ + if (event_tap_state == EVENT_TAP_OFF) + return -1; + + bdrv_event_tap_unregister(); + qemu_net_event_tap_unregister(); + event_tap_state = EVENT_TAP_OFF; + + return 0; +} + +void event_tap_suspend(void) +{ + if (event_tap_state == EVENT_TAP_ON) + event_tap_state = EVENT_TAP_SUSPEND; +} + +void event_tap_resume(void) +{ + if (event_tap_state == EVENT_TAP_SUSPEND) + event_tap_state = EVENT_TAP_ON; +} + +int event_tap_get_state(void) +{ + return event_tap_state; +} + +void event_tap_ioport(int index, uint32_t address, uint32_t data) +{ + if (event_tap_state != EVENT_TAP_ON) { + return; + } + + last_event_tap.mode = EVENT_TAP_IOPORT; + last_event_tap.ioport.index = index; + last_event_tap.ioport.address = address; + last_event_tap.ioport.data = data; +} + +void event_tap_mmio(uint64_t address, uint8_t *buf, int len) +{ + if (event_tap_state != EVENT_TAP_ON || len > MMIO_BUF_SIZE) { + return; + } + + last_event_tap.mode = EVENT_TAP_MMIO; + last_event_tap.mmio.address = address; + last_event_tap.mmio.len = len; + memcpy(last_event_tap.mmio.buf, buf, len); +} + +static void event_tap_reset(void) +{ + memset(&last_event_tap, 0, sizeof(last_event_tap)); +} + +void event_tap_replay(void) +{ + if (event_tap_state != EVENT_TAP_REPLAY) { + return; + } + + switch (last_event_tap.mode) { + case EVENT_TAP_IOPORT: + switch (last_event_tap.ioport.index) { + case 0: + cpu_outb(last_event_tap.ioport.address, last_event_tap.ioport.data); + break; + case 1: + cpu_outw(last_event_tap.ioport.address, last_event_tap.ioport.data); + break; + case 2: + cpu_outl(last_event_tap.ioport.address, last_event_tap.ioport.data); + break; + } + event_tap_reset(); + break; + case EVENT_TAP_MMIO: + cpu_physical_memory_rw(last_event_tap.mmio.address, + last_event_tap.mmio.buf, + last_event_tap.mmio.len, 1); + event_tap_reset(); + break; + } +} + +static void event_tap_save(QEMUFile *f, void *opaque) +{ + qemu_put_byte(f, last_event_tap.mode); + + if (last_event_tap.mode == EVENT_TAP_IOPORT) { + qemu_put_be32(f, last_event_tap.ioport.index); + qemu_put_be32(f, last_event_tap.ioport.address); + qemu_put_byte(f, last_event_tap.ioport.data); + } else { + qemu_put_be64(f, last_event_tap.mmio.address); + qemu_put_byte(f, last_event_tap.mmio.len); + qemu_put_buffer(f, last_event_tap.mmio.buf, last_event_tap.mmio.len); + } +} + +static int event_tap_load(QEMUFile *f, void *opaque, int version_id) +{ + last_event_tap.mode = qemu_get_byte(f); + + if (last_event_tap.mode == EVENT_TAP_IOPORT) { + last_event_tap.ioport.index = qemu_get_be32(f); + last_event_tap.ioport.address = qemu_get_be32(f); + last_event_tap.ioport.data = qemu_get_byte(f); + } else { + last_event_tap.mmio.address = qemu_get_be64(f); + last_event_tap.mmio.len = qemu_get_byte(f); + qemu_get_buffer(f, last_event_tap.mmio.buf, last_event_tap.mmio.len); + } + + event_tap_state = EVENT_TAP_REPLAY; + + return 0; +} + +void event_tap_init(void) +{ + register_savevm("event-tap", 0, 1, + event_tap_save, event_tap_load, &last_event_tap); +} diff --git a/event-tap.h b/event-tap.h new file mode 100644 index 0000000..d5f3042 --- /dev/null +++ b/event-tap.h @@ -0,0 +1,32 @@ +/* + * Event Tap functions for QEMU + * + * Copyright (c) 2010 Nippon Telegraph and Telephone Corporation. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef EVENT_TAP_H +#define EVENT_TAP_H + +#include "qemu-common.h" + +enum EVENT_TAP_STATE { + EVENT_TAP_OFF, + EVENT_TAP_ON, + EVENT_TAP_SUSPEND, + EVENT_TAP_REPLAY, +}; + +int event_tap_register(int (*cb)(void)); +int event_tap_unregister(void); +void event_tap_suspend(void); +void event_tap_resume(void); +int event_tap_get_state(void); +void event_tap_ioport(int index, uint32_t address, uint32_t data); +void event_tap_mmio(uint64_t address, uint8_t *buf, int len); +void event_tap_replay(void); +void event_tap_init(void); + +#endif