From patchwork Fri Jan 15 03:12:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Yan X-Patchwork-Id: 567898 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 7C93A140556 for ; Fri, 15 Jan 2016 14:12:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=A6Wec+gU; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6C991A76FF; Fri, 15 Jan 2016 04:12:45 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ye_o8RmYxdri; Fri, 15 Jan 2016 04:12:45 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DB138621BB; Fri, 15 Jan 2016 04:12:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A50B4A7655 for ; Fri, 15 Jan 2016 04:12:35 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cOOd2LpCt9m6 for ; Fri, 15 Jan 2016 04:12:35 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by theia.denx.de (Postfix) with ESMTPS id 2FAA9A74D6 for ; Fri, 15 Jan 2016 04:12:32 +0100 (CET) Received: by mail-pa0-f67.google.com with SMTP id a20so23912077pag.3 for ; Thu, 14 Jan 2016 19:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=Vr6cf5TwEdg3T89Bm2XDVsTkKei7ernfFaxx+/ua8AQ=; b=A6Wec+gU22QFdL0e5q1xjGqInynZlVYhjV0hbA5FHbk6zgUyFhIfYVM+NW52HzEzeF bH8tGWcc7M4vCNucZdc0z8AN9wSVFmg+fM88bBgX5nnjxNv+RcdIPj7OP5kdLO1Hx4s6 lm9IxvqipgD6fSI/TQMqr+02bPMKNi4Q7PlN3I2rPIAd3q/kCfb7kjN7sKzIXoc8UaOW rjnN1jHRsLIgHvcz/j4P+lwjCA7W7M6O8wDESNW6+7Mit5Bc28h4DkG5WAaFoHF8yB5C rF9zAV++2cxWGcssY/pOILxw3Vr/pR9sy+HoKby+gPU7Rc3unMRAgBuf3uINS3LkHNVq MrHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Vr6cf5TwEdg3T89Bm2XDVsTkKei7ernfFaxx+/ua8AQ=; b=WQTLBwep0/d0ZdiLO/llDTv9vOsYRRnk4PRxIuN9xbObpz3G0VXvBl+R/2oB2SMhkK yVTnkKtrFuXeBmrTPT0ogvXwL6RJf0Rna9aUbyw59hol7YdzByH/XqG4YRa0Oc/uQnor GVhB43nLUxpGmVWNIrYtcfsNQGJ1MROclGXWMHwwNpxKM1wgF0sYbM3dPgRsACC4naUV 5paZxfHX7t5vgVUZMeV7hsekDus+RdE/EFHG7BRJDERVWcjr0TDob2pDhh5aoHRkqixo /ZIOyHBll6w1OeZ2Y8851aRq2LzyR5yqIKX5kPc0fKl5k+8oSVC7IgVrxJUDZgLnu0sf prQA== X-Gm-Message-State: ALoCoQlBI1MDDSWdGjDyF/UNz6jwoyLKo7ou9FI91QGjVJotpeKnMoQbnVlPfRh4WN1DR1Oq2oDcxogWqU+Av9qb1e1zx1ijSA== X-Received: by 10.66.102.73 with SMTP id fm9mr11600344pab.32.1452827550388; Thu, 14 Jan 2016 19:12:30 -0800 (PST) Received: from pa-dbc1131.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id xv2sm12254218pab.10.2016.01.14.19.12.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Jan 2016 19:12:29 -0800 (PST) From: Miao Yan To: u-boot@lists.denx.de, sjg@chromium.org, bmeng.cn@gmail.com Date: Thu, 14 Jan 2016 19:12:18 -0800 Message-Id: <1452827541-10537-2-git-send-email-yanmiaobest@gmail.com> X-Mailer: git-send-email 2.6.3.444.gfd13a2e In-Reply-To: <1452827541-10537-1-git-send-email-yanmiaobest@gmail.com> References: <1452827541-10537-1-git-send-email-yanmiaobest@gmail.com> Subject: [U-Boot] [PATCH 1/4] x86: qemu: re-structure qemu_fwcfg_list_firmware() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Re-write the logic in qemu_fwcfg_list_firmware(), add a function qemu_cfg_read_firmware_list() to handle reading firmware list. Signed-off-by: Miao Yan --- arch/x86/cpu/qemu/fw_cfg.c | 60 +++++++++++++++++++++++++++++++++---------- arch/x86/include/asm/fw_cfg.h | 8 ++++++ 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c index 0599214..b22026c 100644 --- a/arch/x86/cpu/qemu/fw_cfg.c +++ b/arch/x86/cpu/qemu/fw_cfg.c @@ -10,10 +10,13 @@ #include #include #include +#include static bool fwcfg_present; static bool fwcfg_dma_present; +static LIST_HEAD(fw_list); + /* Read configuration item using fw_cfg PIO interface */ static void qemu_fwcfg_read_entry_pio(uint16_t entry, uint32_t size, void *address) @@ -162,29 +165,58 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr) return 0; } -static int qemu_fwcfg_list_firmware(void) +static int qemu_fwcfg_read_firmware_list(void) { int i; uint32_t count; - struct fw_cfg_files *files; + struct fw_file *file; + struct list_head *entry; + + /* don't read it twice */ + if (!list_empty(&fw_list)) + return 0; qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, &count); if (!count) return 0; count = be32_to_cpu(count); - files = malloc(count * sizeof(struct fw_cfg_file)); - if (!files) - return -ENOMEM; - - files->count = count; - qemu_fwcfg_read_entry(FW_CFG_INVALID, - count * sizeof(struct fw_cfg_file), - files->files); - - for (i = 0; i < files->count; i++) - printf("%-56s\n", files->files[i].name); - free(files); + for (i = 0; i < count; i++) { + file = malloc(sizeof(*file)); + if (!file) { + printf("error: allocating resource\n"); + goto err; + } + qemu_fwcfg_read_entry(FW_CFG_INVALID, + sizeof(struct fw_cfg_file), &file->cfg); + file->addr = 0; + list_add_tail(&file->list, &fw_list); + } + return 0; + +err: + list_for_each(entry, &fw_list) { + file = list_entry(entry, struct fw_file, list); + free(file); + } + return -ENOMEM; +} + +static int qemu_fwcfg_list_firmware(void) +{ + int ret; + struct list_head *entry; + struct fw_file *file; + + /* make sure fw_list is loaded */ + ret = qemu_fwcfg_read_firmware_list(); + if (ret) + return ret; + + list_for_each(entry, &fw_list) { + file = list_entry(entry, struct fw_file, list); + printf("%-56s\n", file->cfg.name); + } return 0; } diff --git a/arch/x86/include/asm/fw_cfg.h b/arch/x86/include/asm/fw_cfg.h index fb110fa..285d805 100644 --- a/arch/x86/include/asm/fw_cfg.h +++ b/arch/x86/include/asm/fw_cfg.h @@ -12,6 +12,8 @@ #define FW_DMA_PORT_LOW 0x514 #define FW_DMA_PORT_HIGH 0x518 +#include + enum qemu_fwcfg_items { FW_CFG_SIGNATURE = 0x00, FW_CFG_ID = 0x01, @@ -67,6 +69,12 @@ struct fw_cfg_file { char name[FW_CFG_MAX_FILE_PATH]; }; +struct fw_file { + struct fw_cfg_file cfg; + unsigned long addr; + struct list_head list; +}; + struct fw_cfg_files { __be32 count; struct fw_cfg_file files[];