From patchwork Thu Jun 4 06:42:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 6544031 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2F43CC0020 for ; Thu, 4 Jun 2015 06:43:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39A8D20752 for ; Thu, 4 Jun 2015 06:43:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3660C2075A for ; Thu, 4 Jun 2015 06:43:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbbFDGnr (ORCPT ); Thu, 4 Jun 2015 02:43:47 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:46527 "EHLO e23smtp08.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752483AbbFDGnl (ORCPT ); Thu, 4 Jun 2015 02:43:41 -0400 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 Jun 2015 16:43:38 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 Jun 2015 16:43:37 +1000 Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id B1C7A2BB005A; Thu, 4 Jun 2015 16:43:36 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t546hSbR38862938; Thu, 4 Jun 2015 16:43:36 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t546h2rZ005595; Thu, 4 Jun 2015 16:43:04 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t546h1ob004584; Thu, 4 Jun 2015 16:43:02 +1000 Received: from bran.ozlabs.ibm.com (unknown [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id E2558A0417; Thu, 4 Jun 2015 16:42:40 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id EE166E387C; Thu, 4 Jun 2015 16:42:40 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id DDA689422B2; Thu, 4 Jun 2015 16:42:40 +1000 (AEST) From: Gavin Shan To: linuxppc-dev@lists.ozlabs.org Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, benh@kernel.crashing.org, bhelgaas@google.com, aik@ozlabs.ru, panto@antoniou-consulting.com, robherring2@gmail.com, grant.likely@linaro.org, Gavin Shan Subject: [PATCH v5 40/42] drivers/of: Allow to specify root node in of_fdt_unflatten_tree() Date: Thu, 4 Jun 2015 16:42:09 +1000 Message-Id: <1433400131-18429-41-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433400131-18429-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1433400131-18429-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15060406-0029-0000-0000-000001A86A74 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 The patch introduces one more argument to of_fdt_unflatten_tree() to specify the root node for the FDT blob, which is going to be unflattened. In the result, the function can be used to unflatten FDT blob, which represents device sub-tree in subsequent patches. Signed-off-by: Gavin Shan --- v5: * Newly introduced --- drivers/of/fdt.c | 26 ++++++++++++++++++-------- drivers/of/unittest.c | 2 +- include/linux/of_fdt.h | 3 ++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index b87c157..b6a6c59 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -380,9 +380,16 @@ static void *unflatten_dt_node(void *blob, struct device_node **nodepp, bool dryrun) { + unsigned long fpsize = 0; + + if (dad) + fpsize = strlen(of_node_full_name(dad)); + else + fpsize = 0; + cur_node_depth = 1; return __unflatten_dt_node(blob, mem, poffset, - dad, nodepp, 0, dryrun); + dad, nodepp, fpsize, dryrun); } /** @@ -393,13 +400,15 @@ static void *unflatten_dt_node(void *blob, * pointers of the nodes so the normal device-tree walking functions * can be used. * @blob: The blob to expand + * @dad: The root node of the created device_node tree * @mynodes: The device_node tree created by the call * @dt_alloc: An allocator that provides a virtual address to memory * for the resulting tree */ static void __unflatten_device_tree(void *blob, - struct device_node **mynodes, - void * (*dt_alloc)(u64 size, u64 align)) + struct device_node *dad, + struct device_node **mynodes, + void * (*dt_alloc)(u64 size, u64 align)) { unsigned long size; int start; @@ -425,7 +434,7 @@ static void __unflatten_device_tree(void *blob, /* First pass, scan for size */ start = 0; size = (unsigned long)unflatten_dt_node(blob, NULL, &start, - NULL, NULL, true); + dad, NULL, true); size = ALIGN(size, 4); pr_debug(" size is %lx, allocating...\n", size); @@ -440,7 +449,7 @@ static void __unflatten_device_tree(void *blob, /* Second pass, do actual unflattening */ start = 0; - unflatten_dt_node(blob, mem, &start, NULL, mynodes, false); + unflatten_dt_node(blob, mem, &start, dad, mynodes, false); if (be32_to_cpup(mem + size) != 0xdeadbeef) pr_warning("End of tree marker overwritten: %08x\n", be32_to_cpup(mem + size)); @@ -462,9 +471,10 @@ static void *kernel_tree_alloc(u64 size, u64 align) * can be used. */ void of_fdt_unflatten_tree(unsigned long *blob, - struct device_node **mynodes) + struct device_node *dad, + struct device_node **mynodes) { - __unflatten_device_tree(blob, mynodes, &kernel_tree_alloc); + __unflatten_device_tree(blob, dad, mynodes, &kernel_tree_alloc); } EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); @@ -1095,7 +1105,7 @@ bool __init early_init_dt_scan(void *params) */ void __init unflatten_device_tree(void) { - __unflatten_device_tree(initial_boot_params, &of_root, + __unflatten_device_tree(initial_boot_params, NULL, &of_root, early_init_dt_alloc_memory_arch); /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1801634..2270830 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -907,7 +907,7 @@ static int __init unittest_data_add(void) "not running tests\n", __func__); return -ENOMEM; } - of_fdt_unflatten_tree(unittest_data, &unittest_data_node); + of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node); if (!unittest_data_node) { pr_warn("%s: No tree to attach; not running tests\n", __func__); return -ENODATA; diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 587ee50..8882640 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -38,7 +38,8 @@ extern bool of_fdt_is_big_endian(const void *blob, extern int of_fdt_match(const void *blob, unsigned long node, const char *const *compat); extern void of_fdt_unflatten_tree(unsigned long *blob, - struct device_node **mynodes); + struct device_node *dad, + struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ extern int __initdata dt_root_addr_cells;