From patchwork Wed Jan 20 09:57:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Yan X-Patchwork-Id: 570606 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 918D8140297 for ; Wed, 20 Jan 2016 20:57:34 +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=yt+Ft+ez; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6FC504BBA0; Wed, 20 Jan 2016 10:57:31 +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 BkV1BdU7NRVf; Wed, 20 Jan 2016 10:57:31 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 320A14B632; Wed, 20 Jan 2016 10:57:25 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C66284BB94 for ; Wed, 20 Jan 2016 10:57:20 +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 1YPCaLpk3QUW for ; Wed, 20 Jan 2016 10:57:20 +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 513454BB89 for ; Wed, 20 Jan 2016 10:57:16 +0100 (CET) Received: by mail-pa0-f67.google.com with SMTP id yy13so177672pab.1 for ; Wed, 20 Jan 2016 01:57:16 -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=nDVvSZoWJogvSkE2QKHz9sDu8HDe0KjKiud3XcyDLzo=; b=yt+Ft+ez9nLLobT5KZGGNJBGTrVPkQo0B0w3degs4oPJh7Ma2c6dATvn30sbTVzJso UVvzxYUW/BVU9d27b1pzQQM16QaKXfYB8kIHABKHaloIWGMo9gpkqc+q78anyGChJIfU yFnMxcIBWz6ZUqWj4WOhzx40A55TrElEA7Bf86jQcD6xFEp5rYV5943JXasIfyaVeBIm 8D5xRswj+NL8EEQgYR+n/l3HVKErhSvaLfMRaI3wflEf8JaJzH/UtuE3Jwygn6I6Xzv4 VtNIg12lswcd0XvWYnVCVcdimO6uI1YA2HLSPYHzgksx+bojd9vyRiLrYEyyKtk5E70P ypqg== 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=nDVvSZoWJogvSkE2QKHz9sDu8HDe0KjKiud3XcyDLzo=; b=W0m5cP0NFKFpRuJ3W0GQkz3ZrnNkAYXy3b8XFVc3julD54N3bNpTNZYLxcug+K5OQz SRkmSx4ICXpaPvOGOWGGQMq7Vn+wjd1J1g2cKH+Q2f7GvJPu1yVeLaUC6oSe6eAdaPfh qDVMFAmgQnD6ThMXs05cdp48os2SVaUbfD9vYLfjR02+4XAtQToyO0V2XimIldyB40XH hD8x25ae8oi92CQ5sz5aGR5aNPtfG4twiDMjkuAef+NhVlfAV7+aCgH13PYWI0EaEg4q neQUhWHlo/a8qos9HI4awLRI7sxo9JLQ4+qaD7JIq737IYJcg8mqWeM9+6cJbvy+QgnT VJeg== X-Gm-Message-State: AG10YORMzAeSXaS8J+BJzGtZf4iusGOiMRH5qkejIyldiamgl8vYkZFjMIf3VtPqcWDQrA== X-Received: by 10.66.227.73 with SMTP id ry9mr39508083pac.120.1453283835436; Wed, 20 Jan 2016 01:57:15 -0800 (PST) Received: from pa-dbc1131.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id fl9sm47778282pab.33.2016.01.20.01.57.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Jan 2016 01:57:14 -0800 (PST) From: Miao Yan To: u-boot@lists.denx.de, bmeng.cn@gmail.com, sjg@chromium.org Date: Wed, 20 Jan 2016 01:57:04 -0800 Message-Id: <1453283827-18947-2-git-send-email-yanmiaobest@gmail.com> X-Mailer: git-send-email 2.6.3.444.gfd13a2e In-Reply-To: <1453283827-18947-1-git-send-email-yanmiaobest@gmail.com> References: <1453283827-18947-1-git-send-email-yanmiaobest@gmail.com> Subject: [U-Boot] [PATCH v3 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_fwcfg_read_firmware_list() to handle reading firmware list. Signed-off-by: Miao Yan Reviewed-by: Bin Meng Tested-by: Bin Meng --- arch/x86/cpu/qemu/fw_cfg.c | 63 +++++++++++++++++++++++++++++++++---------- arch/x86/include/asm/fw_cfg.h | 9 ++++--- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/arch/x86/cpu/qemu/fw_cfg.c b/arch/x86/cpu/qemu/fw_cfg.c index 0599214..bcd34af 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,61 @@ 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..2acf43e 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,9 +69,10 @@ struct fw_cfg_file { char name[FW_CFG_MAX_FILE_PATH]; }; -struct fw_cfg_files { - __be32 count; - struct fw_cfg_file files[]; +struct fw_file { + struct fw_cfg_file cfg; /* firmware file information */ + unsigned long addr; /* firmware file in-memory address */ + struct list_head list; /* list node to link to fw_list */ }; struct fw_cfg_dma_access {