aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/sysfs.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2008-08-18 00:23:51 -0400
committerPaul Mackerras <paulus@samba.org>2008-08-20 02:34:58 -0400
commitb950bdd0fc247d0ab4aea88d46e8cced3eac949e (patch)
treedaea275d042511774a6abd558d963e1199aedb65 /arch/powerpc/kernel/sysfs.c
parent41eba0ad0033967eda346dd833194e96fdf5f405 (diff)
powerpc: Expose PMCs & cache topology in sysfs on 32-bit
The file arch/powerpc/kernel/sysfs.c is currently only compiled for 64-bit kernels. It contain code to register CPU sysdevs in sysfs and add various properties such as cache topology and raw access by root to performance monitor counters (PMCs). A lot of that can be re-used as is on 32-bits. This makes the file be built for both, with appropriate ifdef'ing for the few bits that are really 64-bit specific, and adds some support for the raw PMCs for 75x and 74xx processors. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel/sysfs.c')
-rw-r--r--arch/powerpc/kernel/sysfs.c106
1 files changed, 88 insertions, 18 deletions
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 12058db70095..ef2ad92a417f 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -15,18 +15,24 @@
15#include <asm/firmware.h> 15#include <asm/firmware.h>
16#include <asm/hvcall.h> 16#include <asm/hvcall.h>
17#include <asm/prom.h> 17#include <asm/prom.h>
18#include <asm/paca.h>
19#include <asm/lppaca.h>
20#include <asm/machdep.h> 18#include <asm/machdep.h>
21#include <asm/smp.h> 19#include <asm/smp.h>
22 20
21#ifdef CONFIG_PPC64
22#include <asm/paca.h>
23#include <asm/lppaca.h>
24#endif
25
23static DEFINE_PER_CPU(struct cpu, cpu_devices); 26static DEFINE_PER_CPU(struct cpu, cpu_devices);
24 27
25static DEFINE_PER_CPU(struct kobject *, cache_toplevel); 28static DEFINE_PER_CPU(struct kobject *, cache_toplevel);
26 29
27/* SMT stuff */ 30/*
31 * SMT snooze delay stuff, 64-bit only for now
32 */
33
34#ifdef CONFIG_PPC64
28 35
29#ifdef CONFIG_PPC_MULTIPLATFORM
30/* Time in microseconds we delay before sleeping in the idle loop */ 36/* Time in microseconds we delay before sleeping in the idle loop */
31DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 }; 37DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };
32 38
@@ -106,7 +112,7 @@ static int __init setup_smt_snooze_delay(char *str)
106} 112}
107__setup("smt-snooze-delay=", setup_smt_snooze_delay); 113__setup("smt-snooze-delay=", setup_smt_snooze_delay);
108 114
109#endif /* CONFIG_PPC_MULTIPLATFORM */ 115#endif /* CONFIG_PPC64 */
110 116
111/* 117/*
112 * Enabling PMCs will slow partition context switch times so we only do 118 * Enabling PMCs will slow partition context switch times so we only do
@@ -115,7 +121,7 @@ __setup("smt-snooze-delay=", setup_smt_snooze_delay);
115 121
116static DEFINE_PER_CPU(char, pmcs_enabled); 122static DEFINE_PER_CPU(char, pmcs_enabled);
117 123
118void ppc64_enable_pmcs(void) 124void ppc_enable_pmcs(void)
119{ 125{
120 /* Only need to enable them once */ 126 /* Only need to enable them once */
121 if (__get_cpu_var(pmcs_enabled)) 127 if (__get_cpu_var(pmcs_enabled))
@@ -126,7 +132,7 @@ void ppc64_enable_pmcs(void)
126 if (ppc_md.enable_pmcs) 132 if (ppc_md.enable_pmcs)
127 ppc_md.enable_pmcs(); 133 ppc_md.enable_pmcs();
128} 134}
129EXPORT_SYMBOL(ppc64_enable_pmcs); 135EXPORT_SYMBOL(ppc_enable_pmcs);
130 136
131/* XXX convert to rusty's on_one_cpu */ 137/* XXX convert to rusty's on_one_cpu */
132static unsigned long run_on_cpu(unsigned long cpu, 138static unsigned long run_on_cpu(unsigned long cpu,
@@ -154,7 +160,7 @@ static unsigned long read_##NAME(unsigned long junk) \
154} \ 160} \
155static unsigned long write_##NAME(unsigned long val) \ 161static unsigned long write_##NAME(unsigned long val) \
156{ \ 162{ \
157 ppc64_enable_pmcs(); \ 163 ppc_enable_pmcs(); \
158 mtspr(ADDRESS, val); \ 164 mtspr(ADDRESS, val); \
159 return 0; \ 165 return 0; \
160} \ 166} \
@@ -184,28 +190,53 @@ static ssize_t __used \
184 * that are implemented on the current processor 190 * that are implemented on the current processor
185 */ 191 */
186 192
193#ifdef CONFIG_PPC64
194#define HAS_PPC_PMC_CLASSIC 1
195#define HAS_PPC_PMC_IBM 1
196#define HAS_PPC_PMC_PA6T 1
197#elif CONFIG_6xx
198#define HAS_PPC_PMC_CLASSIC 1
199#define HAS_PPC_PMC_IBM 1
200#define HAS_PPC_PMC_G4 1
201#endif
202
203
204#ifdef HAS_PPC_PMC_CLASSIC
187SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0); 205SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
188SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1); 206SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
189SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
190SYSFS_PMCSETUP(pmc1, SPRN_PMC1); 207SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
191SYSFS_PMCSETUP(pmc2, SPRN_PMC2); 208SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
192SYSFS_PMCSETUP(pmc3, SPRN_PMC3); 209SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
193SYSFS_PMCSETUP(pmc4, SPRN_PMC4); 210SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
194SYSFS_PMCSETUP(pmc5, SPRN_PMC5); 211SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
195SYSFS_PMCSETUP(pmc6, SPRN_PMC6); 212SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
213
214#ifdef HAS_PPC_PMC_G4
215SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2);
216#endif
217
218#ifdef CONFIG_PPC64
196SYSFS_PMCSETUP(pmc7, SPRN_PMC7); 219SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
197SYSFS_PMCSETUP(pmc8, SPRN_PMC8); 220SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
221
222SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
198SYSFS_PMCSETUP(purr, SPRN_PURR); 223SYSFS_PMCSETUP(purr, SPRN_PURR);
199SYSFS_PMCSETUP(spurr, SPRN_SPURR); 224SYSFS_PMCSETUP(spurr, SPRN_SPURR);
200SYSFS_PMCSETUP(dscr, SPRN_DSCR); 225SYSFS_PMCSETUP(dscr, SPRN_DSCR);
201 226
227static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
228static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL);
229static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr);
230static SYSDEV_ATTR(purr, 0600, show_purr, store_purr);
231#endif /* CONFIG_PPC64 */
232
233#ifdef HAS_PPC_PMC_PA6T
202SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0); 234SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0);
203SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1); 235SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1);
204SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2); 236SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2);
205SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3); 237SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3);
206SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4); 238SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4);
207SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5); 239SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5);
208
209#ifdef CONFIG_DEBUG_KERNEL 240#ifdef CONFIG_DEBUG_KERNEL
210SYSFS_PMCSETUP(hid0, SPRN_HID0); 241SYSFS_PMCSETUP(hid0, SPRN_HID0);
211SYSFS_PMCSETUP(hid1, SPRN_HID1); 242SYSFS_PMCSETUP(hid1, SPRN_HID1);
@@ -236,28 +267,37 @@ SYSFS_PMCSETUP(tsr1, SPRN_PA6T_TSR1);
236SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2); 267SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2);
237SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3); 268SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3);
238#endif /* CONFIG_DEBUG_KERNEL */ 269#endif /* CONFIG_DEBUG_KERNEL */
270#endif /* HAS_PPC_PMC_PA6T */
239 271
240static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra); 272#ifdef HAS_PPC_PMC_IBM
241static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL);
242static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr);
243static SYSDEV_ATTR(purr, 0600, show_purr, store_purr);
244
245static struct sysdev_attribute ibm_common_attrs[] = { 273static struct sysdev_attribute ibm_common_attrs[] = {
246 _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), 274 _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
247 _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), 275 _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
248}; 276};
277#endif /* HAS_PPC_PMC_G4 */
278
279#ifdef HAS_PPC_PMC_G4
280static struct sysdev_attribute g4_common_attrs[] = {
281 _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
282 _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
283 _SYSDEV_ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2),
284};
285#endif /* HAS_PPC_PMC_G4 */
249 286
250static struct sysdev_attribute ibm_pmc_attrs[] = { 287static struct sysdev_attribute classic_pmc_attrs[] = {
251 _SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1), 288 _SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1),
252 _SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2), 289 _SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2),
253 _SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3), 290 _SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3),
254 _SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4), 291 _SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4),
255 _SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5), 292 _SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5),
256 _SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6), 293 _SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6),
294#ifdef CONFIG_PPC64
257 _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7), 295 _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7),
258 _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8), 296 _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8),
297#endif
259}; 298};
260 299
300#ifdef HAS_PPC_PMC_PA6T
261static struct sysdev_attribute pa6t_attrs[] = { 301static struct sysdev_attribute pa6t_attrs[] = {
262 _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0), 302 _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
263 _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1), 303 _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
@@ -298,6 +338,8 @@ static struct sysdev_attribute pa6t_attrs[] = {
298 _SYSDEV_ATTR(tsr3, 0600, show_tsr3, store_tsr3), 338 _SYSDEV_ATTR(tsr3, 0600, show_tsr3, store_tsr3),
299#endif /* CONFIG_DEBUG_KERNEL */ 339#endif /* CONFIG_DEBUG_KERNEL */
300}; 340};
341#endif /* HAS_PPC_PMC_PA6T */
342#endif /* HAS_PPC_PMC_CLASSIC */
301 343
302struct cache_desc { 344struct cache_desc {
303 struct kobject kobj; 345 struct kobject kobj;
@@ -588,23 +630,36 @@ static void __cpuinit register_cpu_online(unsigned int cpu)
588 struct sysdev_attribute *attrs, *pmc_attrs; 630 struct sysdev_attribute *attrs, *pmc_attrs;
589 int i, nattrs; 631 int i, nattrs;
590 632
633#ifdef CONFIG_PPC64
591 if (!firmware_has_feature(FW_FEATURE_ISERIES) && 634 if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
592 cpu_has_feature(CPU_FTR_SMT)) 635 cpu_has_feature(CPU_FTR_SMT))
593 sysdev_create_file(s, &attr_smt_snooze_delay); 636 sysdev_create_file(s, &attr_smt_snooze_delay);
637#endif
594 638
595 /* PMC stuff */ 639 /* PMC stuff */
596 switch (cur_cpu_spec->pmc_type) { 640 switch (cur_cpu_spec->pmc_type) {
641#ifdef HAS_PPC_PMC_IBM
597 case PPC_PMC_IBM: 642 case PPC_PMC_IBM:
598 attrs = ibm_common_attrs; 643 attrs = ibm_common_attrs;
599 nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); 644 nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
600 pmc_attrs = ibm_pmc_attrs; 645 pmc_attrs = classic_pmc_attrs;
601 break; 646 break;
647#endif /* HAS_PPC_PMC_IBM */
648#ifdef HAS_PPC_PMC_G4
649 case PPC_PMC_G4:
650 attrs = g4_common_attrs;
651 nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
652 pmc_attrs = classic_pmc_attrs;
653 break;
654#endif /* HAS_PPC_PMC_G4 */
655#ifdef HAS_PPC_PMC_PA6T
602 case PPC_PMC_PA6T: 656 case PPC_PMC_PA6T:
603 /* PA Semi starts counting at PMC0 */ 657 /* PA Semi starts counting at PMC0 */
604 attrs = pa6t_attrs; 658 attrs = pa6t_attrs;
605 nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); 659 nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
606 pmc_attrs = NULL; 660 pmc_attrs = NULL;
607 break; 661 break;
662#endif /* HAS_PPC_PMC_PA6T */
608 default: 663 default:
609 attrs = NULL; 664 attrs = NULL;
610 nattrs = 0; 665 nattrs = 0;
@@ -618,6 +673,7 @@ static void __cpuinit register_cpu_online(unsigned int cpu)
618 for (i = 0; i < cur_cpu_spec->num_pmcs; i++) 673 for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
619 sysdev_create_file(s, &pmc_attrs[i]); 674 sysdev_create_file(s, &pmc_attrs[i]);
620 675
676#ifdef CONFIG_PPC64
621 if (cpu_has_feature(CPU_FTR_MMCRA)) 677 if (cpu_has_feature(CPU_FTR_MMCRA))
622 sysdev_create_file(s, &attr_mmcra); 678 sysdev_create_file(s, &attr_mmcra);
623 679
@@ -629,6 +685,7 @@ static void __cpuinit register_cpu_online(unsigned int cpu)
629 685
630 if (cpu_has_feature(CPU_FTR_DSCR)) 686 if (cpu_has_feature(CPU_FTR_DSCR))
631 sysdev_create_file(s, &attr_dscr); 687 sysdev_create_file(s, &attr_dscr);
688#endif /* CONFIG_PPC64 */
632 689
633 create_cache_info(s); 690 create_cache_info(s);
634} 691}
@@ -664,17 +721,28 @@ static void unregister_cpu_online(unsigned int cpu)
664 721
665 /* PMC stuff */ 722 /* PMC stuff */
666 switch (cur_cpu_spec->pmc_type) { 723 switch (cur_cpu_spec->pmc_type) {
724#ifdef HAS_PPC_PMC_IBM
667 case PPC_PMC_IBM: 725 case PPC_PMC_IBM:
668 attrs = ibm_common_attrs; 726 attrs = ibm_common_attrs;
669 nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute); 727 nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
670 pmc_attrs = ibm_pmc_attrs; 728 pmc_attrs = classic_pmc_attrs;
729 break;
730#endif /* HAS_PPC_PMC_IBM */
731#ifdef HAS_PPC_PMC_G4
732 case PPC_PMC_G4:
733 attrs = g4_common_attrs;
734 nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
735 pmc_attrs = classic_pmc_attrs;
671 break; 736 break;
737#endif /* HAS_PPC_PMC_G4 */
738#ifdef HAS_PPC_PMC_PA6T
672 case PPC_PMC_PA6T: 739 case PPC_PMC_PA6T:
673 /* PA Semi starts counting at PMC0 */ 740 /* PA Semi starts counting at PMC0 */
674 attrs = pa6t_attrs; 741 attrs = pa6t_attrs;
675 nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute); 742 nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
676 pmc_attrs = NULL; 743 pmc_attrs = NULL;
677 break; 744 break;
745#endif /* HAS_PPC_PMC_PA6T */
678 default: 746 default:
679 attrs = NULL; 747 attrs = NULL;
680 nattrs = 0; 748 nattrs = 0;
@@ -688,6 +756,7 @@ static void unregister_cpu_online(unsigned int cpu)
688 for (i = 0; i < cur_cpu_spec->num_pmcs; i++) 756 for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
689 sysdev_remove_file(s, &pmc_attrs[i]); 757 sysdev_remove_file(s, &pmc_attrs[i]);
690 758
759#ifdef CONFIG_PPC64
691 if (cpu_has_feature(CPU_FTR_MMCRA)) 760 if (cpu_has_feature(CPU_FTR_MMCRA))
692 sysdev_remove_file(s, &attr_mmcra); 761 sysdev_remove_file(s, &attr_mmcra);
693 762
@@ -699,6 +768,7 @@ static void unregister_cpu_online(unsigned int cpu)
699 768
700 if (cpu_has_feature(CPU_FTR_DSCR)) 769 if (cpu_has_feature(CPU_FTR_DSCR))
701 sysdev_remove_file(s, &attr_dscr); 770 sysdev_remove_file(s, &attr_dscr);
771#endif /* CONFIG_PPC64 */
702 772
703 remove_cache_info(s); 773 remove_cache_info(s);
704} 774}