From patchwork Wed Nov 27 23:31:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 21822 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1695A23FEC for ; Wed, 27 Nov 2013 23:32:09 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id o6sf26040642oag.7 for ; Wed, 27 Nov 2013 15:32:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=mR0L/p/gMyjrYcMHsGMFrNFjAunNnJeuoz+gCWX0A68=; b=jZNJLRSI+LAIOtONIA6zGFeI2KPZ4V+KwhXP2MtsNXoBvLUA7s4qz7sMFOwzYk6UC0 fWoib62bOsxQXxpn1nxK2Cu9J9n/DQqBE9dZwe9Ct/5GvNdl3rEFMmlH1n5/qpll8qOI dGVtTBS1hs0wEvbZkkwA1jnDejRe4mZ2w28ujRfmh9qvchxrmRLDpPivtApWJEHBWjbW cb0ORpi2DAywtIH5/GnzUbMqxJ+CKgwFIE8Sc5Zk6emT0ZjYFtrqOCHRDwq6MD1uIdnC pdbDvc08zazWqzfpIWIZ7PixA/AwDKACaNPoKbcGKh3T/o8RNWQmfUpQey79Rh+1zkCg 0/YA== X-Gm-Message-State: ALoCoQm6IsK/cLf9IZ/AxJIJr5xGFexcKR/O4W9U/HVxJG7Am3XEG+H42u7+KjpPcx5t2+Y2WFXL X-Received: by 10.42.84.136 with SMTP id m8mr12891665icl.9.1385595128713; Wed, 27 Nov 2013 15:32:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.127.46 with SMTP id nd14ls3272534qeb.19.gmail; Wed, 27 Nov 2013 15:32:08 -0800 (PST) X-Received: by 10.52.118.98 with SMTP id kl2mr9223446vdb.30.1385595128548; Wed, 27 Nov 2013 15:32:08 -0800 (PST) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id ry8si21785166vcb.46.2013.11.27.15.32.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Nov 2013 15:32:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ld13so5285246vcb.6 for ; Wed, 27 Nov 2013 15:32:08 -0800 (PST) X-Received: by 10.58.136.231 with SMTP id qd7mr35741224veb.1.1385595128463; Wed, 27 Nov 2013 15:32:08 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp24570vcz; Wed, 27 Nov 2013 15:32:08 -0800 (PST) X-Received: by 10.50.117.3 with SMTP id ka3mr305600igb.15.1385595127827; Wed, 27 Nov 2013 15:32:07 -0800 (PST) Received: from mail-ie0-f181.google.com (mail-ie0-f181.google.com [209.85.223.181]) by mx.google.com with ESMTPS id hb7si40011280icc.26.2013.11.27.15.32.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Nov 2013 15:32:07 -0800 (PST) Received-SPF: neutral (google.com: 209.85.223.181 is neither permitted nor denied by best guess record for domain of roy.franz@linaro.org) client-ip=209.85.223.181; Received: by mail-ie0-f181.google.com with SMTP id e14so12708834iej.26 for ; Wed, 27 Nov 2013 15:32:07 -0800 (PST) X-Received: by 10.50.143.10 with SMTP id sa10mr387015igb.8.1385595127502; Wed, 27 Nov 2013 15:32:07 -0800 (PST) Received: from rfranz-v430.caveonetworks.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id p5sm41764439igj.10.2013.11.27.15.32.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2013 15:32:06 -0800 (PST) From: Roy Franz To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, matt.fleming@intel.com, linux@arm.linux.org.uk Cc: leif.lindholm@linaro.org, grant.likely@linaro.org, dave.martin@arm.com, msalter@redhat.com, patches@linaro.org, Roy Franz Subject: [PATCH V5 2/6] Add shared update_fdt() function for ARM/ARM64 Date: Wed, 27 Nov 2013 15:31:51 -0800 Message-Id: <1385595115-21488-3-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1385595115-21488-1-git-send-email-roy.franz@linaro.org> References: <1385595115-21488-1-git-send-email-roy.franz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: roy.franz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Both ARM and ARM64 stubs will update the device tree that they pass to the kernel. In both cases they primarily need to add the same UEFI related information, so the function can be shared. Create a new FDT related file for this to avoid use of architecture #ifdefs in efi-stub-helper.c Change EFI allocation type for memory map to EFI_RUNTIME_SERVICES_DATA, since we are passing this buffer to the kernel, or immediately freeing it. Signed-off-by: Roy Franz Acked-by: Grant Likely --- drivers/firmware/efi/efi-stub-helper.c | 9 ++- drivers/firmware/efi/fdt.c | 115 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/efi/fdt.c diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index b6bffbf..bc9e37a 100644 --- a/drivers/firmware/efi/efi-stub-helper.c +++ b/drivers/firmware/efi/efi-stub-helper.c @@ -4,6 +4,7 @@ * implementation files. * * Copyright 2011 Intel Corporation; author Matt Fleming + * Copyright 2013 Linaro Limited; author Roy Franz * * This file is part of the Linux kernel, and is made available * under the terms of the GNU General Public License version 2. @@ -63,10 +64,16 @@ again: /* * Add an additional efi_memory_desc_t because we're doing an * allocation which may be in a new descriptor region. + * We allocate as EFI_RUNTIME_SERVICES_DATA since this is what + * we want for when we pass the memory map to the kernel. This + * function is also used to get the memory map for other uses, + * but is always freed by the stub so the allocation type + * doesn't matter. */ *map_size += sizeof(*m); status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, - EFI_LOADER_DATA, *map_size, (void **)&m); + EFI_RUNTIME_SERVICES_DATA, *map_size, + (void **)&m); if (status != EFI_SUCCESS) goto fail; diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/fdt.c new file mode 100644 index 0000000..7f1431b --- /dev/null +++ b/drivers/firmware/efi/fdt.c @@ -0,0 +1,115 @@ +/* + * FDT related Helper functions used by the EFI stub on multiple + * architectures. This should be #included by the EFI stub + * implementation files. + * + * Copyright 2013 Linaro Limited; author Roy Franz + * + * This file is part of the Linux kernel, and is made available + * under the terms of the GNU General Public License version 2. + * + */ + +static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, + void *fdt, int new_fdt_size, char *cmdline_ptr, + u64 initrd_addr, u64 initrd_size, + efi_memory_desc_t *memory_map, + unsigned long map_size, unsigned long desc_size, + u32 desc_ver) +{ + int node; + int status; + u32 fdt_val32; + u64 fdt_val64; + /* Copy definition of linux_banner here. Since this code is + * built as part of the decompressor for ARM v7, pulling + * in version.c where linux_banner is defined for the + * kernel brings other kernel dependencies with it. + */ + const char linux_banner[] = + "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@" + LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n"; + + status = fdt_open_into(orig_fdt, fdt, new_fdt_size); + if (status != 0) + goto fdt_set_fail; + + node = fdt_subnode_offset(fdt, 0, "chosen"); + if (node < 0) { + node = fdt_add_subnode(fdt, 0, "chosen"); + if (node < 0) { + status = node; /* node is error code when negative */ + goto fdt_set_fail; + } + } + + if ((cmdline_ptr != NULL) && (strlen(cmdline_ptr) > 0)) { + status = fdt_setprop(fdt, node, "bootargs", cmdline_ptr, + strlen(cmdline_ptr) + 1); + if (status) + goto fdt_set_fail; + } + + /* Set intird address/end in device tree, if present */ + if (initrd_size != 0) { + u64 initrd_image_end; + u64 initrd_image_start = cpu_to_fdt64(initrd_addr); + status = fdt_setprop(fdt, node, "linux,initrd-start", + &initrd_image_start, sizeof(u64)); + if (status) + goto fdt_set_fail; + initrd_image_end = cpu_to_fdt64(initrd_addr + initrd_size); + status = fdt_setprop(fdt, node, "linux,initrd-end", + &initrd_image_end, sizeof(u64)); + if (status) + goto fdt_set_fail; + } + + /* Add FDT entries for EFI runtime services in chosen node. */ + node = fdt_subnode_offset(fdt, 0, "chosen"); + fdt_val64 = cpu_to_fdt64((u64)(unsigned long)sys_table); + status = fdt_setprop(fdt, node, "linux,uefi-system-table", + &fdt_val64, sizeof(fdt_val64)); + if (status) + goto fdt_set_fail; + + fdt_val64 = cpu_to_fdt64((u64)(unsigned long)memory_map); + status = fdt_setprop(fdt, node, "linux,uefi-mmap-start", + &fdt_val64, sizeof(fdt_val64)); + if (status) + goto fdt_set_fail; + + fdt_val32 = cpu_to_fdt32(map_size); + status = fdt_setprop(fdt, node, "linux,uefi-mmap-size", + &fdt_val32, sizeof(fdt_val32)); + if (status) + goto fdt_set_fail; + + fdt_val32 = cpu_to_fdt32(desc_size); + status = fdt_setprop(fdt, node, "linux,uefi-mmap-desc-size", + &fdt_val32, sizeof(fdt_val32)); + if (status) + goto fdt_set_fail; + + fdt_val32 = cpu_to_fdt32(desc_ver); + status = fdt_setprop(fdt, node, "linux,uefi-mmap-desc-ver", + &fdt_val32, sizeof(fdt_val32)); + if (status) + goto fdt_set_fail; + + /* Add kernel version banner so stub/kernel match can be + * verified. + */ + status = fdt_setprop_string(fdt, node, "linux,uefi-stub-kern-ver", + linux_banner); + if (status) + goto fdt_set_fail; + + return EFI_SUCCESS; + +fdt_set_fail: + if (status == -FDT_ERR_NOSPACE) + return EFI_BUFFER_TOO_SMALL; + + return EFI_LOAD_ERROR; +}