From patchwork Mon Oct 7 09:35:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 281050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BE4582C0097 for ; Mon, 7 Oct 2013 20:57:19 +1100 (EST) Received: from localhost ([::1]:58311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7FK-0007W7-DR for incoming@patchwork.ozlabs.org; Mon, 07 Oct 2013 05:36:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7BN-00024v-GD for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VT7BH-0000hZ-Hy for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VT7BH-0000hQ-A7 for qemu-devel@nongnu.org; Mon, 07 Oct 2013 05:32:47 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r979WjAj018168 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Oct 2013 05:32:45 -0400 Received: from redhat.com (vpn1-7-45.ams2.redhat.com [10.36.7.45]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r979WgS3001781; Mon, 7 Oct 2013 05:32:43 -0400 Date: Mon, 7 Oct 2013 12:35:09 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Anthony Liguori Message-ID: <1381138458-6848-6-git-send-email-mst@redhat.com> References: <1381138458-6848-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1381138458-6848-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, imammedo@redhat.com, afaerber@suse.de, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v9 05/27] fw_cfg: interface to trigger callback on read X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Reviewed-by: Gerd Hoffmann Tested-by: Gerd Hoffmann Signed-off-by: Michael S. Tsirkin --- include/hw/nvram/fw_cfg.h | 4 ++++ hw/nvram/fw_cfg.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index f60dd67..2ab0fc2 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -60,6 +60,7 @@ typedef struct FWCfgFiles { } FWCfgFiles; typedef void (*FWCfgCallback)(void *opaque, uint8_t *data); +typedef void (*FWCfgReadCallback)(void *opaque, uint32_t offset); void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len); void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); @@ -70,6 +71,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback, void *callback_opaque, void *data, size_t len); void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data, size_t len); +void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, + FWCfgReadCallback callback, void *callback_opaque, + void *data, size_t len); FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, hwaddr crl_addr, hwaddr data_addr); diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index d0820e5..f5dc3ea 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -42,6 +42,7 @@ typedef struct FWCfgEntry { uint8_t *data; void *callback_opaque; FWCfgCallback callback; + FWCfgReadCallback read_callback; } FWCfgEntry; struct FWCfgState { @@ -249,8 +250,12 @@ static uint8_t fw_cfg_read(FWCfgState *s) if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len) ret = 0; - else + else { + if (e->read_callback) { + e->read_callback(e->callback_opaque, s->cur_offset); + } ret = e->data[s->cur_offset++]; + } trace_fw_cfg_read(s, ret); return ret; @@ -381,7 +386,10 @@ static const VMStateDescription vmstate_fw_cfg = { } }; -void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len) +static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key, + FWCfgReadCallback callback, + void *callback_opaque, + void *data, size_t len) { int arch = !!(key & FW_CFG_ARCH_LOCAL); @@ -391,6 +399,13 @@ void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len) s->entries[arch][key].data = data; s->entries[arch][key].len = (uint32_t)len; + s->entries[arch][key].read_callback = callback; + s->entries[arch][key].callback_opaque = callback_opaque; +} + +void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len) +{ + fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len); } void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value) @@ -444,8 +459,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback, s->entries[arch][key].callback = callback; } -void fw_cfg_add_file(FWCfgState *s, const char *filename, - void *data, size_t len) +void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, + FWCfgReadCallback callback, void *callback_opaque, + void *data, size_t len) { int i, index; size_t dsize; @@ -459,7 +475,8 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, index = be32_to_cpu(s->files->count); assert(index < FW_CFG_FILE_SLOTS); - fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len); + fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index, + callback, callback_opaque, data, len); pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name), filename); @@ -477,6 +494,12 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, s->files->count = cpu_to_be32(index+1); } +void fw_cfg_add_file(FWCfgState *s, const char *filename, + void *data, size_t len) +{ + fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len); +} + static void fw_cfg_machine_ready(struct Notifier *n, void *data) { size_t len;