From patchwork Sun Mar 16 21:22:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 3840371 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 B4BDDBF540 for ; Sun, 16 Mar 2014 21:23:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78868201FA for ; Sun, 16 Mar 2014 21:23:00 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37C9A20120 for ; Sun, 16 Mar 2014 21:22:59 +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 1WPIWB-0002k3-I1; Sun, 16 Mar 2014 21:22:51 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WPIW8-0000fs-WC; Sun, 16 Mar 2014 21:22:49 +0000 Received: from gloria.sntech.de ([95.129.55.99]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WPIW4-0000ey-UU for linux-arm-kernel@lists.infradead.org; Sun, 16 Mar 2014 21:22:46 +0000 Received: from 146-52-32-105-dynip.superkabel.de ([146.52.32.105] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WPIVN-000103-Aj; Sun, 16 Mar 2014 22:22:01 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: David Gibson , Jon Loeliger Subject: [PATCH] dtc: add ability to make nodes conditional on them being referenced Date: Sun, 16 Mar 2014 22:22:02 +0100 Message-ID: <199290403.sj4aYrj8FC@diego> User-Agent: KMail/4.11.5 (Linux/3.12-1-amd64; KDE/4.11.3; x86_64; ; ) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140316_172245_081922_62426D4C X-CRM114-Status: GOOD ( 14.38 ) X-Spam-Score: -1.9 (-) Cc: devicetree@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, Philipp Zabel , grant.likely@linaro.org, Maxime Ripard , devicetree-compiler@vger.kernel.org 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: , 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, 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 From: Heiko Stuebner On i.MX, which carries a lot of pin-groups of which most are unused on individual boards, they noticed that this plethora of nodes also results in the runtime-lookup-performance also degrading [0]. A i.MX-specific solution defining the pingroups in the board files but using macros to reference the pingroup-data was not well received. This patch is trying to solve this issue in a more general way, by adding the ability to mark nodes as needing to be referenced somewhere in the tree. To mark a node a needing to be referenced it must be prefixed with /delete-unreferenced/. This makes dtc check the nodes reference-status when creating the flattened tree, dropping it if unreferenced. For example, the i.MX6SL pingroup /delete-unreferenced/ pinctrl_ecspi1_1: ecspi1grp-1 { fsl,pins = < MX6SL_PAD_ECSPI1_MISO__ECSPI1_MISO 0x100b1 MX6SL_PAD_ECSPI1_MOSI__ECSPI1_MOSI 0x100b1 MX6SL_PAD_ECSPI1_SCLK__ECSPI1_SCLK 0x100b1 >; }; would only be included in the dtb if it got referenced somewhere as pingroup via node { pinctrl-0 <&pinctrl_ecscpi1_1>; }; [0] http://thread.gmane.org/gmane.linux.ports.arm.kernel/275912/ Signed-off-by: Heiko Stuebner --- A sample implementation using the in-tree dtc in the linux kernel can be found at [1] and the very first rfc at [2]. [1] http://comments.gmane.org/gmane.linux.drivers.devicetree/62357 [2] http://comments.gmane.org/gmane.linux.drivers.devicetree/60145 checks.c | 2 ++ dtc-lexer.l | 7 +++++++ dtc-parser.y | 5 +++++ dtc.h | 4 ++++ flattree.c | 3 +++ livetree.c | 14 ++++++++++++++ 6 files changed, 35 insertions(+) diff --git a/checks.c b/checks.c index 47eda65..a82ba8d 100644 --- a/checks.c +++ b/checks.c @@ -472,6 +472,8 @@ static void fixup_phandle_references(struct check *c, struct node *dt, phandle = get_node_phandle(dt, refnode); *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle); + + reference_node(refnode); } } ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL, diff --git a/dtc-lexer.l b/dtc-lexer.l index 0821bde..6d7865d 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -140,6 +140,13 @@ static void lexical_error(const char *fmt, ...); return DT_DEL_NODE; } +<*>"/delete-unreferenced/" { + DPRINT("Keyword: /delete-unreferenced/\n"); + DPRINT("\n"); + BEGIN(PROPNODENAME); + return DT_DEL_UNREFERENCED; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref = xstrdup(yytext); diff --git a/dtc-parser.y b/dtc-parser.y index ea57e0a..a203bed 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -60,6 +60,7 @@ extern bool treesource_error; %token DT_BITS %token DT_DEL_PROP %token DT_DEL_NODE +%token DT_DEL_UNREFERENCED %token DT_PROPNODENAME %token DT_LITERAL %token DT_CHAR_LITERAL @@ -450,6 +451,10 @@ subnode: { $$ = name_node(build_node_delete(), $2); } + | DT_DEL_UNREFERENCED subnode + { + $$ = check_node_referenced($2); + } | DT_LABEL subnode { add_label(&$2->labels, $1); diff --git a/dtc.h b/dtc.h index 20de073..ff45059 100644 --- a/dtc.h +++ b/dtc.h @@ -158,6 +158,8 @@ struct node { int addr_cells, size_cells; struct label *labels; + + int needs_reference, is_referenced; }; #define for_each_label_withdel(l0, l) \ @@ -192,6 +194,8 @@ struct property *reverse_properties(struct property *first); struct node *build_node(struct property *proplist, struct node *children); struct node *build_node_delete(void); struct node *name_node(struct node *node, char *name); +struct node *check_node_referenced(struct node *node); +struct node *reference_node(struct node *node); struct node *chain_node(struct node *first, struct node *list); struct node *merge_nodes(struct node *old_node, struct node *new_node); diff --git a/flattree.c b/flattree.c index bd99fa2..105e8fa 100644 --- a/flattree.c +++ b/flattree.c @@ -266,6 +266,9 @@ static void flatten_tree(struct node *tree, struct emitter *emit, if (tree->deleted) return; + if (tree->needs_reference && !tree->is_referenced) + return; + emit->beginnode(etarget, tree->labels); if (vi->flags & FTF_FULLPATH) diff --git a/livetree.c b/livetree.c index b61465f..98bb33d 100644 --- a/livetree.c +++ b/livetree.c @@ -134,6 +134,20 @@ struct node *name_node(struct node *node, char *name) return node; } +struct node *check_node_referenced(struct node *node) +{ + node->needs_reference = 1; + + return node; +} + +struct node *reference_node(struct node *node) +{ + node->is_referenced = 1; + + return node; +} + struct node *merge_nodes(struct node *old_node, struct node *new_node) { struct property *new_prop, *old_prop;