2 * PowerPC hash table management proc entry. Will show information
3 * about the current hash table and will allow changes to it.
5 * Written by Cort Dougan (cort@cs.nmt.edu)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/proc_fs.h>
17 #include <linux/stat.h>
18 #include <linux/sysctl.h>
19 #include <linux/ctype.h>
20 #include <linux/threads.h>
21 #include <linux/smp_lock.h>
22 #include <linux/seq_file.h>
23 #include <linux/init.h>
24 #include <linux/bitops.h>
26 #include <asm/uaccess.h>
28 #include <asm/residual.h>
30 #include <asm/pgtable.h>
31 #include <asm/cputable.h>
32 #include <asm/system.h>
35 static int ppc_htab_show(struct seq_file
*m
, void *v
);
36 static ssize_t
ppc_htab_write(struct file
* file
, const char __user
* buffer
,
37 size_t count
, loff_t
*ppos
);
38 extern PTE
*Hash
, *Hash_end
;
39 extern unsigned long Hash_size
, Hash_mask
;
40 extern unsigned long _SDR1
;
41 extern unsigned long htab_reloads
;
42 extern unsigned long htab_preloads
;
43 extern unsigned long htab_evicts
;
44 extern unsigned long pte_misses
;
45 extern unsigned long pte_errors
;
46 extern unsigned int primary_pteg_full
;
47 extern unsigned int htab_hash_searches
;
49 static int ppc_htab_open(struct inode
*inode
, struct file
*file
)
51 return single_open(file
, ppc_htab_show
, NULL
);
54 struct file_operations ppc_htab_operations
= {
55 .open
= ppc_htab_open
,
58 .write
= ppc_htab_write
,
59 .release
= single_release
,
62 static char *pmc1_lookup(unsigned long mmcr0
)
64 switch ( mmcr0
& (0x7f<<7) )
68 case MMCR0_PMC1_CYCLES
:
70 case MMCR0_PMC1_ICACHEMISS
:
79 static char *pmc2_lookup(unsigned long mmcr0
)
81 switch ( mmcr0
& 0x3f )
85 case MMCR0_PMC2_CYCLES
:
87 case MMCR0_PMC2_DCACHEMISS
:
91 case MMCR0_PMC2_LOADMISSTIME
:
92 return "load miss time";
99 * print some useful info about the hash table. This function
100 * is _REALLY_ slow (see the nested for loops below) but nothing
101 * in here should be really timing critical. -- Cort
103 static int ppc_htab_show(struct seq_file
*m
, void *v
)
105 unsigned long mmcr0
= 0, pmc1
= 0, pmc2
= 0;
106 #if defined(CONFIG_PPC_STD_MMU) && !defined(CONFIG_PPC64BRIDGE)
107 unsigned int kptes
= 0, uptes
= 0;
109 #endif /* CONFIG_PPC_STD_MMU */
111 if (cpu_has_feature(CPU_FTR_604_PERF_MON
)) {
112 mmcr0
= mfspr(SPRN_MMCR0
);
113 pmc1
= mfspr(SPRN_PMC1
);
114 pmc2
= mfspr(SPRN_PMC2
);
116 "604 Performance Monitoring\n"
117 "MMCR0\t\t: %08lx %s%s ",
119 ( mmcr0
>>28 & 0x2 ) ? "(user mode counted)" : "",
120 ( mmcr0
>>28 & 0x4 ) ? "(kernel mode counted)" : "");
122 "\nPMC1\t\t: %08lx (%s)\n"
123 "PMC2\t\t: %08lx (%s)\n",
124 pmc1
, pmc1_lookup(mmcr0
),
125 pmc2
, pmc2_lookup(mmcr0
));
128 #ifdef CONFIG_PPC_STD_MMU
129 /* if we don't have a htab */
130 if ( Hash_size
== 0 ) {
131 seq_printf(m
, "No Hash Table used\n");
135 #ifndef CONFIG_PPC64BRIDGE
136 for (ptr
= Hash
; ptr
< Hash_end
; ptr
++) {
137 unsigned int mctx
, vsid
;
141 /* undo the esid skew */
143 mctx
= ((vsid
- (vsid
& 0xf) * 0x111) >> 4) & 0xfffff;
152 "PTE Hash Table Information\n"
155 "Address\t\t: %08lx\n"
157 #ifndef CONFIG_PPC64BRIDGE
159 "Kernel ptes\t: %u\n"
160 "Percent full\t: %lu%%\n"
162 , (unsigned long)(Hash_size
>>10),
163 (Hash_size
/(sizeof(PTE
)*8)),
165 Hash_size
/sizeof(PTE
)
166 #ifndef CONFIG_PPC64BRIDGE
169 ((kptes
+uptes
)*100) / (Hash_size
/sizeof(PTE
))
179 htab_reloads
, htab_preloads
, htab_hash_searches
,
180 primary_pteg_full
, htab_evicts
);
181 #endif /* CONFIG_PPC_STD_MMU */
184 "Non-error misses: %lu\n"
185 "Error misses\t: %lu\n",
186 pte_misses
, pte_errors
);
191 * Allow user to define performance counters and resize the hash table
193 static ssize_t
ppc_htab_write(struct file
* file
, const char __user
* ubuffer
,
194 size_t count
, loff_t
*ppos
)
196 #ifdef CONFIG_PPC_STD_MMU
200 if (!capable(CAP_SYS_ADMIN
))
202 if (strncpy_from_user(buffer
, ubuffer
, 15))
206 /* don't set the htab size for now */
207 if ( !strncmp( buffer
, "size ", 5) )
210 if ( !strncmp( buffer
, "reset", 5) )
212 if (cpu_has_feature(CPU_FTR_604_PERF_MON
)) {
213 /* reset PMC1 and PMC2 */
223 /* Everything below here requires the performance monitor feature. */
224 if (!cpu_has_feature(CPU_FTR_604_PERF_MON
))
227 /* turn off performance monitoring */
228 if ( !strncmp( buffer
, "off", 3) )
230 mtspr(SPRN_MMCR0
, 0);
235 if ( !strncmp( buffer
, "user", 4) )
237 /* setup mmcr0 and clear the correct pmc */
238 tmp
= (mfspr(SPRN_MMCR0
) & ~(0x60000000)) | 0x20000000;
239 mtspr(SPRN_MMCR0
, tmp
);
244 if ( !strncmp( buffer
, "kernel", 6) )
246 /* setup mmcr0 and clear the correct pmc */
247 tmp
= (mfspr(SPRN_MMCR0
) & ~(0x60000000)) | 0x40000000;
248 mtspr(SPRN_MMCR0
, tmp
);
254 if ( !strncmp( buffer
, "dtlb", 4) )
256 /* setup mmcr0 and clear the correct pmc */
257 tmp
= (mfspr(SPRN_MMCR0
) & ~(0x7F << 7)) | MMCR0_PMC1_DTLB
;
258 mtspr(SPRN_MMCR0
, tmp
);
262 if ( !strncmp( buffer
, "ic miss", 7) )
264 /* setup mmcr0 and clear the correct pmc */
265 tmp
= (mfspr(SPRN_MMCR0
) & ~(0x7F<<7)) | MMCR0_PMC1_ICACHEMISS
;
266 mtspr(SPRN_MMCR0
, tmp
);
271 if ( !strncmp( buffer
, "load miss time", 14) )
273 /* setup mmcr0 and clear the correct pmc */
275 "mfspr %0,%1\n\t" /* get current mccr0 */
276 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
277 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
278 "mtspr %1,%0 \n\t" /* set new mccr0 */
279 "mtspr %3,%4 \n\t" /* reset the pmc */
282 "i" (MMCR0_PMC2_LOADMISSTIME
),
283 "i" (SPRN_PMC2
), "r" (0) );
286 if ( !strncmp( buffer
, "itlb", 4) )
288 /* setup mmcr0 and clear the correct pmc */
290 "mfspr %0,%1\n\t" /* get current mccr0 */
291 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
292 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
293 "mtspr %1,%0 \n\t" /* set new mccr0 */
294 "mtspr %3,%4 \n\t" /* reset the pmc */
296 : "i" (SPRN_MMCR0
), "i" (MMCR0_PMC2_ITLB
),
297 "i" (SPRN_PMC2
), "r" (0) );
300 if ( !strncmp( buffer
, "dc miss", 7) )
302 /* setup mmcr0 and clear the correct pmc */
304 "mfspr %0,%1\n\t" /* get current mccr0 */
305 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
306 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
307 "mtspr %1,%0 \n\t" /* set new mccr0 */
308 "mtspr %3,%4 \n\t" /* reset the pmc */
310 : "i" (SPRN_MMCR0
), "i" (MMCR0_PMC2_DCACHEMISS
),
311 "i" (SPRN_PMC2
), "r" (0) );
315 #else /* CONFIG_PPC_STD_MMU */
317 #endif /* CONFIG_PPC_STD_MMU */
320 int proc_dol2crvec(ctl_table
*table
, int write
, struct file
*filp
,
321 void __user
*buffer_arg
, size_t *lenp
, loff_t
*ppos
)
323 int vleft
, first
=1, len
, left
, val
;
324 char __user
*buffer
= (char __user
*) buffer_arg
;
325 #define TMPBUFLEN 256
326 char buf
[TMPBUFLEN
], *p
;
327 static const char *sizestrings
[4] = {
328 "2MB", "256KB", "512KB", "1MB"
330 static const char *clockstrings
[8] = {
331 "clock disabled", "+1 clock", "+1.5 clock", "reserved(3)",
332 "+2 clock", "+2.5 clock", "+3 clock", "reserved(7)"
334 static const char *typestrings
[4] = {
335 "flow-through burst SRAM", "reserved SRAM",
336 "pipelined burst SRAM", "pipelined late-write SRAM"
338 static const char *holdstrings
[4] = {
339 "0.5", "1.0", "(reserved2)", "(reserved3)"
342 if (!cpu_has_feature(CPU_FTR_L2CR
))
345 if ( /*!table->maxlen ||*/ (*ppos
&& !write
)) {
350 vleft
= table
->maxlen
/ sizeof(int);
353 for (; left
/*&& vleft--*/; first
=0) {
357 if(get_user(c
, buffer
))
367 if (len
> TMPBUFLEN
-1)
369 if(copy_from_user(buf
, buffer
, len
))
373 if (*p
< '0' || *p
> '9')
375 val
= simple_strtoul(p
, &p
, 0);
377 if ((len
< left
) && *p
&& !isspace(*p
))
387 p
+= sprintf(p
, "0x%08x: ", val
);
388 p
+= sprintf(p
, " %s", (val
>> 31) & 1 ? "enabled" :
390 p
+= sprintf(p
, ", %sparity", (val
>>30)&1 ? "" : "no ");
391 p
+= sprintf(p
, ", %s", sizestrings
[(val
>> 28) & 3]);
392 p
+= sprintf(p
, ", %s", clockstrings
[(val
>> 25) & 7]);
393 p
+= sprintf(p
, ", %s", typestrings
[(val
>> 23) & 2]);
394 p
+= sprintf(p
, "%s", (val
>>22)&1 ? ", data only" : "");
395 p
+= sprintf(p
, "%s", (val
>>20)&1 ? ", ZZ enabled": "");
396 p
+= sprintf(p
, ", %s", (val
>>19)&1 ? "write-through" :
398 p
+= sprintf(p
, "%s", (val
>>18)&1 ? ", testing" : "");
399 p
+= sprintf(p
, ", %sns hold",holdstrings
[(val
>>16)&3]);
400 p
+= sprintf(p
, "%s", (val
>>15)&1 ? ", DLL slow" : "");
401 p
+= sprintf(p
, "%s", (val
>>14)&1 ? ", diff clock" :"");
402 p
+= sprintf(p
, "%s", (val
>>13)&1 ? ", DLL bypass" :"");
404 p
+= sprintf(p
,"\n");
409 if (copy_to_user(buffer
, buf
, len
))
417 if (!write
&& !first
&& left
) {
418 if(put_user('\n', (char __user
*) buffer
))
423 char __user
*s
= (char __user
*) buffer
;
442 * Register our sysctl.
444 static ctl_table htab_ctl_table
[]={
446 .ctl_name
= KERN_PPC_L2CR
,
449 .proc_handler
= &proc_dol2crvec
,
453 static ctl_table htab_sysctl_root
[] = {
454 { 1, "kernel", NULL
, 0, 0755, htab_ctl_table
, },
459 register_ppc_htab_sysctl(void)
461 register_sysctl_table(htab_sysctl_root
, 0);
466 __initcall(register_ppc_htab_sysctl
);