Blame SOURCES/kvm-fw_cfg-add-write-callback.patch

9bac43
From 57c6cfd7cf03d6fcc26dfd6a2481b8997616739a Mon Sep 17 00:00:00 2001
9bac43
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9bac43
Date: Mon, 27 Nov 2017 22:51:04 +0100
9bac43
Subject: [PATCH 06/21] fw_cfg: add write callback
9bac43
MIME-Version: 1.0
9bac43
Content-Type: text/plain; charset=UTF-8
9bac43
Content-Transfer-Encoding: 8bit
9bac43
9bac43
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Message-id: <20171127225111.24518-3-marcandre.lureau@redhat.com>
9bac43
Patchwork-id: 77922
9bac43
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 2/9] fw_cfg: add write callback
9bac43
Bugzilla: 1398633
9bac43
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9bac43
RH-Acked-by: Andrew Jones <drjones@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Reintroduce the write callback that was removed when write support was
9bac43
removed in commit 023e3148567ac898c7258138f8e86c3c2bb40d07.
9bac43
9bac43
Contrary to the previous callback implementation, the write_cb
9bac43
callback is called whenever a write happened, so handlers must be
9bac43
ready to handle partial write as necessary.
9bac43
9bac43
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
9bac43
(cherry picked from commit 5f9252f7cc12c5cec1b3c6695aca02eb52ea7acc)
9bac43
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/acpi/vmgenid.c         |  2 +-
9bac43
 hw/core/loader.c          |  2 +-
9bac43
 hw/i386/acpi-build.c      |  2 +-
9bac43
 hw/isa/lpc_ich9.c         |  4 ++--
9bac43
 hw/nvram/fw_cfg.c         | 14 ++++++++++----
9bac43
 include/hw/nvram/fw_cfg.h |  3 +++
9bac43
 6 files changed, 18 insertions(+), 9 deletions(-)
9bac43
9bac43
diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c
9bac43
index a32b847..c1e935d 100644
9bac43
--- a/hw/acpi/vmgenid.c
9bac43
+++ b/hw/acpi/vmgenid.c
9bac43
@@ -124,7 +124,7 @@ void vmgenid_add_fw_cfg(VmGenIdState *vms, FWCfgState *s, GArray *guid)
9bac43
     fw_cfg_add_file(s, VMGENID_GUID_FW_CFG_FILE, guid->data,
9bac43
                     VMGENID_FW_CFG_SIZE);
9bac43
     /* Create a read-write fw_cfg file for Address */
9bac43
-    fw_cfg_add_file_callback(s, VMGENID_ADDR_FW_CFG_FILE, NULL, NULL,
9bac43
+    fw_cfg_add_file_callback(s, VMGENID_ADDR_FW_CFG_FILE, NULL, NULL, NULL,
9bac43
                              vms->vmgenid_addr_le,
9bac43
                              ARRAY_SIZE(vms->vmgenid_addr_le), false);
9bac43
 }
9bac43
diff --git a/hw/core/loader.c b/hw/core/loader.c
9bac43
index 4593061..91669d6 100644
9bac43
--- a/hw/core/loader.c
9bac43
+++ b/hw/core/loader.c
9bac43
@@ -1023,7 +1023,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
9bac43
         }
9bac43
 
9bac43
         fw_cfg_add_file_callback(fw_cfg, fw_file_name,
9bac43
-                                 fw_callback, callback_opaque,
9bac43
+                                 fw_callback, NULL, callback_opaque,
9bac43
                                  data, rom->datasize, read_only);
9bac43
     }
9bac43
     return mr;
9bac43
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
9bac43
index e38fff2..a61560f 100644
9bac43
--- a/hw/i386/acpi-build.c
9bac43
+++ b/hw/i386/acpi-build.c
9bac43
@@ -2924,7 +2924,7 @@ void acpi_setup(void)
9bac43
 
9bac43
         build_state->rsdp = g_memdup(tables.rsdp->data, rsdp_size);
9bac43
         fw_cfg_add_file_callback(pcms->fw_cfg, ACPI_BUILD_RSDP_FILE,
9bac43
-                                 acpi_build_update, build_state,
9bac43
+                                 acpi_build_update, NULL, build_state,
9bac43
                                  build_state->rsdp, rsdp_size, true);
9bac43
         build_state->rsdp_mr = NULL;
