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 | |
| 7 | #include <linux/config.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/threads.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/ioport.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | #include <linux/errno.h> |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 15 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/page.h> |
| 18 | #include <asm/oplib.h> |
| 19 | #include <asm/system.h> |
| 20 | #include <asm/smp.h> |
| 21 | #include <asm/spitfire.h> |
| 22 | #include <asm/timer.h> |
| 23 | #include <asm/cpudata.h> |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 24 | #include <asm/vdev.h> |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 25 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* Used to synchronize acceses to NatSemi SUPER I/O chip configure |
| 28 | * operations in asm/ns87303.h |
| 29 | */ |
| 30 | DEFINE_SPINLOCK(ns87303_lock); |
| 31 | |
| 32 | extern void cpu_probe(void); |
| 33 | extern void central_probe(void); |
| 34 | |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 35 | u32 sun4v_vdev_devhandle; |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 36 | struct device_node *sun4v_vdev_root; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 37 | |
| 38 | struct vdev_intmap { |
| 39 | unsigned int phys; |
| 40 | unsigned int irq; |
| 41 | unsigned int cnode; |
| 42 | unsigned int cinterrupt; |
| 43 | }; |
| 44 | |
| 45 | struct vdev_intmask { |
| 46 | unsigned int phys; |
| 47 | unsigned int interrupt; |
| 48 | unsigned int __unused; |
| 49 | }; |
| 50 | |
| 51 | static struct vdev_intmap *vdev_intmap; |
| 52 | static int vdev_num_intmap; |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 53 | static struct vdev_intmask *vdev_intmask; |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 54 | |
| 55 | static void __init sun4v_virtual_device_probe(void) |
| 56 | { |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 57 | struct linux_prom64_registers *regs; |
| 58 | struct property *prop; |
| 59 | struct device_node *dp; |
| 60 | int sz; |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 61 | |
| 62 | if (tlb_type != hypervisor) |
| 63 | return; |
| 64 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 65 | dp = of_find_node_by_name(NULL, "virtual-devices"); |
| 66 | if (!dp) { |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 67 | prom_printf("SUN4V: Fatal error, no virtual-devices node.\n"); |
| 68 | prom_halt(); |
| 69 | } |
| 70 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 71 | sun4v_vdev_root = dp; |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 72 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 73 | prop = of_find_property(dp, "reg", NULL); |
| 74 | regs = prop->value; |
| 75 | sun4v_vdev_devhandle = (regs[0].phys_addr >> 32UL) & 0x0fffffff; |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 76 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 77 | prop = of_find_property(dp, "interrupt-map", &sz); |
| 78 | vdev_intmap = prop->value; |
| 79 | vdev_num_intmap = sz / sizeof(struct vdev_intmap); |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 80 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 81 | prop = of_find_property(dp, "interrupt-map-mask", NULL); |
| 82 | vdev_intmask = prop->value; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 83 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 84 | printk("%s: Virtual Device Bus devhandle[%x]\n", |
| 85 | dp->full_name, sun4v_vdev_devhandle); |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 86 | } |
| 87 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 88 | unsigned int sun4v_vdev_device_interrupt(struct device_node *dev_node) |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 89 | { |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 90 | struct property *prop; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 91 | unsigned int irq, reg; |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 92 | int i; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 93 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 94 | prop = of_find_property(dev_node, "interrupts", NULL); |
| 95 | if (!prop) { |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 96 | printk("VDEV: Cannot get \"interrupts\" " |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 97 | "property for OBP node %s\n", |
| 98 | dev_node->full_name); |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 99 | return 0; |
| 100 | } |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 101 | irq = *(unsigned int *) prop->value; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 102 | |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 103 | prop = of_find_property(dev_node, "reg", NULL); |
| 104 | if (!prop) { |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 105 | printk("VDEV: Cannot get \"reg\" " |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 106 | "property for OBP node %s\n", |
| 107 | dev_node->full_name); |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 108 | return 0; |
| 109 | } |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 110 | reg = *(unsigned int *) prop->value; |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 111 | |
| 112 | for (i = 0; i < vdev_num_intmap; i++) { |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 113 | if (vdev_intmap[i].phys == (reg & vdev_intmask->phys) && |
| 114 | vdev_intmap[i].irq == (irq & vdev_intmask->interrupt)) { |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 115 | irq = vdev_intmap[i].cinterrupt; |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (i == vdev_num_intmap) { |
| 121 | printk("VDEV: No matching interrupt map entry " |
David S. Miller | 6760d28 | 2006-06-21 22:56:20 -0700 | [diff] [blame] | 122 | "for OBP node %s\n", dev_node->full_name); |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
David S. Miller | e18e2a0 | 2006-06-20 01:23:32 -0700 | [diff] [blame] | 126 | return sun4v_build_irq(sun4v_vdev_devhandle, irq); |
David S. Miller | 9d29a3f | 2006-02-15 19:48:54 -0800 | [diff] [blame] | 127 | } |
| 128 | |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 129 | static const char *cpu_mid_prop(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | if (tlb_type == spitfire) |
| 132 | return "upa-portid"; |
| 133 | return "portid"; |
| 134 | } |
| 135 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 136 | static int get_cpu_mid(struct device_node *dp) |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 137 | { |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 138 | struct property *prop; |
| 139 | |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 140 | if (tlb_type == hypervisor) { |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 141 | struct linux_prom64_registers *reg; |
| 142 | int len; |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 143 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 144 | prop = of_find_property(dp, "cpuid", &len); |
| 145 | if (prop && len == 4) |
| 146 | return *(int *) prop->value; |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 147 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 148 | prop = of_find_property(dp, "reg", NULL); |
| 149 | reg = prop->value; |
| 150 | return (reg[0].phys_addr >> 32) & 0x0fffffffUL; |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 151 | } else { |
| 152 | const char *prop_name = cpu_mid_prop(); |
| 153 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 154 | prop = of_find_property(dp, prop_name, NULL); |
| 155 | if (prop) |
| 156 | return *(int *) prop->value; |
| 157 | return 0; |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 161 | static int check_cpu_node(struct device_node *dp, int *cur_inst, |
| 162 | int (*compare)(struct device_node *, int, void *), |
| 163 | void *compare_arg, |
| 164 | struct device_node **dev_node, int *mid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 166 | if (strcmp(dp->type, "cpu")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return -ENODEV; |
| 168 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 169 | if (!compare(dp, *cur_inst, compare_arg)) { |
| 170 | if (dev_node) |
| 171 | *dev_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (mid) |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 173 | *mid = get_cpu_mid(dp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | (*cur_inst)++; |
| 178 | |
| 179 | return -ENODEV; |
| 180 | } |
| 181 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 182 | static int __cpu_find_by(int (*compare)(struct device_node *, int, void *), |
| 183 | void *compare_arg, |
| 184 | struct device_node **dev_node, int *mid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 186 | struct device_node *dp; |
| 187 | int cur_inst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | cur_inst = 0; |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 190 | for_each_node_by_type(dp, "cpu") { |
| 191 | int err = check_cpu_node(dp, &cur_inst, |
| 192 | compare, compare_arg, |
| 193 | dev_node, mid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if (err == 0) |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | return -ENODEV; |
| 199 | } |
| 200 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 201 | 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] | 202 | { |
| 203 | int desired_instance = (int) (long) _arg; |
| 204 | |
| 205 | if (instance == desired_instance) |
| 206 | return 0; |
| 207 | return -ENODEV; |
| 208 | } |
| 209 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 210 | 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] | 211 | { |
| 212 | return __cpu_find_by(cpu_instance_compare, (void *)(long)instance, |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 213 | dev_node, mid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 216 | 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] | 217 | { |
| 218 | int desired_mid = (int) (long) _arg; |
| 219 | int this_mid; |
| 220 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 221 | this_mid = get_cpu_mid(dp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (this_mid == desired_mid) |
| 223 | return 0; |
| 224 | return -ENODEV; |
| 225 | } |
| 226 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 227 | int cpu_find_by_mid(int mid, struct device_node **dev_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
| 229 | return __cpu_find_by(cpu_mid_compare, (void *)(long)mid, |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 230 | dev_node, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void __init device_scan(void) |
| 234 | { |
| 235 | /* FIX ME FAST... -DaveM */ |
| 236 | ioport_resource.end = 0xffffffffffffffffUL; |
| 237 | |
| 238 | prom_printf("Booting Linux...\n"); |
| 239 | |
| 240 | #ifndef CONFIG_SMP |
| 241 | { |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 242 | struct device_node *dp; |
| 243 | int err, def; |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 244 | |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 245 | err = cpu_find_by_instance(0, &dp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (err) { |
| 247 | prom_printf("No cpu nodes, cannot continue\n"); |
| 248 | prom_halt(); |
| 249 | } |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 250 | cpu_data(0).clock_tick = |
| 251 | of_getintprop_default(dp, "clock-frequency", 0); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 252 | |
| 253 | def = ((tlb_type == hypervisor) ? |
| 254 | (8 * 1024) : |
| 255 | (16 * 1024)); |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 256 | cpu_data(0).dcache_size = of_getintprop_default(dp, |
| 257 | "dcache-size", |
| 258 | def); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 259 | |
| 260 | def = 32; |
David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 261 | cpu_data(0).dcache_line_size = |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 262 | of_getintprop_default(dp, "dcache-line-size", def); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 263 | |
| 264 | def = 16 * 1024; |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 265 | cpu_data(0).icache_size = of_getintprop_default(dp, |
| 266 | "icache-size", |
| 267 | def); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 268 | |
| 269 | def = 32; |
David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 270 | cpu_data(0).icache_line_size = |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 271 | of_getintprop_default(dp, "icache-line-size", def); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 272 | |
| 273 | def = ((tlb_type == hypervisor) ? |
| 274 | (3 * 1024 * 1024) : |
| 275 | (4 * 1024 * 1024)); |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 276 | cpu_data(0).ecache_size = of_getintprop_default(dp, |
| 277 | "ecache-size", |
| 278 | def); |
David S. Miller | f03b8a5 | 2006-02-15 00:35:50 -0800 | [diff] [blame] | 279 | |
| 280 | def = 64; |
David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 281 | cpu_data(0).ecache_line_size = |
David S. Miller | 07f8e5f | 2006-06-21 23:34:02 -0700 | [diff] [blame^] | 282 | of_getintprop_default(dp, "ecache-line-size", def); |
David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 283 | printk("CPU[0]: Caches " |
| 284 | "D[sz(%d):line_sz(%d)] " |
| 285 | "I[sz(%d):line_sz(%d)] " |
| 286 | "E[sz(%d):line_sz(%d)]\n", |
| 287 | cpu_data(0).dcache_size, cpu_data(0).dcache_line_size, |
| 288 | cpu_data(0).icache_size, cpu_data(0).icache_line_size, |
| 289 | cpu_data(0).ecache_size, cpu_data(0).ecache_line_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | #endif |
| 292 | |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame] | 293 | sun4v_virtual_device_probe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | central_probe(); |
| 295 | |
| 296 | cpu_probe(); |
| 297 | } |