diff options
author | Rob Herring <robh@kernel.org> | 2014-04-01 23:48:01 -0400 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2014-04-30 01:59:16 -0400 |
commit | c972de14971f1482ab482f0a7abc85679a23326a (patch) | |
tree | 84d2055f6ab0517978736c20a3204f99b3cc8e21 /drivers/of/fdt.c | |
parent | e6a6928c3ea1d0195ed75a091e345696b916c09b (diff) |
of/fdt: use libfdt accessors for header data
With libfdt support, we can take advantage of helper accessors in libfdt
for accessing the FDT header data. This makes the code more readable and
makes the FDT blob structure more opaque to the kernel. This also
prepares for removing struct boot_param_header completely.
Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Tested-by: Michal Simek <michal.simek@xilinx.com>
Tested-by: Grant Likely <grant.likely@linaro.org>
Tested-by: Stephen Chivers <schivers@csc.com>
Diffstat (limited to 'drivers/of/fdt.c')
-rw-r--r-- | drivers/of/fdt.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 8e820a2b106d..0b38a6aa8603 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c | |||
@@ -34,7 +34,7 @@ | |||
34 | * On match, returns a non-zero value with smaller values returned for more | 34 | * On match, returns a non-zero value with smaller values returned for more |
35 | * specific compatible values. | 35 | * specific compatible values. |
36 | */ | 36 | */ |
37 | int of_fdt_is_compatible(struct boot_param_header *blob, | 37 | int of_fdt_is_compatible(const void *blob, |
38 | unsigned long node, const char *compat) | 38 | unsigned long node, const char *compat) |
39 | { | 39 | { |
40 | const char *cp; | 40 | const char *cp; |
@@ -59,7 +59,7 @@ int of_fdt_is_compatible(struct boot_param_header *blob, | |||
59 | /** | 59 | /** |
60 | * of_fdt_match - Return true if node matches a list of compatible values | 60 | * of_fdt_match - Return true if node matches a list of compatible values |
61 | */ | 61 | */ |
62 | int of_fdt_match(struct boot_param_header *blob, unsigned long node, | 62 | int of_fdt_match(const void *blob, unsigned long node, |
63 | const char *const *compat) | 63 | const char *const *compat) |
64 | { | 64 | { |
65 | unsigned int tmp, score = 0; | 65 | unsigned int tmp, score = 0; |
@@ -98,7 +98,7 @@ static void *unflatten_dt_alloc(void **mem, unsigned long size, | |||
98 | * @allnextpp: pointer to ->allnext from last allocated device_node | 98 | * @allnextpp: pointer to ->allnext from last allocated device_node |
99 | * @fpsize: Size of the node path up at the current depth. | 99 | * @fpsize: Size of the node path up at the current depth. |
100 | */ | 100 | */ |
101 | static void * unflatten_dt_node(struct boot_param_header *blob, | 101 | static void * unflatten_dt_node(void *blob, |
102 | void *mem, | 102 | void *mem, |
103 | int *poffset, | 103 | int *poffset, |
104 | struct device_node *dad, | 104 | struct device_node *dad, |
@@ -295,7 +295,7 @@ static void * unflatten_dt_node(struct boot_param_header *blob, | |||
295 | * @dt_alloc: An allocator that provides a virtual address to memory | 295 | * @dt_alloc: An allocator that provides a virtual address to memory |
296 | * for the resulting tree | 296 | * for the resulting tree |
297 | */ | 297 | */ |
298 | static void __unflatten_device_tree(struct boot_param_header *blob, | 298 | static void __unflatten_device_tree(void *blob, |
299 | struct device_node **mynodes, | 299 | struct device_node **mynodes, |
300 | void * (*dt_alloc)(u64 size, u64 align)) | 300 | void * (*dt_alloc)(u64 size, u64 align)) |
301 | { | 301 | { |
@@ -312,11 +312,11 @@ static void __unflatten_device_tree(struct boot_param_header *blob, | |||
312 | } | 312 | } |
313 | 313 | ||
314 | pr_debug("Unflattening device tree:\n"); | 314 | pr_debug("Unflattening device tree:\n"); |
315 | pr_debug("magic: %08x\n", be32_to_cpu(blob->magic)); | 315 | pr_debug("magic: %08x\n", fdt_magic(blob)); |
316 | pr_debug("size: %08x\n", be32_to_cpu(blob->totalsize)); | 316 | pr_debug("size: %08x\n", fdt_totalsize(blob)); |
317 | pr_debug("version: %08x\n", be32_to_cpu(blob->version)); | 317 | pr_debug("version: %08x\n", fdt_version(blob)); |
318 | 318 | ||
319 | if (be32_to_cpu(blob->magic) != OF_DT_HEADER) { | 319 | if (fdt_check_header(blob)) { |
320 | pr_err("Invalid device tree blob header\n"); | 320 | pr_err("Invalid device tree blob header\n"); |
321 | return; | 321 | return; |
322 | } | 322 | } |
@@ -363,9 +363,7 @@ static void *kernel_tree_alloc(u64 size, u64 align) | |||
363 | void of_fdt_unflatten_tree(unsigned long *blob, | 363 | void of_fdt_unflatten_tree(unsigned long *blob, |
364 | struct device_node **mynodes) | 364 | struct device_node **mynodes) |
365 | { | 365 | { |
366 | struct boot_param_header *device_tree = | 366 | __unflatten_device_tree(blob, mynodes, &kernel_tree_alloc); |
367 | (struct boot_param_header *)blob; | ||
368 | __unflatten_device_tree(device_tree, mynodes, &kernel_tree_alloc); | ||
369 | } | 367 | } |
370 | EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); | 368 | EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); |
371 | 369 | ||
@@ -852,7 +850,7 @@ bool __init early_init_dt_scan(void *params) | |||
852 | initial_boot_params = params; | 850 | initial_boot_params = params; |
853 | 851 | ||
854 | /* check device tree validity */ | 852 | /* check device tree validity */ |
855 | if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) { | 853 | if (fdt_check_header(params)) { |
856 | initial_boot_params = NULL; | 854 | initial_boot_params = NULL; |
857 | return false; | 855 | return false; |
858 | } | 856 | } |
@@ -907,9 +905,9 @@ void __init unflatten_and_copy_device_tree(void) | |||
907 | return; | 905 | return; |
908 | } | 906 | } |
909 | 907 | ||
910 | size = __be32_to_cpu(initial_boot_params->totalsize); | 908 | size = fdt_totalsize(initial_boot_params); |
911 | dt = early_init_dt_alloc_memory_arch(size, | 909 | dt = early_init_dt_alloc_memory_arch(size, |
912 | __alignof__(struct boot_param_header)); | 910 | roundup_pow_of_two(FDT_V17_SIZE)); |
913 | 911 | ||
914 | if (dt) { | 912 | if (dt) { |
915 | memcpy(dt, initial_boot_params, size); | 913 | memcpy(dt, initial_boot_params, size); |