From patchwork Sat Sep 28 16:23:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 2957951 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 731EFBFF0B for ; Sat, 28 Sep 2013 16:23:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9DCA02035F for ; Sat, 28 Sep 2013 16:23:55 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AA87202D1 for ; Sat, 28 Sep 2013 16:23:54 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPxIv-0006Zi-9y; Sat, 28 Sep 2013 16:23:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPxIs-0005Kz-Pc; Sat, 28 Sep 2013 16:23:34 +0000 Received: from mail-qc0-f177.google.com ([209.85.216.177]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VPxIo-0005JC-KM for linux-arm-kernel@lists.infradead.org; Sat, 28 Sep 2013 16:23:31 +0000 Received: by mail-qc0-f177.google.com with SMTP id x12so2547558qcv.36 for ; Sat, 28 Sep 2013 09:23:07 -0700 (PDT) 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=YpVLUf1J8f5RCE2WK7a6xDsapjqXHaFvgfeXuBQeKXQ=; b=DwkZVx31zaDjy4EpY4cZgaZwkONNkJZIvyTyj5qajwJKuj7V3HORbB9WThY649HUrA hSEVtS+sGOT1WiMyZmLihucxS0P8CQkzikszYj0P+Cz6GM6VqHgnosOqZUdAlfaRcpFG /y3ZVSj4R1EwDI2GOMgIdap9Z6pPZ/qxGWqhKK7JD87YftYUIXsTMunJOto9s6wukSHC Nl1QwL0NirW9J9oy8TpHGxVewyzVyey++Dg+PCgw6Y722z42RloMmmYB3aUm0cSAi3/Z EeiLqEoRaKL2btvBfRmGW6yS+GOTL3qres0zLpaESu1J5+HBY3YexE5GFhzHyHG51v8/ gVMw== X-Gm-Message-State: ALoCoQmples/TdCRZcc9iZwVrOlZR89u3V/UW78m0//P4irVXwDQBYk2ufJziAFX6gNP+jVSGiJ9 X-Received: by 10.224.120.74 with SMTP id c10mr21370527qar.13.1380385387857; Sat, 28 Sep 2013 09:23:07 -0700 (PDT) Received: from rfranz-t520.caveonetworks.com (static-108-20-23-67.bstnma.fios.verizon.net. [108.20.23.67]) by mx.google.com with ESMTPSA id l2sm31145506qad.10.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 28 Sep 2013 09:23:07 -0700 (PDT) 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 Subject: [PATCH 2/6] Add shared update_fdt() function for ARM/ARM64 Date: Sat, 28 Sep 2013 09:23:19 -0700 Message-Id: <1380385403-31904-3-git-send-email-roy.franz@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1380385403-31904-1-git-send-email-roy.franz@linaro.org> References: <1380385403-31904-1-git-send-email-roy.franz@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130928_122330_741322_8815FAF1 X-CRM114-Status: GOOD ( 14.94 ) X-Spam-Score: -2.6 (--) Cc: grant.likely@linaro.org, Roy Franz , dave.martin@arm.com, leif.lindholm@linaro.org, msalter@redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Roy Franz --- drivers/firmware/efi/efi-stub-helper.c | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index cc0581d..d3448a9 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. @@ -636,3 +637,88 @@ static char *efi_convert_cmdline_to_ascii(efi_system_table_t *sys_table_arg, *cmd_line_len = options_size; return (char *)cmdline_addr; } + +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) +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; + + 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,efi-system-table", + &fdt_val64, sizeof(fdt_val64)); + if (status) + goto fdt_set_fail; + + fdt_val32 = cpu_to_fdt32(desc_size); + status = fdt_setprop(fdt, node, "linux,efi-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,efi-mmap-desc-version", + &fdt_val32, sizeof(fdt_val32)); + if (status) + goto fdt_set_fail; + + + /* Stuff the whole memory map into FDT */ + status = fdt_setprop(fdt, node, "linux,efi-mmap", + memory_map, map_size); + 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; +} +#endif