0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/init.h>
0009 #include <linux/export.h>
0010 #include <linux/errno.h>
0011 #include <linux/types.h>
0012 #include <linux/memblock.h>
0013 #include <linux/of.h>
0014 #include <linux/of_fdt.h>
0015 #include <linux/of_irq.h>
0016 #include <linux/of_platform.h>
0017 #include <linux/smp.h>
0018
0019 #include <asm/cputype.h>
0020 #include <asm/setup.h>
0021 #include <asm/page.h>
0022 #include <asm/prom.h>
0023 #include <asm/smp_plat.h>
0024 #include <asm/mach/arch.h>
0025 #include <asm/mach-types.h>
0026
0027
0028 #ifdef CONFIG_SMP
0029 extern struct of_cpu_method __cpu_method_of_table[];
0030
0031 static const struct of_cpu_method __cpu_method_of_table_sentinel
0032 __used __section("__cpu_method_of_table_end");
0033
0034
0035 static int __init set_smp_ops_by_method(struct device_node *node)
0036 {
0037 const char *method;
0038 struct of_cpu_method *m = __cpu_method_of_table;
0039
0040 if (of_property_read_string(node, "enable-method", &method))
0041 return 0;
0042
0043 for (; m->method; m++)
0044 if (!strcmp(m->method, method)) {
0045 smp_set_ops(m->ops);
0046 return 1;
0047 }
0048
0049 return 0;
0050 }
0051 #else
0052 static inline int set_smp_ops_by_method(struct device_node *node)
0053 {
0054 return 1;
0055 }
0056 #endif
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 void __init arm_dt_init_cpu_maps(void)
0067 {
0068
0069
0070
0071
0072
0073
0074 struct device_node *cpu, *cpus;
0075 int found_method = 0;
0076 u32 i, j, cpuidx = 1;
0077 u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
0078
0079 u32 tmp_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
0080 bool bootcpu_valid = false;
0081 cpus = of_find_node_by_path("/cpus");
0082
0083 if (!cpus)
0084 return;
0085
0086 for_each_of_cpu_node(cpu) {
0087 u32 hwid = of_get_cpu_hwid(cpu, 0);
0088
0089 pr_debug(" * %pOF...\n", cpu);
0090
0091
0092
0093
0094
0095 if (hwid & ~MPIDR_HWID_BITMASK) {
0096 of_node_put(cpu);
0097 return;
0098 }
0099
0100
0101
0102
0103
0104
0105
0106
0107 for (j = 0; j < cpuidx; j++)
0108 if (WARN(tmp_map[j] == hwid,
0109 "Duplicate /cpu reg properties in the DT\n")) {
0110 of_node_put(cpu);
0111 return;
0112 }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 if (hwid == mpidr) {
0124 i = 0;
0125 bootcpu_valid = true;
0126 } else {
0127 i = cpuidx++;
0128 }
0129
0130 if (WARN(cpuidx > nr_cpu_ids, "DT /cpu %u nodes greater than "
0131 "max cores %u, capping them\n",
0132 cpuidx, nr_cpu_ids)) {
0133 cpuidx = nr_cpu_ids;
0134 of_node_put(cpu);
0135 break;
0136 }
0137
0138 tmp_map[i] = hwid;
0139
0140 if (!found_method)
0141 found_method = set_smp_ops_by_method(cpu);
0142 }
0143
0144
0145
0146
0147
0148 if (!found_method)
0149 set_smp_ops_by_method(cpus);
0150
0151 if (!bootcpu_valid) {
0152 pr_warn("DT missing boot CPU MPIDR[23:0], fall back to default cpu_logical_map\n");
0153 return;
0154 }
0155
0156
0157
0158
0159
0160
0161 for (i = 0; i < cpuidx; i++) {
0162 set_cpu_possible(i, true);
0163 cpu_logical_map(i) = tmp_map[i];
0164 pr_debug("cpu logical map 0x%x\n", cpu_logical_map(i));
0165 }
0166 }
0167
0168 bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
0169 {
0170 return phys_id == cpu_logical_map(cpu);
0171 }
0172
0173 static const void * __init arch_get_next_mach(const char *const **match)
0174 {
0175 static const struct machine_desc *mdesc = __arch_info_begin;
0176 const struct machine_desc *m = mdesc;
0177
0178 if (m >= __arch_info_end)
0179 return NULL;
0180
0181 mdesc++;
0182 *match = m->dt_compat;
0183 return m;
0184 }
0185
0186
0187
0188
0189
0190
0191
0192
0193 const struct machine_desc * __init setup_machine_fdt(void *dt_virt)
0194 {
0195 const struct machine_desc *mdesc, *mdesc_best = NULL;
0196
0197 #if defined(CONFIG_ARCH_MULTIPLATFORM) || defined(CONFIG_ARM_SINGLE_ARMV7M)
0198 DT_MACHINE_START(GENERIC_DT, "Generic DT based system")
0199 .l2c_aux_val = 0x0,
0200 .l2c_aux_mask = ~0x0,
0201 MACHINE_END
0202
0203 mdesc_best = &__mach_desc_GENERIC_DT;
0204 #endif
0205
0206 if (!dt_virt || !early_init_dt_verify(dt_virt))
0207 return NULL;
0208
0209 mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach);
0210
0211 if (!mdesc) {
0212 const char *prop;
0213 int size;
0214 unsigned long dt_root;
0215
0216 early_print("\nError: unrecognized/unsupported "
0217 "device tree compatible list:\n[ ");
0218
0219 dt_root = of_get_flat_dt_root();
0220 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
0221 while (size > 0) {
0222 early_print("'%s' ", prop);
0223 size -= strlen(prop) + 1;
0224 prop += strlen(prop) + 1;
0225 }
0226 early_print("]\n\n");
0227
0228 dump_machine_table();
0229 }
0230
0231
0232 if (mdesc->dt_fixup)
0233 mdesc->dt_fixup();
0234
0235 early_init_dt_scan_nodes();
0236
0237
0238 __machine_arch_type = mdesc->nr;
0239
0240 return mdesc;
0241 }