9bac43
     } else {
9bac43
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
9bac43
index 39f56ba..ec3c9f7 100644
9bac43
--- a/hw/isa/lpc_ich9.c
9bac43
+++ b/hw/isa/lpc_ich9.c
9bac43
@@ -402,12 +402,12 @@ void ich9_lpc_pm_init(PCIDevice *lpc_pci, bool smm_enabled)
9bac43
          * just link them into fw_cfg here.
9bac43
          */
9bac43
         fw_cfg_add_file_callback(fw_cfg, "etc/smi/requested-features",
9bac43
-                                 NULL, NULL,
9bac43
+                                 NULL, NULL, NULL,
9bac43
                                  lpc->smi_guest_features_le,
9bac43
                                  sizeof lpc->smi_guest_features_le,
9bac43
                                  false);
9bac43
         fw_cfg_add_file_callback(fw_cfg, "etc/smi/features-ok",
9bac43
-                                 smi_features_ok_callback, lpc,
9bac43
+                                 smi_features_ok_callback, NULL, lpc,
9bac43
                                  &lpc->smi_features_ok,
9bac43
                                  sizeof lpc->smi_features_ok,
9bac43
                                  true);
9bac43
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
9bac43
index e3bd626..753ac0e 100644
9bac43
--- a/hw/nvram/fw_cfg.c
9bac43
+++ b/hw/nvram/fw_cfg.c
9bac43
@@ -56,6 +56,7 @@ struct FWCfgEntry {
9bac43
     uint8_t *data;
9bac43
     void *callback_opaque;
9bac43
     FWCfgCallback select_cb;
9bac43
+    FWCfgWriteCallback write_cb;
9bac43
 };
9bac43
 
9bac43
 #define JPG_FILE 0
9bac43
@@ -370,6 +371,8 @@ static void fw_cfg_dma_transfer(FWCfgState *s)
9bac43
                     dma_memory_read(s->dma_as, dma.address,
9bac43
                                     &e->data[s->cur_offset], len)) {
9bac43
                     dma.control |= FW_CFG_DMA_CTL_ERROR;
9bac43
+                } else if (e->write_cb) {
9bac43
+                    e->write_cb(e->callback_opaque, s->cur_offset, len);
9bac43
                 }
9bac43
             }
9bac43
 
9bac43
@@ -570,6 +573,7 @@ static const VMStateDescription vmstate_fw_cfg = {
9bac43
 
9bac43
 static void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
9bac43
                                       FWCfgCallback select_cb,
9bac43
+                                      FWCfgWriteCallback write_cb,
9bac43
                                       void *callback_opaque,
9bac43
                                       void *data, size_t len,
9bac43
                                       bool read_only)
9bac43
@@ -584,6 +588,7 @@ static void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
9bac43
     s->entries[arch][key].data = data;
9bac43
     s->entries[arch][key].len = (uint32_t)len;
9bac43
     s->entries[arch][key].select_cb = select_cb;
9bac43
+    s->entries[arch][key].write_cb = write_cb;
9bac43
     s->entries[arch][key].callback_opaque = callback_opaque;
9bac43
     s->entries[arch][key].allow_write = !read_only;
9bac43
 }
9bac43
@@ -610,7 +615,7 @@ static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
9bac43
 
9bac43
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
9bac43
 {
9bac43
-    fw_cfg_add_bytes_callback(s, key, NULL, NULL, data, len, true);
9bac43
+    fw_cfg_add_bytes_callback(s, key, NULL, NULL, NULL, data, len, true);
9bac43
 }
9bac43
 
9bac43
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
9bac43
@@ -737,6 +742,7 @@ static int get_fw_cfg_order(FWCfgState *s, const char *name)
9bac43
 
9bac43
 void fw_cfg_add_file_callback(FWCfgState *s,  const char *filename,
9bac43
                               FWCfgCallback select_cb,
9bac43
+                              FWCfgWriteCallback write_cb,
9bac43
                               void *callback_opaque,
9bac43
                               void *data, size_t len, bool read_only)
9bac43
 {
9bac43
@@ -800,7 +806,7 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char *filename,
9bac43
     }
9bac43
 
9bac43
     fw_cfg_add_bytes_callback(s, FW_CFG_FILE_FIRST + index,
9bac43
-                              select_cb,
9bac43
+                              select_cb, write_cb,
9bac43
                               callback_opaque, data, len,
9bac43
                               read_only);
9bac43
 
9bac43
@@ -815,7 +821,7 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char *filename,
9bac43
 void fw_cfg_add_file(FWCfgState *s,  const char *filename,
9bac43
                      void *data, size_t len)
9bac43
 {
9bac43
-    fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len, true);
9bac43
+    fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
9bac43
 }
9bac43
 
9bac43
 void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
9bac43
@@ -838,7 +844,7 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
9bac43
         }
9bac43
     }
9bac43
     /* add new one */
9bac43
-    fw_cfg_add_file_callback(s, filename, NULL, NULL, data, len, true);
9bac43
+    fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
9bac43
     return NULL;
9bac43
 }
9bac43
 
9bac43
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
9bac43
index f50d068..7ccbae5 100644
9bac43
--- a/include/hw/nvram/fw_cfg.h
9bac43
+++ b/include/hw/nvram/fw_cfg.h
9bac43
@@ -45,6 +45,7 @@ typedef struct FWCfgDmaAccess {
9bac43
 } QEMU_PACKED FWCfgDmaAccess;
9bac43
 
9bac43
 typedef void (*FWCfgCallback)(void *opaque);
9bac43
+typedef void (*FWCfgWriteCallback)(void *opaque, off_t start, size_t len);
9bac43
 
9bac43
 struct FWCfgState {
9bac43
     /*< private >*/
9bac43
@@ -183,6 +184,7 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
9bac43
  * @s: fw_cfg device being modified
9bac43
  * @filename: name of new fw_cfg file item
9bac43
  * @select_cb: callback function when selecting
9bac43
+ * @write_cb: callback function after a write
9bac43
  * @callback_opaque: argument to be passed into callback function
9bac43
  * @data: pointer to start of item data
9bac43
  * @len: size of item data
9bac43
@@ -202,6 +204,7 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,
9bac43
  */
9bac43
 void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
9bac43
                               FWCfgCallback select_cb,
9bac43
+                              FWCfgWriteCallback write_cb,
9bac43
                               void *callback_opaque,
9bac43
                               void *data, size_t len, bool read_only);
9bac43
 
9bac43
-- 
9bac43
1.8.3.1
9bac43