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 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 73 | val = of_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 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 172 | |
| 173 | /* Let's define all possible registers, we'll only hook up the ones |
| 174 | * that are implemented on the current processor |
| 175 | */ |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); |
| 178 | SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); |
| 179 | SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); |
| 180 | SYSFS_PMCSETUP(pmc1, SPRN_PMC1); |
| 181 | SYSFS_PMCSETUP(pmc2, SPRN_PMC2); |
| 182 | SYSFS_PMCSETUP(pmc3, SPRN_PMC3); |
| 183 | SYSFS_PMCSETUP(pmc4, SPRN_PMC4); |
| 184 | SYSFS_PMCSETUP(pmc5, SPRN_PMC5); |
| 185 | SYSFS_PMCSETUP(pmc6, SPRN_PMC6); |
| 186 | SYSFS_PMCSETUP(pmc7, SPRN_PMC7); |
| 187 | SYSFS_PMCSETUP(pmc8, SPRN_PMC8); |
| 188 | SYSFS_PMCSETUP(purr, SPRN_PURR); |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 189 | SYSFS_PMCSETUP(spurr, SPRN_SPURR); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 190 | SYSFS_PMCSETUP(dscr, SPRN_DSCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Olof Johansson | 25fc530 | 2007-04-18 16:38:21 +1000 | [diff] [blame^] | 192 | SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0); |
| 193 | SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1); |
| 194 | SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2); |
| 195 | SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3); |
| 196 | SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4); |
| 197 | SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 198 | |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra); |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 201 | static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 202 | static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr); |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 203 | static SYSDEV_ATTR(purr, 0600, show_purr, store_purr); |
| 204 | |
| 205 | static struct sysdev_attribute ibm_common_attrs[] = { |
| 206 | _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), |
| 207 | _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), |
| 208 | }; |
| 209 | |
| 210 | static struct sysdev_attribute ibm_pmc_attrs[] = { |
| 211 | _SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1), |
| 212 | _SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2), |
| 213 | _SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3), |
| 214 | _SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4), |
| 215 | _SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5), |
| 216 | _SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6), |
| 217 | _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7), |
| 218 | _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8), |
| 219 | }; |
| 220 | |
| 221 | static struct sysdev_attribute pa6t_attrs[] = { |
| 222 | _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), |
| 223 | _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), |
| 224 | _SYSDEV_ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0), |
| 225 | _SYSDEV_ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1), |
| 226 | _SYSDEV_ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2), |
| 227 | _SYSDEV_ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3), |
| 228 | _SYSDEV_ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4), |
| 229 | _SYSDEV_ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5), |
| 230 | }; |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | static void register_cpu_online(unsigned int cpu) |
| 234 | { |
| 235 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 236 | struct sys_device *s = &c->sysdev; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 237 | struct sysdev_attribute *attrs, *pmc_attrs; |
| 238 | int i, nattrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Stephen Rothwell | ad5cb17 | 2006-11-13 14:46:04 +1100 | [diff] [blame] | 240 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
| 241 | cpu_has_feature(CPU_FTR_SMT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | sysdev_create_file(s, &attr_smt_snooze_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | /* PMC stuff */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 245 | switch (cur_cpu_spec->pmc_type) { |
| 246 | case PPC_PMC_IBM: |
| 247 | attrs = ibm_common_attrs; |
| 248 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); |
| 249 | pmc_attrs = ibm_pmc_attrs; |
| 250 | break; |
| 251 | case PPC_PMC_PA6T: |
| 252 | /* PA Semi starts counting at PMC0 */ |
| 253 | attrs = pa6t_attrs; |
| 254 | nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); |
| 255 | pmc_attrs = NULL; |
| 256 | break; |
| 257 | default: |
| 258 | attrs = NULL; |
| 259 | nattrs = 0; |
| 260 | pmc_attrs = NULL; |
| 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 263 | for (i = 0; i < nattrs; i++) |
| 264 | sysdev_create_file(s, &attrs[i]); |
| 265 | |
| 266 | if (pmc_attrs) |
| 267 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) |
| 268 | sysdev_create_file(s, &pmc_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
| 271 | sysdev_create_file(s, &attr_mmcra); |
| 272 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 273 | if (cpu_has_feature(CPU_FTR_PURR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | sysdev_create_file(s, &attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 275 | |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 276 | if (cpu_has_feature(CPU_FTR_SPURR)) |
| 277 | sysdev_create_file(s, &attr_spurr); |
| 278 | |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 279 | if (cpu_has_feature(CPU_FTR_DSCR)) |
| 280 | sysdev_create_file(s, &attr_dscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | #ifdef CONFIG_HOTPLUG_CPU |
| 284 | static void unregister_cpu_online(unsigned int cpu) |
| 285 | { |
| 286 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 287 | struct sys_device *s = &c->sysdev; |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 288 | struct sysdev_attribute *attrs, *pmc_attrs; |
| 289 | int i, nattrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 291 | BUG_ON(!c->hotpluggable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Stephen Rothwell | ad5cb17 | 2006-11-13 14:46:04 +1100 | [diff] [blame] | 293 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
| 294 | cpu_has_feature(CPU_FTR_SMT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | sysdev_remove_file(s, &attr_smt_snooze_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | /* PMC stuff */ |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 298 | switch (cur_cpu_spec->pmc_type) { |
| 299 | case PPC_PMC_IBM: |
| 300 | attrs = ibm_common_attrs; |
| 301 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); |
| 302 | pmc_attrs = ibm_pmc_attrs; |
| 303 | break; |
| 304 | case PPC_PMC_PA6T: |
| 305 | /* PA Semi starts counting at PMC0 */ |
| 306 | attrs = pa6t_attrs; |
| 307 | nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); |
| 308 | pmc_attrs = NULL; |
| 309 | break; |
| 310 | default: |
| 311 | attrs = NULL; |
| 312 | nattrs = 0; |
| 313 | pmc_attrs = NULL; |
| 314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Olof Johansson | 6529c13 | 2007-01-28 21:25:57 -0600 | [diff] [blame] | 316 | for (i = 0; i < nattrs; i++) |
| 317 | sysdev_remove_file(s, &attrs[i]); |
| 318 | |
| 319 | if (pmc_attrs) |
| 320 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) |
| 321 | sysdev_remove_file(s, &pmc_attrs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
| 324 | sysdev_remove_file(s, &attr_mmcra); |
| 325 | |
Michael Neuling | afd0542 | 2006-07-28 13:58:37 +1000 | [diff] [blame] | 326 | if (cpu_has_feature(CPU_FTR_PURR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | sysdev_remove_file(s, &attr_purr); |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 328 | |
Anton Blanchard | f050982 | 2006-12-08 17:51:13 +1100 | [diff] [blame] | 329 | if (cpu_has_feature(CPU_FTR_SPURR)) |
| 330 | sysdev_remove_file(s, &attr_spurr); |
| 331 | |
Anton Blanchard | 4c198557 | 2006-12-08 17:46:58 +1100 | [diff] [blame] | 332 | if (cpu_has_feature(CPU_FTR_DSCR)) |
| 333 | sysdev_remove_file(s, &attr_dscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 336 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 337 | static int __cpuinit sysfs_cpu_notify(struct notifier_block *self, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | unsigned long action, void *hcpu) |
| 339 | { |
| 340 | unsigned int cpu = (unsigned int)(long)hcpu; |
| 341 | |
| 342 | switch (action) { |
| 343 | case CPU_ONLINE: |
| 344 | register_cpu_online(cpu); |
| 345 | break; |
| 346 | #ifdef CONFIG_HOTPLUG_CPU |
| 347 | case CPU_DEAD: |
| 348 | unregister_cpu_online(cpu); |
| 349 | break; |
| 350 | #endif |
| 351 | } |
| 352 | return NOTIFY_OK; |
| 353 | } |
| 354 | |
Chandra Seetharaman | 8c78f30 | 2006-07-30 03:03:35 -0700 | [diff] [blame] | 355 | static struct notifier_block __cpuinitdata sysfs_cpu_nb = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | .notifier_call = sysfs_cpu_notify, |
| 357 | }; |
| 358 | |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 359 | static DEFINE_MUTEX(cpu_mutex); |
| 360 | |
| 361 | int cpu_add_sysdev_attr(struct sysdev_attribute *attr) |
| 362 | { |
| 363 | int cpu; |
| 364 | |
| 365 | mutex_lock(&cpu_mutex); |
| 366 | |
| 367 | for_each_possible_cpu(cpu) { |
| 368 | sysdev_create_file(get_cpu_sysdev(cpu), attr); |
| 369 | } |
| 370 | |
| 371 | mutex_unlock(&cpu_mutex); |
| 372 | return 0; |
| 373 | } |
| 374 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr); |
| 375 | |
| 376 | int cpu_add_sysdev_attr_group(struct attribute_group *attrs) |
| 377 | { |
| 378 | int cpu; |
| 379 | struct sys_device *sysdev; |
| 380 | |
| 381 | mutex_lock(&cpu_mutex); |
| 382 | |
| 383 | for_each_possible_cpu(cpu) { |
| 384 | sysdev = get_cpu_sysdev(cpu); |
| 385 | sysfs_create_group(&sysdev->kobj, attrs); |
| 386 | } |
| 387 | |
| 388 | mutex_unlock(&cpu_mutex); |
| 389 | return 0; |
| 390 | } |
| 391 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group); |
| 392 | |
| 393 | |
| 394 | void cpu_remove_sysdev_attr(struct sysdev_attribute *attr) |
| 395 | { |
| 396 | int cpu; |
| 397 | |
| 398 | mutex_lock(&cpu_mutex); |
| 399 | |
| 400 | for_each_possible_cpu(cpu) { |
| 401 | sysdev_remove_file(get_cpu_sysdev(cpu), attr); |
| 402 | } |
| 403 | |
| 404 | mutex_unlock(&cpu_mutex); |
| 405 | } |
| 406 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr); |
| 407 | |
| 408 | void cpu_remove_sysdev_attr_group(struct attribute_group *attrs) |
| 409 | { |
| 410 | int cpu; |
| 411 | struct sys_device *sysdev; |
| 412 | |
| 413 | mutex_lock(&cpu_mutex); |
| 414 | |
| 415 | for_each_possible_cpu(cpu) { |
| 416 | sysdev = get_cpu_sysdev(cpu); |
| 417 | sysfs_remove_group(&sysdev->kobj, attrs); |
| 418 | } |
| 419 | |
| 420 | mutex_unlock(&cpu_mutex); |
| 421 | } |
| 422 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group); |
| 423 | |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /* NUMA stuff */ |
| 426 | |
| 427 | #ifdef CONFIG_NUMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | static void register_nodes(void) |
| 429 | { |
| 430 | int i; |
| 431 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 432 | for (i = 0; i < MAX_NUMNODES; i++) |
| 433 | register_one_node(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 435 | |
| 436 | int sysfs_add_device_to_node(struct sys_device *dev, int nid) |
| 437 | { |
| 438 | struct node *node = &node_devices[nid]; |
| 439 | return sysfs_create_link(&node->sysdev.kobj, &dev->kobj, |
| 440 | kobject_name(&dev->kobj)); |
| 441 | } |
| 442 | |
| 443 | void sysfs_remove_device_from_node(struct sys_device *dev, int nid) |
| 444 | { |
| 445 | struct node *node = &node_devices[nid]; |
| 446 | sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj)); |
| 447 | } |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | #else |
| 450 | static void register_nodes(void) |
| 451 | { |
| 452 | return; |
| 453 | } |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | #endif |
| 456 | |
Jeremy Kerr | 953039c | 2006-05-01 12:16:12 -0700 | [diff] [blame] | 457 | EXPORT_SYMBOL_GPL(sysfs_add_device_to_node); |
| 458 | EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* Only valid if CPU is present. */ |
| 461 | static ssize_t show_physical_id(struct sys_device *dev, char *buf) |
| 462 | { |
| 463 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
| 464 | |
| 465 | return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id)); |
| 466 | } |
| 467 | static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL); |
| 468 | |
| 469 | static int __init topology_init(void) |
| 470 | { |
| 471 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | register_nodes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | register_cpu_notifier(&sysfs_cpu_nb); |
| 475 | |
KAMEZAWA Hiroyuki | 0e55195 | 2006-03-28 14:50:51 -0800 | [diff] [blame] | 476 | for_each_possible_cpu(cpu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* |
| 480 | * For now, we just see if the system supports making |
| 481 | * the RTAS calls for CPU hotplug. But, there may be a |
| 482 | * more comprehensive way to do this for an individual |
| 483 | * CPU. For instance, the boot cpu might never be valid |
| 484 | * for hotplugging. |
| 485 | */ |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 486 | if (ppc_md.cpu_die) |
| 487 | c->hotpluggable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 489 | if (cpu_online(cpu) || c->hotpluggable) { |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 490 | register_cpu(c, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | sysdev_create_file(&c->sysdev, &attr_physical_id); |
| 493 | } |
| 494 | |
| 495 | if (cpu_online(cpu)) |
| 496 | register_cpu_online(cpu); |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | __initcall(topology_init); |