All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergio Lopez <slp@redhat.com>
To: qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, Sergio Lopez <slp@redhat.com>,
	mst@redhat.com, lersek@redhat.com, kraxel@redhat.com,
	pbonzini@redhat.com, imammedo@redhat.com, sgarzare@redhat.com,
	philmd@redhat.com, rth@twiddle.net
Subject: [PATCH v8 10/15] fw_cfg: add "modify" functions for all types
Date: Thu, 10 Oct 2019 16:31:21 +0200	[thread overview]
Message-ID: <20191010143125.67246-12-slp@redhat.com> (raw)
In-Reply-To: <20191010143125.67246-1-slp@redhat.com>

This allows to alter the contents of an already added item.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/nvram/fw_cfg.h | 42 +++++++++++++++++++++++++++++++++++++++
 hw/nvram/fw_cfg.c         | 29 +++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 80e435d303..b5291eefad 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -98,6 +98,20 @@ 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);
 
+/**
+ * fw_cfg_modify_string:
+ * @s: fw_cfg device being modified
+ * @key: selector key value for new fw_cfg item
+ * @value: NUL-terminated ascii string
+ *
+ * Replace the fw_cfg item available by selecting the given key. The new
+ * data will consist of a dynamically allocated copy of the provided string,
+ * including its NUL terminator. The data being replaced, assumed to have
+ * been dynamically allocated during an earlier call to either
+ * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returning.
+ */
+void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value);
+
 /**
  * fw_cfg_add_i16:
  * @s: fw_cfg device being modified
@@ -136,6 +150,20 @@ void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, uint16_t value);
  */
 void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
 
+/**
+ * fw_cfg_modify_i32:
+ * @s: fw_cfg device being modified
+ * @key: selector key value for new fw_cfg item
+ * @value: 32-bit integer
+ *
+ * Replace the fw_cfg item available by selecting the given key. The new
+ * data will consist of a dynamically allocated copy of the given 32-bit
+ * value, converted to little-endian representation. The data being replaced,
+ * assumed to have been dynamically allocated during an earlier call to
+ * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returning.
+ */
+void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value);
+
 /**
  * fw_cfg_add_i64:
  * @s: fw_cfg device being modified
@@ -148,6 +176,20 @@ void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
  */
 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
 
+/**
+ * fw_cfg_modify_i64:
+ * @s: fw_cfg device being modified
+ * @key: selector key value for new fw_cfg item
+ * @value: 64-bit integer
+ *
+ * Replace the fw_cfg item available by selecting the given key. The new
+ * data will consist of a dynamically allocated copy of the given 64-bit
+ * value, converted to little-endian representation. The data being replaced,
+ * assumed to have been dynamically allocated during an earlier call to
+ * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returning.
+ */
+void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value);
+
 /**
  * fw_cfg_add_file:
  * @s: fw_cfg device being modified
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 7dc3ac378e..aef1727250 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -690,6 +690,15 @@ void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
     fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz);
 }
 
+void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value)
+{
+    size_t sz = strlen(value) + 1;
+    char *old;
+
+    old = fw_cfg_modify_bytes_read(s, key, g_memdup(value, sz), sz);
+    g_free(old);
+}
+
 void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
 {
     uint16_t *copy;
@@ -720,6 +729,16 @@ void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
     fw_cfg_add_bytes(s, key, copy, sizeof(value));
 }
 
+void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value)
+{
+    uint32_t *copy, *old;
+
+    copy = g_malloc(sizeof(value));
+    *copy = cpu_to_le32(value);
+    old = fw_cfg_modify_bytes_read(s, key, copy, sizeof(value));
+    g_free(old);
+}
+
 void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
 {
     uint64_t *copy;
@@ -730,6 +749,16 @@ void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
     fw_cfg_add_bytes(s, key, copy, sizeof(value));
 }
 
+void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value)
+{
+    uint64_t *copy, *old;
+
+    copy = g_malloc(sizeof(value));
+    *copy = cpu_to_le64(value);
+    old = fw_cfg_modify_bytes_read(s, key, copy, sizeof(value));
+    g_free(old);
+}
+
 void fw_cfg_set_order_override(FWCfgState *s, int order)
 {
     assert(s->fw_cfg_order_override == 0);
-- 
2.21.0



  parent reply	other threads:[~2019-10-10 14:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 14:31 [PATCH v8 00/15] Introduce the microvm machine type Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 01/15] hw/virtio: Factorize virtio-mmio headers Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 02/15] hw/i386/pc: rename functions shared with non-PC machines Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 03/15] hw/i386/pc: fix code style issues on functions that will be moved out Sergio Lopez
2019-10-10 15:36   ` Philippe Mathieu-Daudé
2019-10-10 14:31 ` [PATCH v8 04/15] hw/i386/pc: replace use of strtol with qemu_strtol in x86_load_linux() Sergio Lopez
2019-10-10 15:47   ` Philippe Mathieu-Daudé
2019-10-11  7:26     ` Sergio Lopez
2019-10-11 15:07       ` Philippe Mathieu-Daudé
2019-10-11 15:16         ` Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 05/15] hw/i386/pc: avoid an assignment in if condition " Sergio Lopez
2019-10-10 15:39   ` Philippe Mathieu-Daudé
2019-10-10 14:31 ` [PATCH v8 06/15] hw/i386/pc: remove commented out code from x86_load_linux() Sergio Lopez
2019-10-10 15:49   ` Philippe Mathieu-Daudé
2019-10-10 14:31 ` Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 07/15] hw/i386/pc: move shared x86 functions to x86.c and export them Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 08/15] hw/i386: split PCMachineState deriving X86MachineState from it Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 09/15] hw/i386: make x86.c independent from PCMachineState Sergio Lopez
2019-10-10 14:31 ` Sergio Lopez [this message]
2019-10-10 14:31 ` [PATCH v8 11/15] hw/intc/apic: reject pic ints if isa_pic == NULL Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 12/15] roms: add microvm-bios (qboot) as binary and git submodule Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 13/15] docs/microvm.rst: document the new microvm machine type Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 14/15] hw/i386: Introduce the " Sergio Lopez
2019-10-10 14:31 ` [PATCH v8 15/15] MAINTAINERS: add microvm related files Sergio Lopez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191010143125.67246-12-slp@redhat.com \
    --to=slp@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sgarzare@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.