From patchwork Tue May 3 05:04:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 617750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qzTf617tKz9ssP for ; Tue, 3 May 2016 15:06:06 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3qzTf60P9hzDqGy for ; Tue, 3 May 2016 15:06:06 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) (using TLSv1.2 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3qzTdm6wp7zDq6B for ; Tue, 3 May 2016 15:05:48 +1000 (AEST) Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 May 2016 15:05:47 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 3 May 2016 15:05:44 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: gwshan@linux.vnet.ibm.com X-IBM-RcptTo: skiboot@lists.ozlabs.org Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 7E58C3578052 for ; Tue, 3 May 2016 15:05:43 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u4355Zj363373492 for ; Tue, 3 May 2016 15:05:43 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u4355AdF029413 for ; Tue, 3 May 2016 15:05:11 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u4355A5v028406; Tue, 3 May 2016 15:05:10 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id F0DE4A0306; Tue, 3 May 2016 15:04:45 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id F1810E3A33; Tue, 3 May 2016 15:04:45 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id C677994268E; Tue, 3 May 2016 15:04:45 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Tue, 3 May 2016 15:04:28 +1000 Message-Id: <1462251882-12762-4-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1462251882-12762-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1462251882-12762-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16050305-1618-0000-0000-000045995D70 Subject: [Skiboot] [PATCH v10 03/17] core/fdt: Allow to specify FDT blob X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The FDT memory block is allocated by skiboot and passed to kernel after the device tree is flattenned. In order to transfer device tree changes for PCI hotplug in subsequent patches, new OPAL API will be introduced to retrieve the sub-tree behind the specified (PCI slot) node. The FDT blob is allocated by kernel in that case. This adds parameters for various functions in core/fdt.c allowing to specify the memory block for the FDT blob, which is allocated by skiboot or kernel. Signed-off-by: Gavin Shan --- core/fdt.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/core/fdt.c b/core/fdt.c index 6d3446e..a9392b1 100644 --- a/core/fdt.c +++ b/core/fdt.c @@ -27,7 +27,6 @@ #include static int fdt_error; -static void *fdt; #undef DEBUG_FDT @@ -44,12 +43,12 @@ static void __save_err(int err, const char *str) #define save_err(...) __save_err(__VA_ARGS__, #__VA_ARGS__) -static void dt_property_cell(const char *name, u32 cell) +static void dt_property_cell(void *fdt, const char *name, u32 cell) { save_err(fdt_property_cell(fdt, name, cell)); } -static void dt_begin_node(const struct dt_node *dn) +static void dt_begin_node(void *fdt, const struct dt_node *dn) { save_err(fdt_begin_node(fdt, dn->name)); @@ -57,23 +56,23 @@ static void dt_begin_node(const struct dt_node *dn) * We add both the new style "phandle" and the legacy * "linux,phandle" properties */ - dt_property_cell("linux,phandle", dn->phandle); - dt_property_cell("phandle", dn->phandle); + dt_property_cell(fdt, "linux,phandle", dn->phandle); + dt_property_cell(fdt, "phandle", dn->phandle); } -static void dt_property(const struct dt_property *p) +static void dt_property(void *fdt, const struct dt_property *p) { save_err(fdt_property(fdt, p->name, p->prop, p->len)); } -static void dt_end_node(void) +static void dt_end_node(void *fdt) { save_err(fdt_end_node(fdt)); } -static void dump_fdt(void) -{ #ifdef DEBUG_FDT +static void dump_fdt(void *fdt) +{ int i, off, depth, err; printf("Device tree %u@%p\n", fdt_totalsize(fdt), fdt); @@ -110,10 +109,10 @@ static void dump_fdt(void) } printf("name: %s [%u]\n", name, off); } -#endif } +#endif -static void flatten_dt_properties(const struct dt_node *dn) +static void flatten_dt_properties(void *fdt, const struct dt_node *dn) { const struct dt_property *p; @@ -123,26 +122,26 @@ static void flatten_dt_properties(const struct dt_node *dn) #ifdef DEBUG_FDT printf("FDT: prop: %s size: %ld\n", p->name, p->len); #endif - dt_property(p); + dt_property(fdt, p); } } -static void flatten_dt_node(const struct dt_node *root) +static void flatten_dt_node(void *fdt, const struct dt_node *root) { const struct dt_node *i; #ifdef DEBUG_FDT printf("FDT: node: %s\n", root->name); #endif - flatten_dt_properties(root); + flatten_dt_properties(fdt, root); list_for_each(&root->children, i, list) { - dt_begin_node(i); - flatten_dt_node(i); - dt_end_node(); + dt_begin_node(fdt, i); + flatten_dt_node(fdt, i); + dt_end_node(fdt); } } -static void create_dtb_reservemap(const struct dt_node *root) +static void create_dtb_reservemap(void *fdt, const struct dt_node *root) { uint64_t base, size; const uint64_t *ranges; @@ -166,6 +165,7 @@ static void create_dtb_reservemap(const struct dt_node *root) void *create_dtb(const struct dt_node *root) { + void *fdt = NULL; size_t len = DEVICE_TREE_MAX_SIZE; uint32_t old_last_phandle = last_phandle; @@ -182,16 +182,16 @@ void *create_dtb(const struct dt_node *root) fdt_create(fdt, len); - create_dtb_reservemap(root); + create_dtb_reservemap(fdt, root); /* Open root node */ - dt_begin_node(root); + dt_begin_node(fdt, root); /* Unflatten our live tree */ - flatten_dt_node(root); + flatten_dt_node(fdt, root); /* Close root node */ - dt_end_node(); + dt_end_node(fdt); save_err(fdt_finish(fdt)); @@ -201,7 +201,9 @@ void *create_dtb(const struct dt_node *root) len *= 2; } while (fdt_error == -FDT_ERR_NOSPACE); - dump_fdt(); +#ifdef DEBUG_FDT + dump_fdt(fdt); +#endif if (fdt_error) { prerror("dtb: error %s\n", fdt_strerror(fdt_error));