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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | /* Used to synchronize acceses to NatSemi SUPER I/O chip configure |
| 27 | * operations in asm/ns87303.h |
| 28 | */ |
| 29 | DEFINE_SPINLOCK(ns87303_lock); |
| 30 | |
| 31 | extern void cpu_probe(void); |
| 32 | extern void central_probe(void); |
| 33 | |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame^] | 34 | u32 sun4v_vdev_devhandle; |
| 35 | int sun4v_vdev_root; |
| 36 | struct linux_prom_pci_intmap *sun4v_vdev_intmap; |
| 37 | int sun4v_vdev_num_intmap; |
| 38 | struct linux_prom_pci_intmap sun4v_vdev_intmask; |
| 39 | |
| 40 | static void __init sun4v_virtual_device_probe(void) |
| 41 | { |
| 42 | struct linux_prom64_registers regs; |
| 43 | struct linux_prom_pci_intmap *ip; |
| 44 | int node, sz, err; |
| 45 | |
| 46 | if (tlb_type != hypervisor) |
| 47 | return; |
| 48 | |
| 49 | node = prom_getchild(prom_root_node); |
| 50 | node = prom_searchsiblings(node, "virtual-devices"); |
| 51 | if (!node) { |
| 52 | prom_printf("SUN4V: Fatal error, no virtual-devices node.\n"); |
| 53 | prom_halt(); |
| 54 | } |
| 55 | |
| 56 | sun4v_vdev_root = node; |
| 57 | |
| 58 | prom_getproperty(node, "reg", (char *)®s, sizeof(regs)); |
| 59 | sun4v_vdev_devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff; |
| 60 | |
| 61 | sz = sizeof(*ip) * 64; |
| 62 | sun4v_vdev_intmap = ip = alloc_bootmem_low_pages(sz); |
| 63 | if (!sun4v_vdev_intmap) { |
| 64 | prom_printf("SUN4V: Error, cannot allocate vdev intmap.\n"); |
| 65 | prom_halt(); |
| 66 | } |
| 67 | |
| 68 | err = prom_getproperty(node, "interrupt-map", (char *) ip, sz); |
| 69 | if (err == -1) { |
| 70 | prom_printf("SUN4V: Fatal error, no vdev interrupt-map.\n"); |
| 71 | prom_halt(); |
| 72 | } |
| 73 | |
| 74 | sun4v_vdev_num_intmap = err / sizeof(*ip); |
| 75 | |
| 76 | err = prom_getproperty(node, "interrupt-map-mask", |
| 77 | (char *) &sun4v_vdev_intmask, |
| 78 | sizeof(sun4v_vdev_intmask)); |
| 79 | if (err == -1) { |
| 80 | prom_printf("SUN4V: Fatal error, no vdev " |
| 81 | "interrupt-map-mask.\n"); |
| 82 | prom_halt(); |
| 83 | } |
| 84 | |
| 85 | printk("SUN4V: virtual-devices devhandle[%x]\n", |
| 86 | sun4v_vdev_devhandle); |
| 87 | } |
| 88 | |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 89 | static const char *cpu_mid_prop(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | if (tlb_type == spitfire) |
| 92 | return "upa-portid"; |
| 93 | return "portid"; |
| 94 | } |
| 95 | |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 96 | static int get_cpu_mid(int prom_node) |
| 97 | { |
| 98 | if (tlb_type == hypervisor) { |
| 99 | struct linux_prom64_registers reg; |
| 100 | |
| 101 | if (prom_getproplen(prom_node, "cpuid") == 4) |
| 102 | return prom_getintdefault(prom_node, "cpuid", 0); |
| 103 | |
| 104 | prom_getproperty(prom_node, "reg", (char *) ®, sizeof(reg)); |
| 105 | return (reg.phys_addr >> 32) & 0x0fffffffUL; |
| 106 | } else { |
| 107 | const char *prop_name = cpu_mid_prop(); |
| 108 | |
| 109 | return prom_getintdefault(prom_node, prop_name, 0); |
| 110 | } |
| 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | static int check_cpu_node(int nd, int *cur_inst, |
| 114 | int (*compare)(int, int, void *), void *compare_arg, |
| 115 | int *prom_node, int *mid) |
| 116 | { |
| 117 | char node_str[128]; |
| 118 | |
| 119 | prom_getstring(nd, "device_type", node_str, sizeof(node_str)); |
| 120 | if (strcmp(node_str, "cpu")) |
| 121 | return -ENODEV; |
| 122 | |
| 123 | if (!compare(nd, *cur_inst, compare_arg)) { |
| 124 | if (prom_node) |
| 125 | *prom_node = nd; |
| 126 | if (mid) |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 127 | *mid = get_cpu_mid(nd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | (*cur_inst)++; |
| 132 | |
| 133 | return -ENODEV; |
| 134 | } |
| 135 | |
| 136 | static int __cpu_find_by(int (*compare)(int, int, void *), void *compare_arg, |
| 137 | int *prom_node, int *mid) |
| 138 | { |
| 139 | int nd, cur_inst, err; |
| 140 | |
| 141 | nd = prom_root_node; |
| 142 | cur_inst = 0; |
| 143 | |
| 144 | err = check_cpu_node(nd, &cur_inst, |
| 145 | compare, compare_arg, |
| 146 | prom_node, mid); |
| 147 | if (err == 0) |
| 148 | return 0; |
| 149 | |
| 150 | nd = prom_getchild(nd); |
| 151 | while ((nd = prom_getsibling(nd)) != 0) { |
| 152 | err = check_cpu_node(nd, &cur_inst, |
| 153 | compare, compare_arg, |
| 154 | prom_node, mid); |
| 155 | if (err == 0) |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | return -ENODEV; |
| 160 | } |
| 161 | |
| 162 | static int cpu_instance_compare(int nd, int instance, void *_arg) |
| 163 | { |
| 164 | int desired_instance = (int) (long) _arg; |
| 165 | |
| 166 | if (instance == desired_instance) |
| 167 | return 0; |
| 168 | return -ENODEV; |
| 169 | } |
| 170 | |
| 171 | int cpu_find_by_instance(int instance, int *prom_node, int *mid) |
| 172 | { |
| 173 | return __cpu_find_by(cpu_instance_compare, (void *)(long)instance, |
| 174 | prom_node, mid); |
| 175 | } |
| 176 | |
| 177 | static int cpu_mid_compare(int nd, int instance, void *_arg) |
| 178 | { |
| 179 | int desired_mid = (int) (long) _arg; |
| 180 | int this_mid; |
| 181 | |
David S. Miller | 4cce4b7 | 2006-02-09 20:46:22 -0800 | [diff] [blame] | 182 | this_mid = get_cpu_mid(nd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if (this_mid == desired_mid) |
| 184 | return 0; |
| 185 | return -ENODEV; |
| 186 | } |
| 187 | |
| 188 | int cpu_find_by_mid(int mid, int *prom_node) |
| 189 | { |
| 190 | return __cpu_find_by(cpu_mid_compare, (void *)(long)mid, |
| 191 | prom_node, NULL); |
| 192 | } |
| 193 | |
| 194 | void __init device_scan(void) |
| 195 | { |
| 196 | /* FIX ME FAST... -DaveM */ |
| 197 | ioport_resource.end = 0xffffffffffffffffUL; |
| 198 | |
| 199 | prom_printf("Booting Linux...\n"); |
| 200 | |
| 201 | #ifndef CONFIG_SMP |
| 202 | { |
| 203 | int err, cpu_node; |
| 204 | err = cpu_find_by_instance(0, &cpu_node, NULL); |
| 205 | if (err) { |
| 206 | prom_printf("No cpu nodes, cannot continue\n"); |
| 207 | prom_halt(); |
| 208 | } |
| 209 | cpu_data(0).clock_tick = prom_getintdefault(cpu_node, |
| 210 | "clock-frequency", |
| 211 | 0); |
David S. Miller | 80dc0d6 | 2005-09-26 00:32:17 -0700 | [diff] [blame] | 212 | cpu_data(0).dcache_size = prom_getintdefault(cpu_node, |
| 213 | "dcache-size", |
| 214 | 16 * 1024); |
| 215 | cpu_data(0).dcache_line_size = |
| 216 | prom_getintdefault(cpu_node, "dcache-line-size", 32); |
| 217 | cpu_data(0).icache_size = prom_getintdefault(cpu_node, |
| 218 | "icache-size", |
| 219 | 16 * 1024); |
| 220 | cpu_data(0).icache_line_size = |
| 221 | prom_getintdefault(cpu_node, "icache-line-size", 32); |
| 222 | cpu_data(0).ecache_size = prom_getintdefault(cpu_node, |
| 223 | "ecache-size", |
| 224 | 4 * 1024 * 1024); |
| 225 | cpu_data(0).ecache_line_size = |
| 226 | prom_getintdefault(cpu_node, "ecache-line-size", 64); |
| 227 | printk("CPU[0]: Caches " |
| 228 | "D[sz(%d):line_sz(%d)] " |
| 229 | "I[sz(%d):line_sz(%d)] " |
| 230 | "E[sz(%d):line_sz(%d)]\n", |
| 231 | cpu_data(0).dcache_size, cpu_data(0).dcache_line_size, |
| 232 | cpu_data(0).icache_size, cpu_data(0).icache_line_size, |
| 233 | cpu_data(0).ecache_size, cpu_data(0).ecache_line_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | #endif |
| 236 | |
David S. Miller | e77227e | 2006-02-13 20:42:16 -0800 | [diff] [blame^] | 237 | sun4v_virtual_device_probe(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | central_probe(); |
| 239 | |
| 240 | cpu_probe(); |
| 241 | } |