1 // SPDX-License-Identifier: GPL-2.0
2 /* devices.c: Initial scan of the prom device tree for important
3 * Sparc device nodes which we need to find.
5 * This is based on the sparc64 version, but sun4m doesn't always use
6 * the hardware MIDs, so be careful.
8 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
11 #include <linux/kernel.h>
12 #include <linux/threads.h>
13 #include <linux/string.h>
14 #include <linux/init.h>
15 #include <linux/errno.h>
18 #include <asm/oplib.h>
21 #include <asm/cpudata.h>
22 #include <asm/cpu_type.h>
23 #include <asm/setup.h>
27 static char *cpu_mid_prop(void)
29 if (sparc_cpu_model == sun4d)
34 static int check_cpu_node(phandle nd, int *cur_inst,
35 int (*compare)(phandle, int, void *), void *compare_arg,
36 phandle *prom_node, int *mid)
38 if (!compare(nd, *cur_inst, compare_arg)) {
42 *mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
43 if (sparc_cpu_model == sun4m)
54 static int __cpu_find_by(int (*compare)(phandle, int, void *),
55 void *compare_arg, phandle *prom_node, int *mid)
57 struct device_node *dp;
61 for_each_node_by_type(dp, "cpu") {
62 int err = check_cpu_node(dp->phandle, &cur_inst,
74 static int cpu_instance_compare(phandle nd, int instance, void *_arg)
76 int desired_instance = (int) _arg;
78 if (instance == desired_instance)
83 int cpu_find_by_instance(int instance, phandle *prom_node, int *mid)
85 return __cpu_find_by(cpu_instance_compare, (void *)instance,
89 static int cpu_mid_compare(phandle nd, int instance, void *_arg)
91 int desired_mid = (int) _arg;
94 this_mid = prom_getintdefault(nd, cpu_mid_prop(), 0);
95 if (this_mid == desired_mid
96 || (sparc_cpu_model == sun4m && (this_mid & 3) == desired_mid))
101 int cpu_find_by_mid(int mid, phandle *prom_node)
103 return __cpu_find_by(cpu_mid_compare, (void *)mid,
107 /* sun4m uses truncated mids since we base the cpuid on the ttable/irqset
108 * address (0-3). This gives us the true hardware mid, which might have
109 * some other bits set. On 4d hardware and software mids are the same.
111 int cpu_get_hwmid(phandle prom_node)
113 return prom_getintdefault(prom_node, cpu_mid_prop(), -ENODEV);
116 void __init device_scan(void)
118 printk(KERN_NOTICE "Booting Linux...\n");
124 err = cpu_find_by_instance(0, &cpu_node, NULL);
126 /* Probably a sun4e, Sun is trying to trick us ;-) */
127 prom_printf("No cpu nodes, cannot continue\n");
130 cpu_data(0).clock_tick = prom_getintdefault(cpu_node,
134 #endif /* !CONFIG_SMP */