Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/sysdev.h> |
| 2 | #include <linux/cpu.h> |
| 3 | #include <linux/smp.h> |
| 4 | #include <linux/percpu.h> |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/sched.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/nodemask.h> |
| 9 | #include <linux/cpumask.h> |
| 10 | #include <linux/notifier.h> |
| 11 | |
| 12 | #include <asm/current.h> |
| 13 | #include <asm/processor.h> |
| 14 | #include <asm/cputable.h> |
Stephen Rothwell | 1ababe1 | 2005-08-03 14:35:25 +1000 | [diff] [blame] | 15 | #include <asm/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/hvcall.h> |
| 17 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/paca.h> |
| 19 | #include <asm/lppaca.h> |
| 20 | #include <asm/machdep.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 21 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
| 24 | |
| 25 | /* SMT stuff */ |
| 26 | |
| 27 | #ifdef CONFIG_PPC_MULTIPLATFORM |
Anton Blanchard | 0ddd3e7 | 2006-09-22 20:30:14 +1000 | [diff] [blame] | 28 | /* Time in microseconds we delay before sleeping in the idle loop */ |
| 29 | DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf, |
| 32 | size_t count) |
| 33 | { |
| 34 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
| 35 | ssize_t ret; |
| 36 | unsigned long snooze; |
| 37 | |
| 38 | ret = sscanf(buf, "%lu", &snooze); |
| 39 | if (ret != 1) |
| 40 | return -EINVAL; |
| 41 | |
| 42 | per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze; |
| 43 | |
| 44 | return count; |
| 45 | } |
| 46 | |
| 47 | static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf) |
| 48 | { |
| 49 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
| 50 | |
| 51 | return sprintf(buf, "%lu\n", per_cpu(smt_snooze_delay, cpu->sysdev.id)); |
| 52 | } |
| 53 | |
| 54 | static SYSDEV_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay, |
| 55 | store_smt_snooze_delay); |
| 56 | |
| 57 | /* Only parse OF options if the matching cmdline option was not specified */ |
| 58 | static int smt_snooze_cmdline; |
| 59 | |
| 60 | static int __init smt_setup(void) |
| 61 | { |
| 62 | struct device_node *options; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 63 | const unsigned int *val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned int cpu; |
| 65 | |
| 66 | if (!cpu_has_feature(CPU_FTR_SMT)) |
Anton Blanchard | 69ed332 | 2006-03-28 14:08:39 +1100 | [diff] [blame] | 67 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | options = find_path_device("/options"); |
| 70 | if (!options) |
Anton Blanchard | 69ed332 | 2006-03-28 14:08:39 +1100 | [diff] [blame] | 71 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 73 | val = get_property(options, "ibm,smt-snooze-delay", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | if (!smt_snooze_cmdline && val) { |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 75 | for_each_possible_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | per_cpu(smt_snooze_delay, cpu) = *val; |
| 77 | } |
| 78 | |
Anton Blanchard | 69ed332 | 2006-03-28 14:08:39 +1100 | [diff] [blame] | 79 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | __initcall(smt_setup); |
| 82 | |
| 83 | static int __init setup_smt_snooze_delay(char *str) |
| 84 | { |
| 85 | unsigned int cpu; |
| 86 | int snooze; |
| 87 | |
| 88 | if (!cpu_has_feature(CPU_FTR_SMT)) |
| 89 | return 1; |
| 90 | |
| 91 | smt_snooze_cmdline = 1; |
| 92 | |
| 93 | if (get_option(&str, &snooze)) { |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 94 | for_each_possible_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | per_cpu(smt_snooze_delay, cpu) = snooze; |
| 96 | } |
| 97 | |
| 98 | return 1; |
| 99 | } |
| 100 | __setup("smt-snooze-delay=", setup_smt_snooze_delay); |
| 101 | |
Michael Ellerman | 180a336 | 2005-08-09 11:13:36 +1000 | [diff] [blame] | 102 | #endif /* CONFIG_PPC_MULTIPLATFORM */ |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Enabling PMCs will slow partition context switch times so we only do |
| 106 | * it the first time we write to the PMCs. |
| 107 | */ |
| 108 | |
| 109 | static DEFINE_PER_CPU(char, pmcs_enabled); |
| 110 | |
| 111 | void ppc64_enable_pmcs(void) |
| 112 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* Only need to enable them once */ |
| 114 | if (__get_cpu_var(pmcs_enabled)) |
| 115 | return; |
| 116 | |
| 117 | __get_cpu_var(pmcs_enabled) = 1; |
| 118 | |
Michael Ellerman | 180a336 | 2005-08-09 11:13:36 +1000 | [diff] [blame] | 119 | if (ppc_md.enable_pmcs) |
| 120 | ppc_md.enable_pmcs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | EXPORT_SYMBOL(ppc64_enable_pmcs); |
| 123 | |
| 124 | /* XXX convert to rusty's on_one_cpu */ |
| 125 | static unsigned long run_on_cpu(unsigned long cpu, |
| 126 | unsigned long (*func)(unsigned long), |
| 127 | unsigned long arg) |
| 128 | { |
| 129 | cpumask_t old_affinity = current->cpus_allowed; |
| 130 | unsigned long ret; |
| 131 | |
| 132 | /* should return -EINVAL to userspace */ |
| 133 | if (set_cpus_allowed(current, cpumask_of_cpu(cpu))) |
| 134 | return 0; |
| 135 | |
| 136 | ret = func(arg); |
| 137 | |
| 138 | set_cpus_allowed(current, old_affinity); |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | #define SYSFS_PMCSETUP(NAME, ADDRESS) \ |
| 144 | static unsigned long read_##NAME(unsigned long junk) \ |
| 145 | { \ |
| 146 | return mfspr(ADDRESS); \ |
| 147 | } \ |
| 148 | static unsigned long write_##NAME(unsigned long val) \ |
| 149 | { \ |
| 150 | ppc64_enable_pmcs(); \ |
| 151 | mtspr(ADDRESS, val); \ |
| 152 | return 0; \ |
| 153 | } \ |
| 154 | static ssize_t show_##NAME(struct sys_device *dev, char *buf) \ |
| 155 | { \ |
| 156 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ |
| 157 | unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \ |
| 158 | return sprintf(buf, "%lx\n", val); \ |
| 159 | } \ |
| 160 | static ssize_t __attribute_used__ \ |
| 161 | store_##NAME(struct sys_device *dev, const char *buf, size_t count) \ |
| 162 | { \ |
| 163 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ |
| 164 | unsigned long val; \ |
| 165 | int ret = sscanf(buf, "%lx", &val); \ |
| 166 | if (ret != 1) \ |
| 167 | return -EINVAL; \ |
| 168 | run_on_cpu(cpu->sysdev.id, write_##NAME, val); \ |
| 169 | return count; \ |
| 170 | } |
| 171 | |
| 172 | SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); |
| 173 | SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); |
| 174 | SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); |
| 175 | SYSFS_PMCSETUP(pmc1, SPRN_PMC1); |
| 176 | SYSFS_PMCSETUP(pmc2, SPRN_PMC2); |
| 177 | SYSFS_PMCSETUP(pmc3, SPRN_PMC3); |
| 178 | SYSFS_PMCSETUP(pmc4, SPRN_PMC4); |
| 179 | SYSFS_PMCSETUP(pmc5, SPRN_PMC5); |
| 180 | SYSFS_PMCSETUP(pmc6, SPRN_PMC6); |
| 181 | SYSFS_PMCSETUP(pmc7, SPRN_PMC7); |
| 182 | SYSFS_PMCSETUP(pmc8, SPRN_PMC8); |
| 183 | SYSFS_PMCSETUP(purr, SPRN_PURR); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame^] | 184 | SYSFS_PMCSETUP(dscr, SPRN_DSCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | static SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0); |
| 187 | static SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1); |
| 188 | static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra); |
| 189 | static SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1); |
| 190 | static SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2); |
| 191 | static SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3); |
| 192 | static SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4); |
| 193 | static SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5); |
| 194 | static SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6); |
| 195 | static SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7); |
| 196 | static SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8); |
| 197 | static SYSDEV_ATTR(purr, 0600, show_purr, NULL); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame^] | 198 | static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | static void register_cpu_online(unsigned int cpu) |
| 201 | { |
| 202 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 203 | struct sys_device *s = &c->sysdev; |
| 204 | |
Stephen Rothwell | ad5cb17 | 2006-11-13 14:46:04 +1100 | [diff] [blame] | 205 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
| 206 | cpu_has_feature(CPU_FTR_SMT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | sysdev_create_file(s, &attr_smt_snooze_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* PMC stuff */ |
| 210 | |
| 211 | sysdev_create_file(s, &attr_mmcr0); |
| 212 | sysdev_create_file(s, &attr_mmcr1); |
| 213 | |
| 214 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
| 215 | sysdev_create_file(s, &attr_mmcra); |
| 216 | |
Anton Blanchard | fd5b437 | 2005-09-06 14:47:49 +1000 | [diff] [blame] | 217 | if (cur_cpu_spec->num_pmcs >= 1) |
| 218 | sysdev_create_file(s, &attr_pmc1); |
| 219 | if (cur_cpu_spec->num_pmcs >= 2) |
| 220 | sysdev_create_file(s, &attr_pmc2); |
| 221 | if (cur_cpu_spec->num_pmcs >= 3) |
| 222 | sysdev_create_file(s, &attr_pmc3); |
| 223 | if (cur_cpu_spec->num_pmcs >= 4) |
| 224 | sysdev_create_file(s, &attr_pmc4); |
| 225 | if (cur_cpu_spec->num_pmcs >= 5) |
| 226 | sysdev_create_file(s, &attr_pmc5); |
| 227 | if (cur_cpu_spec->num_pmcs >= 6) |
| 228 | sysdev_create_file(s, &attr_pmc6); |
| 229 | if (cur_cpu_spec->num_pmcs >= 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | sysdev_create_file(s, &attr_pmc7); |
Anton Blanchard | fd5b437 | 2005-09-06 14:47:49 +1000 | [diff] [blame] | 231 | if (cur_cpu_spec->num_pmcs >= 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | sysdev_create_file(s, &attr_pmc8); |
David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 233 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 234 | if (cpu_has_feature(CPU_FTR_PURR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | sysdev_create_file(s, &attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame^] | 236 | |
| 237 | if (cpu_has_feature(CPU_FTR_DSCR)) |
| 238 | sysdev_create_file(s, &attr_dscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | #ifdef CONFIG_HOTPLUG_CPU |
| 242 | static void unregister_cpu_online(unsigned int cpu) |
| 243 | { |
| 244 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 245 | struct sys_device *s = &c->sysdev; |
| 246 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 247 | BUG_ON(!c->hotpluggable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Stephen Rothwell | ad5cb17 | 2006-11-13 14:46:04 +1100 | [diff] [blame] | 249 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
| 250 | cpu_has_feature(CPU_FTR_SMT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | sysdev_remove_file(s, &attr_smt_snooze_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* PMC stuff */ |
| 254 | |
| 255 | sysdev_remove_file(s, &attr_mmcr0); |
| 256 | sysdev_remove_file(s, &attr_mmcr1); |
| 257 | |
| 258 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
| 259 | sysdev_remove_file(s, &attr_mmcra); |
| 260 | |
Anton Blanchard | fd5b437 | 2005-09-06 14:47:49 +1000 | [diff] [blame] | 261 | if (cur_cpu_spec->num_pmcs >= 1) |
| 262 | sysdev_remove_file(s, &attr_pmc1); |
| 263 | if (cur_cpu_spec->num_pmcs >= 2) |
| 264 | sysdev_remove_file(s, &attr_pmc2); |
| 265 | if (cur_cpu_spec->num_pmcs >= 3) |
| 266 | sysdev_remove_file(s, &attr_pmc3); |
| 267 | if (cur_cpu_spec->num_pmcs >= 4) |
| 268 | sysdev_remove_file(s, &attr_pmc4); |
| 269 | if (cur_cpu_spec->num_pmcs >= 5) |
| 270 | sysdev_remove_file(s, &attr_pmc5); |
| 271 | if (cur_cpu_spec->num_pmcs >= 6) |
| 272 | sysdev_remove_file(s, &attr_pmc6); |
| 273 | if (cur_cpu_spec->num_pmcs >= 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | sysdev_remove_file(s, &attr_pmc7); |
Anton Blanchard | fd5b437 | 2005-09-06 14:47:49 +1000 | [diff] [blame] | 275 | if (cur_cpu_spec->num_pmcs >= 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | sysdev_remove_file(s, &attr_pmc8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 278 | if (cpu_has_feature(CPU_FTR_PURR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | sysdev_remove_file(s, &attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame^] | 280 | |
| 281 | if (cpu_has_feature(CPU_FTR_DSCR)) |
| 282 | sysdev_remove_file(s, &attr_dscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 285 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 286 | static int __cpuinit sysfs_cpu_notify(struct notifier_block *self, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | unsigned long action, void *hcpu) |
| 288 | { |
| 289 | unsigned int cpu = (unsigned int)(long)hcpu; |
| 290 | |
| 291 | switch (action) { |
| 292 | case CPU_ONLINE: |
| 293 | register_cpu_online(cpu); |
| 294 | break; |
| 295 | #ifdef CONFIG_HOTPLUG_CPU |
| 296 | case CPU_DEAD: |
| 297 | unregister_cpu_online(cpu); |
| 298 | break; |
| 299 | #endif |
| 300 | } |
| 301 | return NOTIFY_OK; |
| 302 | } |
| 303 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 304 | static struct notifier_block __cpuinitdata sysfs_cpu_nb = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | .notifier_call = sysfs_cpu_notify, |
| 306 | }; |
| 307 | |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 308 | static DEFINE_MUTEX(cpu_mutex); |
| 309 | |
| 310 | int cpu_add_sysdev_attr(struct sysdev_attribute *attr) |
| 311 | { |
| 312 | int cpu; |
| 313 | |
| 314 | mutex_lock(&cpu_mutex); |
| 315 | |
| 316 | for_each_possible_cpu(cpu) { |
| 317 | sysdev_create_file(get_cpu_sysdev(cpu), attr); |
| 318 | } |
| 319 | |
| 320 | mutex_unlock(&cpu_mutex); |
| 321 | return 0; |
| 322 | } |
| 323 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr); |
| 324 | |
| 325 | int cpu_add_sysdev_attr_group(struct attribute_group *attrs) |
| 326 | { |
| 327 | int cpu; |
| 328 | struct sys_device *sysdev; |
| 329 | |
| 330 | mutex_lock(&cpu_mutex); |
| 331 | |
| 332 | for_each_possible_cpu(cpu) { |
| 333 | sysdev = get_cpu_sysdev(cpu); |
| 334 | sysfs_create_group(&sysdev->kobj, attrs); |
| 335 | } |
| 336 | |
| 337 | mutex_unlock(&cpu_mutex); |
| 338 | return 0; |
| 339 | } |
| 340 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group); |
| 341 | |
| 342 | |
| 343 | void cpu_remove_sysdev_attr(struct sysdev_attribute *attr) |
| 344 | { |
| 345 | int cpu; |
| 346 | |
| 347 | mutex_lock(&cpu_mutex); |
| 348 | |
| 349 | for_each_possible_cpu(cpu) { |
| 350 | sysdev_remove_file(get_cpu_sysdev(cpu), attr); |
| 351 | } |
| 352 | |
| 353 | mutex_unlock(&cpu_mutex); |
| 354 | } |
| 355 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr); |
| 356 | |
| 357 | void cpu_remove_sysdev_attr_group(struct attribute_group *attrs) |
| 358 | { |
| 359 | int cpu; |
| 360 | struct sys_device *sysdev; |
| 361 | |
| 362 | mutex_lock(&cpu_mutex); |
| 363 | |
| 364 | for_each_possible_cpu(cpu) { |
| 365 | sysdev = get_cpu_sysdev(cpu); |
| 366 | sysfs_remove_group(&sysdev->kobj, attrs); |
| 367 | } |
| 368 | |
| 369 | mutex_unlock(&cpu_mutex); |
| 370 | } |
| 371 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group); |
| 372 | |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* NUMA stuff */ |
| 375 | |
| 376 | #ifdef CONFIG_NUMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | static void register_nodes(void) |
| 378 | { |
| 379 | int i; |
| 380 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 381 | for (i = 0; i < MAX_NUMNODES; i++) |
| 382 | register_one_node(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 384 | |
| 385 | int sysfs_add_device_to_node(struct sys_device *dev, int nid) |
| 386 | { |
| 387 | struct node *node = &node_devices[nid]; |
| 388 | return sysfs_create_link(&node->sysdev.kobj, &dev->kobj, |
| 389 | kobject_name(&dev->kobj)); |
| 390 | } |
| 391 | |
| 392 | void sysfs_remove_device_from_node(struct sys_device *dev, int nid) |
| 393 | { |
| 394 | struct node *node = &node_devices[nid]; |
| 395 | sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj)); |
| 396 | } |
| 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | #else |
| 399 | static void register_nodes(void) |
| 400 | { |
| 401 | return; |
| 402 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #endif |
| 405 | |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 406 | EXPORT_SYMBOL_GPL(sysfs_add_device_to_node); |
| 407 | EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* Only valid if CPU is present. */ |
| 410 | static ssize_t show_physical_id(struct sys_device *dev, char *buf) |
| 411 | { |
| 412 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
| 413 | |
| 414 | return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id)); |
| 415 | } |
| 416 | static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL); |
| 417 | |
| 418 | static int __init topology_init(void) |
| 419 | { |
| 420 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | register_nodes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | register_cpu_notifier(&sysfs_cpu_nb); |
| 424 | |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 425 | for_each_possible_cpu(cpu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* |
| 429 | * For now, we just see if the system supports making |
| 430 | * the RTAS calls for CPU hotplug. But, there may be a |
| 431 | * more comprehensive way to do this for an individual |
| 432 | * CPU. For instance, the boot cpu might never be valid |
| 433 | * for hotplugging. |
| 434 | */ |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 435 | if (ppc_md.cpu_die) |
| 436 | c->hotpluggable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 438 | if (cpu_online(cpu) || c->hotpluggable) { |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 439 | register_cpu(c, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | sysdev_create_file(&c->sysdev, &attr_physical_id); |
| 442 | } |
| 443 | |
| 444 | if (cpu_online(cpu)) |
| 445 | register_cpu_online(cpu); |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | __initcall(topology_init); |