| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* devices.c: Initial scan of the prom device tree for important | 
|  | 2 | *            Sparc device nodes which we need to find. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) | 
|  | 5 | */ | 
|  | 6 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/kernel.h> | 
|  | 8 | #include <linux/threads.h> | 
|  | 9 | #include <linux/init.h> | 
|  | 10 | #include <linux/ioport.h> | 
|  | 11 | #include <linux/string.h> | 
|  | 12 | #include <linux/spinlock.h> | 
|  | 13 | #include <linux/errno.h> | 
| David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 14 | #include <linux/bootmem.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 |  | 
|  | 16 | #include <asm/page.h> | 
|  | 17 | #include <asm/oplib.h> | 
|  | 18 | #include <asm/system.h> | 
|  | 19 | #include <asm/smp.h> | 
|  | 20 | #include <asm/spitfire.h> | 
|  | 21 | #include <asm/timer.h> | 
|  | 22 | #include <asm/cpudata.h> | 
|  | 23 |  | 
|  | 24 | /* Used to synchronize acceses to NatSemi SUPER I/O chip configure | 
|  | 25 | * operations in asm/ns87303.h | 
|  | 26 | */ | 
|  | 27 | DEFINE_SPINLOCK(ns87303_lock); | 
|  | 28 |  | 
|  | 29 | extern void cpu_probe(void); | 
|  | 30 | extern void central_probe(void); | 
|  | 31 |  | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 32 | static const char *cpu_mid_prop(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { | 
|  | 34 | if (tlb_type == spitfire) | 
|  | 35 | return "upa-portid"; | 
|  | 36 | return "portid"; | 
|  | 37 | } | 
|  | 38 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 39 | static int get_cpu_mid(struct device_node *dp) | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 40 | { | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 41 | struct property *prop; | 
|  | 42 |  | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 43 | if (tlb_type == hypervisor) { | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 44 | struct linux_prom64_registers *reg; | 
|  | 45 | int len; | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 46 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 47 | prop = of_find_property(dp, "cpuid", &len); | 
|  | 48 | if (prop && len == 4) | 
|  | 49 | return *(int *) prop->value; | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 50 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 51 | prop = of_find_property(dp, "reg", NULL); | 
|  | 52 | reg = prop->value; | 
|  | 53 | return (reg[0].phys_addr >> 32) & 0x0fffffffUL; | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 54 | } else { | 
|  | 55 | const char *prop_name = cpu_mid_prop(); | 
|  | 56 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 57 | prop = of_find_property(dp, prop_name, NULL); | 
|  | 58 | if (prop) | 
|  | 59 | return *(int *) prop->value; | 
|  | 60 | return 0; | 
| David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 61 | } | 
|  | 62 | } | 
|  | 63 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 64 | static int check_cpu_node(struct device_node *dp, int *cur_inst, | 
|  | 65 | int (*compare)(struct device_node *, int, void *), | 
|  | 66 | void *compare_arg, | 
|  | 67 | struct device_node **dev_node, int *mid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 69 | if (!compare(dp, *cur_inst, compare_arg)) { | 
|  | 70 | if (dev_node) | 
|  | 71 | *dev_node = dp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (mid) | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 73 | *mid = get_cpu_mid(dp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return 0; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | (*cur_inst)++; | 
|  | 78 |  | 
|  | 79 | return -ENODEV; | 
|  | 80 | } | 
|  | 81 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 82 | static int __cpu_find_by(int (*compare)(struct device_node *, int, void *), | 
|  | 83 | void *compare_arg, | 
|  | 84 | struct device_node **dev_node, int *mid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 86 | struct device_node *dp; | 
|  | 87 | int cur_inst; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | cur_inst = 0; | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 90 | for_each_node_by_type(dp, "cpu") { | 
|  | 91 | int err = check_cpu_node(dp, &cur_inst, | 
|  | 92 | compare, compare_arg, | 
|  | 93 | dev_node, mid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (err == 0) | 
|  | 95 | return 0; | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | return -ENODEV; | 
|  | 99 | } | 
|  | 100 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 101 | static int cpu_instance_compare(struct device_node *dp, int instance, void *_arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { | 
|  | 103 | int desired_instance = (int) (long) _arg; | 
|  | 104 |  | 
|  | 105 | if (instance == desired_instance) | 
|  | 106 | return 0; | 
|  | 107 | return -ENODEV; | 
|  | 108 | } | 
|  | 109 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 110 | int cpu_find_by_instance(int instance, struct device_node **dev_node, int *mid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { | 
|  | 112 | return __cpu_find_by(cpu_instance_compare, (void *)(long)instance, | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 113 | dev_node, mid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 116 | static int cpu_mid_compare(struct device_node *dp, int instance, void *_arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { | 
|  | 118 | int desired_mid = (int) (long) _arg; | 
|  | 119 | int this_mid; | 
|  | 120 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 121 | this_mid = get_cpu_mid(dp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (this_mid == desired_mid) | 
|  | 123 | return 0; | 
|  | 124 | return -ENODEV; | 
|  | 125 | } | 
|  | 126 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 127 | int cpu_find_by_mid(int mid, struct device_node **dev_node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { | 
|  | 129 | return __cpu_find_by(cpu_mid_compare, (void *)(long)mid, | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 130 | dev_node, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
|  | 133 | void __init device_scan(void) | 
|  | 134 | { | 
|  | 135 | /* FIX ME FAST... -DaveM */ | 
|  | 136 | ioport_resource.end = 0xffffffffffffffffUL; | 
|  | 137 |  | 
|  | 138 | prom_printf("Booting Linux...\n"); | 
|  | 139 |  | 
|  | 140 | #ifndef CONFIG_SMP | 
|  | 141 | { | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 142 | struct device_node *dp; | 
|  | 143 | int err, def; | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 144 |  | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 145 | err = cpu_find_by_instance(0, &dp, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if (err) { | 
|  | 147 | prom_printf("No cpu nodes, cannot continue\n"); | 
|  | 148 | prom_halt(); | 
|  | 149 | } | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 150 | cpu_data(0).clock_tick = | 
|  | 151 | of_getintprop_default(dp, "clock-frequency", 0); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 152 |  | 
|  | 153 | def = ((tlb_type == hypervisor) ? | 
|  | 154 | (8 * 1024) : | 
|  | 155 | (16 * 1024)); | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 156 | cpu_data(0).dcache_size = of_getintprop_default(dp, | 
|  | 157 | "dcache-size", | 
|  | 158 | def); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 159 |  | 
|  | 160 | def = 32; | 
| David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 161 | cpu_data(0).dcache_line_size = | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 162 | of_getintprop_default(dp, "dcache-line-size", def); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 163 |  | 
|  | 164 | def = 16 * 1024; | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 165 | cpu_data(0).icache_size = of_getintprop_default(dp, | 
|  | 166 | "icache-size", | 
|  | 167 | def); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 168 |  | 
|  | 169 | def = 32; | 
| David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 170 | cpu_data(0).icache_line_size = | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 171 | of_getintprop_default(dp, "icache-line-size", def); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 172 |  | 
|  | 173 | def = ((tlb_type == hypervisor) ? | 
|  | 174 | (3 * 1024 * 1024) : | 
|  | 175 | (4 * 1024 * 1024)); | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 176 | cpu_data(0).ecache_size = of_getintprop_default(dp, | 
|  | 177 | "ecache-size", | 
|  | 178 | def); | 
| David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 179 |  | 
|  | 180 | def = 64; | 
| David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 181 | cpu_data(0).ecache_line_size = | 
| David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame] | 182 | of_getintprop_default(dp, "ecache-line-size", def); | 
| David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 183 | printk("CPU[0]: Caches " | 
|  | 184 | "D[sz(%d):line_sz(%d)] " | 
|  | 185 | "I[sz(%d):line_sz(%d)] " | 
|  | 186 | "E[sz(%d):line_sz(%d)]\n", | 
|  | 187 | cpu_data(0).dcache_size, cpu_data(0).dcache_line_size, | 
|  | 188 | cpu_data(0).icache_size, cpu_data(0).icache_line_size, | 
|  | 189 | cpu_data(0).ecache_size, cpu_data(0).ecache_line_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } | 
|  | 191 | #endif | 
|  | 192 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | central_probe(); | 
|  | 194 |  | 
|  | 195 | cpu_probe(); | 
|  | 196 | } |