xref: /linux/arch/powerpc/kernel/sysfs.c (revision 12633e803a2a556f6469e0933d08233d0844a2d9)
1d3d2176aSDavid Gibson #include <linux/sysdev.h>
2d3d2176aSDavid Gibson #include <linux/cpu.h>
3d3d2176aSDavid Gibson #include <linux/smp.h>
4d3d2176aSDavid Gibson #include <linux/percpu.h>
5d3d2176aSDavid Gibson #include <linux/init.h>
6d3d2176aSDavid Gibson #include <linux/sched.h>
7d3d2176aSDavid Gibson #include <linux/module.h>
8d3d2176aSDavid Gibson #include <linux/nodemask.h>
9d3d2176aSDavid Gibson #include <linux/cpumask.h>
10d3d2176aSDavid Gibson #include <linux/notifier.h>
11d3d2176aSDavid Gibson 
12d3d2176aSDavid Gibson #include <asm/current.h>
13d3d2176aSDavid Gibson #include <asm/processor.h>
14d3d2176aSDavid Gibson #include <asm/cputable.h>
15d3d2176aSDavid Gibson #include <asm/firmware.h>
16d3d2176aSDavid Gibson #include <asm/hvcall.h>
17d3d2176aSDavid Gibson #include <asm/prom.h>
18d3d2176aSDavid Gibson #include <asm/machdep.h>
19d3d2176aSDavid Gibson #include <asm/smp.h>
20a6dbf93aSPaul Mackerras #include <asm/pmc.h>
21d3d2176aSDavid Gibson 
2293197a36SNathan Lynch #include "cacheinfo.h"
2393197a36SNathan Lynch 
24b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
25b950bdd0SBenjamin Herrenschmidt #include <asm/paca.h>
26b950bdd0SBenjamin Herrenschmidt #include <asm/lppaca.h>
27b950bdd0SBenjamin Herrenschmidt #endif
28b950bdd0SBenjamin Herrenschmidt 
29d3d2176aSDavid Gibson static DEFINE_PER_CPU(struct cpu, cpu_devices);
30d3d2176aSDavid Gibson 
31b950bdd0SBenjamin Herrenschmidt /*
32b950bdd0SBenjamin Herrenschmidt  * SMT snooze delay stuff, 64-bit only for now
33b950bdd0SBenjamin Herrenschmidt  */
34d3d2176aSDavid Gibson 
35b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
36b950bdd0SBenjamin Herrenschmidt 
370ddd3e7dSAnton Blanchard /* Time in microseconds we delay before sleeping in the idle loop */
380ddd3e7dSAnton Blanchard DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };
39d3d2176aSDavid Gibson 
404a0b2b4dSAndi Kleen static ssize_t store_smt_snooze_delay(struct sys_device *dev,
414a0b2b4dSAndi Kleen 				      struct sysdev_attribute *attr,
424a0b2b4dSAndi Kleen 				      const char *buf,
43d3d2176aSDavid Gibson 				      size_t count)
44d3d2176aSDavid Gibson {
45d3d2176aSDavid Gibson 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
46d3d2176aSDavid Gibson 	ssize_t ret;
47d3d2176aSDavid Gibson 	unsigned long snooze;
48d3d2176aSDavid Gibson 
49d3d2176aSDavid Gibson 	ret = sscanf(buf, "%lu", &snooze);
50d3d2176aSDavid Gibson 	if (ret != 1)
51d3d2176aSDavid Gibson 		return -EINVAL;
52d3d2176aSDavid Gibson 
53d3d2176aSDavid Gibson 	per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze;
54d3d2176aSDavid Gibson 
55d3d2176aSDavid Gibson 	return count;
56d3d2176aSDavid Gibson }
57d3d2176aSDavid Gibson 
584a0b2b4dSAndi Kleen static ssize_t show_smt_snooze_delay(struct sys_device *dev,
594a0b2b4dSAndi Kleen 				     struct sysdev_attribute *attr,
604a0b2b4dSAndi Kleen 				     char *buf)
61d3d2176aSDavid Gibson {
62d3d2176aSDavid Gibson 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
63d3d2176aSDavid Gibson 
64d3d2176aSDavid Gibson 	return sprintf(buf, "%lu\n", per_cpu(smt_snooze_delay, cpu->sysdev.id));
65d3d2176aSDavid Gibson }
66d3d2176aSDavid Gibson 
67d3d2176aSDavid Gibson static SYSDEV_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
68d3d2176aSDavid Gibson 		   store_smt_snooze_delay);
69d3d2176aSDavid Gibson 
70d3d2176aSDavid Gibson /* Only parse OF options if the matching cmdline option was not specified */
71d3d2176aSDavid Gibson static int smt_snooze_cmdline;
72d3d2176aSDavid Gibson 
73d3d2176aSDavid Gibson static int __init smt_setup(void)
74d3d2176aSDavid Gibson {
75d3d2176aSDavid Gibson 	struct device_node *options;
76a7f67bdfSJeremy Kerr 	const unsigned int *val;
77d3d2176aSDavid Gibson 	unsigned int cpu;
78d3d2176aSDavid Gibson 
79d3d2176aSDavid Gibson 	if (!cpu_has_feature(CPU_FTR_SMT))
8069ed3324SAnton Blanchard 		return -ENODEV;
81d3d2176aSDavid Gibson 
828c8dc322SStephen Rothwell 	options = of_find_node_by_path("/options");
83d3d2176aSDavid Gibson 	if (!options)
8469ed3324SAnton Blanchard 		return -ENODEV;
85d3d2176aSDavid Gibson 
86e2eb6392SStephen Rothwell 	val = of_get_property(options, "ibm,smt-snooze-delay", NULL);
87d3d2176aSDavid Gibson 	if (!smt_snooze_cmdline && val) {
880e551954SKAMEZAWA Hiroyuki 		for_each_possible_cpu(cpu)
89d3d2176aSDavid Gibson 			per_cpu(smt_snooze_delay, cpu) = *val;
90d3d2176aSDavid Gibson 	}
91d3d2176aSDavid Gibson 
928c8dc322SStephen Rothwell 	of_node_put(options);
9369ed3324SAnton Blanchard 	return 0;
94d3d2176aSDavid Gibson }
95d3d2176aSDavid Gibson __initcall(smt_setup);
96d3d2176aSDavid Gibson 
97d3d2176aSDavid Gibson static int __init setup_smt_snooze_delay(char *str)
98d3d2176aSDavid Gibson {
99d3d2176aSDavid Gibson 	unsigned int cpu;
100d3d2176aSDavid Gibson 	int snooze;
101d3d2176aSDavid Gibson 
102d3d2176aSDavid Gibson 	if (!cpu_has_feature(CPU_FTR_SMT))
103d3d2176aSDavid Gibson 		return 1;
104d3d2176aSDavid Gibson 
105d3d2176aSDavid Gibson 	smt_snooze_cmdline = 1;
106d3d2176aSDavid Gibson 
107d3d2176aSDavid Gibson 	if (get_option(&str, &snooze)) {
1080e551954SKAMEZAWA Hiroyuki 		for_each_possible_cpu(cpu)
109d3d2176aSDavid Gibson 			per_cpu(smt_snooze_delay, cpu) = snooze;
110d3d2176aSDavid Gibson 	}
111d3d2176aSDavid Gibson 
112d3d2176aSDavid Gibson 	return 1;
113d3d2176aSDavid Gibson }
114d3d2176aSDavid Gibson __setup("smt-snooze-delay=", setup_smt_snooze_delay);
115d3d2176aSDavid Gibson 
116b950bdd0SBenjamin Herrenschmidt #endif /* CONFIG_PPC64 */
117d3d2176aSDavid Gibson 
118d3d2176aSDavid Gibson /*
119d3d2176aSDavid Gibson  * Enabling PMCs will slow partition context switch times so we only do
120d3d2176aSDavid Gibson  * it the first time we write to the PMCs.
121d3d2176aSDavid Gibson  */
122d3d2176aSDavid Gibson 
123d3d2176aSDavid Gibson static DEFINE_PER_CPU(char, pmcs_enabled);
124d3d2176aSDavid Gibson 
125b950bdd0SBenjamin Herrenschmidt void ppc_enable_pmcs(void)
126d3d2176aSDavid Gibson {
127a6dbf93aSPaul Mackerras 	ppc_set_pmu_inuse(1);
128a6dbf93aSPaul Mackerras 
129d3d2176aSDavid Gibson 	/* Only need to enable them once */
130d3d2176aSDavid Gibson 	if (__get_cpu_var(pmcs_enabled))
131d3d2176aSDavid Gibson 		return;
132d3d2176aSDavid Gibson 
133d3d2176aSDavid Gibson 	__get_cpu_var(pmcs_enabled) = 1;
134d3d2176aSDavid Gibson 
135d3d2176aSDavid Gibson 	if (ppc_md.enable_pmcs)
136d3d2176aSDavid Gibson 		ppc_md.enable_pmcs();
137d3d2176aSDavid Gibson }
138b950bdd0SBenjamin Herrenschmidt EXPORT_SYMBOL(ppc_enable_pmcs);
139d3d2176aSDavid Gibson 
140d3d2176aSDavid Gibson #define SYSFS_PMCSETUP(NAME, ADDRESS) \
1419a371934SRusty Russell static void read_##NAME(void *val) \
142d3d2176aSDavid Gibson { \
143ec78c8acSBenjamin Herrenschmidt 	*(unsigned long *)val = mfspr(ADDRESS);	\
144d3d2176aSDavid Gibson } \
145ec78c8acSBenjamin Herrenschmidt static void write_##NAME(void *val) \
146d3d2176aSDavid Gibson { \
147b950bdd0SBenjamin Herrenschmidt 	ppc_enable_pmcs(); \
1489a371934SRusty Russell 	mtspr(ADDRESS, *(unsigned long *)val);	\
149d3d2176aSDavid Gibson } \
1504a0b2b4dSAndi Kleen static ssize_t show_##NAME(struct sys_device *dev, \
1514a0b2b4dSAndi Kleen 			struct sysdev_attribute *attr, \
1524a0b2b4dSAndi Kleen 			char *buf) \
153d3d2176aSDavid Gibson { \
154d3d2176aSDavid Gibson 	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
1559a371934SRusty Russell 	unsigned long val; \
1569a371934SRusty Russell 	smp_call_function_single(cpu->sysdev.id, read_##NAME, &val, 1);	\
157d3d2176aSDavid Gibson 	return sprintf(buf, "%lx\n", val); \
158d3d2176aSDavid Gibson } \
1593ff6eeccSAdrian Bunk static ssize_t __used \
1604a0b2b4dSAndi Kleen 	store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \
1614a0b2b4dSAndi Kleen 			const char *buf, size_t count) \
162d3d2176aSDavid Gibson { \
163d3d2176aSDavid Gibson 	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
164d3d2176aSDavid Gibson 	unsigned long val; \
165d3d2176aSDavid Gibson 	int ret = sscanf(buf, "%lx", &val); \
166d3d2176aSDavid Gibson 	if (ret != 1) \
167d3d2176aSDavid Gibson 		return -EINVAL; \
1689a371934SRusty Russell 	smp_call_function_single(cpu->sysdev.id, write_##NAME, &val, 1); \
169d3d2176aSDavid Gibson 	return count; \
170d3d2176aSDavid Gibson }
171d3d2176aSDavid Gibson 
1726529c13dSOlof Johansson 
1736529c13dSOlof Johansson /* Let's define all possible registers, we'll only hook up the ones
1746529c13dSOlof Johansson  * that are implemented on the current processor
1756529c13dSOlof Johansson  */
1766529c13dSOlof Johansson 
17733a7f122SKumar Gala #if defined(CONFIG_PPC64)
178b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_CLASSIC	1
179b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_IBM		1
180b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_PA6T	1
18133a7f122SKumar Gala #elif defined(CONFIG_6xx)
182b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_CLASSIC	1
183b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_IBM		1
184b950bdd0SBenjamin Herrenschmidt #define HAS_PPC_PMC_G4		1
185b950bdd0SBenjamin Herrenschmidt #endif
186b950bdd0SBenjamin Herrenschmidt 
187b950bdd0SBenjamin Herrenschmidt 
188b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_CLASSIC
189d3d2176aSDavid Gibson SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
190d3d2176aSDavid Gibson SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
191d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
192d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
193d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
194d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
195d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
196d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
197b950bdd0SBenjamin Herrenschmidt 
198b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_G4
199b950bdd0SBenjamin Herrenschmidt SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2);
200b950bdd0SBenjamin Herrenschmidt #endif
201b950bdd0SBenjamin Herrenschmidt 
202b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
203d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
204d3d2176aSDavid Gibson SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
205b950bdd0SBenjamin Herrenschmidt 
206b950bdd0SBenjamin Herrenschmidt SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
207d3d2176aSDavid Gibson SYSFS_PMCSETUP(purr, SPRN_PURR);
208f050982aSAnton Blanchard SYSFS_PMCSETUP(spurr, SPRN_SPURR);
2094c198557SAnton Blanchard SYSFS_PMCSETUP(dscr, SPRN_DSCR);
210d3d2176aSDavid Gibson 
211b950bdd0SBenjamin Herrenschmidt static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
212b950bdd0SBenjamin Herrenschmidt static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL);
213b950bdd0SBenjamin Herrenschmidt static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr);
214b950bdd0SBenjamin Herrenschmidt static SYSDEV_ATTR(purr, 0600, show_purr, store_purr);
215b950bdd0SBenjamin Herrenschmidt #endif /* CONFIG_PPC64 */
216b950bdd0SBenjamin Herrenschmidt 
217b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_PA6T
21825fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0);
21925fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1);
22025fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2);
22125fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3);
22225fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4);
22325fc530eSOlof Johansson SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5);
2242e1957fdSOlof Johansson #ifdef CONFIG_DEBUG_KERNEL
2252e1957fdSOlof Johansson SYSFS_PMCSETUP(hid0, SPRN_HID0);
2262e1957fdSOlof Johansson SYSFS_PMCSETUP(hid1, SPRN_HID1);
2272e1957fdSOlof Johansson SYSFS_PMCSETUP(hid4, SPRN_HID4);
2282e1957fdSOlof Johansson SYSFS_PMCSETUP(hid5, SPRN_HID5);
2292e1957fdSOlof Johansson SYSFS_PMCSETUP(ima0, SPRN_PA6T_IMA0);
2302e1957fdSOlof Johansson SYSFS_PMCSETUP(ima1, SPRN_PA6T_IMA1);
2312e1957fdSOlof Johansson SYSFS_PMCSETUP(ima2, SPRN_PA6T_IMA2);
2322e1957fdSOlof Johansson SYSFS_PMCSETUP(ima3, SPRN_PA6T_IMA3);
2332e1957fdSOlof Johansson SYSFS_PMCSETUP(ima4, SPRN_PA6T_IMA4);
2342e1957fdSOlof Johansson SYSFS_PMCSETUP(ima5, SPRN_PA6T_IMA5);
2352e1957fdSOlof Johansson SYSFS_PMCSETUP(ima6, SPRN_PA6T_IMA6);
2362e1957fdSOlof Johansson SYSFS_PMCSETUP(ima7, SPRN_PA6T_IMA7);
2372e1957fdSOlof Johansson SYSFS_PMCSETUP(ima8, SPRN_PA6T_IMA8);
2382e1957fdSOlof Johansson SYSFS_PMCSETUP(ima9, SPRN_PA6T_IMA9);
2392e1957fdSOlof Johansson SYSFS_PMCSETUP(imaat, SPRN_PA6T_IMAAT);
2402e1957fdSOlof Johansson SYSFS_PMCSETUP(btcr, SPRN_PA6T_BTCR);
2412e1957fdSOlof Johansson SYSFS_PMCSETUP(pccr, SPRN_PA6T_PCCR);
2422e1957fdSOlof Johansson SYSFS_PMCSETUP(rpccr, SPRN_PA6T_RPCCR);
2432e1957fdSOlof Johansson SYSFS_PMCSETUP(der, SPRN_PA6T_DER);
2442e1957fdSOlof Johansson SYSFS_PMCSETUP(mer, SPRN_PA6T_MER);
2452e1957fdSOlof Johansson SYSFS_PMCSETUP(ber, SPRN_PA6T_BER);
2462e1957fdSOlof Johansson SYSFS_PMCSETUP(ier, SPRN_PA6T_IER);
2472e1957fdSOlof Johansson SYSFS_PMCSETUP(sier, SPRN_PA6T_SIER);
2482e1957fdSOlof Johansson SYSFS_PMCSETUP(siar, SPRN_PA6T_SIAR);
2492e1957fdSOlof Johansson SYSFS_PMCSETUP(tsr0, SPRN_PA6T_TSR0);
2502e1957fdSOlof Johansson SYSFS_PMCSETUP(tsr1, SPRN_PA6T_TSR1);
2512e1957fdSOlof Johansson SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2);
2522e1957fdSOlof Johansson SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3);
2532e1957fdSOlof Johansson #endif /* CONFIG_DEBUG_KERNEL */
254b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_PA6T */
2556529c13dSOlof Johansson 
256b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_IBM
2576529c13dSOlof Johansson static struct sysdev_attribute ibm_common_attrs[] = {
2586529c13dSOlof Johansson 	_SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
2596529c13dSOlof Johansson 	_SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
2606529c13dSOlof Johansson };
261b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_G4 */
2626529c13dSOlof Johansson 
263b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_G4
264b950bdd0SBenjamin Herrenschmidt static struct sysdev_attribute g4_common_attrs[] = {
265b950bdd0SBenjamin Herrenschmidt 	_SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
266b950bdd0SBenjamin Herrenschmidt 	_SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
267b950bdd0SBenjamin Herrenschmidt 	_SYSDEV_ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2),
268b950bdd0SBenjamin Herrenschmidt };
269b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_G4 */
270b950bdd0SBenjamin Herrenschmidt 
271b950bdd0SBenjamin Herrenschmidt static struct sysdev_attribute classic_pmc_attrs[] = {
2726529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1),
2736529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2),
2746529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3),
2756529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4),
2766529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5),
2776529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6),
278b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
2796529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7),
2806529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8),
281b950bdd0SBenjamin Herrenschmidt #endif
2826529c13dSOlof Johansson };
2836529c13dSOlof Johansson 
284b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_PA6T
2856529c13dSOlof Johansson static struct sysdev_attribute pa6t_attrs[] = {
2866529c13dSOlof Johansson 	_SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
2876529c13dSOlof Johansson 	_SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
2886529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0),
2896529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1),
2906529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2),
2916529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3),
2926529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4),
2936529c13dSOlof Johansson 	_SYSDEV_ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5),
2942e1957fdSOlof Johansson #ifdef CONFIG_DEBUG_KERNEL
2952e1957fdSOlof Johansson 	_SYSDEV_ATTR(hid0, 0600, show_hid0, store_hid0),
2962e1957fdSOlof Johansson 	_SYSDEV_ATTR(hid1, 0600, show_hid1, store_hid1),
2972e1957fdSOlof Johansson 	_SYSDEV_ATTR(hid4, 0600, show_hid4, store_hid4),
2982e1957fdSOlof Johansson 	_SYSDEV_ATTR(hid5, 0600, show_hid5, store_hid5),
2992e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima0, 0600, show_ima0, store_ima0),
3002e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima1, 0600, show_ima1, store_ima1),
3012e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima2, 0600, show_ima2, store_ima2),
3022e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima3, 0600, show_ima3, store_ima3),
3032e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima4, 0600, show_ima4, store_ima4),
3042e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima5, 0600, show_ima5, store_ima5),
3052e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima6, 0600, show_ima6, store_ima6),
3062e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima7, 0600, show_ima7, store_ima7),
3072e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima8, 0600, show_ima8, store_ima8),
3082e1957fdSOlof Johansson 	_SYSDEV_ATTR(ima9, 0600, show_ima9, store_ima9),
3092e1957fdSOlof Johansson 	_SYSDEV_ATTR(imaat, 0600, show_imaat, store_imaat),
3102e1957fdSOlof Johansson 	_SYSDEV_ATTR(btcr, 0600, show_btcr, store_btcr),
3112e1957fdSOlof Johansson 	_SYSDEV_ATTR(pccr, 0600, show_pccr, store_pccr),
3122e1957fdSOlof Johansson 	_SYSDEV_ATTR(rpccr, 0600, show_rpccr, store_rpccr),
3132e1957fdSOlof Johansson 	_SYSDEV_ATTR(der, 0600, show_der, store_der),
3142e1957fdSOlof Johansson 	_SYSDEV_ATTR(mer, 0600, show_mer, store_mer),
3152e1957fdSOlof Johansson 	_SYSDEV_ATTR(ber, 0600, show_ber, store_ber),
3162e1957fdSOlof Johansson 	_SYSDEV_ATTR(ier, 0600, show_ier, store_ier),
3172e1957fdSOlof Johansson 	_SYSDEV_ATTR(sier, 0600, show_sier, store_sier),
3182e1957fdSOlof Johansson 	_SYSDEV_ATTR(siar, 0600, show_siar, store_siar),
3192e1957fdSOlof Johansson 	_SYSDEV_ATTR(tsr0, 0600, show_tsr0, store_tsr0),
3202e1957fdSOlof Johansson 	_SYSDEV_ATTR(tsr1, 0600, show_tsr1, store_tsr1),
3212e1957fdSOlof Johansson 	_SYSDEV_ATTR(tsr2, 0600, show_tsr2, store_tsr2),
3222e1957fdSOlof Johansson 	_SYSDEV_ATTR(tsr3, 0600, show_tsr3, store_tsr3),
3232e1957fdSOlof Johansson #endif /* CONFIG_DEBUG_KERNEL */
3246529c13dSOlof Johansson };
325b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_PA6T */
326b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_CLASSIC */
3276529c13dSOlof Johansson 
3289ba1984eSNathan Lynch static void __cpuinit register_cpu_online(unsigned int cpu)
329d3d2176aSDavid Gibson {
330d3d2176aSDavid Gibson 	struct cpu *c = &per_cpu(cpu_devices, cpu);
331d3d2176aSDavid Gibson 	struct sys_device *s = &c->sysdev;
3326529c13dSOlof Johansson 	struct sysdev_attribute *attrs, *pmc_attrs;
3336529c13dSOlof Johansson 	int i, nattrs;
334d3d2176aSDavid Gibson 
335b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
336ad5cb17fSStephen Rothwell 	if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
337ad5cb17fSStephen Rothwell 			cpu_has_feature(CPU_FTR_SMT))
338d3d2176aSDavid Gibson 		sysdev_create_file(s, &attr_smt_snooze_delay);
339b950bdd0SBenjamin Herrenschmidt #endif
340d3d2176aSDavid Gibson 
341d3d2176aSDavid Gibson 	/* PMC stuff */
3426529c13dSOlof Johansson 	switch (cur_cpu_spec->pmc_type) {
343b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_IBM
3446529c13dSOlof Johansson 	case PPC_PMC_IBM:
3456529c13dSOlof Johansson 		attrs = ibm_common_attrs;
3466529c13dSOlof Johansson 		nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
347b950bdd0SBenjamin Herrenschmidt 		pmc_attrs = classic_pmc_attrs;
3486529c13dSOlof Johansson 		break;
349b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_IBM */
350b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_G4
351b950bdd0SBenjamin Herrenschmidt 	case PPC_PMC_G4:
352b950bdd0SBenjamin Herrenschmidt 		attrs = g4_common_attrs;
353b950bdd0SBenjamin Herrenschmidt 		nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
354b950bdd0SBenjamin Herrenschmidt 		pmc_attrs = classic_pmc_attrs;
355b950bdd0SBenjamin Herrenschmidt 		break;
356b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_G4 */
357b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_PA6T
3586529c13dSOlof Johansson 	case PPC_PMC_PA6T:
3596529c13dSOlof Johansson 		/* PA Semi starts counting at PMC0 */
3606529c13dSOlof Johansson 		attrs = pa6t_attrs;
3616529c13dSOlof Johansson 		nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
3626529c13dSOlof Johansson 		pmc_attrs = NULL;
3636529c13dSOlof Johansson 		break;
364b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_PA6T */
3656529c13dSOlof Johansson 	default:
3666529c13dSOlof Johansson 		attrs = NULL;
3676529c13dSOlof Johansson 		nattrs = 0;
3686529c13dSOlof Johansson 		pmc_attrs = NULL;
3696529c13dSOlof Johansson 	}
370d3d2176aSDavid Gibson 
3716529c13dSOlof Johansson 	for (i = 0; i < nattrs; i++)
3726529c13dSOlof Johansson 		sysdev_create_file(s, &attrs[i]);
3736529c13dSOlof Johansson 
3746529c13dSOlof Johansson 	if (pmc_attrs)
3756529c13dSOlof Johansson 		for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
3766529c13dSOlof Johansson 			sysdev_create_file(s, &pmc_attrs[i]);
377d3d2176aSDavid Gibson 
378b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
379d3d2176aSDavid Gibson 	if (cpu_has_feature(CPU_FTR_MMCRA))
380d3d2176aSDavid Gibson 		sysdev_create_file(s, &attr_mmcra);
381d3d2176aSDavid Gibson 
382afd05423SMichael Neuling 	if (cpu_has_feature(CPU_FTR_PURR))
383d3d2176aSDavid Gibson 		sysdev_create_file(s, &attr_purr);
3844c198557SAnton Blanchard 
385f050982aSAnton Blanchard 	if (cpu_has_feature(CPU_FTR_SPURR))
386f050982aSAnton Blanchard 		sysdev_create_file(s, &attr_spurr);
387f050982aSAnton Blanchard 
3884c198557SAnton Blanchard 	if (cpu_has_feature(CPU_FTR_DSCR))
3894c198557SAnton Blanchard 		sysdev_create_file(s, &attr_dscr);
390b950bdd0SBenjamin Herrenschmidt #endif /* CONFIG_PPC64 */
391124c27d3SNathan Lynch 
39293197a36SNathan Lynch 	cacheinfo_cpu_online(cpu);
393d3d2176aSDavid Gibson }
394d3d2176aSDavid Gibson 
395d3d2176aSDavid Gibson #ifdef CONFIG_HOTPLUG_CPU
396d3d2176aSDavid Gibson static void unregister_cpu_online(unsigned int cpu)
397d3d2176aSDavid Gibson {
398d3d2176aSDavid Gibson 	struct cpu *c = &per_cpu(cpu_devices, cpu);
399d3d2176aSDavid Gibson 	struct sys_device *s = &c->sysdev;
4006529c13dSOlof Johansson 	struct sysdev_attribute *attrs, *pmc_attrs;
4016529c13dSOlof Johansson 	int i, nattrs;
402d3d2176aSDavid Gibson 
40372486f1fSSiddha, Suresh B 	BUG_ON(!c->hotpluggable);
404d3d2176aSDavid Gibson 
405a1e0eb10SMilton Miller #ifdef CONFIG_PPC64
406ad5cb17fSStephen Rothwell 	if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
407ad5cb17fSStephen Rothwell 			cpu_has_feature(CPU_FTR_SMT))
408d3d2176aSDavid Gibson 		sysdev_remove_file(s, &attr_smt_snooze_delay);
409a1e0eb10SMilton Miller #endif
410d3d2176aSDavid Gibson 
411d3d2176aSDavid Gibson 	/* PMC stuff */
4126529c13dSOlof Johansson 	switch (cur_cpu_spec->pmc_type) {
413b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_IBM
4146529c13dSOlof Johansson 	case PPC_PMC_IBM:
4156529c13dSOlof Johansson 		attrs = ibm_common_attrs;
4166529c13dSOlof Johansson 		nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
417b950bdd0SBenjamin Herrenschmidt 		pmc_attrs = classic_pmc_attrs;
4186529c13dSOlof Johansson 		break;
419b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_IBM */
420b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_G4
421b950bdd0SBenjamin Herrenschmidt 	case PPC_PMC_G4:
422b950bdd0SBenjamin Herrenschmidt 		attrs = g4_common_attrs;
423b950bdd0SBenjamin Herrenschmidt 		nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
424b950bdd0SBenjamin Herrenschmidt 		pmc_attrs = classic_pmc_attrs;
425b950bdd0SBenjamin Herrenschmidt 		break;
426b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_G4 */
427b950bdd0SBenjamin Herrenschmidt #ifdef HAS_PPC_PMC_PA6T
4286529c13dSOlof Johansson 	case PPC_PMC_PA6T:
4296529c13dSOlof Johansson 		/* PA Semi starts counting at PMC0 */
4306529c13dSOlof Johansson 		attrs = pa6t_attrs;
4316529c13dSOlof Johansson 		nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
4326529c13dSOlof Johansson 		pmc_attrs = NULL;
4336529c13dSOlof Johansson 		break;
434b950bdd0SBenjamin Herrenschmidt #endif /* HAS_PPC_PMC_PA6T */
4356529c13dSOlof Johansson 	default:
4366529c13dSOlof Johansson 		attrs = NULL;
4376529c13dSOlof Johansson 		nattrs = 0;
4386529c13dSOlof Johansson 		pmc_attrs = NULL;
4396529c13dSOlof Johansson 	}
440d3d2176aSDavid Gibson 
4416529c13dSOlof Johansson 	for (i = 0; i < nattrs; i++)
4426529c13dSOlof Johansson 		sysdev_remove_file(s, &attrs[i]);
4436529c13dSOlof Johansson 
4446529c13dSOlof Johansson 	if (pmc_attrs)
4456529c13dSOlof Johansson 		for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
4466529c13dSOlof Johansson 			sysdev_remove_file(s, &pmc_attrs[i]);
447d3d2176aSDavid Gibson 
448b950bdd0SBenjamin Herrenschmidt #ifdef CONFIG_PPC64
449d3d2176aSDavid Gibson 	if (cpu_has_feature(CPU_FTR_MMCRA))
450d3d2176aSDavid Gibson 		sysdev_remove_file(s, &attr_mmcra);
451d3d2176aSDavid Gibson 
452afd05423SMichael Neuling 	if (cpu_has_feature(CPU_FTR_PURR))
453d3d2176aSDavid Gibson 		sysdev_remove_file(s, &attr_purr);
4544c198557SAnton Blanchard 
455f050982aSAnton Blanchard 	if (cpu_has_feature(CPU_FTR_SPURR))
456f050982aSAnton Blanchard 		sysdev_remove_file(s, &attr_spurr);
457f050982aSAnton Blanchard 
4584c198557SAnton Blanchard 	if (cpu_has_feature(CPU_FTR_DSCR))
4594c198557SAnton Blanchard 		sysdev_remove_file(s, &attr_dscr);
460b950bdd0SBenjamin Herrenschmidt #endif /* CONFIG_PPC64 */
461124c27d3SNathan Lynch 
46293197a36SNathan Lynch 	cacheinfo_cpu_offline(cpu);
463d3d2176aSDavid Gibson }
464*12633e80SNathan Fontenot 
465*12633e80SNathan Fontenot #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
466*12633e80SNathan Fontenot ssize_t arch_cpu_probe(const char *buf, size_t count)
467*12633e80SNathan Fontenot {
468*12633e80SNathan Fontenot 	if (ppc_md.cpu_probe)
469*12633e80SNathan Fontenot 		return ppc_md.cpu_probe(buf, count);
470*12633e80SNathan Fontenot 
471*12633e80SNathan Fontenot 	return -EINVAL;
472*12633e80SNathan Fontenot }
473*12633e80SNathan Fontenot 
474*12633e80SNathan Fontenot ssize_t arch_cpu_release(const char *buf, size_t count)
475*12633e80SNathan Fontenot {
476*12633e80SNathan Fontenot 	if (ppc_md.cpu_release)
477*12633e80SNathan Fontenot 		return ppc_md.cpu_release(buf, count);
478*12633e80SNathan Fontenot 
479*12633e80SNathan Fontenot 	return -EINVAL;
480*12633e80SNathan Fontenot }
481*12633e80SNathan Fontenot #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
482*12633e80SNathan Fontenot 
483d3d2176aSDavid Gibson #endif /* CONFIG_HOTPLUG_CPU */
484d3d2176aSDavid Gibson 
4858c78f307SChandra Seetharaman static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
486d3d2176aSDavid Gibson 				      unsigned long action, void *hcpu)
487d3d2176aSDavid Gibson {
488d3d2176aSDavid Gibson 	unsigned int cpu = (unsigned int)(long)hcpu;
489d3d2176aSDavid Gibson 
490d3d2176aSDavid Gibson 	switch (action) {
491d3d2176aSDavid Gibson 	case CPU_ONLINE:
4928bb78442SRafael J. Wysocki 	case CPU_ONLINE_FROZEN:
493d3d2176aSDavid Gibson 		register_cpu_online(cpu);
494d3d2176aSDavid Gibson 		break;
495d3d2176aSDavid Gibson #ifdef CONFIG_HOTPLUG_CPU
496d3d2176aSDavid Gibson 	case CPU_DEAD:
4978bb78442SRafael J. Wysocki 	case CPU_DEAD_FROZEN:
498d3d2176aSDavid Gibson 		unregister_cpu_online(cpu);
499d3d2176aSDavid Gibson 		break;
500d3d2176aSDavid Gibson #endif
501d3d2176aSDavid Gibson 	}
502d3d2176aSDavid Gibson 	return NOTIFY_OK;
503d3d2176aSDavid Gibson }
504d3d2176aSDavid Gibson 
5058c78f307SChandra Seetharaman static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
506d3d2176aSDavid Gibson 	.notifier_call	= sysfs_cpu_notify,
507d3d2176aSDavid Gibson };
508d3d2176aSDavid Gibson 
5090344c6c5SChristian Krafft static DEFINE_MUTEX(cpu_mutex);
5100344c6c5SChristian Krafft 
5110344c6c5SChristian Krafft int cpu_add_sysdev_attr(struct sysdev_attribute *attr)
5120344c6c5SChristian Krafft {
5130344c6c5SChristian Krafft 	int cpu;
5140344c6c5SChristian Krafft 
5150344c6c5SChristian Krafft 	mutex_lock(&cpu_mutex);
5160344c6c5SChristian Krafft 
5170344c6c5SChristian Krafft 	for_each_possible_cpu(cpu) {
5180344c6c5SChristian Krafft 		sysdev_create_file(get_cpu_sysdev(cpu), attr);
5190344c6c5SChristian Krafft 	}
5200344c6c5SChristian Krafft 
5210344c6c5SChristian Krafft 	mutex_unlock(&cpu_mutex);
5220344c6c5SChristian Krafft 	return 0;
5230344c6c5SChristian Krafft }
5240344c6c5SChristian Krafft EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr);
5250344c6c5SChristian Krafft 
5260344c6c5SChristian Krafft int cpu_add_sysdev_attr_group(struct attribute_group *attrs)
5270344c6c5SChristian Krafft {
5280344c6c5SChristian Krafft 	int cpu;
5290344c6c5SChristian Krafft 	struct sys_device *sysdev;
5306bcc4c01SOlof Johansson 	int ret;
5310344c6c5SChristian Krafft 
5320344c6c5SChristian Krafft 	mutex_lock(&cpu_mutex);
5330344c6c5SChristian Krafft 
5340344c6c5SChristian Krafft 	for_each_possible_cpu(cpu) {
5350344c6c5SChristian Krafft 		sysdev = get_cpu_sysdev(cpu);
5366bcc4c01SOlof Johansson 		ret = sysfs_create_group(&sysdev->kobj, attrs);
5376bcc4c01SOlof Johansson 		WARN_ON(ret != 0);
5380344c6c5SChristian Krafft 	}
5390344c6c5SChristian Krafft 
5400344c6c5SChristian Krafft 	mutex_unlock(&cpu_mutex);
5410344c6c5SChristian Krafft 	return 0;
5420344c6c5SChristian Krafft }
5430344c6c5SChristian Krafft EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group);
5440344c6c5SChristian Krafft 
5450344c6c5SChristian Krafft 
5460344c6c5SChristian Krafft void cpu_remove_sysdev_attr(struct sysdev_attribute *attr)
5470344c6c5SChristian Krafft {
5480344c6c5SChristian Krafft 	int cpu;
5490344c6c5SChristian Krafft 
5500344c6c5SChristian Krafft 	mutex_lock(&cpu_mutex);
5510344c6c5SChristian Krafft 
5520344c6c5SChristian Krafft 	for_each_possible_cpu(cpu) {
5530344c6c5SChristian Krafft 		sysdev_remove_file(get_cpu_sysdev(cpu), attr);
5540344c6c5SChristian Krafft 	}
5550344c6c5SChristian Krafft 
5560344c6c5SChristian Krafft 	mutex_unlock(&cpu_mutex);
5570344c6c5SChristian Krafft }
5580344c6c5SChristian Krafft EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr);
5590344c6c5SChristian Krafft 
5600344c6c5SChristian Krafft void cpu_remove_sysdev_attr_group(struct attribute_group *attrs)
5610344c6c5SChristian Krafft {
5620344c6c5SChristian Krafft 	int cpu;
5630344c6c5SChristian Krafft 	struct sys_device *sysdev;
5640344c6c5SChristian Krafft 
5650344c6c5SChristian Krafft 	mutex_lock(&cpu_mutex);
5660344c6c5SChristian Krafft 
5670344c6c5SChristian Krafft 	for_each_possible_cpu(cpu) {
5680344c6c5SChristian Krafft 		sysdev = get_cpu_sysdev(cpu);
5690344c6c5SChristian Krafft 		sysfs_remove_group(&sysdev->kobj, attrs);
5700344c6c5SChristian Krafft 	}
5710344c6c5SChristian Krafft 
5720344c6c5SChristian Krafft 	mutex_unlock(&cpu_mutex);
5730344c6c5SChristian Krafft }
5740344c6c5SChristian Krafft EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group);
5750344c6c5SChristian Krafft 
5760344c6c5SChristian Krafft 
577d3d2176aSDavid Gibson /* NUMA stuff */
578d3d2176aSDavid Gibson 
579d3d2176aSDavid Gibson #ifdef CONFIG_NUMA
580d3d2176aSDavid Gibson static void register_nodes(void)
581d3d2176aSDavid Gibson {
582d3d2176aSDavid Gibson 	int i;
583d3d2176aSDavid Gibson 
5840fc44159SYasunori Goto 	for (i = 0; i < MAX_NUMNODES; i++)
5850fc44159SYasunori Goto 		register_one_node(i);
586d3d2176aSDavid Gibson }
587953039c8SJeremy Kerr 
588953039c8SJeremy Kerr int sysfs_add_device_to_node(struct sys_device *dev, int nid)
589953039c8SJeremy Kerr {
590953039c8SJeremy Kerr 	struct node *node = &node_devices[nid];
591953039c8SJeremy Kerr 	return sysfs_create_link(&node->sysdev.kobj, &dev->kobj,
592953039c8SJeremy Kerr 			kobject_name(&dev->kobj));
593953039c8SJeremy Kerr }
59412654f77SJohannes Berg EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
595953039c8SJeremy Kerr 
596953039c8SJeremy Kerr void sysfs_remove_device_from_node(struct sys_device *dev, int nid)
597953039c8SJeremy Kerr {
598953039c8SJeremy Kerr 	struct node *node = &node_devices[nid];
599953039c8SJeremy Kerr 	sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj));
600953039c8SJeremy Kerr }
60112654f77SJohannes Berg EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
602953039c8SJeremy Kerr 
603d3d2176aSDavid Gibson #else
604d3d2176aSDavid Gibson static void register_nodes(void)
605d3d2176aSDavid Gibson {
606d3d2176aSDavid Gibson 	return;
607d3d2176aSDavid Gibson }
608953039c8SJeremy Kerr 
609d3d2176aSDavid Gibson #endif
610d3d2176aSDavid Gibson 
611d3d2176aSDavid Gibson /* Only valid if CPU is present. */
61200bf6e90SStephen Rothwell static ssize_t show_physical_id(struct sys_device *dev,
61300bf6e90SStephen Rothwell 				struct sysdev_attribute *attr, char *buf)
614d3d2176aSDavid Gibson {
615d3d2176aSDavid Gibson 	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
616d3d2176aSDavid Gibson 
617d3d2176aSDavid Gibson 	return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id));
618d3d2176aSDavid Gibson }
619d3d2176aSDavid Gibson static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL);
620d3d2176aSDavid Gibson 
621d3d2176aSDavid Gibson static int __init topology_init(void)
622d3d2176aSDavid Gibson {
623d3d2176aSDavid Gibson 	int cpu;
624d3d2176aSDavid Gibson 
625d3d2176aSDavid Gibson 	register_nodes();
626d3d2176aSDavid Gibson 	register_cpu_notifier(&sysfs_cpu_nb);
627d3d2176aSDavid Gibson 
6280e551954SKAMEZAWA Hiroyuki 	for_each_possible_cpu(cpu) {
629d3d2176aSDavid Gibson 		struct cpu *c = &per_cpu(cpu_devices, cpu);
630d3d2176aSDavid Gibson 
631d3d2176aSDavid Gibson 		/*
632d3d2176aSDavid Gibson 		 * For now, we just see if the system supports making
633d3d2176aSDavid Gibson 		 * the RTAS calls for CPU hotplug.  But, there may be a
634d3d2176aSDavid Gibson 		 * more comprehensive way to do this for an individual
635d3d2176aSDavid Gibson 		 * CPU.  For instance, the boot cpu might never be valid
636d3d2176aSDavid Gibson 		 * for hotplugging.
637d3d2176aSDavid Gibson 		 */
63872486f1fSSiddha, Suresh B 		if (ppc_md.cpu_die)
63972486f1fSSiddha, Suresh B 			c->hotpluggable = 1;
640d3d2176aSDavid Gibson 
64172486f1fSSiddha, Suresh B 		if (cpu_online(cpu) || c->hotpluggable) {
64276b67ed9SKAMEZAWA Hiroyuki 			register_cpu(c, cpu);
643d3d2176aSDavid Gibson 
644d3d2176aSDavid Gibson 			sysdev_create_file(&c->sysdev, &attr_physical_id);
645d3d2176aSDavid Gibson 		}
646d3d2176aSDavid Gibson 
647d3d2176aSDavid Gibson 		if (cpu_online(cpu))
648d3d2176aSDavid Gibson 			register_cpu_online(cpu);
649d3d2176aSDavid Gibson 	}
650d3d2176aSDavid Gibson 
651d3d2176aSDavid Gibson 	return 0;
652d3d2176aSDavid Gibson }
653e9e77ce8SKevin Corry subsys_initcall(topology_init);
654