aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2009-11-23 22:06:59 -0500
committerGrant Likely <grant.likely@secretlab.ca>2009-11-23 22:06:59 -0500
commitca900cfa2944448bdb76e1246f282e59bc65f472 (patch)
treeafddd9358f1772cc5467c3c012a0c3e998a3c8c7
parent31a6a87dfc34fbf02aef9a160adf558ec56d3ccd (diff)
of/flattree: merge of_get_flat_dt_prop
Merge common code between PowerPC and Microblaze Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Reviewed-by: Wolfram Sang <w.sang@pengutronix.de> Tested-by: Michal Simek <monstr@monstr.eu>
-rw-r--r--arch/microblaze/kernel/prom.c42
-rw-r--r--arch/powerpc/kernel/prom.c42
-rw-r--r--drivers/of/fdt.c43
3 files changed, 43 insertions, 84 deletions
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c
index 7eb6f8bdb81a..d75c6253c0de 100644
--- a/arch/microblaze/kernel/prom.c
+++ b/arch/microblaze/kernel/prom.c
@@ -50,48 +50,6 @@ typedef u32 cell_t;
50/* export that to outside world */ 50/* export that to outside world */
51struct device_node *of_chosen; 51struct device_node *of_chosen;
52 52
53/**
54 * This function can be used within scan_flattened_dt callback to get
55 * access to properties
56 */
57void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
58 unsigned long *size)
59{
60 unsigned long p = node;
61
62 do {
63 u32 tag = *((u32 *)p);
64 u32 sz, noff;
65 const char *nstr;
66
67 p += 4;
68 if (tag == OF_DT_NOP)
69 continue;
70 if (tag != OF_DT_PROP)
71 return NULL;
72
73 sz = *((u32 *)p);
74 noff = *((u32 *)(p + 4));
75 p += 8;
76 if (initial_boot_params->version < 0x10)
77 p = _ALIGN(p, sz >= 8 ? 8 : 4);
78
79 nstr = find_flat_dt_string(noff);
80 if (nstr == NULL) {
81 printk(KERN_WARNING "Can't find property index"
82 " name !\n");
83 return NULL;
84 }
85 if (strcmp(name, nstr) == 0) {
86 if (size)
87 *size = sz;
88 return (void *)p;
89 }
90 p += sz;
91 p = _ALIGN(p, 4);
92 } while (1);
93}
94
95int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) 53int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
96{ 54{
97 const char *cp; 55 const char *cp;
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index b5d5f85e9c2c..cd0a2bfc978b 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -80,48 +80,6 @@ extern rwlock_t devtree_lock; /* temporary while merging */
80/* export that to outside world */ 80/* export that to outside world */
81struct device_node *of_chosen; 81struct device_node *of_chosen;
82 82
83/**
84 * This function can be used within scan_flattened_dt callback to get
85 * access to properties
86 */
87void* __init of_get_flat_dt_prop(unsigned long node, const char *name,
88 unsigned long *size)
89{
90 unsigned long p = node;
91
92 do {
93 u32 tag = *((u32 *)p);
94 u32 sz, noff;
95 const char *nstr;
96
97 p += 4;
98 if (tag == OF_DT_NOP)
99 continue;
100 if (tag != OF_DT_PROP)
101 return NULL;
102
103 sz = *((u32 *)p);
104 noff = *((u32 *)(p + 4));
105 p += 8;
106 if (initial_boot_params->version < 0x10)
107 p = _ALIGN(p, sz >= 8 ? 8 : 4);
108
109 nstr = find_flat_dt_string(noff);
110 if (nstr == NULL) {
111 printk(KERN_WARNING "Can't find property index"
112 " name !\n");
113 return NULL;
114 }
115 if (strcmp(name, nstr) == 0) {
116 if (size)
117 *size = sz;
118 return (void *)p;
119 }
120 p += sz;
121 p = _ALIGN(p, 4);
122 } while(1);
123}
124
125int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) 83int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
126{ 84{
127 const char* cp; 85 const char* cp;
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index f41d739aa2f7..b17a9086cbfc 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -99,3 +99,46 @@ unsigned long __init of_get_flat_dt_root(void)
99 return _ALIGN(p + strlen((char *)p) + 1, 4); 99 return _ALIGN(p + strlen((char *)p) + 1, 4);
100} 100}
101 101
102/**
103 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
104 *
105 * This function can be used within scan_flattened_dt callback to get
106 * access to properties
107 */
108void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
109 unsigned long *size)
110{
111 unsigned long p = node;
112
113 do {
114 u32 tag = *((u32 *)p);
115 u32 sz, noff;
116 const char *nstr;
117
118 p += 4;
119 if (tag == OF_DT_NOP)
120 continue;
121 if (tag != OF_DT_PROP)
122 return NULL;
123
124 sz = *((u32 *)p);
125 noff = *((u32 *)(p + 4));
126 p += 8;
127 if (initial_boot_params->version < 0x10)
128 p = _ALIGN(p, sz >= 8 ? 8 : 4);
129
130 nstr = find_flat_dt_string(noff);
131 if (nstr == NULL) {
132 pr_warning("Can't find property index name !\n");
133 return NULL;
134 }
135 if (strcmp(name, nstr) == 0) {
136 if (size)
137 *size = sz;
138 return (void *)p;
139 }
140 p += sz;
141 p = _ALIGN(p, 4);
142 } while (1);
143}
144