From patchwork Sat Feb 20 01:13:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 62445 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp106418lbl; Fri, 19 Feb 2016 17:15:53 -0800 (PST) X-Received: by 10.66.62.134 with SMTP id y6mr22202995par.43.1455930951385; Fri, 19 Feb 2016 17:15:51 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id g77si19866991pfd.189.2016.02.19.17.15.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Feb 2016 17:15:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aWw87-0002CU-SD; Sat, 20 Feb 2016 01:14:39 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aWw7R-0001rM-6J for linux-arm-kernel@lists.infradead.org; Sat, 20 Feb 2016 01:14:00 +0000 Received: by mail-pf0-x229.google.com with SMTP id x65so59898303pfb.1 for ; Fri, 19 Feb 2016 17:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F3Os4xPzzE80mZpCOZstPkpZiQP1Bm2Dy2QzRPAzRmo=; b=UHfdA2f2qf/98vWebf6tvL4Evb1Cg6RP8llPyB0UCpYuZK5xa/UR18Hui49TW5zfDZ Cq64bZMi+FngOnz+zm6YJxEQUyXqExj8XX9v56B7i84OqPnsU8bpCG/fx54v6KHNTgGp 5Ui+9U+wshsaRH3lSIcdHZL0P9LI9Et2i0zWSQ2wwLT+ZVYgjZQ8K9/bwqQ99b3qK2pw Vd/iUM1j7dHHDuou6ugCiFDfTKNJMdnkfNxnluG5zfNn3iGKHiwfCtDBUN/OUNOBAdBa Blgsoby3xgz6d8kqPCMzsZiFwrluRi6DrIR9strJoaTUfyv+yiCO4z4Xp88vW+cktyXA F/JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F3Os4xPzzE80mZpCOZstPkpZiQP1Bm2Dy2QzRPAzRmo=; b=bD3L24bsu92yJVQQtNVSKJoekQE5caBQI1jJmDrMdo4z1mojyxqD1sAL7W91Tib5UD vi2+mFVRaQMV9gMBEz81AzTVVDwlrrKM1NA76T6ZwhlkRoHRPOcwzzLuWWxoaZs8Ubr5 ASdww+s2ummdkdmKgampuOts1/9cRdMGLr7LQEaXOH7bflrUrfAe2Wdx/uiDQqDcQ5Gz u10PRAhA+Xd9MLFcW6Mduu/xPU92Wmr/RlYjpSZzRvp4Vj5t1ZyrZPlz/Hz75AdeSN77 WFEO7Wk73keKS5LDUCtAIFzHfH8dcjXjg8bD/0DZ8gyh0Q3SbJxc16UG4K5uZoKra+NU 1nFQ== X-Gm-Message-State: AG10YOTEPJjJBuxlh8yDh0TqGh2Sf5qvGmwRqPdZPE2vRoJ4gJBadYo31uS3zBy2uY1jfA== X-Received: by 10.98.10.139 with SMTP id 11mr22416001pfk.87.1455930816205; Fri, 19 Feb 2016 17:13:36 -0800 (PST) Received: from dl.caveonetworks.com ([64.2.3.194]) by smtp.gmail.com with ESMTPSA id m16sm20316239pfi.75.2016.02.19.17.13.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Feb 2016 17:13:31 -0800 (PST) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id u1K1DR5f005430; Fri, 19 Feb 2016 17:13:27 -0800 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id u1K1DRtw005429; Fri, 19 Feb 2016 17:13:27 -0800 From: David Daney To: Will Deacon , linux-arm-kernel@lists.infradead.org, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , devicetree@vger.kernel.org, Ard Biesheuvel , Frank Rowand , Grant Likely , Catalin Marinas , Matt Fleming , linux-efi@vger.kernel.org, Ganapatrao Kulkarni , Robert Richter Subject: [PATCH v11 04/10] arm64/efi: move EFI /chosen node parsing before early FDT processing Date: Fri, 19 Feb 2016 17:13:13 -0800 Message-Id: <1455930799-5371-5-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1455930799-5371-1-git-send-email-ddaney.cavm@gmail.com> References: <1455930799-5371-1-git-send-email-ddaney.cavm@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160219_171357_527030_AD1CA1D7 X-CRM114-Status: GOOD ( 23.62 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ddaney.cavm[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, David Daney MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org From: Ard Biesheuvel The early FDT processing is responsible for enumerating the DT memory nodes and installing them as memblocks. This should only be done if we are not booting via EFI, but at this point, we don't know yet if that is the case or not. So move part of the EFI init to before the early FDT processing. This involves making some changes to the way EFI discovers the locations of the EFI system table and the memory map, since those values are retrieved from the FDT as well. Instead the of_scan infrastructure, it now uses libfdt directly to access the /chosen node. Signed-off-by: Ard Biesheuvel [ rric: Ported to v4.5-rc1 ] Signed-off-by: Robert Richter Signed-off-by: David Daney --- arch/arm64/include/asm/efi.h | 2 ++ arch/arm64/kernel/setup.c | 3 ++ drivers/firmware/efi/arm-init.c | 34 ++++++++++++------- drivers/firmware/efi/efi-fdt.c | 72 ++++++++++++++++------------------------- include/linux/efi.h | 2 +- 5 files changed, 55 insertions(+), 58 deletions(-) -- 1.8.3.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index 8e88a69..acc7f65 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -8,8 +8,10 @@ #ifdef CONFIG_EFI extern void efi_init(void); +extern void efi_parse_fdt(void *fdt); #else #define efi_init() +#define efi_parse_fdt(x) #endif int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 8119479..3f57233 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -181,6 +181,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys) { void *dt_virt = fixmap_remap_fdt(dt_phys); + if (dt_virt) + efi_parse_fdt(dt_virt); + if (!dt_virt || !early_init_dt_scan(dt_virt)) { pr_crit("\n" "Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n" diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c index 9e15d57..9fe0464 100644 --- a/drivers/firmware/efi/arm-init.c +++ b/drivers/firmware/efi/arm-init.c @@ -170,22 +170,35 @@ static __init void reserve_regions(void) if (efi_enabled(EFI_DBG)) pr_cont("\n"); } - - set_bit(EFI_MEMMAP, &efi.flags); } -void __init efi_init(void) +void __init efi_parse_fdt(void *fdt) { struct efi_fdt_params params; /* Grab UEFI information placed in FDT by stub */ - if (!efi_get_fdt_params(¶ms)) + if (!efi_get_fdt_params(fdt, ¶ms)) return; efi_system_table = params.system_table; memmap.phys_map = params.mmap; - memmap.map = early_memremap(params.mmap, params.mmap_size); + memmap.desc_size = params.desc_size; + memmap.desc_version = params.desc_ver; + memmap.nr_map = params.mmap_size / params.desc_size; + + set_bit(EFI_MEMMAP, &efi.flags); +} + +void __init efi_init(void) +{ + int mmap_size = memmap.nr_map * memmap.desc_size; + u64 phys_map = memmap.phys_map; + + if (!efi_enabled(EFI_MEMMAP)) + return; + + memmap.map = early_memremap(phys_map, mmap_size); if (memmap.map == NULL) { /* * If we are booting via UEFI, the UEFI memory map is the only @@ -194,16 +207,13 @@ void __init efi_init(void) */ panic("Unable to map EFI memory map.\n"); } - memmap.map_end = memmap.map + params.mmap_size; - memmap.desc_size = params.desc_size; - memmap.desc_version = params.desc_ver; + memmap.map_end = memmap.map + mmap_size; if (uefi_init() < 0) return; reserve_regions(); - early_memunmap(memmap.map, params.mmap_size); - memblock_mark_nomap(params.mmap & PAGE_MASK, - PAGE_ALIGN(params.mmap_size + - (params.mmap & ~PAGE_MASK))); + early_memunmap(memmap.map, mmap_size); + memblock_mark_nomap(phys_map & PAGE_MASK, + PAGE_ALIGN(mmap_size + (phys_map & ~PAGE_MASK))); } diff --git a/drivers/firmware/efi/efi-fdt.c b/drivers/firmware/efi/efi-fdt.c index 8f3ce66..e6622d3 100644 --- a/drivers/firmware/efi/efi-fdt.c +++ b/drivers/firmware/efi/efi-fdt.c @@ -8,8 +8,7 @@ #include #include -#include -#include +#include #define UEFI_PARAM(name, prop, field) \ { \ @@ -32,60 +31,43 @@ static __initdata struct { UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver) }; -struct param_info { - int found; - void *params; -}; - -static int __init fdt_find_uefi_params(unsigned long node, const char *uname, - int depth, void *data) +int __init efi_get_fdt_params(void *fdt, struct efi_fdt_params *params) { - struct param_info *info = data; const void *prop; - void *dest; - u64 val; - int i, len; + int node, i; + + pr_info("Getting EFI parameters from FDT:\n"); - if (depth != 1 || strcmp(uname, "chosen") != 0) - return 0; + node = fdt_path_offset(fdt, "/chosen"); + if (node < 0) { + pr_err("/chosen node not found!\n"); + return false; + } for (i = 0; i < ARRAY_SIZE(dt_params); i++) { - prop = of_get_flat_dt_prop(node, dt_params[i].propname, &len); - if (!prop) - return 0; - dest = info->params + dt_params[i].offset; - info->found++; + void *dest; + int len; + u64 val; - val = of_read_number(prop, len / sizeof(u32)); + prop = fdt_getprop(fdt, node, dt_params[i].propname, &len); + if (!prop || len != dt_params[i].size) + goto not_found; + dest = (void *)params + dt_params[i].offset; if (dt_params[i].size == sizeof(u32)) - *(u32 *)dest = val; + val = *(u32 *)dest = be32_to_cpup(prop); else - *(u64 *)dest = val; + val = *(u64 *)dest = be64_to_cpup(prop); - if (efi_enabled(EFI_DBG)) - pr_info(" %s: 0x%0*llx\n", dt_params[i].name, - dt_params[i].size * 2, val); + pr_info(" %s: 0x%0*llx\n", dt_params[i].name, + dt_params[i].size * 2, val); } - return 1; -} + return true; -int __init efi_get_fdt_params(struct efi_fdt_params *params) -{ - struct param_info info; - int ret; - - pr_info("Getting EFI parameters from FDT:\n"); - - info.found = 0; - info.params = params; - - ret = of_scan_flat_dt(fdt_find_uefi_params, &info); - if (!info.found) +not_found: + if (i == 0) pr_info("UEFI not found.\n"); - else if (!ret) - pr_err("Can't find '%s' in device tree!\n", - dt_params[info.found].name); - - return ret; + else + pr_err("Can't find '%s' in device tree!\n", dt_params[i].name); + return false; } diff --git a/include/linux/efi.h b/include/linux/efi.h index 569b5a8..ede2c21 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -915,7 +915,7 @@ extern void efi_initialize_iomem_resources(struct resource *code_resource, struct resource *data_resource, struct resource *bss_resource); extern void efi_get_time(struct timespec *now); extern void efi_reserve_boot_services(void); -extern int efi_get_fdt_params(struct efi_fdt_params *params); +extern int efi_get_fdt_params(void *fdt, struct efi_fdt_params *params); extern struct efi_memory_map memmap; extern struct kobject *efi_kobj;