diff options
author | Jeremy Kerr <jeremy.kerr@canonical.com> | 2010-01-30 03:45:26 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-02-09 10:34:10 -0500 |
commit | 337148812f97368a8ec4a69f1691e4c5ce3af494 (patch) | |
tree | 3fa2e5477c657cb2ebc40db9182d0989a5d60e13 /drivers/of/fdt.c | |
parent | 2e89e685a8fd0e8334de967739d11e2e28c1a4dd (diff) |
of: assume big-endian properties, adding conversions where necessary
Properties in the device tree are specified as big-endian. At present,
the only platforms to support device trees are also big-endian, so we've
been acessing the properties as raw values.
We'd like to add device tree support to little-endian platforms too, so
add endian conversion to the sites where we access property values in
the common of code.
Compiled on powerpc (ppc44x_defconfig & ppc64_defconfig) and arm (fdt
support only for now).
Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of/fdt.c')
-rw-r--r-- | drivers/of/fdt.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 968a86af530..5c5f03ef7f0 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c | |||
@@ -51,7 +51,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node, | |||
51 | int depth = -1; | 51 | int depth = -1; |
52 | 52 | ||
53 | do { | 53 | do { |
54 | u32 tag = *((u32 *)p); | 54 | u32 tag = be32_to_cpup((__be32 *)p); |
55 | char *pathp; | 55 | char *pathp; |
56 | 56 | ||
57 | p += 4; | 57 | p += 4; |
@@ -64,7 +64,7 @@ int __init of_scan_flat_dt(int (*it)(unsigned long node, | |||
64 | if (tag == OF_DT_END) | 64 | if (tag == OF_DT_END) |
65 | break; | 65 | break; |
66 | if (tag == OF_DT_PROP) { | 66 | if (tag == OF_DT_PROP) { |
67 | u32 sz = *((u32 *)p); | 67 | u32 sz = be32_to_cpup((__be32 *)p); |
68 | p += 8; | 68 | p += 8; |
69 | if (initial_boot_params->version < 0x10) | 69 | if (initial_boot_params->version < 0x10) |
70 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | 70 | p = _ALIGN(p, sz >= 8 ? 8 : 4); |
@@ -103,9 +103,9 @@ unsigned long __init of_get_flat_dt_root(void) | |||
103 | unsigned long p = ((unsigned long)initial_boot_params) + | 103 | unsigned long p = ((unsigned long)initial_boot_params) + |
104 | initial_boot_params->off_dt_struct; | 104 | initial_boot_params->off_dt_struct; |
105 | 105 | ||
106 | while (*((u32 *)p) == OF_DT_NOP) | 106 | while (be32_to_cpup((__be32 *)p) == OF_DT_NOP) |
107 | p += 4; | 107 | p += 4; |
108 | BUG_ON(*((u32 *)p) != OF_DT_BEGIN_NODE); | 108 | BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE); |
109 | p += 4; | 109 | p += 4; |
110 | return _ALIGN(p + strlen((char *)p) + 1, 4); | 110 | return _ALIGN(p + strlen((char *)p) + 1, 4); |
111 | } | 111 | } |
@@ -122,7 +122,7 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name, | |||
122 | unsigned long p = node; | 122 | unsigned long p = node; |
123 | 123 | ||
124 | do { | 124 | do { |
125 | u32 tag = *((u32 *)p); | 125 | u32 tag = be32_to_cpup((__be32 *)p); |
126 | u32 sz, noff; | 126 | u32 sz, noff; |
127 | const char *nstr; | 127 | const char *nstr; |
128 | 128 | ||
@@ -132,8 +132,8 @@ void *__init of_get_flat_dt_prop(unsigned long node, const char *name, | |||
132 | if (tag != OF_DT_PROP) | 132 | if (tag != OF_DT_PROP) |
133 | return NULL; | 133 | return NULL; |
134 | 134 | ||
135 | sz = *((u32 *)p); | 135 | sz = be32_to_cpup((__be32 *)p); |
136 | noff = *((u32 *)(p + 4)); | 136 | noff = be32_to_cpup((__be32 *)(p + 4)); |
137 | p += 8; | 137 | p += 8; |
138 | if (initial_boot_params->version < 0x10) | 138 | if (initial_boot_params->version < 0x10) |
139 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | 139 | p = _ALIGN(p, sz >= 8 ? 8 : 4); |
@@ -210,7 +210,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
210 | int has_name = 0; | 210 | int has_name = 0; |
211 | int new_format = 0; | 211 | int new_format = 0; |
212 | 212 | ||
213 | tag = *((u32 *)(*p)); | 213 | tag = be32_to_cpup((__be32 *)(*p)); |
214 | if (tag != OF_DT_BEGIN_NODE) { | 214 | if (tag != OF_DT_BEGIN_NODE) { |
215 | pr_err("Weird tag at start of node: %x\n", tag); | 215 | pr_err("Weird tag at start of node: %x\n", tag); |
216 | return mem; | 216 | return mem; |
@@ -285,7 +285,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
285 | u32 sz, noff; | 285 | u32 sz, noff; |
286 | char *pname; | 286 | char *pname; |
287 | 287 | ||
288 | tag = *((u32 *)(*p)); | 288 | tag = be32_to_cpup((__be32 *)(*p)); |
289 | if (tag == OF_DT_NOP) { | 289 | if (tag == OF_DT_NOP) { |
290 | *p += 4; | 290 | *p += 4; |
291 | continue; | 291 | continue; |
@@ -293,8 +293,8 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
293 | if (tag != OF_DT_PROP) | 293 | if (tag != OF_DT_PROP) |
294 | break; | 294 | break; |
295 | *p += 4; | 295 | *p += 4; |
296 | sz = *((u32 *)(*p)); | 296 | sz = be32_to_cpup((__be32 *)(*p)); |
297 | noff = *((u32 *)((*p) + 4)); | 297 | noff = be32_to_cpup((__be32 *)((*p) + 4)); |
298 | *p += 8; | 298 | *p += 8; |
299 | if (initial_boot_params->version < 0x10) | 299 | if (initial_boot_params->version < 0x10) |
300 | *p = _ALIGN(*p, sz >= 8 ? 8 : 4); | 300 | *p = _ALIGN(*p, sz >= 8 ? 8 : 4); |
@@ -367,7 +367,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
367 | } | 367 | } |
368 | while (tag == OF_DT_BEGIN_NODE) { | 368 | while (tag == OF_DT_BEGIN_NODE) { |
369 | mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); | 369 | mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); |
370 | tag = *((u32 *)(*p)); | 370 | tag = be32_to_cpup((__be32 *)(*p)); |
371 | } | 371 | } |
372 | if (tag != OF_DT_END_NODE) { | 372 | if (tag != OF_DT_END_NODE) { |
373 | pr_err("Weird tag at end of node: %x\n", tag); | 373 | pr_err("Weird tag at end of node: %x\n", tag); |
@@ -385,7 +385,7 @@ unsigned long __init unflatten_dt_node(unsigned long mem, | |||
385 | void __init early_init_dt_check_for_initrd(unsigned long node) | 385 | void __init early_init_dt_check_for_initrd(unsigned long node) |
386 | { | 386 | { |
387 | unsigned long start, end, len; | 387 | unsigned long start, end, len; |
388 | u32 *prop; | 388 | __be32 *prop; |
389 | 389 | ||
390 | pr_debug("Looking for initrd properties... "); | 390 | pr_debug("Looking for initrd properties... "); |
391 | 391 | ||
@@ -414,17 +414,22 @@ inline void early_init_dt_check_for_initrd(unsigned long node) | |||
414 | int __init early_init_dt_scan_root(unsigned long node, const char *uname, | 414 | int __init early_init_dt_scan_root(unsigned long node, const char *uname, |
415 | int depth, void *data) | 415 | int depth, void *data) |
416 | { | 416 | { |
417 | u32 *prop; | 417 | __be32 *prop; |
418 | 418 | ||
419 | if (depth != 0) | 419 | if (depth != 0) |
420 | return 0; | 420 | return 0; |
421 | 421 | ||
422 | dt_root_size_cells = OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | ||
423 | dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | ||
424 | |||
422 | prop = of_get_flat_dt_prop(node, "#size-cells", NULL); | 425 | prop = of_get_flat_dt_prop(node, "#size-cells", NULL); |
423 | dt_root_size_cells = prop ? *prop : OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | 426 | if (prop) |
427 | dt_root_size_cells = be32_to_cpup(prop); | ||
424 | pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells); | 428 | pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells); |
425 | 429 | ||
426 | prop = of_get_flat_dt_prop(node, "#address-cells", NULL); | 430 | prop = of_get_flat_dt_prop(node, "#address-cells", NULL); |
427 | dt_root_addr_cells = prop ? *prop : OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | 431 | if (prop) |
432 | dt_root_addr_cells = be32_to_cpup(prop); | ||
428 | pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells); | 433 | pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells); |
429 | 434 | ||
430 | /* break now */ | 435 | /* break now */ |
@@ -549,7 +554,7 @@ void __init unflatten_device_tree(void) | |||
549 | mem = lmb_alloc(size + 4, __alignof__(struct device_node)); | 554 | mem = lmb_alloc(size + 4, __alignof__(struct device_node)); |
550 | mem = (unsigned long) __va(mem); | 555 | mem = (unsigned long) __va(mem); |
551 | 556 | ||
552 | ((u32 *)mem)[size / 4] = 0xdeadbeef; | 557 | ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef); |
553 | 558 | ||
554 | pr_debug(" unflattening %lx...\n", mem); | 559 | pr_debug(" unflattening %lx...\n", mem); |
555 | 560 | ||
@@ -557,11 +562,11 @@ void __init unflatten_device_tree(void) | |||
557 | start = ((unsigned long)initial_boot_params) + | 562 | start = ((unsigned long)initial_boot_params) + |
558 | initial_boot_params->off_dt_struct; | 563 | initial_boot_params->off_dt_struct; |
559 | unflatten_dt_node(mem, &start, NULL, &allnextp, 0); | 564 | unflatten_dt_node(mem, &start, NULL, &allnextp, 0); |
560 | if (*((u32 *)start) != OF_DT_END) | 565 | if (be32_to_cpup((__be32 *)start) != OF_DT_END) |
561 | pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start)); | 566 | pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start)); |
562 | if (((u32 *)mem)[size / 4] != 0xdeadbeef) | 567 | if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef) |
563 | pr_warning("End of tree marker overwritten: %08x\n", | 568 | pr_warning("End of tree marker overwritten: %08x\n", |
564 | ((u32 *)mem)[size / 4]); | 569 | be32_to_cpu(((__be32 *)mem)[size / 4])); |
565 | *allnextp = NULL; | 570 | *allnextp = NULL; |
566 | 571 | ||
567 | /* Get pointer to OF "/chosen" node for use everywhere */ | 572 | /* Get pointer to OF "/chosen" node for use everywhere */ |