[POWERPC] Define of_read_ulong helper
authorPaul Mackerras <paulus@samba.org>
Tue, 19 Sep 2006 04:06:27 +0000 (14:06 +1000)
committerPaul Mackerras <paulus@samba.org>
Wed, 20 Sep 2006 05:09:48 +0000 (15:09 +1000)
There are various places where we want to extract an unsigned long
value from a device-tree property that can be 1 or 2 cells in length.
This replaces some open-coded calculations, and one place where we
assumed without checking that properties were the length we wanted,
with a little of_read_ulong() helper.

Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/kernel/prom.c
arch/powerpc/kernel/setup-common.c
arch/powerpc/kernel/time.c
include/asm-powerpc/prom.h

index bf2005b2feb61dedab2203d0e958b12890f9df54..eb913f80bfb1f6540aaad75d584fc2af2646b95f 100644 (file)
@@ -757,24 +757,9 @@ static int __init early_init_dt_scan_root(unsigned long node,
 static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
 {
        cell_t *p = *cellp;
-       unsigned long r;
 
-       /* Ignore more than 2 cells */
-       while (s > sizeof(unsigned long) / 4) {
-               p++;
-               s--;
-       }
-       r = *p++;
-#ifdef CONFIG_PPC64
-       if (s > 1) {
-               r <<= 32;
-               r |= *(p++);
-               s--;
-       }
-#endif
-
-       *cellp = p;
-       return r;
+       *cellp = p + s;
+       return of_read_ulong(p, s);
 }
 
 
index 465e7435efbcd21849d4757d761d117094abd0c5..0af3fc1bdcc929fd37a457d6c05ef1521bf5ab0d 100644 (file)
@@ -304,18 +304,21 @@ struct seq_operations cpuinfo_op = {
 void __init check_for_initrd(void)
 {
 #ifdef CONFIG_BLK_DEV_INITRD
-       const unsigned long *prop;
+       const unsigned int *prop;
+       int len;
 
        DBG(" -> check_for_initrd()\n");
 
        if (of_chosen) {
-               prop = get_property(of_chosen, "linux,initrd-start", NULL);
+               prop = get_property(of_chosen, "linux,initrd-start", &len);
                if (prop != NULL) {
-                       initrd_start = (unsigned long)__va(*prop);
+                       initrd_start = (unsigned long)
+                               __va(of_read_ulong(prop, len / 4));
                        prop = get_property(of_chosen,
-                                       "linux,initrd-end", NULL);
+                                       "linux,initrd-end", &len);
                        if (prop != NULL) {
-                               initrd_end = (unsigned long)__va(*prop);
+                               initrd_end = (unsigned long)
+                                       __va(of_read_ulong(prop, len / 4));
                                initrd_below_start_ok = 1;
                        } else
                                initrd_start = 0;
index b9a2061cfdb7e3b25f42d97e76b57b7e97ce7924..7a3c3f791ade2aaac30bbadc0994da40ea12e80a 100644 (file)
@@ -870,9 +870,7 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
                fp = get_property(cpu, name, NULL);
                if (fp) {
                        found = 1;
-                       *val = 0;
-                       while (cells--)
-                               *val = (*val << 32) | *fp++;
+                       *val = of_read_ulong(fp, cells);
                }
 
                of_node_put(cpu);
index c15e66a2e68120359490cba34a3b67987bafb454..5246297693369d677ca698ca3e2cc795e2f1faf4 100644 (file)
@@ -197,7 +197,7 @@ extern int release_OF_resource(struct device_node* node, int index);
  */
 
 
-/* Helper to read a big number */
+/* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const u32 *cell, int size)
 {
        u64 r = 0;
@@ -206,6 +206,16 @@ static inline u64 of_read_number(const u32 *cell, int size)
        return r;
 }
 
+/* Like of_read_number, but we want an unsigned long result */
+#ifdef CONFIG_PPC32
+static inline unsigned long of_read_ulong(const u32 *cell, int size)
+{
+       return cell[size-1];
+}
+#else
+#define of_read_ulong(cell, size)      of_read_number(cell, size)
+#endif
+
 /* Translate an OF address block into a CPU physical address
  */
 #define OF_BAD_ADDR    ((u64)-1)