devices.c 4.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/* devices.c: Initial scan of the prom device tree for important
 *            Sparc device nodes which we need to find.
 *
 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
 */

#include <linux/kernel.h>
#include <linux/threads.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
14
#include <linux/bootmem.h>
L
Linus Torvalds 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

#include <asm/page.h>
#include <asm/oplib.h>
#include <asm/system.h>
#include <asm/smp.h>
#include <asm/spitfire.h>
#include <asm/timer.h>
#include <asm/cpudata.h>

/* Used to synchronize acceses to NatSemi SUPER I/O chip configure
 * operations in asm/ns87303.h
 */
DEFINE_SPINLOCK(ns87303_lock);

extern void cpu_probe(void);
extern void central_probe(void);

32
static const char *cpu_mid_prop(void)
L
Linus Torvalds 已提交
33 34 35 36 37 38
{
	if (tlb_type == spitfire)
		return "upa-portid";
	return "portid";
}

39
static int get_cpu_mid(struct device_node *dp)
40
{
41 42
	struct property *prop;

43
	if (tlb_type == hypervisor) {
44 45
		struct linux_prom64_registers *reg;
		int len;
46

47 48 49
		prop = of_find_property(dp, "cpuid", &len);
		if (prop && len == 4)
			return *(int *) prop->value;
50

51 52 53
		prop = of_find_property(dp, "reg", NULL);
		reg = prop->value;
		return (reg[0].phys_addr >> 32) & 0x0fffffffUL;
54 55 56
	} else {
		const char *prop_name = cpu_mid_prop();

57 58 59 60
		prop = of_find_property(dp, prop_name, NULL);
		if (prop)
			return *(int *) prop->value;
		return 0;
61 62 63
	}
}

64 65 66 67
static int check_cpu_node(struct device_node *dp, int *cur_inst,
			  int (*compare)(struct device_node *, int, void *),
			  void *compare_arg,
			  struct device_node **dev_node, int *mid)
L
Linus Torvalds 已提交
68
{
69
	if (strcmp(dp->type, "cpu"))
L
Linus Torvalds 已提交
70 71
		return -ENODEV;

72 73 74
	if (!compare(dp, *cur_inst, compare_arg)) {
		if (dev_node)
			*dev_node = dp;
L
Linus Torvalds 已提交
75
		if (mid)
76
			*mid = get_cpu_mid(dp);
L
Linus Torvalds 已提交
77 78 79 80 81 82 83 84
		return 0;
	}

	(*cur_inst)++;

	return -ENODEV;
}

85 86 87
static int __cpu_find_by(int (*compare)(struct device_node *, int, void *),
			 void *compare_arg,
			 struct device_node **dev_node, int *mid)
L
Linus Torvalds 已提交
88
{
89 90
	struct device_node *dp;
	int cur_inst;
L
Linus Torvalds 已提交
91 92

	cur_inst = 0;
93 94 95 96
	for_each_node_by_type(dp, "cpu") {
		int err = check_cpu_node(dp, &cur_inst,
					 compare, compare_arg,
					 dev_node, mid);
L
Linus Torvalds 已提交
97 98 99 100 101 102 103
		if (err == 0)
			return 0;
	}

	return -ENODEV;
}

104
static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg)
L
Linus Torvalds 已提交
105 106 107 108 109 110 111 112
{
	int desired_instance = (int) (long) _arg;

	if (instance == desired_instance)
		return 0;
	return -ENODEV;
}

113
int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid)
L
Linus Torvalds 已提交
114 115
{
	return __cpu_find_by(cpu_instance_compare, (void *)(long)instance,
116
			     dev_node, mid);
L
Linus Torvalds 已提交
117 118
}

119
static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg)
L
Linus Torvalds 已提交
120 121 122 123
{
	int desired_mid = (int) (long) _arg;
	int this_mid;

124
	this_mid = get_cpu_mid(dp);
L
Linus Torvalds 已提交
125 126 127 128 129
	if (this_mid == desired_mid)
		return 0;
	return -ENODEV;
}

130
int cpu_find_by_mid(int mid, struct device_node **dev_node)
L
Linus Torvalds 已提交
131 132
{
	return __cpu_find_by(cpu_mid_compare, (void *)(long)mid,
133
			     dev_node, NULL);
L
Linus Torvalds 已提交
134 135 136 137 138 139 140 141 142 143 144
}

void __init device_scan(void)
{
	/* FIX ME FAST... -DaveM */
	ioport_resource.end = 0xffffffffffffffffUL;

	prom_printf("Booting Linux...\n");

#ifndef CONFIG_SMP
	{
145 146
		struct device_node *dp;
		int err, def;
147

148
		err = cpu_find_by_instance(0, &dp, NULL);
L
Linus Torvalds 已提交
149 150 151 152
		if (err) {
			prom_printf("No cpu nodes, cannot continue\n");
			prom_halt();
		}
153 154
		cpu_data(0).clock_tick =
			of_getintprop_default(dp, "clock-frequency", 0);
155 156 157 158

		def = ((tlb_type == hypervisor) ?
		       (8 * 1024) :
		       (16 * 1024));
159 160 161
		cpu_data(0).dcache_size = of_getintprop_default(dp,
								"dcache-size",
								def);
162 163

		def = 32;
164
		cpu_data(0).dcache_line_size =
165
			of_getintprop_default(dp, "dcache-line-size", def);
166 167

		def = 16 * 1024;
168 169 170
		cpu_data(0).icache_size = of_getintprop_default(dp,
								"icache-size",
								def);
171 172

		def = 32;
173
		cpu_data(0).icache_line_size =
174
			of_getintprop_default(dp, "icache-line-size", def);
175 176 177 178

		def = ((tlb_type == hypervisor) ?
		       (3 * 1024 * 1024) :
		       (4 * 1024 * 1024));
179 180 181
		cpu_data(0).ecache_size = of_getintprop_default(dp,
								"ecache-size",
								def);
182 183

		def = 64;
184
		cpu_data(0).ecache_line_size =
185
			of_getintprop_default(dp, "ecache-line-size", def);
186 187 188 189 190 191 192
		printk("CPU[0]: Caches "
		       "D[sz(%d):line_sz(%d)] "
		       "I[sz(%d):line_sz(%d)] "
		       "E[sz(%d):line_sz(%d)]\n",
		       cpu_data(0).dcache_size, cpu_data(0).dcache_line_size,
		       cpu_data(0).icache_size, cpu_data(0).icache_line_size,
		       cpu_data(0).ecache_size, cpu_data(0).ecache_line_size);
L
Linus Torvalds 已提交
193 194 195 196 197 198 199
	}
#endif

	central_probe();

	cpu_probe();
}