Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1ababe11 | 15 | #include <asm/firmware.h> |
1da177e4 LT |
16 | #include <asm/hvcall.h> |
17 | #include <asm/prom.h> | |
1da177e4 LT |
18 | #include <asm/paca.h> |
19 | #include <asm/lppaca.h> | |
20 | #include <asm/machdep.h> | |
2249ca9d | 21 | #include <asm/smp.h> |
1da177e4 LT |
22 | |
23 | static DEFINE_PER_CPU(struct cpu, cpu_devices); | |
24 | ||
25 | /* SMT stuff */ | |
26 | ||
27 | #ifdef CONFIG_PPC_MULTIPLATFORM | |
0ddd3e7d AB |
28 | /* Time in microseconds we delay before sleeping in the idle loop */ |
29 | DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 }; | |
1da177e4 | 30 | |
4a0b2b4d AK |
31 | static ssize_t store_smt_snooze_delay(struct sys_device *dev, |
32 | struct sysdev_attribute *attr, | |
33 | const char *buf, | |
1da177e4 LT |
34 | size_t count) |
35 | { | |
36 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | |
37 | ssize_t ret; | |
38 | unsigned long snooze; | |
39 | ||
40 | ret = sscanf(buf, "%lu", &snooze); | |
41 | if (ret != 1) | |
42 | return -EINVAL; | |
43 | ||
44 | per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze; | |
45 | ||
46 | return count; | |
47 | } | |
48 | ||
4a0b2b4d AK |
49 | static ssize_t show_smt_snooze_delay(struct sys_device *dev, |
50 | struct sysdev_attribute *attr, | |
51 | char *buf) | |
1da177e4 LT |
52 | { |
53 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | |
54 | ||
55 | return sprintf(buf, "%lu\n", per_cpu(smt_snooze_delay, cpu->sysdev.id)); | |
56 | } | |
57 | ||
58 | static SYSDEV_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay, | |
59 | store_smt_snooze_delay); | |
60 | ||
61 | /* Only parse OF options if the matching cmdline option was not specified */ | |
62 | static int smt_snooze_cmdline; | |
63 | ||
64 | static int __init smt_setup(void) | |
65 | { | |
66 | struct device_node *options; | |
a7f67bdf | 67 | const unsigned int *val; |
1da177e4 LT |
68 | unsigned int cpu; |
69 | ||
70 | if (!cpu_has_feature(CPU_FTR_SMT)) | |
69ed3324 | 71 | return -ENODEV; |
1da177e4 | 72 | |
8c8dc322 | 73 | options = of_find_node_by_path("/options"); |
1da177e4 | 74 | if (!options) |
69ed3324 | 75 | return -ENODEV; |
1da177e4 | 76 | |
e2eb6392 | 77 | val = of_get_property(options, "ibm,smt-snooze-delay", NULL); |
1da177e4 | 78 | if (!smt_snooze_cmdline && val) { |
0e551954 | 79 | for_each_possible_cpu(cpu) |
1da177e4 LT |
80 | per_cpu(smt_snooze_delay, cpu) = *val; |
81 | } | |
82 | ||
8c8dc322 | 83 | of_node_put(options); |
69ed3324 | 84 | return 0; |
1da177e4 LT |
85 | } |
86 | __initcall(smt_setup); | |
87 | ||
88 | static int __init setup_smt_snooze_delay(char *str) | |
89 | { | |
90 | unsigned int cpu; | |
91 | int snooze; | |
92 | ||
93 | if (!cpu_has_feature(CPU_FTR_SMT)) | |
94 | return 1; | |
95 | ||
96 | smt_snooze_cmdline = 1; | |
97 | ||
98 | if (get_option(&str, &snooze)) { | |
0e551954 | 99 | for_each_possible_cpu(cpu) |
1da177e4 LT |
100 | per_cpu(smt_snooze_delay, cpu) = snooze; |
101 | } | |
102 | ||
103 | return 1; | |
104 | } | |
105 | __setup("smt-snooze-delay=", setup_smt_snooze_delay); | |
106 | ||
180a3362 ME |
107 | #endif /* CONFIG_PPC_MULTIPLATFORM */ |
108 | ||
1da177e4 LT |
109 | /* |
110 | * Enabling PMCs will slow partition context switch times so we only do | |
111 | * it the first time we write to the PMCs. | |
112 | */ | |
113 | ||
114 | static DEFINE_PER_CPU(char, pmcs_enabled); | |
115 | ||
116 | void ppc64_enable_pmcs(void) | |
117 | { | |
1da177e4 LT |
118 | /* Only need to enable them once */ |
119 | if (__get_cpu_var(pmcs_enabled)) | |
120 | return; | |
121 | ||
122 | __get_cpu_var(pmcs_enabled) = 1; | |
123 | ||
180a3362 ME |
124 | if (ppc_md.enable_pmcs) |
125 | ppc_md.enable_pmcs(); | |
1da177e4 | 126 | } |
1da177e4 LT |
127 | EXPORT_SYMBOL(ppc64_enable_pmcs); |
128 | ||
129 | /* XXX convert to rusty's on_one_cpu */ | |
130 | static unsigned long run_on_cpu(unsigned long cpu, | |
131 | unsigned long (*func)(unsigned long), | |
132 | unsigned long arg) | |
133 | { | |
134 | cpumask_t old_affinity = current->cpus_allowed; | |
135 | unsigned long ret; | |
136 | ||
137 | /* should return -EINVAL to userspace */ | |
138 | if (set_cpus_allowed(current, cpumask_of_cpu(cpu))) | |
139 | return 0; | |
140 | ||
141 | ret = func(arg); | |
142 | ||
143 | set_cpus_allowed(current, old_affinity); | |
144 | ||
145 | return ret; | |
146 | } | |
147 | ||
148 | #define SYSFS_PMCSETUP(NAME, ADDRESS) \ | |
149 | static unsigned long read_##NAME(unsigned long junk) \ | |
150 | { \ | |
151 | return mfspr(ADDRESS); \ | |
152 | } \ | |
153 | static unsigned long write_##NAME(unsigned long val) \ | |
154 | { \ | |
155 | ppc64_enable_pmcs(); \ | |
156 | mtspr(ADDRESS, val); \ | |
157 | return 0; \ | |
158 | } \ | |
4a0b2b4d AK |
159 | static ssize_t show_##NAME(struct sys_device *dev, \ |
160 | struct sysdev_attribute *attr, \ | |
161 | char *buf) \ | |
1da177e4 LT |
162 | { \ |
163 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ | |
164 | unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \ | |
165 | return sprintf(buf, "%lx\n", val); \ | |
166 | } \ | |
3ff6eecc | 167 | static ssize_t __used \ |
4a0b2b4d AK |
168 | store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \ |
169 | const char *buf, size_t count) \ | |
1da177e4 LT |
170 | { \ |
171 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ | |
172 | unsigned long val; \ | |
173 | int ret = sscanf(buf, "%lx", &val); \ | |
174 | if (ret != 1) \ | |
175 | return -EINVAL; \ | |
176 | run_on_cpu(cpu->sysdev.id, write_##NAME, val); \ | |
177 | return count; \ | |
178 | } | |
179 | ||
6529c13d OJ |
180 | |
181 | /* Let's define all possible registers, we'll only hook up the ones | |
182 | * that are implemented on the current processor | |
183 | */ | |
184 | ||
1da177e4 LT |
185 | SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); |
186 | SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); | |
187 | SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); | |
188 | SYSFS_PMCSETUP(pmc1, SPRN_PMC1); | |
189 | SYSFS_PMCSETUP(pmc2, SPRN_PMC2); | |
190 | SYSFS_PMCSETUP(pmc3, SPRN_PMC3); | |
191 | SYSFS_PMCSETUP(pmc4, SPRN_PMC4); | |
192 | SYSFS_PMCSETUP(pmc5, SPRN_PMC5); | |
193 | SYSFS_PMCSETUP(pmc6, SPRN_PMC6); | |
194 | SYSFS_PMCSETUP(pmc7, SPRN_PMC7); | |
195 | SYSFS_PMCSETUP(pmc8, SPRN_PMC8); | |
196 | SYSFS_PMCSETUP(purr, SPRN_PURR); | |
f050982a | 197 | SYSFS_PMCSETUP(spurr, SPRN_SPURR); |
4c198557 | 198 | SYSFS_PMCSETUP(dscr, SPRN_DSCR); |
1da177e4 | 199 | |
25fc530e OJ |
200 | SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0); |
201 | SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1); | |
202 | SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2); | |
203 | SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3); | |
204 | SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4); | |
205 | SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5); | |
6529c13d | 206 | |
2e1957fd OJ |
207 | #ifdef CONFIG_DEBUG_KERNEL |
208 | SYSFS_PMCSETUP(hid0, SPRN_HID0); | |
209 | SYSFS_PMCSETUP(hid1, SPRN_HID1); | |
210 | SYSFS_PMCSETUP(hid4, SPRN_HID4); | |
211 | SYSFS_PMCSETUP(hid5, SPRN_HID5); | |
212 | SYSFS_PMCSETUP(ima0, SPRN_PA6T_IMA0); | |
213 | SYSFS_PMCSETUP(ima1, SPRN_PA6T_IMA1); | |
214 | SYSFS_PMCSETUP(ima2, SPRN_PA6T_IMA2); | |
215 | SYSFS_PMCSETUP(ima3, SPRN_PA6T_IMA3); | |
216 | SYSFS_PMCSETUP(ima4, SPRN_PA6T_IMA4); | |
217 | SYSFS_PMCSETUP(ima5, SPRN_PA6T_IMA5); | |
218 | SYSFS_PMCSETUP(ima6, SPRN_PA6T_IMA6); | |
219 | SYSFS_PMCSETUP(ima7, SPRN_PA6T_IMA7); | |
220 | SYSFS_PMCSETUP(ima8, SPRN_PA6T_IMA8); | |
221 | SYSFS_PMCSETUP(ima9, SPRN_PA6T_IMA9); | |
222 | SYSFS_PMCSETUP(imaat, SPRN_PA6T_IMAAT); | |
223 | SYSFS_PMCSETUP(btcr, SPRN_PA6T_BTCR); | |
224 | SYSFS_PMCSETUP(pccr, SPRN_PA6T_PCCR); | |
225 | SYSFS_PMCSETUP(rpccr, SPRN_PA6T_RPCCR); | |
226 | SYSFS_PMCSETUP(der, SPRN_PA6T_DER); | |
227 | SYSFS_PMCSETUP(mer, SPRN_PA6T_MER); | |
228 | SYSFS_PMCSETUP(ber, SPRN_PA6T_BER); | |
229 | SYSFS_PMCSETUP(ier, SPRN_PA6T_IER); | |
230 | SYSFS_PMCSETUP(sier, SPRN_PA6T_SIER); | |
231 | SYSFS_PMCSETUP(siar, SPRN_PA6T_SIAR); | |
232 | SYSFS_PMCSETUP(tsr0, SPRN_PA6T_TSR0); | |
233 | SYSFS_PMCSETUP(tsr1, SPRN_PA6T_TSR1); | |
234 | SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2); | |
235 | SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3); | |
236 | #endif /* CONFIG_DEBUG_KERNEL */ | |
6529c13d | 237 | |
1da177e4 | 238 | static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra); |
f050982a | 239 | static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL); |
4c198557 | 240 | static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr); |
6529c13d OJ |
241 | static SYSDEV_ATTR(purr, 0600, show_purr, store_purr); |
242 | ||
243 | static struct sysdev_attribute ibm_common_attrs[] = { | |
244 | _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), | |
245 | _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), | |
246 | }; | |
247 | ||
248 | static struct sysdev_attribute ibm_pmc_attrs[] = { | |
249 | _SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1), | |
250 | _SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2), | |
251 | _SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3), | |
252 | _SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4), | |
253 | _SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5), | |
254 | _SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6), | |
255 | _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7), | |
256 | _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8), | |
257 | }; | |
258 | ||
259 | static struct sysdev_attribute pa6t_attrs[] = { | |
260 | _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), | |
261 | _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), | |
262 | _SYSDEV_ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0), | |
263 | _SYSDEV_ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1), | |
264 | _SYSDEV_ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2), | |
265 | _SYSDEV_ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3), | |
266 | _SYSDEV_ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4), | |
267 | _SYSDEV_ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5), | |
2e1957fd OJ |
268 | #ifdef CONFIG_DEBUG_KERNEL |
269 | _SYSDEV_ATTR(hid0, 0600, show_hid0, store_hid0), | |
270 | _SYSDEV_ATTR(hid1, 0600, show_hid1, store_hid1), | |
271 | _SYSDEV_ATTR(hid4, 0600, show_hid4, store_hid4), | |
272 | _SYSDEV_ATTR(hid5, 0600, show_hid5, store_hid5), | |
273 | _SYSDEV_ATTR(ima0, 0600, show_ima0, store_ima0), | |
274 | _SYSDEV_ATTR(ima1, 0600, show_ima1, store_ima1), | |
275 | _SYSDEV_ATTR(ima2, 0600, show_ima2, store_ima2), | |
276 | _SYSDEV_ATTR(ima3, 0600, show_ima3, store_ima3), | |
277 | _SYSDEV_ATTR(ima4, 0600, show_ima4, store_ima4), | |
278 | _SYSDEV_ATTR(ima5, 0600, show_ima5, store_ima5), | |
279 | _SYSDEV_ATTR(ima6, 0600, show_ima6, store_ima6), | |
280 | _SYSDEV_ATTR(ima7, 0600, show_ima7, store_ima7), | |
281 | _SYSDEV_ATTR(ima8, 0600, show_ima8, store_ima8), | |
282 | _SYSDEV_ATTR(ima9, 0600, show_ima9, store_ima9), | |
283 | _SYSDEV_ATTR(imaat, 0600, show_imaat, store_imaat), | |
284 | _SYSDEV_ATTR(btcr, 0600, show_btcr, store_btcr), | |
285 | _SYSDEV_ATTR(pccr, 0600, show_pccr, store_pccr), | |
286 | _SYSDEV_ATTR(rpccr, 0600, show_rpccr, store_rpccr), | |
287 | _SYSDEV_ATTR(der, 0600, show_der, store_der), | |
288 | _SYSDEV_ATTR(mer, 0600, show_mer, store_mer), | |
289 | _SYSDEV_ATTR(ber, 0600, show_ber, store_ber), | |
290 | _SYSDEV_ATTR(ier, 0600, show_ier, store_ier), | |
291 | _SYSDEV_ATTR(sier, 0600, show_sier, store_sier), | |
292 | _SYSDEV_ATTR(siar, 0600, show_siar, store_siar), | |
293 | _SYSDEV_ATTR(tsr0, 0600, show_tsr0, store_tsr0), | |
294 | _SYSDEV_ATTR(tsr1, 0600, show_tsr1, store_tsr1), | |
295 | _SYSDEV_ATTR(tsr2, 0600, show_tsr2, store_tsr2), | |
296 | _SYSDEV_ATTR(tsr3, 0600, show_tsr3, store_tsr3), | |
297 | #endif /* CONFIG_DEBUG_KERNEL */ | |
6529c13d OJ |
298 | }; |
299 | ||
1da177e4 LT |
300 | |
301 | static void register_cpu_online(unsigned int cpu) | |
302 | { | |
303 | struct cpu *c = &per_cpu(cpu_devices, cpu); | |
304 | struct sys_device *s = &c->sysdev; | |
6529c13d OJ |
305 | struct sysdev_attribute *attrs, *pmc_attrs; |
306 | int i, nattrs; | |
1da177e4 | 307 | |
ad5cb17f SR |
308 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
309 | cpu_has_feature(CPU_FTR_SMT)) | |
1da177e4 | 310 | sysdev_create_file(s, &attr_smt_snooze_delay); |
1da177e4 LT |
311 | |
312 | /* PMC stuff */ | |
6529c13d OJ |
313 | switch (cur_cpu_spec->pmc_type) { |
314 | case PPC_PMC_IBM: | |
315 | attrs = ibm_common_attrs; | |
316 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); | |
317 | pmc_attrs = ibm_pmc_attrs; | |
318 | break; | |
319 | case PPC_PMC_PA6T: | |
320 | /* PA Semi starts counting at PMC0 */ | |
321 | attrs = pa6t_attrs; | |
322 | nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); | |
323 | pmc_attrs = NULL; | |
324 | break; | |
325 | default: | |
326 | attrs = NULL; | |
327 | nattrs = 0; | |
328 | pmc_attrs = NULL; | |
329 | } | |
330 | ||
331 | for (i = 0; i < nattrs; i++) | |
332 | sysdev_create_file(s, &attrs[i]); | |
1da177e4 | 333 | |
6529c13d OJ |
334 | if (pmc_attrs) |
335 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) | |
336 | sysdev_create_file(s, &pmc_attrs[i]); | |
1da177e4 LT |
337 | |
338 | if (cpu_has_feature(CPU_FTR_MMCRA)) | |
339 | sysdev_create_file(s, &attr_mmcra); | |
340 | ||
afd05423 | 341 | if (cpu_has_feature(CPU_FTR_PURR)) |
1da177e4 | 342 | sysdev_create_file(s, &attr_purr); |
4c198557 | 343 | |
f050982a AB |
344 | if (cpu_has_feature(CPU_FTR_SPURR)) |
345 | sysdev_create_file(s, &attr_spurr); | |
346 | ||
4c198557 AB |
347 | if (cpu_has_feature(CPU_FTR_DSCR)) |
348 | sysdev_create_file(s, &attr_dscr); | |
1da177e4 LT |
349 | } |
350 | ||
351 | #ifdef CONFIG_HOTPLUG_CPU | |
352 | static void unregister_cpu_online(unsigned int cpu) | |
353 | { | |
354 | struct cpu *c = &per_cpu(cpu_devices, cpu); | |
355 | struct sys_device *s = &c->sysdev; | |
6529c13d OJ |
356 | struct sysdev_attribute *attrs, *pmc_attrs; |
357 | int i, nattrs; | |
1da177e4 | 358 | |
72486f1f | 359 | BUG_ON(!c->hotpluggable); |
1da177e4 | 360 | |
ad5cb17f SR |
361 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
362 | cpu_has_feature(CPU_FTR_SMT)) | |
1da177e4 | 363 | sysdev_remove_file(s, &attr_smt_snooze_delay); |
1da177e4 LT |
364 | |
365 | /* PMC stuff */ | |
6529c13d OJ |
366 | switch (cur_cpu_spec->pmc_type) { |
367 | case PPC_PMC_IBM: | |
368 | attrs = ibm_common_attrs; | |
369 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); | |
370 | pmc_attrs = ibm_pmc_attrs; | |
371 | break; | |
372 | case PPC_PMC_PA6T: | |
373 | /* PA Semi starts counting at PMC0 */ | |
374 | attrs = pa6t_attrs; | |
375 | nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); | |
376 | pmc_attrs = NULL; | |
377 | break; | |
378 | default: | |
379 | attrs = NULL; | |
380 | nattrs = 0; | |
381 | pmc_attrs = NULL; | |
382 | } | |
1da177e4 | 383 | |
6529c13d OJ |
384 | for (i = 0; i < nattrs; i++) |
385 | sysdev_remove_file(s, &attrs[i]); | |
386 | ||
387 | if (pmc_attrs) | |
388 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) | |
389 | sysdev_remove_file(s, &pmc_attrs[i]); | |
1da177e4 LT |
390 | |
391 | if (cpu_has_feature(CPU_FTR_MMCRA)) | |
392 | sysdev_remove_file(s, &attr_mmcra); | |
393 | ||
afd05423 | 394 | if (cpu_has_feature(CPU_FTR_PURR)) |
1da177e4 | 395 | sysdev_remove_file(s, &attr_purr); |
4c198557 | 396 | |
f050982a AB |
397 | if (cpu_has_feature(CPU_FTR_SPURR)) |
398 | sysdev_remove_file(s, &attr_spurr); | |
399 | ||
4c198557 AB |
400 | if (cpu_has_feature(CPU_FTR_DSCR)) |
401 | sysdev_remove_file(s, &attr_dscr); | |
1da177e4 LT |
402 | } |
403 | #endif /* CONFIG_HOTPLUG_CPU */ | |
404 | ||
8c78f307 | 405 | static int __cpuinit sysfs_cpu_notify(struct notifier_block *self, |
1da177e4 LT |
406 | unsigned long action, void *hcpu) |
407 | { | |
408 | unsigned int cpu = (unsigned int)(long)hcpu; | |
409 | ||
410 | switch (action) { | |
411 | case CPU_ONLINE: | |
8bb78442 | 412 | case CPU_ONLINE_FROZEN: |
1da177e4 LT |
413 | register_cpu_online(cpu); |
414 | break; | |
415 | #ifdef CONFIG_HOTPLUG_CPU | |
416 | case CPU_DEAD: | |
8bb78442 | 417 | case CPU_DEAD_FROZEN: |
1da177e4 LT |
418 | unregister_cpu_online(cpu); |
419 | break; | |
420 | #endif | |
421 | } | |
422 | return NOTIFY_OK; | |
423 | } | |
424 | ||
8c78f307 | 425 | static struct notifier_block __cpuinitdata sysfs_cpu_nb = { |
1da177e4 LT |
426 | .notifier_call = sysfs_cpu_notify, |
427 | }; | |
428 | ||
0344c6c5 CK |
429 | static DEFINE_MUTEX(cpu_mutex); |
430 | ||
431 | int cpu_add_sysdev_attr(struct sysdev_attribute *attr) | |
432 | { | |
433 | int cpu; | |
434 | ||
435 | mutex_lock(&cpu_mutex); | |
436 | ||
437 | for_each_possible_cpu(cpu) { | |
438 | sysdev_create_file(get_cpu_sysdev(cpu), attr); | |
439 | } | |
440 | ||
441 | mutex_unlock(&cpu_mutex); | |
442 | return 0; | |
443 | } | |
444 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr); | |
445 | ||
446 | int cpu_add_sysdev_attr_group(struct attribute_group *attrs) | |
447 | { | |
448 | int cpu; | |
449 | struct sys_device *sysdev; | |
6bcc4c01 | 450 | int ret; |
0344c6c5 CK |
451 | |
452 | mutex_lock(&cpu_mutex); | |
453 | ||
454 | for_each_possible_cpu(cpu) { | |
455 | sysdev = get_cpu_sysdev(cpu); | |
6bcc4c01 OJ |
456 | ret = sysfs_create_group(&sysdev->kobj, attrs); |
457 | WARN_ON(ret != 0); | |
0344c6c5 CK |
458 | } |
459 | ||
460 | mutex_unlock(&cpu_mutex); | |
461 | return 0; | |
462 | } | |
463 | EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group); | |
464 | ||
465 | ||
466 | void cpu_remove_sysdev_attr(struct sysdev_attribute *attr) | |
467 | { | |
468 | int cpu; | |
469 | ||
470 | mutex_lock(&cpu_mutex); | |
471 | ||
472 | for_each_possible_cpu(cpu) { | |
473 | sysdev_remove_file(get_cpu_sysdev(cpu), attr); | |
474 | } | |
475 | ||
476 | mutex_unlock(&cpu_mutex); | |
477 | } | |
478 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr); | |
479 | ||
480 | void cpu_remove_sysdev_attr_group(struct attribute_group *attrs) | |
481 | { | |
482 | int cpu; | |
483 | struct sys_device *sysdev; | |
484 | ||
485 | mutex_lock(&cpu_mutex); | |
486 | ||
487 | for_each_possible_cpu(cpu) { | |
488 | sysdev = get_cpu_sysdev(cpu); | |
489 | sysfs_remove_group(&sysdev->kobj, attrs); | |
490 | } | |
491 | ||
492 | mutex_unlock(&cpu_mutex); | |
493 | } | |
494 | EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group); | |
495 | ||
496 | ||
1da177e4 LT |
497 | /* NUMA stuff */ |
498 | ||
499 | #ifdef CONFIG_NUMA | |
1da177e4 LT |
500 | static void register_nodes(void) |
501 | { | |
502 | int i; | |
503 | ||
0fc44159 YG |
504 | for (i = 0; i < MAX_NUMNODES; i++) |
505 | register_one_node(i); | |
1da177e4 | 506 | } |
953039c8 JK |
507 | |
508 | int sysfs_add_device_to_node(struct sys_device *dev, int nid) | |
509 | { | |
510 | struct node *node = &node_devices[nid]; | |
511 | return sysfs_create_link(&node->sysdev.kobj, &dev->kobj, | |
512 | kobject_name(&dev->kobj)); | |
513 | } | |
12654f77 | 514 | EXPORT_SYMBOL_GPL(sysfs_add_device_to_node); |
953039c8 JK |
515 | |
516 | void sysfs_remove_device_from_node(struct sys_device *dev, int nid) | |
517 | { | |
518 | struct node *node = &node_devices[nid]; | |
519 | sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj)); | |
520 | } | |
12654f77 | 521 | EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); |
953039c8 | 522 | |
1da177e4 LT |
523 | #else |
524 | static void register_nodes(void) | |
525 | { | |
526 | return; | |
527 | } | |
953039c8 | 528 | |
1da177e4 LT |
529 | #endif |
530 | ||
531 | /* Only valid if CPU is present. */ | |
532 | static ssize_t show_physical_id(struct sys_device *dev, char *buf) | |
533 | { | |
534 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | |
535 | ||
536 | return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id)); | |
537 | } | |
538 | static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL); | |
539 | ||
540 | static int __init topology_init(void) | |
541 | { | |
542 | int cpu; | |
1da177e4 LT |
543 | |
544 | register_nodes(); | |
1da177e4 LT |
545 | register_cpu_notifier(&sysfs_cpu_nb); |
546 | ||
0e551954 | 547 | for_each_possible_cpu(cpu) { |
1da177e4 LT |
548 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
549 | ||
1da177e4 LT |
550 | /* |
551 | * For now, we just see if the system supports making | |
552 | * the RTAS calls for CPU hotplug. But, there may be a | |
553 | * more comprehensive way to do this for an individual | |
554 | * CPU. For instance, the boot cpu might never be valid | |
555 | * for hotplugging. | |
556 | */ | |
72486f1f SS |
557 | if (ppc_md.cpu_die) |
558 | c->hotpluggable = 1; | |
1da177e4 | 559 | |
72486f1f | 560 | if (cpu_online(cpu) || c->hotpluggable) { |
76b67ed9 | 561 | register_cpu(c, cpu); |
1da177e4 LT |
562 | |
563 | sysdev_create_file(&c->sysdev, &attr_physical_id); | |
564 | } | |
565 | ||
566 | if (cpu_online(cpu)) | |
567 | register_cpu_online(cpu); | |
568 | } | |
569 | ||
570 | return 0; | |
571 | } | |
e9e77ce8 | 572 | subsys_initcall(topology_init); |