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