]>
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 | 18 | #include <asm/machdep.h> |
2249ca9d | 19 | #include <asm/smp.h> |
1da177e4 | 20 | |
93197a36 NL |
21 | #include "cacheinfo.h" |
22 | ||
b950bdd0 BH |
23 | #ifdef CONFIG_PPC64 |
24 | #include <asm/paca.h> | |
25 | #include <asm/lppaca.h> | |
26 | #endif | |
27 | ||
1da177e4 LT |
28 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
29 | ||
b950bdd0 BH |
30 | /* |
31 | * SMT snooze delay stuff, 64-bit only for now | |
32 | */ | |
33 | ||
34 | #ifdef CONFIG_PPC64 | |
1da177e4 | 35 | |
0ddd3e7d AB |
36 | /* Time in microseconds we delay before sleeping in the idle loop */ |
37 | DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 }; | |
1da177e4 | 38 | |
4a0b2b4d AK |
39 | static ssize_t store_smt_snooze_delay(struct sys_device *dev, |
40 | struct sysdev_attribute *attr, | |
41 | const char *buf, | |
1da177e4 LT |
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 | ||
4a0b2b4d AK |
57 | static ssize_t show_smt_snooze_delay(struct sys_device *dev, |
58 | struct sysdev_attribute *attr, | |
59 | char *buf) | |
1da177e4 LT |
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; | |
a7f67bdf | 75 | const unsigned int *val; |
1da177e4 LT |
76 | unsigned int cpu; |
77 | ||
78 | if (!cpu_has_feature(CPU_FTR_SMT)) | |
69ed3324 | 79 | return -ENODEV; |
1da177e4 | 80 | |
8c8dc322 | 81 | options = of_find_node_by_path("/options"); |
1da177e4 | 82 | if (!options) |
69ed3324 | 83 | return -ENODEV; |
1da177e4 | 84 | |
e2eb6392 | 85 | val = of_get_property(options, "ibm,smt-snooze-delay", NULL); |
1da177e4 | 86 | if (!smt_snooze_cmdline && val) { |
0e551954 | 87 | for_each_possible_cpu(cpu) |
1da177e4 LT |
88 | per_cpu(smt_snooze_delay, cpu) = *val; |
89 | } | |
90 | ||
8c8dc322 | 91 | of_node_put(options); |
69ed3324 | 92 | return 0; |
1da177e4 LT |
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)) { | |
0e551954 | 107 | for_each_possible_cpu(cpu) |
1da177e4 LT |
108 | per_cpu(smt_snooze_delay, cpu) = snooze; |
109 | } | |
110 | ||
111 | return 1; | |
112 | } | |
113 | __setup("smt-snooze-delay=", setup_smt_snooze_delay); | |
114 | ||
b950bdd0 | 115 | #endif /* CONFIG_PPC64 */ |
180a3362 | 116 | |
1da177e4 LT |
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 | ||
b950bdd0 | 124 | void ppc_enable_pmcs(void) |
1da177e4 | 125 | { |
1da177e4 LT |
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 | ||
180a3362 ME |
132 | if (ppc_md.enable_pmcs) |
133 | ppc_md.enable_pmcs(); | |
1da177e4 | 134 | } |
b950bdd0 | 135 | EXPORT_SYMBOL(ppc_enable_pmcs); |
1da177e4 | 136 | |
1da177e4 LT |
137 | |
138 | #define SYSFS_PMCSETUP(NAME, ADDRESS) \ | |
9a371934 | 139 | static void read_##NAME(void *val) \ |
1da177e4 | 140 | { \ |
9a371934 | 141 | mtspr(ADDRESS, *(unsigned long *)val); \ |
1da177e4 LT |
142 | } \ |
143 | static unsigned long write_##NAME(unsigned long val) \ | |
144 | { \ | |
b950bdd0 | 145 | ppc_enable_pmcs(); \ |
9a371934 | 146 | mtspr(ADDRESS, *(unsigned long *)val); \ |
1da177e4 LT |
147 | return 0; \ |
148 | } \ | |
4a0b2b4d AK |
149 | static ssize_t show_##NAME(struct sys_device *dev, \ |
150 | struct sysdev_attribute *attr, \ | |
151 | char *buf) \ | |
1da177e4 LT |
152 | { \ |
153 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); \ | |
9a371934 RR |
154 | unsigned long val; \ |
155 | smp_call_function_single(cpu->sysdev.id, read_##NAME, &val, 1); \ | |
1da177e4 LT |
156 | return sprintf(buf, "%lx\n", val); \ |
157 | } \ | |
3ff6eecc | 158 | static ssize_t __used \ |
4a0b2b4d AK |
159 | store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \ |
160 | const char *buf, size_t count) \ | |
1da177e4 LT |
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; \ | |
9a371934 | 167 | smp_call_function_single(cpu->sysdev.id, write_##NAME, &val, 1); \ |
1da177e4 LT |
168 | return count; \ |
169 | } | |
170 | ||
6529c13d OJ |
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 | ||
33a7f122 | 176 | #if defined(CONFIG_PPC64) |
b950bdd0 BH |
177 | #define HAS_PPC_PMC_CLASSIC 1 |
178 | #define HAS_PPC_PMC_IBM 1 | |
179 | #define HAS_PPC_PMC_PA6T 1 | |
33a7f122 | 180 | #elif defined(CONFIG_6xx) |
b950bdd0 BH |
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 | |
1da177e4 LT |
188 | SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); |
189 | SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); | |
1da177e4 LT |
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); | |
b950bdd0 BH |
196 | |
197 | #ifdef HAS_PPC_PMC_G4 | |
198 | SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2); | |
199 | #endif | |
200 | ||
201 | #ifdef CONFIG_PPC64 | |
1da177e4 LT |
202 | SYSFS_PMCSETUP(pmc7, SPRN_PMC7); |
203 | SYSFS_PMCSETUP(pmc8, SPRN_PMC8); | |
b950bdd0 BH |
204 | |
205 | SYSFS_PMCSETUP(mmcra, SPRN_MMCRA); | |
1da177e4 | 206 | SYSFS_PMCSETUP(purr, SPRN_PURR); |
f050982a | 207 | SYSFS_PMCSETUP(spurr, SPRN_SPURR); |
4c198557 | 208 | SYSFS_PMCSETUP(dscr, SPRN_DSCR); |
1da177e4 | 209 | |
b950bdd0 BH |
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 | |
25fc530e OJ |
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); | |
2e1957fd OJ |
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 */ | |
b950bdd0 | 253 | #endif /* HAS_PPC_PMC_PA6T */ |
6529c13d | 254 | |
b950bdd0 | 255 | #ifdef HAS_PPC_PMC_IBM |
6529c13d OJ |
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 | }; | |
b950bdd0 BH |
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 */ | |
6529c13d | 269 | |
b950bdd0 | 270 | static struct sysdev_attribute classic_pmc_attrs[] = { |
6529c13d OJ |
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), | |
b950bdd0 | 277 | #ifdef CONFIG_PPC64 |
6529c13d OJ |
278 | _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7), |
279 | _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8), | |
b950bdd0 | 280 | #endif |
6529c13d OJ |
281 | }; |
282 | ||
b950bdd0 | 283 | #ifdef HAS_PPC_PMC_PA6T |
6529c13d OJ |
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), | |
2e1957fd OJ |
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 */ | |
6529c13d | 323 | }; |
b950bdd0 BH |
324 | #endif /* HAS_PPC_PMC_PA6T */ |
325 | #endif /* HAS_PPC_PMC_CLASSIC */ | |
6529c13d | 326 | |
9ba1984e | 327 | static void __cpuinit register_cpu_online(unsigned int cpu) |
1da177e4 LT |
328 | { |
329 | struct cpu *c = &per_cpu(cpu_devices, cpu); | |
330 | struct sys_device *s = &c->sysdev; | |
6529c13d OJ |
331 | struct sysdev_attribute *attrs, *pmc_attrs; |
332 | int i, nattrs; | |
1da177e4 | 333 | |
b950bdd0 | 334 | #ifdef CONFIG_PPC64 |
ad5cb17f SR |
335 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
336 | cpu_has_feature(CPU_FTR_SMT)) | |
1da177e4 | 337 | sysdev_create_file(s, &attr_smt_snooze_delay); |
b950bdd0 | 338 | #endif |
1da177e4 LT |
339 | |
340 | /* PMC stuff */ | |
6529c13d | 341 | switch (cur_cpu_spec->pmc_type) { |
b950bdd0 | 342 | #ifdef HAS_PPC_PMC_IBM |
6529c13d OJ |
343 | case PPC_PMC_IBM: |
344 | attrs = ibm_common_attrs; | |
345 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); | |
b950bdd0 | 346 | pmc_attrs = classic_pmc_attrs; |
6529c13d | 347 | break; |
b950bdd0 BH |
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 | |
6529c13d OJ |
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; | |
b950bdd0 | 363 | #endif /* HAS_PPC_PMC_PA6T */ |
6529c13d OJ |
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]); | |
1da177e4 | 372 | |
6529c13d OJ |
373 | if (pmc_attrs) |
374 | for (i = 0; i < cur_cpu_spec->num_pmcs; i++) | |
375 | sysdev_create_file(s, &pmc_attrs[i]); | |
1da177e4 | 376 | |
b950bdd0 | 377 | #ifdef CONFIG_PPC64 |
1da177e4 LT |
378 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
379 | sysdev_create_file(s, &attr_mmcra); | |
380 | ||
afd05423 | 381 | if (cpu_has_feature(CPU_FTR_PURR)) |
1da177e4 | 382 | sysdev_create_file(s, &attr_purr); |
4c198557 | 383 | |
f050982a AB |
384 | if (cpu_has_feature(CPU_FTR_SPURR)) |
385 | sysdev_create_file(s, &attr_spurr); | |
386 | ||
4c198557 AB |
387 | if (cpu_has_feature(CPU_FTR_DSCR)) |
388 | sysdev_create_file(s, &attr_dscr); | |
b950bdd0 | 389 | #endif /* CONFIG_PPC64 */ |
124c27d3 | 390 | |
93197a36 | 391 | cacheinfo_cpu_online(cpu); |
1da177e4 LT |
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; | |
6529c13d OJ |
399 | struct sysdev_attribute *attrs, *pmc_attrs; |
400 | int i, nattrs; | |
1da177e4 | 401 | |
72486f1f | 402 | BUG_ON(!c->hotpluggable); |
1da177e4 | 403 | |
a1e0eb10 | 404 | #ifdef CONFIG_PPC64 |
ad5cb17f SR |
405 | if (!firmware_has_feature(FW_FEATURE_ISERIES) && |
406 | cpu_has_feature(CPU_FTR_SMT)) | |
1da177e4 | 407 | sysdev_remove_file(s, &attr_smt_snooze_delay); |
a1e0eb10 | 408 | #endif |
1da177e4 LT |
409 | |
410 | /* PMC stuff */ | |
6529c13d | 411 | switch (cur_cpu_spec->pmc_type) { |
b950bdd0 | 412 | #ifdef HAS_PPC_PMC_IBM |
6529c13d OJ |
413 | case PPC_PMC_IBM: |
414 | attrs = ibm_common_attrs; | |
415 | nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); | |
b950bdd0 BH |
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; | |
6529c13d | 424 | break; |
b950bdd0 BH |
425 | #endif /* HAS_PPC_PMC_G4 */ |
426 | #ifdef HAS_PPC_PMC_PA6T | |
6529c13d OJ |
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; | |
b950bdd0 | 433 | #endif /* HAS_PPC_PMC_PA6T */ |
6529c13d OJ |
434 | default: |
435 | attrs = NULL; | |
436 | nattrs = 0; | |
437 | pmc_attrs = NULL; | |
438 | } | |
1da177e4 | 439 | |
6529c13d OJ |
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]); | |
1da177e4 | 446 | |
b950bdd0 | 447 | #ifdef CONFIG_PPC64 |
1da177e4 LT |
448 | if (cpu_has_feature(CPU_FTR_MMCRA)) |
449 | sysdev_remove_file(s, &attr_mmcra); | |
450 | ||
afd05423 | 451 | if (cpu_has_feature(CPU_FTR_PURR)) |
1da177e4 | 452 | sysdev_remove_file(s, &attr_purr); |
4c198557 | 453 | |
f050982a AB |
454 | if (cpu_has_feature(CPU_FTR_SPURR)) |
455 | sysdev_remove_file(s, &attr_spurr); | |
456 | ||
4c198557 AB |
457 | if (cpu_has_feature(CPU_FTR_DSCR)) |
458 | sysdev_remove_file(s, &attr_dscr); | |
b950bdd0 | 459 | #endif /* CONFIG_PPC64 */ |
124c27d3 | 460 | |
93197a36 | 461 | cacheinfo_cpu_offline(cpu); |
1da177e4 LT |
462 | } |
463 | #endif /* CONFIG_HOTPLUG_CPU */ | |
464 | ||
8c78f307 | 465 | static int __cpuinit sysfs_cpu_notify(struct notifier_block *self, |
1da177e4 LT |
466 | unsigned long action, void *hcpu) |
467 | { | |
468 | unsigned int cpu = (unsigned int)(long)hcpu; | |
469 | ||
470 | switch (action) { | |
471 | case CPU_ONLINE: | |
8bb78442 | 472 | case CPU_ONLINE_FROZEN: |
1da177e4 LT |
473 | register_cpu_online(cpu); |
474 | break; | |
475 | #ifdef CONFIG_HOTPLUG_CPU | |
476 | case CPU_DEAD: | |
8bb78442 | 477 | case CPU_DEAD_FROZEN: |
1da177e4 LT |
478 | unregister_cpu_online(cpu); |
479 | break; | |
480 | #endif | |
481 | } | |
482 | return NOTIFY_OK; | |
483 | } | |
484 | ||
8c78f307 | 485 | static struct notifier_block __cpuinitdata sysfs_cpu_nb = { |
1da177e4 LT |
486 | .notifier_call = sysfs_cpu_notify, |
487 | }; | |
488 | ||
0344c6c5 CK |
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; | |
6bcc4c01 | 510 | int ret; |
0344c6c5 CK |
511 | |
512 | mutex_lock(&cpu_mutex); | |
513 | ||
514 | for_each_possible_cpu(cpu) { | |
515 | sysdev = get_cpu_sysdev(cpu); | |
6bcc4c01 OJ |
516 | ret = sysfs_create_group(&sysdev->kobj, attrs); |
517 | WARN_ON(ret != 0); | |
0344c6c5 CK |
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 | ||
1da177e4 LT |
557 | /* NUMA stuff */ |
558 | ||
559 | #ifdef CONFIG_NUMA | |
1da177e4 LT |
560 | static void register_nodes(void) |
561 | { | |
562 | int i; | |
563 | ||
0fc44159 YG |
564 | for (i = 0; i < MAX_NUMNODES; i++) |
565 | register_one_node(i); | |
1da177e4 | 566 | } |
953039c8 JK |
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 | } | |
12654f77 | 574 | EXPORT_SYMBOL_GPL(sysfs_add_device_to_node); |
953039c8 JK |
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 | } | |
12654f77 | 581 | EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); |
953039c8 | 582 | |
1da177e4 LT |
583 | #else |
584 | static void register_nodes(void) | |
585 | { | |
586 | return; | |
587 | } | |
953039c8 | 588 | |
1da177e4 LT |
589 | #endif |
590 | ||
591 | /* Only valid if CPU is present. */ | |
00bf6e90 SR |
592 | static ssize_t show_physical_id(struct sys_device *dev, |
593 | struct sysdev_attribute *attr, char *buf) | |
1da177e4 LT |
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; | |
1da177e4 LT |
604 | |
605 | register_nodes(); | |
1da177e4 LT |
606 | register_cpu_notifier(&sysfs_cpu_nb); |
607 | ||
0e551954 | 608 | for_each_possible_cpu(cpu) { |
1da177e4 LT |
609 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
610 | ||
1da177e4 LT |
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 | */ | |
72486f1f SS |
618 | if (ppc_md.cpu_die) |
619 | c->hotpluggable = 1; | |
1da177e4 | 620 | |
72486f1f | 621 | if (cpu_online(cpu) || c->hotpluggable) { |
76b67ed9 | 622 | register_cpu(c, cpu); |
1da177e4 LT |
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 | } | |
e9e77ce8 | 633 | subsys_initcall(topology_init); |