1 #include <linux/sysdev.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>
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>
19 #include <asm/lppaca.h>
20 #include <asm/machdep.h>
23 static DEFINE_PER_CPU(struct cpu
, cpu_devices
);
25 static DEFINE_PER_CPU(struct kobject
*, cache_toplevel
);
29 #ifdef CONFIG_PPC_MULTIPLATFORM
30 /* Time in microseconds we delay before sleeping in the idle loop */
31 DEFINE_PER_CPU(unsigned long, smt_snooze_delay
) = { 100 };
33 static ssize_t
store_smt_snooze_delay(struct sys_device
*dev
,
34 struct sysdev_attribute
*attr
,
38 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
42 ret
= sscanf(buf
, "%lu", &snooze
);
46 per_cpu(smt_snooze_delay
, cpu
->sysdev
.id
) = snooze
;
51 static ssize_t
show_smt_snooze_delay(struct sys_device
*dev
,
52 struct sysdev_attribute
*attr
,
55 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
57 return sprintf(buf
, "%lu\n", per_cpu(smt_snooze_delay
, cpu
->sysdev
.id
));
60 static SYSDEV_ATTR(smt_snooze_delay
, 0644, show_smt_snooze_delay
,
61 store_smt_snooze_delay
);
63 /* Only parse OF options if the matching cmdline option was not specified */
64 static int smt_snooze_cmdline
;
66 static int __init
smt_setup(void)
68 struct device_node
*options
;
69 const unsigned int *val
;
72 if (!cpu_has_feature(CPU_FTR_SMT
))
75 options
= of_find_node_by_path("/options");
79 val
= of_get_property(options
, "ibm,smt-snooze-delay", NULL
);
80 if (!smt_snooze_cmdline
&& val
) {
81 for_each_possible_cpu(cpu
)
82 per_cpu(smt_snooze_delay
, cpu
) = *val
;
88 __initcall(smt_setup
);
90 static int __init
setup_smt_snooze_delay(char *str
)
95 if (!cpu_has_feature(CPU_FTR_SMT
))
98 smt_snooze_cmdline
= 1;
100 if (get_option(&str
, &snooze
)) {
101 for_each_possible_cpu(cpu
)
102 per_cpu(smt_snooze_delay
, cpu
) = snooze
;
107 __setup("smt-snooze-delay=", setup_smt_snooze_delay
);
109 #endif /* CONFIG_PPC_MULTIPLATFORM */
112 * Enabling PMCs will slow partition context switch times so we only do
113 * it the first time we write to the PMCs.
116 static DEFINE_PER_CPU(char, pmcs_enabled
);
118 void ppc64_enable_pmcs(void)
120 /* Only need to enable them once */
121 if (__get_cpu_var(pmcs_enabled
))
124 __get_cpu_var(pmcs_enabled
) = 1;
126 if (ppc_md
.enable_pmcs
)
127 ppc_md
.enable_pmcs();
129 EXPORT_SYMBOL(ppc64_enable_pmcs
);
131 /* XXX convert to rusty's on_one_cpu */
132 static unsigned long run_on_cpu(unsigned long cpu
,
133 unsigned long (*func
)(unsigned long),
136 cpumask_t old_affinity
= current
->cpus_allowed
;
139 /* should return -EINVAL to userspace */
140 if (set_cpus_allowed(current
, cpumask_of_cpu(cpu
)))
145 set_cpus_allowed(current
, old_affinity
);
150 #define SYSFS_PMCSETUP(NAME, ADDRESS) \
151 static unsigned long read_##NAME(unsigned long junk) \
153 return mfspr(ADDRESS); \
155 static unsigned long write_##NAME(unsigned long val) \
157 ppc64_enable_pmcs(); \
158 mtspr(ADDRESS, val); \
161 static ssize_t show_##NAME(struct sys_device *dev, \
162 struct sysdev_attribute *attr, \
165 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
166 unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
167 return sprintf(buf, "%lx\n", val); \
169 static ssize_t __used \
170 store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \
171 const char *buf, size_t count) \
173 struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
175 int ret = sscanf(buf, "%lx", &val); \
178 run_on_cpu(cpu->sysdev.id, write_##NAME, val); \
183 /* Let's define all possible registers, we'll only hook up the ones
184 * that are implemented on the current processor
187 SYSFS_PMCSETUP(mmcr0
, SPRN_MMCR0
);
188 SYSFS_PMCSETUP(mmcr1
, SPRN_MMCR1
);
189 SYSFS_PMCSETUP(mmcra
, SPRN_MMCRA
);
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 SYSFS_PMCSETUP(pmc7
, SPRN_PMC7
);
197 SYSFS_PMCSETUP(pmc8
, SPRN_PMC8
);
198 SYSFS_PMCSETUP(purr
, SPRN_PURR
);
199 SYSFS_PMCSETUP(spurr
, SPRN_SPURR
);
200 SYSFS_PMCSETUP(dscr
, SPRN_DSCR
);
202 SYSFS_PMCSETUP(pa6t_pmc0
, SPRN_PA6T_PMC0
);
203 SYSFS_PMCSETUP(pa6t_pmc1
, SPRN_PA6T_PMC1
);
204 SYSFS_PMCSETUP(pa6t_pmc2
, SPRN_PA6T_PMC2
);
205 SYSFS_PMCSETUP(pa6t_pmc3
, SPRN_PA6T_PMC3
);
206 SYSFS_PMCSETUP(pa6t_pmc4
, SPRN_PA6T_PMC4
);
207 SYSFS_PMCSETUP(pa6t_pmc5
, SPRN_PA6T_PMC5
);
209 #ifdef CONFIG_DEBUG_KERNEL
210 SYSFS_PMCSETUP(hid0
, SPRN_HID0
);
211 SYSFS_PMCSETUP(hid1
, SPRN_HID1
);
212 SYSFS_PMCSETUP(hid4
, SPRN_HID4
);
213 SYSFS_PMCSETUP(hid5
, SPRN_HID5
);
214 SYSFS_PMCSETUP(ima0
, SPRN_PA6T_IMA0
);
215 SYSFS_PMCSETUP(ima1
, SPRN_PA6T_IMA1
);
216 SYSFS_PMCSETUP(ima2
, SPRN_PA6T_IMA2
);
217 SYSFS_PMCSETUP(ima3
, SPRN_PA6T_IMA3
);
218 SYSFS_PMCSETUP(ima4
, SPRN_PA6T_IMA4
);
219 SYSFS_PMCSETUP(ima5
, SPRN_PA6T_IMA5
);
220 SYSFS_PMCSETUP(ima6
, SPRN_PA6T_IMA6
);
221 SYSFS_PMCSETUP(ima7
, SPRN_PA6T_IMA7
);
222 SYSFS_PMCSETUP(ima8
, SPRN_PA6T_IMA8
);
223 SYSFS_PMCSETUP(ima9
, SPRN_PA6T_IMA9
);
224 SYSFS_PMCSETUP(imaat
, SPRN_PA6T_IMAAT
);
225 SYSFS_PMCSETUP(btcr
, SPRN_PA6T_BTCR
);
226 SYSFS_PMCSETUP(pccr
, SPRN_PA6T_PCCR
);
227 SYSFS_PMCSETUP(rpccr
, SPRN_PA6T_RPCCR
);
228 SYSFS_PMCSETUP(der
, SPRN_PA6T_DER
);
229 SYSFS_PMCSETUP(mer
, SPRN_PA6T_MER
);
230 SYSFS_PMCSETUP(ber
, SPRN_PA6T_BER
);
231 SYSFS_PMCSETUP(ier
, SPRN_PA6T_IER
);
232 SYSFS_PMCSETUP(sier
, SPRN_PA6T_SIER
);
233 SYSFS_PMCSETUP(siar
, SPRN_PA6T_SIAR
);
234 SYSFS_PMCSETUP(tsr0
, SPRN_PA6T_TSR0
);
235 SYSFS_PMCSETUP(tsr1
, SPRN_PA6T_TSR1
);
236 SYSFS_PMCSETUP(tsr2
, SPRN_PA6T_TSR2
);
237 SYSFS_PMCSETUP(tsr3
, SPRN_PA6T_TSR3
);
238 #endif /* CONFIG_DEBUG_KERNEL */
240 static SYSDEV_ATTR(mmcra
, 0600, show_mmcra
, store_mmcra
);
241 static SYSDEV_ATTR(spurr
, 0600, show_spurr
, NULL
);
242 static SYSDEV_ATTR(dscr
, 0600, show_dscr
, store_dscr
);
243 static SYSDEV_ATTR(purr
, 0600, show_purr
, store_purr
);
245 static struct sysdev_attribute ibm_common_attrs
[] = {
246 _SYSDEV_ATTR(mmcr0
, 0600, show_mmcr0
, store_mmcr0
),
247 _SYSDEV_ATTR(mmcr1
, 0600, show_mmcr1
, store_mmcr1
),
250 static struct sysdev_attribute ibm_pmc_attrs
[] = {
251 _SYSDEV_ATTR(pmc1
, 0600, show_pmc1
, store_pmc1
),
252 _SYSDEV_ATTR(pmc2
, 0600, show_pmc2
, store_pmc2
),
253 _SYSDEV_ATTR(pmc3
, 0600, show_pmc3
, store_pmc3
),
254 _SYSDEV_ATTR(pmc4
, 0600, show_pmc4
, store_pmc4
),
255 _SYSDEV_ATTR(pmc5
, 0600, show_pmc5
, store_pmc5
),
256 _SYSDEV_ATTR(pmc6
, 0600, show_pmc6
, store_pmc6
),
257 _SYSDEV_ATTR(pmc7
, 0600, show_pmc7
, store_pmc7
),
258 _SYSDEV_ATTR(pmc8
, 0600, show_pmc8
, store_pmc8
),
261 static struct sysdev_attribute pa6t_attrs
[] = {
262 _SYSDEV_ATTR(mmcr0
, 0600, show_mmcr0
, store_mmcr0
),
263 _SYSDEV_ATTR(mmcr1
, 0600, show_mmcr1
, store_mmcr1
),
264 _SYSDEV_ATTR(pmc0
, 0600, show_pa6t_pmc0
, store_pa6t_pmc0
),
265 _SYSDEV_ATTR(pmc1
, 0600, show_pa6t_pmc1
, store_pa6t_pmc1
),
266 _SYSDEV_ATTR(pmc2
, 0600, show_pa6t_pmc2
, store_pa6t_pmc2
),
267 _SYSDEV_ATTR(pmc3
, 0600, show_pa6t_pmc3
, store_pa6t_pmc3
),
268 _SYSDEV_ATTR(pmc4
, 0600, show_pa6t_pmc4
, store_pa6t_pmc4
),
269 _SYSDEV_ATTR(pmc5
, 0600, show_pa6t_pmc5
, store_pa6t_pmc5
),
270 #ifdef CONFIG_DEBUG_KERNEL
271 _SYSDEV_ATTR(hid0
, 0600, show_hid0
, store_hid0
),
272 _SYSDEV_ATTR(hid1
, 0600, show_hid1
, store_hid1
),
273 _SYSDEV_ATTR(hid4
, 0600, show_hid4
, store_hid4
),
274 _SYSDEV_ATTR(hid5
, 0600, show_hid5
, store_hid5
),
275 _SYSDEV_ATTR(ima0
, 0600, show_ima0
, store_ima0
),
276 _SYSDEV_ATTR(ima1
, 0600, show_ima1
, store_ima1
),
277 _SYSDEV_ATTR(ima2
, 0600, show_ima2
, store_ima2
),
278 _SYSDEV_ATTR(ima3
, 0600, show_ima3
, store_ima3
),
279 _SYSDEV_ATTR(ima4
, 0600, show_ima4
, store_ima4
),
280 _SYSDEV_ATTR(ima5
, 0600, show_ima5
, store_ima5
),
281 _SYSDEV_ATTR(ima6
, 0600, show_ima6
, store_ima6
),
282 _SYSDEV_ATTR(ima7
, 0600, show_ima7
, store_ima7
),
283 _SYSDEV_ATTR(ima8
, 0600, show_ima8
, store_ima8
),
284 _SYSDEV_ATTR(ima9
, 0600, show_ima9
, store_ima9
),
285 _SYSDEV_ATTR(imaat
, 0600, show_imaat
, store_imaat
),
286 _SYSDEV_ATTR(btcr
, 0600, show_btcr
, store_btcr
),
287 _SYSDEV_ATTR(pccr
, 0600, show_pccr
, store_pccr
),
288 _SYSDEV_ATTR(rpccr
, 0600, show_rpccr
, store_rpccr
),
289 _SYSDEV_ATTR(der
, 0600, show_der
, store_der
),
290 _SYSDEV_ATTR(mer
, 0600, show_mer
, store_mer
),
291 _SYSDEV_ATTR(ber
, 0600, show_ber
, store_ber
),
292 _SYSDEV_ATTR(ier
, 0600, show_ier
, store_ier
),
293 _SYSDEV_ATTR(sier
, 0600, show_sier
, store_sier
),
294 _SYSDEV_ATTR(siar
, 0600, show_siar
, store_siar
),
295 _SYSDEV_ATTR(tsr0
, 0600, show_tsr0
, store_tsr0
),
296 _SYSDEV_ATTR(tsr1
, 0600, show_tsr1
, store_tsr1
),
297 _SYSDEV_ATTR(tsr2
, 0600, show_tsr2
, store_tsr2
),
298 _SYSDEV_ATTR(tsr3
, 0600, show_tsr3
, store_tsr3
),
299 #endif /* CONFIG_DEBUG_KERNEL */
304 struct cache_desc
*next
;
305 const char *type
; /* Instruction, Data, or Unified */
306 u32 size
; /* total cache size in KB */
307 u32 line_size
; /* in bytes */
308 u32 nr_sets
; /* number of sets */
309 u32 level
; /* e.g. 1, 2, 3... */
310 u32 associativity
; /* e.g. 8-way... 0 is fully associative */
313 DEFINE_PER_CPU(struct cache_desc
*, cache_desc
);
315 static struct cache_desc
*kobj_to_cache_desc(struct kobject
*k
)
317 return container_of(k
, struct cache_desc
, kobj
);
320 static void cache_desc_release(struct kobject
*k
)
322 struct cache_desc
*desc
= kobj_to_cache_desc(k
);
324 pr_debug("%s: releasing %s\n", __func__
, kobject_name(k
));
327 kobject_put(&desc
->next
->kobj
);
329 kfree(kobj_to_cache_desc(k
));
332 static ssize_t
cache_desc_show(struct kobject
*k
, struct attribute
*attr
, char *buf
)
334 struct kobj_attribute
*kobj_attr
;
336 kobj_attr
= container_of(attr
, struct kobj_attribute
, attr
);
338 return kobj_attr
->show(k
, kobj_attr
, buf
);
341 static struct sysfs_ops cache_desc_sysfs_ops
= {
342 .show
= cache_desc_show
,
345 static struct kobj_type cache_desc_type
= {
346 .release
= cache_desc_release
,
347 .sysfs_ops
= &cache_desc_sysfs_ops
,
350 static ssize_t
cache_size_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
352 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
354 return sprintf(buf
, "%uK\n", cache
->size
);
357 static struct kobj_attribute cache_size_attr
=
358 __ATTR(size
, 0444, cache_size_show
, NULL
);
360 static ssize_t
cache_line_size_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
362 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
364 return sprintf(buf
, "%u\n", cache
->line_size
);
367 static struct kobj_attribute cache_line_size_attr
=
368 __ATTR(coherency_line_size
, 0444, cache_line_size_show
, NULL
);
370 static ssize_t
cache_nr_sets_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
372 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
374 return sprintf(buf
, "%u\n", cache
->nr_sets
);
377 static struct kobj_attribute cache_nr_sets_attr
=
378 __ATTR(number_of_sets
, 0444, cache_nr_sets_show
, NULL
);
380 static ssize_t
cache_type_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
382 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
384 return sprintf(buf
, "%s\n", cache
->type
);
387 static struct kobj_attribute cache_type_attr
=
388 __ATTR(type
, 0444, cache_type_show
, NULL
);
390 static ssize_t
cache_level_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
392 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
394 return sprintf(buf
, "%u\n", cache
->level
);
397 static struct kobj_attribute cache_level_attr
=
398 __ATTR(level
, 0444, cache_level_show
, NULL
);
400 static ssize_t
cache_assoc_show(struct kobject
*k
, struct kobj_attribute
*attr
, char *buf
)
402 struct cache_desc
*cache
= kobj_to_cache_desc(k
);
404 return sprintf(buf
, "%u\n", cache
->associativity
);
407 static struct kobj_attribute cache_assoc_attr
=
408 __ATTR(ways_of_associativity
, 0444, cache_assoc_show
, NULL
);
410 struct cache_desc_info
{
412 const char *size_prop
;
413 const char *line_size_prop
;
414 const char *nr_sets_prop
;
417 /* PowerPC Processor binding says the [di]-cache-* must be equal on
418 * unified caches, so just use d-cache properties. */
419 static struct cache_desc_info ucache_info
= {
421 .size_prop
= "d-cache-size",
422 .line_size_prop
= "d-cache-line-size",
423 .nr_sets_prop
= "d-cache-sets",
426 static struct cache_desc_info dcache_info
= {
428 .size_prop
= "d-cache-size",
429 .line_size_prop
= "d-cache-line-size",
430 .nr_sets_prop
= "d-cache-sets",
433 static struct cache_desc_info icache_info
= {
434 .type
= "Instruction",
435 .size_prop
= "i-cache-size",
436 .line_size_prop
= "i-cache-line-size",
437 .nr_sets_prop
= "i-cache-sets",
440 static struct cache_desc
* __cpuinit
create_cache_desc(struct device_node
*np
, struct kobject
*parent
, int index
, int level
, struct cache_desc_info
*info
)
442 const u32
*cache_line_size
;
443 struct cache_desc
*new;
444 const u32
*cache_size
;
448 new = kzalloc(sizeof(*new), GFP_KERNEL
);
452 rc
= kobject_init_and_add(&new->kobj
, &cache_desc_type
, parent
,
458 new->type
= info
->type
;
459 rc
= sysfs_create_file(&new->kobj
, &cache_type_attr
.attr
);
464 rc
= sysfs_create_file(&new->kobj
, &cache_level_attr
.attr
);
468 cache_size
= of_get_property(np
, info
->size_prop
, NULL
);
470 new->size
= *cache_size
/ 1024;
471 rc
= sysfs_create_file(&new->kobj
,
472 &cache_size_attr
.attr
);
476 /* coherency_line_size */
477 cache_line_size
= of_get_property(np
, info
->line_size_prop
, NULL
);
478 if (cache_line_size
) {
479 new->line_size
= *cache_line_size
;
480 rc
= sysfs_create_file(&new->kobj
,
481 &cache_line_size_attr
.attr
);
486 nr_sets
= of_get_property(np
, info
->nr_sets_prop
, NULL
);
488 new->nr_sets
= *nr_sets
;
489 rc
= sysfs_create_file(&new->kobj
,
490 &cache_nr_sets_attr
.attr
);
494 /* ways_of_associativity */
495 if (new->nr_sets
== 1) {
496 /* fully associative */
497 new->associativity
= 0;
501 if (new->nr_sets
&& new->size
&& new->line_size
) {
502 /* If we have values for all of these we can derive
503 * the associativity. */
505 ((new->size
* 1024) / new->nr_sets
) / new->line_size
;
507 rc
= sysfs_create_file(&new->kobj
,
508 &cache_assoc_attr
.attr
);
518 static bool cache_is_unified(struct device_node
*np
)
520 return of_get_property(np
, "cache-unified", NULL
);
523 static struct cache_desc
* __cpuinit
create_cache_index_info(struct device_node
*np
, struct kobject
*parent
, int index
, int level
)
525 const phandle
*next_cache_phandle
;
526 struct device_node
*next_cache
;
527 struct cache_desc
*new, **end
;
529 pr_debug("%s(node = %s, index = %d)\n", __func__
, np
->full_name
, index
);
531 if (cache_is_unified(np
)) {
532 new = create_cache_desc(np
, parent
, index
, level
,
535 new = create_cache_desc(np
, parent
, index
, level
,
539 new->next
= create_cache_desc(np
, parent
, index
, level
,
550 next_cache_phandle
= of_get_property(np
, "l2-cache", NULL
);
551 if (!next_cache_phandle
)
554 next_cache
= of_find_node_by_phandle(*next_cache_phandle
);
558 *end
= create_cache_index_info(next_cache
, parent
, ++index
, ++level
);
560 of_node_put(next_cache
);
565 static void __cpuinit
create_cache_info(struct sys_device
*sysdev
)
567 struct kobject
*cache_toplevel
;
568 struct device_node
*np
= NULL
;
569 int cpu
= sysdev
->id
;
571 cache_toplevel
= kobject_create_and_add("cache", &sysdev
->kobj
);
574 per_cpu(cache_toplevel
, cpu
) = cache_toplevel
;
575 np
= of_get_cpu_node(cpu
, NULL
);
577 per_cpu(cache_desc
, cpu
) =
578 create_cache_index_info(np
, cache_toplevel
, 0, 1);
584 static void __cpuinit
register_cpu_online(unsigned int cpu
)
586 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
587 struct sys_device
*s
= &c
->sysdev
;
588 struct sysdev_attribute
*attrs
, *pmc_attrs
;
591 if (!firmware_has_feature(FW_FEATURE_ISERIES
) &&
592 cpu_has_feature(CPU_FTR_SMT
))
593 sysdev_create_file(s
, &attr_smt_snooze_delay
);
596 switch (cur_cpu_spec
->pmc_type
) {
598 attrs
= ibm_common_attrs
;
599 nattrs
= sizeof(ibm_common_attrs
) / sizeof(struct sysdev_attribute
);
600 pmc_attrs
= ibm_pmc_attrs
;
603 /* PA Semi starts counting at PMC0 */
605 nattrs
= sizeof(pa6t_attrs
) / sizeof(struct sysdev_attribute
);
614 for (i
= 0; i
< nattrs
; i
++)
615 sysdev_create_file(s
, &attrs
[i
]);
618 for (i
= 0; i
< cur_cpu_spec
->num_pmcs
; i
++)
619 sysdev_create_file(s
, &pmc_attrs
[i
]);
621 if (cpu_has_feature(CPU_FTR_MMCRA
))
622 sysdev_create_file(s
, &attr_mmcra
);
624 if (cpu_has_feature(CPU_FTR_PURR
))
625 sysdev_create_file(s
, &attr_purr
);
627 if (cpu_has_feature(CPU_FTR_SPURR
))
628 sysdev_create_file(s
, &attr_spurr
);
630 if (cpu_has_feature(CPU_FTR_DSCR
))
631 sysdev_create_file(s
, &attr_dscr
);
633 create_cache_info(s
);
636 #ifdef CONFIG_HOTPLUG_CPU
637 static void remove_cache_info(struct sys_device
*sysdev
)
639 struct kobject
*cache_toplevel
;
640 struct cache_desc
*cache_desc
;
641 int cpu
= sysdev
->id
;
643 cache_desc
= per_cpu(cache_desc
, cpu
);
644 if (cache_desc
!= NULL
) {
645 sysfs_remove_file(&cache_desc
->kobj
, &cache_size_attr
.attr
);
646 sysfs_remove_file(&cache_desc
->kobj
, &cache_line_size_attr
.attr
);
647 sysfs_remove_file(&cache_desc
->kobj
, &cache_type_attr
.attr
);
648 sysfs_remove_file(&cache_desc
->kobj
, &cache_level_attr
.attr
);
649 sysfs_remove_file(&cache_desc
->kobj
, &cache_nr_sets_attr
.attr
);
650 sysfs_remove_file(&cache_desc
->kobj
, &cache_assoc_attr
.attr
);
652 kobject_put(&cache_desc
->kobj
);
654 cache_toplevel
= per_cpu(cache_toplevel
, cpu
);
655 if (cache_toplevel
!= NULL
)
656 kobject_put(cache_toplevel
);
659 static void unregister_cpu_online(unsigned int cpu
)
661 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
662 struct sys_device
*s
= &c
->sysdev
;
663 struct sysdev_attribute
*attrs
, *pmc_attrs
;
666 BUG_ON(!c
->hotpluggable
);
668 if (!firmware_has_feature(FW_FEATURE_ISERIES
) &&
669 cpu_has_feature(CPU_FTR_SMT
))
670 sysdev_remove_file(s
, &attr_smt_snooze_delay
);
673 switch (cur_cpu_spec
->pmc_type
) {
675 attrs
= ibm_common_attrs
;
676 nattrs
= sizeof(ibm_common_attrs
) / sizeof(struct sysdev_attribute
);
677 pmc_attrs
= ibm_pmc_attrs
;
680 /* PA Semi starts counting at PMC0 */
682 nattrs
= sizeof(pa6t_attrs
) / sizeof(struct sysdev_attribute
);
691 for (i
= 0; i
< nattrs
; i
++)
692 sysdev_remove_file(s
, &attrs
[i
]);
695 for (i
= 0; i
< cur_cpu_spec
->num_pmcs
; i
++)
696 sysdev_remove_file(s
, &pmc_attrs
[i
]);
698 if (cpu_has_feature(CPU_FTR_MMCRA
))
699 sysdev_remove_file(s
, &attr_mmcra
);
701 if (cpu_has_feature(CPU_FTR_PURR
))
702 sysdev_remove_file(s
, &attr_purr
);
704 if (cpu_has_feature(CPU_FTR_SPURR
))
705 sysdev_remove_file(s
, &attr_spurr
);
707 if (cpu_has_feature(CPU_FTR_DSCR
))
708 sysdev_remove_file(s
, &attr_dscr
);
710 remove_cache_info(s
);
712 #endif /* CONFIG_HOTPLUG_CPU */
714 static int __cpuinit
sysfs_cpu_notify(struct notifier_block
*self
,
715 unsigned long action
, void *hcpu
)
717 unsigned int cpu
= (unsigned int)(long)hcpu
;
721 case CPU_ONLINE_FROZEN
:
722 register_cpu_online(cpu
);
724 #ifdef CONFIG_HOTPLUG_CPU
726 case CPU_DEAD_FROZEN
:
727 unregister_cpu_online(cpu
);
734 static struct notifier_block __cpuinitdata sysfs_cpu_nb
= {
735 .notifier_call
= sysfs_cpu_notify
,
738 static DEFINE_MUTEX(cpu_mutex
);
740 int cpu_add_sysdev_attr(struct sysdev_attribute
*attr
)
744 mutex_lock(&cpu_mutex
);
746 for_each_possible_cpu(cpu
) {
747 sysdev_create_file(get_cpu_sysdev(cpu
), attr
);
750 mutex_unlock(&cpu_mutex
);
753 EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr
);
755 int cpu_add_sysdev_attr_group(struct attribute_group
*attrs
)
758 struct sys_device
*sysdev
;
761 mutex_lock(&cpu_mutex
);
763 for_each_possible_cpu(cpu
) {
764 sysdev
= get_cpu_sysdev(cpu
);
765 ret
= sysfs_create_group(&sysdev
->kobj
, attrs
);
769 mutex_unlock(&cpu_mutex
);
772 EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group
);
775 void cpu_remove_sysdev_attr(struct sysdev_attribute
*attr
)
779 mutex_lock(&cpu_mutex
);
781 for_each_possible_cpu(cpu
) {
782 sysdev_remove_file(get_cpu_sysdev(cpu
), attr
);
785 mutex_unlock(&cpu_mutex
);
787 EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr
);
789 void cpu_remove_sysdev_attr_group(struct attribute_group
*attrs
)
792 struct sys_device
*sysdev
;
794 mutex_lock(&cpu_mutex
);
796 for_each_possible_cpu(cpu
) {
797 sysdev
= get_cpu_sysdev(cpu
);
798 sysfs_remove_group(&sysdev
->kobj
, attrs
);
801 mutex_unlock(&cpu_mutex
);
803 EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group
);
809 static void register_nodes(void)
813 for (i
= 0; i
< MAX_NUMNODES
; i
++)
814 register_one_node(i
);
817 int sysfs_add_device_to_node(struct sys_device
*dev
, int nid
)
819 struct node
*node
= &node_devices
[nid
];
820 return sysfs_create_link(&node
->sysdev
.kobj
, &dev
->kobj
,
821 kobject_name(&dev
->kobj
));
823 EXPORT_SYMBOL_GPL(sysfs_add_device_to_node
);
825 void sysfs_remove_device_from_node(struct sys_device
*dev
, int nid
)
827 struct node
*node
= &node_devices
[nid
];
828 sysfs_remove_link(&node
->sysdev
.kobj
, kobject_name(&dev
->kobj
));
830 EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node
);
833 static void register_nodes(void)
840 /* Only valid if CPU is present. */
841 static ssize_t
show_physical_id(struct sys_device
*dev
,
842 struct sysdev_attribute
*attr
, char *buf
)
844 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
846 return sprintf(buf
, "%d\n", get_hard_smp_processor_id(cpu
->sysdev
.id
));
848 static SYSDEV_ATTR(physical_id
, 0444, show_physical_id
, NULL
);
850 static int __init
topology_init(void)
855 register_cpu_notifier(&sysfs_cpu_nb
);
857 for_each_possible_cpu(cpu
) {
858 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
861 * For now, we just see if the system supports making
862 * the RTAS calls for CPU hotplug. But, there may be a
863 * more comprehensive way to do this for an individual
864 * CPU. For instance, the boot cpu might never be valid
870 if (cpu_online(cpu
) || c
->hotpluggable
) {
871 register_cpu(c
, cpu
);
873 sysdev_create_file(&c
->sysdev
, &attr_physical_id
);
877 register_cpu_online(cpu
);
882 subsys_initcall(topology_init
);