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