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/capability.h>
20 #include <linux/ctype.h>
21 #include <linux/threads.h>
22 #include <linux/smp_lock.h>
23 #include <linux/seq_file.h>
24 #include <linux/init.h>
25 #include <linux/bitops.h>
27 #include <asm/uaccess.h>
29 #include <asm/residual.h>
31 #include <asm/pgtable.h>
32 #include <asm/cputable.h>
33 #include <asm/system.h>
36 static int ppc_htab_show(struct seq_file *m, void *v);
37 static ssize_t ppc_htab_write(struct file * file, const char __user * buffer,
38 size_t count, loff_t *ppos);
39 extern PTE *Hash, *Hash_end;
40 extern unsigned long Hash_size, Hash_mask;
41 extern unsigned long _SDR1;
42 extern unsigned long htab_reloads;
43 extern unsigned long htab_preloads;
44 extern unsigned long htab_evicts;
45 extern unsigned long pte_misses;
46 extern unsigned long pte_errors;
47 extern unsigned int primary_pteg_full;
48 extern unsigned int htab_hash_searches;
50 static int ppc_htab_open(struct inode *inode, struct file *file)
52 return single_open(file, ppc_htab_show, NULL);
55 const struct file_operations ppc_htab_operations = {
56 .open = ppc_htab_open,
59 .write = ppc_htab_write,
60 .release = single_release,
63 static char *pmc1_lookup(unsigned long mmcr0)
65 switch ( mmcr0 & (0x7f<<7) )
69 case MMCR0_PMC1_CYCLES:
71 case MMCR0_PMC1_ICACHEMISS:
80 static char *pmc2_lookup(unsigned long mmcr0)
82 switch ( mmcr0 & 0x3f )
86 case MMCR0_PMC2_CYCLES:
88 case MMCR0_PMC2_DCACHEMISS:
92 case MMCR0_PMC2_LOADMISSTIME:
93 return "load miss time";
100 * print some useful info about the hash table. This function
101 * is _REALLY_ slow (see the nested for loops below) but nothing
102 * in here should be really timing critical. -- Cort
104 static int ppc_htab_show(struct seq_file *m, void *v)
106 unsigned long mmcr0 = 0, pmc1 = 0, pmc2 = 0;
107 #if defined(CONFIG_PPC_STD_MMU)
108 unsigned int kptes = 0, uptes = 0;
110 #endif /* CONFIG_PPC_STD_MMU */
112 if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
113 mmcr0 = mfspr(SPRN_MMCR0);
114 pmc1 = mfspr(SPRN_PMC1);
115 pmc2 = mfspr(SPRN_PMC2);
117 "604 Performance Monitoring\n"
118 "MMCR0\t\t: %08lx %s%s ",
120 ( mmcr0>>28 & 0x2 ) ? "(user mode counted)" : "",
121 ( mmcr0>>28 & 0x4 ) ? "(kernel mode counted)" : "");
123 "\nPMC1\t\t: %08lx (%s)\n"
124 "PMC2\t\t: %08lx (%s)\n",
125 pmc1, pmc1_lookup(mmcr0),
126 pmc2, pmc2_lookup(mmcr0));
129 #ifdef CONFIG_PPC_STD_MMU
130 /* if we don't have a htab */
131 if ( Hash_size == 0 ) {
132 seq_printf(m, "No Hash Table used\n");
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;
151 "PTE Hash Table Information\n"
154 "Address\t\t: %08lx\n"
157 "Kernel ptes\t: %u\n"
158 "Percent full\t: %lu%%\n"
159 , (unsigned long)(Hash_size>>10),
160 (Hash_size/(sizeof(PTE)*8)),
162 Hash_size/sizeof(PTE)
165 ((kptes+uptes)*100) / (Hash_size/sizeof(PTE))
174 htab_reloads, htab_preloads, htab_hash_searches,
175 primary_pteg_full, htab_evicts);
176 #endif /* CONFIG_PPC_STD_MMU */
179 "Non-error misses: %lu\n"
180 "Error misses\t: %lu\n",
181 pte_misses, pte_errors);
186 * Allow user to define performance counters and resize the hash table
188 static ssize_t ppc_htab_write(struct file * file, const char __user * ubuffer,
189 size_t count, loff_t *ppos)
191 #ifdef CONFIG_PPC_STD_MMU
195 if (!capable(CAP_SYS_ADMIN))
197 if (strncpy_from_user(buffer, ubuffer, 15))
201 /* don't set the htab size for now */
202 if ( !strncmp( buffer, "size ", 5) )
205 if ( !strncmp( buffer, "reset", 5) )
207 if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
208 /* reset PMC1 and PMC2 */
218 /* Everything below here requires the performance monitor feature. */
219 if (!cpu_has_feature(CPU_FTR_604_PERF_MON))
222 /* turn off performance monitoring */
223 if ( !strncmp( buffer, "off", 3) )
225 mtspr(SPRN_MMCR0, 0);
230 if ( !strncmp( buffer, "user", 4) )
232 /* setup mmcr0 and clear the correct pmc */
233 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x20000000;
234 mtspr(SPRN_MMCR0, tmp);
239 if ( !strncmp( buffer, "kernel", 6) )
241 /* setup mmcr0 and clear the correct pmc */
242 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x40000000;
243 mtspr(SPRN_MMCR0, tmp);
249 if ( !strncmp( buffer, "dtlb", 4) )
251 /* setup mmcr0 and clear the correct pmc */
252 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F << 7)) | MMCR0_PMC1_DTLB;
253 mtspr(SPRN_MMCR0, tmp);
257 if ( !strncmp( buffer, "ic miss", 7) )
259 /* setup mmcr0 and clear the correct pmc */
260 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F<<7)) | MMCR0_PMC1_ICACHEMISS;
261 mtspr(SPRN_MMCR0, tmp);
266 if ( !strncmp( buffer, "load miss time", 14) )
268 /* setup mmcr0 and clear the correct pmc */
270 "mfspr %0,%1\n\t" /* get current mccr0 */
271 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
272 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
273 "mtspr %1,%0 \n\t" /* set new mccr0 */
274 "mtspr %3,%4 \n\t" /* reset the pmc */
277 "i" (MMCR0_PMC2_LOADMISSTIME),
278 "i" (SPRN_PMC2), "r" (0) );
281 if ( !strncmp( buffer, "itlb", 4) )
283 /* setup mmcr0 and clear the correct pmc */
285 "mfspr %0,%1\n\t" /* get current mccr0 */
286 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
287 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
288 "mtspr %1,%0 \n\t" /* set new mccr0 */
289 "mtspr %3,%4 \n\t" /* reset the pmc */
291 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_ITLB),
292 "i" (SPRN_PMC2), "r" (0) );
295 if ( !strncmp( buffer, "dc miss", 7) )
297 /* setup mmcr0 and clear the correct pmc */
299 "mfspr %0,%1\n\t" /* get current mccr0 */
300 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
301 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
302 "mtspr %1,%0 \n\t" /* set new mccr0 */
303 "mtspr %3,%4 \n\t" /* reset the pmc */
305 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_DCACHEMISS),
306 "i" (SPRN_PMC2), "r" (0) );
310 #else /* CONFIG_PPC_STD_MMU */
312 #endif /* CONFIG_PPC_STD_MMU */
315 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
316 void __user *buffer_arg, size_t *lenp, loff_t *ppos)
318 int vleft, first=1, len, left, val;
319 char __user *buffer = (char __user *) buffer_arg;
320 #define TMPBUFLEN 256
321 char buf[TMPBUFLEN], *p;
322 static const char *sizestrings[4] = {
323 "2MB", "256KB", "512KB", "1MB"
325 static const char *clockstrings[8] = {
326 "clock disabled", "+1 clock", "+1.5 clock", "reserved(3)",
327 "+2 clock", "+2.5 clock", "+3 clock", "reserved(7)"
329 static const char *typestrings[4] = {
330 "flow-through burst SRAM", "reserved SRAM",
331 "pipelined burst SRAM", "pipelined late-write SRAM"
333 static const char *holdstrings[4] = {
334 "0.5", "1.0", "(reserved2)", "(reserved3)"
337 if (!cpu_has_feature(CPU_FTR_L2CR))
340 if ( /*!table->maxlen ||*/ (*ppos && !write)) {
345 vleft = table->maxlen / sizeof(int);
348 for (; left /*&& vleft--*/; first=0) {
352 if(get_user(c, buffer))
362 if (len > TMPBUFLEN-1)
364 if(copy_from_user(buf, buffer, len))
368 if (*p < '0' || *p > '9')
370 val = simple_strtoul(p, &p, 0);
372 if ((len < left) && *p && !isspace(*p))
382 p += sprintf(p, "0x%08x: ", val);
383 p += sprintf(p, " %s", (val >> 31) & 1 ? "enabled" :
385 p += sprintf(p, ", %sparity", (val>>30)&1 ? "" : "no ");
386 p += sprintf(p, ", %s", sizestrings[(val >> 28) & 3]);
387 p += sprintf(p, ", %s", clockstrings[(val >> 25) & 7]);
388 p += sprintf(p, ", %s", typestrings[(val >> 23) & 2]);
389 p += sprintf(p, "%s", (val>>22)&1 ? ", data only" : "");
390 p += sprintf(p, "%s", (val>>20)&1 ? ", ZZ enabled": "");
391 p += sprintf(p, ", %s", (val>>19)&1 ? "write-through" :
393 p += sprintf(p, "%s", (val>>18)&1 ? ", testing" : "");
394 p += sprintf(p, ", %sns hold",holdstrings[(val>>16)&3]);
395 p += sprintf(p, "%s", (val>>15)&1 ? ", DLL slow" : "");
396 p += sprintf(p, "%s", (val>>14)&1 ? ", diff clock" :"");
397 p += sprintf(p, "%s", (val>>13)&1 ? ", DLL bypass" :"");
399 p += sprintf(p,"\n");
404 if (copy_to_user(buffer, buf, len))
412 if (!write && !first && left) {
413 if(put_user('\n', (char __user *) buffer))
418 char __user *s = (char __user *) buffer;
437 * Register our sysctl.
439 static ctl_table htab_ctl_table[]={
441 .ctl_name = KERN_PPC_L2CR,
444 .proc_handler = &proc_dol2crvec,
448 static ctl_table htab_sysctl_root[] = {
449 { 1, "kernel", NULL, 0, 0755, htab_ctl_table, },
454 register_ppc_htab_sysctl(void)
456 register_sysctl_table(htab_sysctl_root, 0);
461 __initcall(register_ppc_htab_sysctl);