0a122b
From 8ef464d9f69895ad603c8104460ec667892be48c Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <8ef464d9f69895ad603c8104460ec667892be48c.1387298827.git.minovotn@redhat.com>
0a122b
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
From: "Michael S. Tsirkin" <mst@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 15:17:56 +0100
0a122b
Subject: [PATCH 26/56] fw_cfg: interface to trigger callback on read
0a122b
0a122b
RH-Author: Michael S. Tsirkin <mst@redhat.com>
0a122b
Message-id: <1387293161-4085-27-git-send-email-mst@redhat.com>
0a122b
Patchwork-id: 56332
0a122b
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 26/57] fw_cfg: interface to trigger callback on read
0a122b
Bugzilla: 1034876
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
0a122b
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Tested-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
(cherry picked from commit d87072ceeccf4f84a64d4bc59124bcd64286c070)
0a122b
---
0a122b
 include/hw/nvram/fw_cfg.h |  4 ++++
0a122b
 hw/nvram/fw_cfg.c         | 33 ++++++++++++++++++++++++++++-----
0a122b
 2 files changed, 32 insertions(+), 5 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/nvram/fw_cfg.c         | 33 ++++++++++++++++++++++++++++-----
0a122b
 include/hw/nvram/fw_cfg.h |  4 ++++
0a122b
 2 files changed, 32 insertions(+), 5 deletions(-)
0a122b
0a122b
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
0a122b
index 064344d..b865c09 100644
0a122b
--- a/hw/nvram/fw_cfg.c
0a122b
+++ b/hw/nvram/fw_cfg.c
0a122b
@@ -41,6 +41,7 @@ typedef struct FWCfgEntry {
0a122b
     uint8_t *data;
0a122b
     void *callback_opaque;
0a122b
     FWCfgCallback callback;
0a122b
+    FWCfgReadCallback read_callback;
0a122b
 } FWCfgEntry;
0a122b
 
0a122b
 struct FWCfgState {
0a122b
@@ -245,8 +246,12 @@ static uint8_t fw_cfg_read(FWCfgState *s)
0a122b
 
0a122b
     if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
0a122b
         ret = 0;
0a122b
-    else
0a122b
+    else {
0a122b
+        if (e->read_callback) {
0a122b
+            e->read_callback(e->callback_opaque, s->cur_offset);
0a122b
+        }
0a122b
         ret = e->data[s->cur_offset++];
0a122b
+    }
0a122b
 
0a122b
     trace_fw_cfg_read(s, ret);
0a122b
     return ret;
0a122b
@@ -377,7 +382,10 @@ static const VMStateDescription vmstate_fw_cfg = {
0a122b
     }
0a122b
 };
0a122b
 
0a122b
-void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
0a122b
+static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key,
0a122b
+                                           FWCfgReadCallback callback,
0a122b
+                                           void *callback_opaque,
0a122b
+                                           void *data, size_t len)
0a122b
 {
0a122b
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
0a122b
 
0a122b
@@ -387,6 +395,13 @@ void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
0a122b
 
0a122b
     s->entries[arch][key].data = data;
0a122b
     s->entries[arch][key].len = (uint32_t)len;
0a122b
+    s->entries[arch][key].read_callback = callback;
0a122b
+    s->entries[arch][key].callback_opaque = callback_opaque;
0a122b
+}
0a122b
+
0a122b
+void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
0a122b
+{
0a122b
+    fw_cfg_add_bytes_read_callback(s, key, NULL, NULL, data, len);
0a122b
 }
0a122b
 
0a122b
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
0a122b
@@ -440,8 +455,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
0a122b
     s->entries[arch][key].callback = callback;
0a122b
 }
0a122b
 
0a122b
-void fw_cfg_add_file(FWCfgState *s,  const char *filename,
0a122b
-                     void *data, size_t len)
0a122b
+void fw_cfg_add_file_callback(FWCfgState *s,  const char *filename,
0a122b
+                              FWCfgReadCallback callback, void *callback_opaque,
0a122b
+                              void *data, size_t len)
0a122b
 {
0a122b
     int i, index;
0a122b
     size_t dsize;
0a122b
@@ -455,7 +471,8 @@ void fw_cfg_add_file(FWCfgState *s,  const char *filename,
0a122b
     index = be32_to_cpu(s->files->count);
0a122b
     assert(index < FW_CFG_FILE_SLOTS);
0a122b
 
0a122b
-    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
0a122b
+    fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index,
0a122b
+                                   callback, callback_opaque, data, len);
0a122b
 
0a122b
     pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
0a122b
             filename);
0a122b
@@ -473,6 +490,12 @@ void fw_cfg_add_file(FWCfgState *s,  const char *filename,
0a122b
     s->files->count = cpu_to_be32(index+1);
0a122b
 }
0a122b
 
0a122b
+void fw_cfg_add_file(FWCfgState *s,  const char *filename,
0a122b
+                     void *data, size_t len)
0a122b
+{
0a122b
+    fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len);
0a122b
+}
0a122b
+
0a122b
 static void fw_cfg_machine_ready(struct Notifier *n, void *data)
0a122b
 {
0a122b
     size_t len;
0a122b
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
0a122b
index f60dd67..2ab0fc2 100644
0a122b
--- a/include/hw/nvram/fw_cfg.h
0a122b
+++ b/include/hw/nvram/fw_cfg.h
0a122b
@@ -60,6 +60,7 @@ typedef struct FWCfgFiles {
0a122b
 } FWCfgFiles;
0a122b
 
0a122b
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
0a122b
+typedef void (*FWCfgReadCallback)(void *opaque, uint32_t offset);
0a122b
 
0a122b
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
0a122b
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value);
0a122b
@@ -70,6 +71,9 @@ void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
0a122b
                          void *callback_opaque, void *data, size_t len);
0a122b
 void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
0a122b
                      size_t len);
0a122b
+void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
0a122b
+                              FWCfgReadCallback callback, void *callback_opaque,
0a122b
+                              void *data, size_t len);
0a122b
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
0a122b
                         hwaddr crl_addr, hwaddr data_addr);
0a122b
 
0a122b
-- 
0a122b
1.7.11.7
0a122b