[Skiboot] [PATCH v9 07/22] core/fdt: Allow to specify FDT blob

Daniel Axtens dja at axtens.net
Tue Dec 1 09:23:15 AEDT 2015


Hi Gavin,

I've had a quick flick though this patch and it looks OK so far.

Stewart: do we need to add some checks against NULL to prevent this
creating a bunch of Coverity/other static analysis warnings?

Regards,
Daniel

> 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 <gwshan at linux.vnet.ibm.com>
> ---
>  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 <ccan/str/str.h>
>  
>  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));
> -- 
> 2.1.0
>
> _______________________________________________
> Skiboot mailing list
> Skiboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 859 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/skiboot/attachments/20151201/ad4c0e3b/attachment.sig>


More information about the Skiboot mailing list