From patchwork Tue Oct 30 04:28:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10660453 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 E6D6713A4 for ; Tue, 30 Oct 2018 04:30:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D51032A183 for ; Tue, 30 Oct 2018 04:30:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C89ED2A18E; Tue, 30 Oct 2018 04:30:27 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 365322A183 for ; Tue, 30 Oct 2018 04:30:25 +0000 (UTC) Received: from localhost ([::1]:50684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHLfd-0003Ow-0S for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Oct 2018 00:30:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHLeM-0002R0-OK for qemu-devel@nongnu.org; Tue, 30 Oct 2018 00:29:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHLeL-0001ib-R8 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 00:29:06 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:43885) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHLeL-0001hw-JY for qemu-devel@nongnu.org; Tue, 30 Oct 2018 00:29:05 -0400 Received: by mail-pf1-x442.google.com with SMTP id h4-v6so5125989pfi.10 for ; Mon, 29 Oct 2018 21:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EnuGByxCNTfSK93ua6tBaFW3p1nHFsWf2nh0Wbb440M=; b=pFiIWTA/bJfYyxSV7BQFKqLwUsqqfIo17y4WxhEaZR6emnoOr9QGp3tFRqNzf2njcd qkW2oFBuZxVHIClyl0HLsjHnHx74Tf/8l854H3e/XNDL/zsxONjYguY86ZBeD3OkG1YQ Gl2WNWwM/6uym5DkDD09qe7wnPziOBczz7JcBPtBwnlkVSV2c9H2+Q1rbqOexUiE0fWL VfjqXFK0YhwoB4zRqjgK7iS+qk6HD20VsY5cvNawn/mGexUmTnzzcXcsogz/wxpGHa0m iRL1Ebs7B2m+14+Zw+BI5IlG3yksekObZuN2KvPao7idt5uflDF9YCdhcs6KCEcOFd97 OgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EnuGByxCNTfSK93ua6tBaFW3p1nHFsWf2nh0Wbb440M=; b=d1SrdDj26VTcsrhsrSKrqZPxn7UlS0+3JuUQhSYD+4ahWfOh8IFC9C4Coz+e0v6IZm HJA6Pjwvj8Xm5oN8FM2WSOjjE8o/tylbUvuWiip8xx+U78aQx85vevdQeduLnpy15N1R RNx0vyE3vV8mElxjeux12ZRS8sTiAy5YOEFsX2bsjkpFFU1BuMBBrXChtwn9RlC9uIRQ j8R/ItPaygAg7La/LZPIVBd32/sM4pExFoUYjKm8CJh4ncn8GfDvcWeH/P5ZPy3TBPma n0eGPiCHAyPLw2/hPIbykiCsROtW4HhrpxaAuq16eJ5RoTrgk/vWJTHOyweSfuwJmFvO lDFg== X-Gm-Message-State: AGRZ1gJ/RZ8iJ+0TgesZB975zrkMuBz2+zdLoZ9YhIQhBAEX/CUwRQvX xIK8U8cvPKPytdhgIjVS0i6C14So0O8= X-Google-Smtp-Source: AJdET5dRwf0uIrncAGuGi1/i0xe8xloe8M27iVTdUHEV0+hRITrzSSExgywzC1itOdllI2iaoWeU9Q== X-Received: by 2002:a62:6b41:: with SMTP id g62-v6mr1333984pfc.106.1540873744728; Mon, 29 Oct 2018 21:29:04 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.65]) by smtp.gmail.com with ESMTPSA id 64-v6sm48233059pfq.10.2018.10.29.21.29.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 21:29:04 -0700 (PDT) From: Li Qiang To: pbonzini@redhat.com, thuth@redhat.com, lvivier@redhat.com, philmd@redhat.com Date: Mon, 29 Oct 2018 21:28:51 -0700 Message-Id: <1540873732-3503-2-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1540873732-3503-1-git-send-email-liq3ea@gmail.com> References: <1540873732-3503-1-git-send-email-liq3ea@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v2 1/2] tests: fw_cfg: add a function to get the fw_cfg file entry 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 , 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 | 33 +++++++++++++++++++++++++++++++++ tests/libqos/fw_cfg.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index d0889d1e22..45338655f4 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 "standard-headers/linux/qemu_fw_cfg.h" void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { @@ -54,6 +55,38 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key) return le64_to_cpu(value); } +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; + uint32_t dsize; + struct fw_cfg_file *p; + 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); + p = (struct fw_cfg_file *)(filesbuf + 4); + for (i = 0; i < count; ++i, ++p) { + if (!strcmp(p->name, filename)) { + uint32_t len = be32_to_cpu(p->size); + uint16_t sel = be16_to_cpu(p->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_select(QFWCFG *fw_cfg, uint16_t key) { qtest_writew(fw_cfg->qts, fw_cfg->base, key); diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 0353416af0..de73722e67 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);