From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <lvivier@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Laszlo Ersek" <lersek@redhat.com>, "Li Qiang" <liq3ea@163.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [Qemu-devel] [PATCH v3 4/7] tests: fw_cfg: add a function to get the fw_cfg file
Date: Mon, 20 May 2019 23:36:57 +0200 [thread overview]
Message-ID: <20190520213700.12620-5-philmd@redhat.com> (raw)
In-Reply-To: <20190520213700.12620-1-philmd@redhat.com>
From: Li Qiang <liq3ea@163.com>
This is useful to write qtest about fw_cfg file entry.
Signed-off-by: Li Qiang <liq3ea@163.com>
Acked-by: Thomas Huth <thuth@redhat.com>
Tested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20190424140643.62457-3-liq3ea@163.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
tests/libqos/fw_cfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++
tests/libqos/fw_cfg.h | 2 ++
2 files changed, 47 insertions(+)
diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c
index c6839c53c80..1f46258f96b 100644
--- a/tests/libqos/fw_cfg.c
+++ b/tests/libqos/fw_cfg.c
@@ -16,6 +16,7 @@
#include "libqos/fw_cfg.h"
#include "libqtest.h"
#include "qemu/bswap.h"
+#include "hw/nvram/fw_cfg.h"
void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
{
@@ -59,6 +60,50 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
qtest_writew(fw_cfg->qts, fw_cfg->base, key);
}
+/*
+ * The caller need check the return value. When the return value is
+ * nonzero, it means that some bytes have been transferred.
+ *
+ * If the fw_cfg file in question is smaller than the allocated & passed-in
+ * buffer, then the buffer has been populated only in part.
+ *
+ * If the fw_cfg file in question is larger than the passed-in
+ * buffer, then the return value explains how much room would have been
+ * necessary in total. And, while the caller's buffer has been fully
+ * populated, it has received only a starting slice of the fw_cfg file.
+ */
+size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename,
+ void *data, size_t buflen)
+{
+ uint32_t count;
+ uint32_t i;
+ unsigned char *filesbuf = NULL;
+ size_t dsize;
+ FWCfgFile *pdir_entry;
+ size_t filesize = 0;
+
+ qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count));
+ count = be32_to_cpu(count);
+ dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file);
+ filesbuf = g_malloc(dsize);
+ qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize);
+ pdir_entry = (FWCfgFile *)(filesbuf + sizeof(uint32_t));
+ for (i = 0; i < count; ++i, ++pdir_entry) {
+ if (!strcmp(pdir_entry->name, filename)) {
+ uint32_t len = be32_to_cpu(pdir_entry->size);
+ uint16_t sel = be16_to_cpu(pdir_entry->select);
+ filesize = len;
+ if (len > buflen) {
+ len = buflen;
+ }
+ qfw_cfg_get(fw_cfg, sel, data, len);
+ break;
+ }
+ }
+ g_free(filesbuf);
+ return filesize;
+}
+
static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
{
uint8_t *ptr = data;
diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h
index 60de81e8633..13325cc4ffe 100644
--- a/tests/libqos/fw_cfg.h
+++ b/tests/libqos/fw_cfg.h
@@ -31,6 +31,8 @@ void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void *data, size_t len);
uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key);
uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key);
uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key);
+size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename,
+ void *data, size_t buflen);
QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base);
void mm_fw_cfg_uninit(QFWCFG *fw_cfg);
--
2.20.1
next prev parent reply other threads:[~2019-05-20 21:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 21:36 [Qemu-devel] [PATCH v3 0/7] fw_cfg_test refactor and add two test cases Philippe Mathieu-Daudé
2019-05-20 21:36 ` [Qemu-devel] [PATCH v3 1/7] tests/libqos: Add io_fw_cfg_uninit() and mm_fw_cfg_uninit() Philippe Mathieu-Daudé
2019-05-21 7:16 ` Laszlo Ersek
2019-05-20 21:36 ` [Qemu-devel] [PATCH v3 2/7] tests/libqos: Add pc_fw_cfg_uninit() and use it Philippe Mathieu-Daudé
2019-05-21 7:21 ` Laszlo Ersek
2019-05-20 21:36 ` [Qemu-devel] [PATCH v3 3/7] tests: refactor fw_cfg_test Philippe Mathieu-Daudé
2019-05-20 21:36 ` Philippe Mathieu-Daudé [this message]
2019-05-20 21:36 ` [Qemu-devel] [PATCH v3 5/7] hw/nvram/fw_cfg: Store 'reboot-timeout' as little endian Philippe Mathieu-Daudé
2019-05-20 21:36 ` [Qemu-devel] [PATCH v3 6/7] tests: fw_cfg: add 'reboot-timeout' test case Philippe Mathieu-Daudé
2019-05-20 21:37 ` [Qemu-devel] [PATCH v3 7/7] tests: fw_cfg: add 'splash-time' " Philippe Mathieu-Daudé
2019-05-22 14:07 ` [Qemu-devel] [PATCH v3 0/7] fw_cfg_test refactor and add two test cases Philippe Mathieu-Daudé
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=20190520213700.12620-5-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=kraxel@redhat.com \
--cc=lersek@redhat.com \
--cc=liq3ea@163.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).