aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/kernel/devtree.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/kernel/devtree.c')
-rw-r--r--arch/arm/kernel/devtree.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index f35906b3d8c9..739c3dfc1da2 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -174,6 +174,19 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
174 return (phys_id & MPIDR_HWID_BITMASK) == cpu_logical_map(cpu); 174 return (phys_id & MPIDR_HWID_BITMASK) == cpu_logical_map(cpu);
175} 175}
176 176
177static const void * __init arch_get_next_mach(const char *const **match)
178{
179 static const struct machine_desc *mdesc = __arch_info_begin;
180 const struct machine_desc *m = mdesc;
181
182 if (m >= __arch_info_end)
183 return NULL;
184
185 mdesc++;
186 *match = m->dt_compat;
187 return m;
188}
189
177/** 190/**
178 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel 191 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
179 * @dt_phys: physical address of dt blob 192 * @dt_phys: physical address of dt blob
@@ -183,11 +196,7 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
183 */ 196 */
184const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys) 197const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
185{ 198{
186 struct boot_param_header *devtree;
187 const struct machine_desc *mdesc, *mdesc_best = NULL; 199 const struct machine_desc *mdesc, *mdesc_best = NULL;
188 unsigned int score, mdesc_score = ~1;
189 unsigned long dt_root;
190 const char *model;
191 200
192#ifdef CONFIG_ARCH_MULTIPLATFORM 201#ifdef CONFIG_ARCH_MULTIPLATFORM
193 DT_MACHINE_START(GENERIC_DT, "Generic DT based system") 202 DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
@@ -196,32 +205,20 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
196 mdesc_best = &__mach_desc_GENERIC_DT; 205 mdesc_best = &__mach_desc_GENERIC_DT;
197#endif 206#endif
198 207
199 if (!dt_phys) 208 if (!dt_phys || !early_init_dt_scan(phys_to_virt(dt_phys)))
200 return NULL; 209 return NULL;
201 210
202 devtree = phys_to_virt(dt_phys); 211 mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach);
203 212
204 /* check device tree validity */ 213 if (!mdesc) {
205 if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
206 return NULL;
207
208 /* Search the mdescs for the 'best' compatible value match */
209 initial_boot_params = devtree;
210 dt_root = of_get_flat_dt_root();
211 for_each_machine_desc(mdesc) {
212 score = of_flat_dt_match(dt_root, mdesc->dt_compat);
213 if (score > 0 && score < mdesc_score) {
214 mdesc_best = mdesc;
215 mdesc_score = score;
216 }
217 }
218 if (!mdesc_best) {
219 const char *prop; 214 const char *prop;
220 long size; 215 long size;
216 unsigned long dt_root;
221 217
222 early_print("\nError: unrecognized/unsupported " 218 early_print("\nError: unrecognized/unsupported "
223 "device tree compatible list:\n[ "); 219 "device tree compatible list:\n[ ");
224 220
221 dt_root = of_get_flat_dt_root();
225 prop = of_get_flat_dt_prop(dt_root, "compatible", &size); 222 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
226 while (size > 0) { 223 while (size > 0) {
227 early_print("'%s' ", prop); 224 early_print("'%s' ", prop);
@@ -233,22 +230,8 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
233 dump_machine_table(); /* does not return */ 230 dump_machine_table(); /* does not return */
234 } 231 }
235 232
236 model = of_get_flat_dt_prop(dt_root, "model", NULL);
237 if (!model)
238 model = of_get_flat_dt_prop(dt_root, "compatible", NULL);
239 if (!model)
240 model = "<unknown>";
241 pr_info("Machine: %s, model: %s\n", mdesc_best->name, model);
242
243 /* Retrieve various information from the /chosen node */
244 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
245 /* Initialize {size,address}-cells info */
246 of_scan_flat_dt(early_init_dt_scan_root, NULL);
247 /* Setup memory, calling early_init_dt_add_memory_arch */
248 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
249
250 /* Change machine number to match the mdesc we're using */ 233 /* Change machine number to match the mdesc we're using */
251 __machine_arch_type = mdesc_best->nr; 234 __machine_arch_type = mdesc->nr;
252 235
253 return mdesc_best; 236 return mdesc;
254} 237}