From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrUOy-0001st-AM for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:20:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrUOu-0000zc-6p for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:20:44 -0400 Received: from relay-05.andrew.cmu.edu ([128.2.157.12]:44028 helo=relay.andrew.cmu.edu) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrUOt-0000z3-MT for qemu-devel@nongnu.org; Wed, 28 Oct 2015 13:20:40 -0400 From: "Gabriel L. Somlo" Date: Wed, 28 Oct 2015 13:20:36 -0400 Message-Id: <1446052836-31737-5-git-send-email-somlo@cmu.edu> In-Reply-To: <1446052836-31737-1-git-send-email-somlo@cmu.edu> References: <1446052836-31737-1-git-send-email-somlo@cmu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 4/4] fw_cfg: streamline (non-DMA) read operations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, jordan.l.justen@intel.com, kraxel@redhat.com, pbonzini@redhat.com, markmb@redhat.com, lersek@redhat.com Replace fw_cfg_comb_read(), fw_cfg_data_mem_read(), and fw_cfg_read() with a single method, fw_cfg_data_read(), which works on all possible read sizes (single- or multi-byte). The new method also eliminates redundant validity checks caused by multi-byte reads repeatedly invoking the old single-byte fw_cfg_read() method. Also update trace_fw_cfg_read() prototype to accept a 64-bit value argument. Cc: Laszlo Ersek Cc: Gerd Hoffmann Cc: Marc Mar=C3=AD Signed-off-by: Gabriel Somlo --- hw/nvram/fw_cfg.c | 37 ++++++++++--------------------------- trace-events | 2 +- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 5de6dbc..cd477f9 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -274,32 +274,20 @@ static int fw_cfg_select(FWCfgState *s, uint16_t ke= y) return ret; } =20 -static uint8_t fw_cfg_read(FWCfgState *s) +static uint64_t fw_cfg_data_read(void *opaque, hwaddr addr, unsigned siz= e) { + FWCfgState *s =3D opaque; int arch =3D !!(s->cur_entry & FW_CFG_ARCH_LOCAL); FWCfgEntry *e =3D &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK= ]; - uint8_t ret; - - if (s->cur_entry =3D=3D FW_CFG_INVALID || !e->data || s->cur_offset = >=3D e->len) - ret =3D 0; - else { - ret =3D e->data[s->cur_offset++]; - } - - trace_fw_cfg_read(s, ret); - return ret; -} - -static uint64_t fw_cfg_data_mem_read(void *opaque, hwaddr addr, - unsigned size) -{ - FWCfgState *s =3D opaque; uint64_t value =3D 0; - unsigned i; =20 - for (i =3D 0; i < size; ++i) { - value =3D (value << 8) | fw_cfg_read(s); + if (s->cur_entry !=3D FW_CFG_INVALID && e->data) { + while (size-- && s->cur_offset < e->len) { + value =3D (value << 8) | e->data[s->cur_offset++]; + } } + + trace_fw_cfg_read(s, value); return value; } =20 @@ -451,11 +439,6 @@ static bool fw_cfg_ctl_mem_valid(void *opaque, hwadd= r addr, return is_write && size =3D=3D 2; } =20 -static uint64_t fw_cfg_comb_read(void *opaque, hwaddr addr, - unsigned size) -{ - return fw_cfg_read(opaque); -} =20 static void fw_cfg_comb_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) @@ -483,7 +466,7 @@ static const MemoryRegionOps fw_cfg_ctl_mem_ops =3D { }; =20 static const MemoryRegionOps fw_cfg_data_mem_ops =3D { - .read =3D fw_cfg_data_mem_read, + .read =3D fw_cfg_data_read, .write =3D fw_cfg_data_mem_write, .endianness =3D DEVICE_BIG_ENDIAN, .valid =3D { @@ -494,7 +477,7 @@ static const MemoryRegionOps fw_cfg_data_mem_ops =3D = { }; =20 static const MemoryRegionOps fw_cfg_comb_mem_ops =3D { - .read =3D fw_cfg_comb_read, + .read =3D fw_cfg_data_read, .write =3D fw_cfg_comb_write, .endianness =3D DEVICE_LITTLE_ENDIAN, .valid.accepts =3D fw_cfg_comb_valid, diff --git a/trace-events b/trace-events index bdfe79f..a0eb1d8 100644 --- a/trace-events +++ b/trace-events @@ -196,7 +196,7 @@ ecc_diag_mem_readb(uint64_t addr, uint32_t ret) "Read= diagnostic %"PRId64"=3D %02x =20 # hw/nvram/fw_cfg.c fw_cfg_select(void *s, uint16_t key, int ret) "%p key %d =3D %d" -fw_cfg_read(void *s, uint8_t ret) "%p =3D %d" +fw_cfg_read(void *s, uint64_t ret) "%p =3D %"PRIx64 fw_cfg_add_file(void *s, int index, char *name, size_t len) "%p #%d: %s = (%zd bytes)" =20 # hw/block/hd-geometry.c --=20 2.4.3