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: 3250891 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 1CA81C045B for ; Wed, 27 Nov 2013 23:33:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2931D2060B for ; Wed, 27 Nov 2013 23:33:58 +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 1D2E82060A for ; Wed, 27 Nov 2013 23:33:57 +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 1VlobS-0006QX-Ny; Wed, 27 Nov 2013 23:33:07 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VlobH-0004x0-8f; Wed, 27 Nov 2013 23:32:55 +0000 Received: from mail-ie0-f176.google.com ([209.85.223.176]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vloar-0004sP-A7 for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2013 23:32:31 +0000 Received: by mail-ie0-f176.google.com with SMTP id at1so12822269iec.21 for ; Wed, 27 Nov 2013 15:32:07 -0800 (PST) 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=mR0L/p/gMyjrYcMHsGMFrNFjAunNnJeuoz+gCWX0A68=; b=ToZXRenY6Gz5n9T6lTWkqPrFLZ2gK/XJaP7wzMTAPA8fcg+GyPWIqveMRhapDjJ2bi xalrzd1Ls51ziybNm9evb5V8n4hRUEgw6rcPEEfpovo47BPzaE6cHFO7o3Dmlt7d1OzK cJlCjlxTiQUQ/NEOozuVizgytEmeS3Pg9nYTThVMFW+6JuU3xDUAt5AgClBCOMTlQ17C KtvJUNkVByFPklFTWVz1qau8SRF2marnYMYsyNnlnpaH+Ca9q4TviDQ+kLXNOHBq+eng oToURNFFENZ+fKJtSd55VBUljuEQsLkth5DARqWr11yPAxc5Ht6r7bjH03Rx06I90GIO z0bQ== X-Gm-Message-State: ALoCoQk+REkj/nRP9pVTRJi7Cp9NSyKSlq/TSIm2FFEQtroUjA9PnvJNNkDaniJ/RGzZX+1JQeWy 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131127_183229_467354_1C42D715 X-CRM114-Status: GOOD ( 20.66 ) X-Spam-Score: -2.6 (--) Cc: patches@linaro.org, leif.lindholm@linaro.org, Roy Franz , msalter@redhat.com, grant.likely@linaro.org, dave.martin@arm.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=-4.2 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. 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; +}