From patchwork Tue Mar 19 02:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10858759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A63861575 for ; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D9AD29502 for ; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 813A429504; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6ED3229502 for ; Tue, 19 Mar 2019 02:34:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:50431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Zm-0004fo-QD for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Mar 2019 22:34:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wx-0003As-Hc for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h64Wt-0001QD-QD for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:05 -0400 Received: from m12-15.163.com ([220.181.12.15]:56355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wr-000100-Cq for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=sJG0O/WEVzfGhWdfvC 5LPYeeVQDEFTGSPwj53vie+BE=; b=BRKDvY+WLcglk3e/1gs2nBWjkAENv45HCt 1tu/Tc5vElLT6yq1jcQXXhivvDrGrrx6QLmAiiuqQQfQLJN30mpuIOh1Web1hA0I OpCzxwpnIFMIsoFdbyWWnmfn/R5CrDQXFj8jKorP7VNsxyR1nMJbkMldi3iY2B+W eKwqWl4xA= Received: from test-VirtualBox.hz.ali.com (unknown [42.120.75.35]) by smtp11 (Coremail) with SMTP id D8CowADnLW1GVJBc54WfAw--.32058S3; Tue, 19 Mar 2019 10:30:33 +0800 (CST) From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com Date: Tue, 19 Mar 2019 10:30:29 +0800 Message-Id: <20190319023030.947-2-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190319023030.947-1-liq3ea@163.com> References: <20190319023030.947-1-liq3ea@163.com> X-CM-TRANSID: D8CowADnLW1GVJBc54WfAw--.32058S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr4kZF4xKF4xAw1UGr4fuFg_yoW5Ww1rpF ZIkFy3trZ3G3WfKrnxJw13JF1agrykXr1UW3y3ZFWFyw17Cr15tFsFk34FkryUXr1UZF45 tw4qgFyYkFn7XaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbo7tUUUUU= X-Originating-IP: [42.120.75.35] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBLwl8bVUMIUWzqQAAsQ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.15 Subject: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is useful to write qtest about fw_cfg file entry. Signed-off-by: Li Qiang --- 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 d0889d1e22..2df33df859 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -16,12 +16,57 @@ #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) { fw_cfg->select(fw_cfg, 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_malloc0(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; +} + void qfw_cfg_read_data(QFWCFG *fw_cfg, void *data, size_t len) { fw_cfg->read(fw_cfg, data, len); diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 0353416af0..4996774f7d 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); QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base);