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>
23 #include <asm/uaccess.h>
24 #include <asm/bitops.h>
26 #include <asm/residual.h>
28 #include <asm/pgtable.h>
29 #include <asm/cputable.h>
30 #include <asm/system.h>
33 static ssize_t ppc_htab_read(struct file * file, char __user * buf,
34 size_t count, loff_t *ppos);
35 static ssize_t ppc_htab_write(struct file * file, const char __user * buffer,
36 size_t count, loff_t *ppos);
37 static long long ppc_htab_lseek(struct file * file, loff_t offset, int orig);
38 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
39 void __user *buffer, size_t *lenp);
41 extern PTE *Hash, *Hash_end;
42 extern unsigned long Hash_size, Hash_mask;
43 extern unsigned long _SDR1;
44 extern unsigned long htab_reloads;
45 extern unsigned long htab_preloads;
46 extern unsigned long htab_evicts;
47 extern unsigned long pte_misses;
48 extern unsigned long pte_errors;
49 extern unsigned int primary_pteg_full;
50 extern unsigned int htab_hash_searches;
52 struct file_operations ppc_htab_operations = {
53 .llseek = ppc_htab_lseek,
54 .read = ppc_htab_read,
55 .write = ppc_htab_write,
58 static char *pmc1_lookup(unsigned long mmcr0)
60 switch ( mmcr0 & (0x7f<<7) )
64 case MMCR0_PMC1_CYCLES:
66 case MMCR0_PMC1_ICACHEMISS:
75 static char *pmc2_lookup(unsigned long mmcr0)
77 switch ( mmcr0 & 0x3f )
81 case MMCR0_PMC2_CYCLES:
83 case MMCR0_PMC2_DCACHEMISS:
87 case MMCR0_PMC2_LOADMISSTIME:
88 return "load miss time";
95 * print some useful info about the hash table. This function
96 * is _REALLY_ slow (see the nested for loops below) but nothing
97 * in here should be really timing critical. -- Cort
99 static ssize_t ppc_htab_read(struct file * file, char __user * buf,
100 size_t count, loff_t *ppos)
102 unsigned long mmcr0 = 0, pmc1 = 0, pmc2 = 0;
104 #ifdef CONFIG_PPC_STD_MMU
105 unsigned int kptes = 0, uptes = 0;
107 #endif /* CONFIG_PPC_STD_MMU */
113 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {
114 mmcr0 = mfspr(SPRN_MMCR0);
115 pmc1 = mfspr(SPRN_PMC1);
116 pmc2 = mfspr(SPRN_PMC2);
117 n += sprintf( buffer + n,
118 "604 Performance Monitoring\n"
119 "MMCR0\t\t: %08lx %s%s ",
121 ( mmcr0>>28 & 0x2 ) ? "(user mode counted)" : "",
122 ( mmcr0>>28 & 0x4 ) ? "(kernel mode counted)" : "");
123 n += sprintf( buffer + n,
124 "\nPMC1\t\t: %08lx (%s)\n"
125 "PMC2\t\t: %08lx (%s)\n",
126 pmc1, pmc1_lookup(mmcr0),
127 pmc2, pmc2_lookup(mmcr0));
130 #ifdef CONFIG_PPC_STD_MMU
131 /* if we don't have a htab */
132 if ( Hash_size == 0 )
134 n += sprintf( buffer + n, "No Hash Table used\n");
138 for (ptr = Hash; ptr < Hash_end; ptr++) {
139 unsigned int mctx, vsid;
143 /* undo the esid skew */
145 mctx = ((vsid - (vsid & 0xf) * 0x111) >> 4) & 0xfffff;
152 n += sprintf( buffer + n,
153 "PTE Hash Table Information\n"
156 "Address\t\t: %08lx\n"
159 "Kernel ptes\t: %u\n"
160 "Percent full\t: %lu%%\n",
161 (unsigned long)(Hash_size>>10),
162 (Hash_size/(sizeof(PTE)*8)),
164 Hash_size/sizeof(PTE),
167 ((kptes+uptes)*100) / (Hash_size/sizeof(PTE))
170 n += sprintf( buffer + n,
176 htab_reloads, htab_preloads, htab_hash_searches,
177 primary_pteg_full, htab_evicts);
179 #endif /* CONFIG_PPC_STD_MMU */
181 n += sprintf( buffer + n,
182 "Non-error misses: %lu\n"
183 "Error misses\t: %lu\n",
184 pte_misses, pte_errors);
185 if (*ppos >= strlen(buffer))
187 if (n > strlen(buffer) - *ppos)
188 n = strlen(buffer) - *ppos;
191 if (copy_to_user(buf, buffer + *ppos, n))
198 * Allow user to define performance counters and resize the hash table
200 static ssize_t ppc_htab_write(struct file * file, const char __user * ubuffer,
201 size_t count, loff_t *ppos)
203 #ifdef CONFIG_PPC_STD_MMU
207 if ( current->uid != 0 )
209 if (strncpy_from_user(buffer, ubuffer, 15))
213 /* don't set the htab size for now */
214 if ( !strncmp( buffer, "size ", 5) )
217 if ( !strncmp( buffer, "reset", 5) )
219 if (cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON) {
220 /* reset PMC1 and PMC2 */
230 /* Everything below here requires the performance monitor feature. */
231 if ( !cur_cpu_spec[0]->cpu_features & CPU_FTR_604_PERF_MON )
234 /* turn off performance monitoring */
235 if ( !strncmp( buffer, "off", 3) )
237 mtspr(SPRN_MMCR0, 0);
242 if ( !strncmp( buffer, "user", 4) )
244 /* setup mmcr0 and clear the correct pmc */
245 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x20000000;
246 mtspr(SPRN_MMCR0, tmp);
251 if ( !strncmp( buffer, "kernel", 6) )
253 /* setup mmcr0 and clear the correct pmc */
254 tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x40000000;
255 mtspr(SPRN_MMCR0, tmp);
261 if ( !strncmp( buffer, "dtlb", 4) )
263 /* setup mmcr0 and clear the correct pmc */
264 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F << 7)) | MMCR0_PMC1_DTLB;
265 mtspr(SPRN_MMCR0, tmp);
269 if ( !strncmp( buffer, "ic miss", 7) )
271 /* setup mmcr0 and clear the correct pmc */
272 tmp = (mfspr(SPRN_MMCR0) & ~(0x7F<<7)) | MMCR0_PMC1_ICACHEMISS;
273 mtspr(SPRN_MMCR0, tmp);
278 if ( !strncmp( buffer, "load miss time", 14) )
280 /* setup mmcr0 and clear the correct pmc */
282 "mfspr %0,%1\n\t" /* get current mccr0 */
283 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
284 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
285 "mtspr %1,%0 \n\t" /* set new mccr0 */
286 "mtspr %3,%4 \n\t" /* reset the pmc */
289 "i" (MMCR0_PMC2_LOADMISSTIME),
290 "i" (SPRN_PMC2), "r" (0) );
293 if ( !strncmp( buffer, "itlb", 4) )
295 /* setup mmcr0 and clear the correct pmc */
297 "mfspr %0,%1\n\t" /* get current mccr0 */
298 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
299 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
300 "mtspr %1,%0 \n\t" /* set new mccr0 */
301 "mtspr %3,%4 \n\t" /* reset the pmc */
303 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_ITLB),
304 "i" (SPRN_PMC2), "r" (0) );
307 if ( !strncmp( buffer, "dc miss", 7) )
309 /* setup mmcr0 and clear the correct pmc */
311 "mfspr %0,%1\n\t" /* get current mccr0 */
312 "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
313 "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
314 "mtspr %1,%0 \n\t" /* set new mccr0 */
315 "mtspr %3,%4 \n\t" /* reset the pmc */
317 : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_DCACHEMISS),
318 "i" (SPRN_PMC2), "r" (0) );
322 #else /* CONFIG_PPC_STD_MMU */
324 #endif /* CONFIG_PPC_STD_MMU */
329 ppc_htab_lseek(struct file * file, loff_t offset, int orig)
331 long long ret = -EINVAL;
336 file->f_pos = offset;
340 file->f_pos += offset;
347 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
348 void __user *buffer_arg, size_t *lenp)
350 int vleft, first=1, len, left, val;
351 char __user *buffer = (char __user *) buffer_arg;
352 #define TMPBUFLEN 256
353 char buf[TMPBUFLEN], *p;
354 static const char *sizestrings[4] = {
355 "2MB", "256KB", "512KB", "1MB"
357 static const char *clockstrings[8] = {
358 "clock disabled", "+1 clock", "+1.5 clock", "reserved(3)",
359 "+2 clock", "+2.5 clock", "+3 clock", "reserved(7)"
361 static const char *typestrings[4] = {
362 "flow-through burst SRAM", "reserved SRAM",
363 "pipelined burst SRAM", "pipelined late-write SRAM"
365 static const char *holdstrings[4] = {
366 "0.5", "1.0", "(reserved2)", "(reserved3)"
369 if (!(cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR))
372 if ( /*!table->maxlen ||*/ (filp->f_pos && !write)) {
377 vleft = table->maxlen / sizeof(int);
380 for (; left /*&& vleft--*/; first=0) {
384 if(get_user(c, buffer))
394 if (len > TMPBUFLEN-1)
396 if(copy_from_user(buf, buffer, len))
400 if (*p < '0' || *p > '9')
402 val = simple_strtoul(p, &p, 0);
404 if ((len < left) && *p && !isspace(*p))
414 p += sprintf(p, "0x%08x: ", val);
415 p += sprintf(p, " %s", (val >> 31) & 1 ? "enabled" :
417 p += sprintf(p, ", %sparity", (val>>30)&1 ? "" : "no ");
418 p += sprintf(p, ", %s", sizestrings[(val >> 28) & 3]);
419 p += sprintf(p, ", %s", clockstrings[(val >> 25) & 7]);
420 p += sprintf(p, ", %s", typestrings[(val >> 23) & 2]);
421 p += sprintf(p, "%s", (val>>22)&1 ? ", data only" : "");
422 p += sprintf(p, "%s", (val>>20)&1 ? ", ZZ enabled": "");
423 p += sprintf(p, ", %s", (val>>19)&1 ? "write-through" :
425 p += sprintf(p, "%s", (val>>18)&1 ? ", testing" : "");
426 p += sprintf(p, ", %sns hold",holdstrings[(val>>16)&3]);
427 p += sprintf(p, "%s", (val>>15)&1 ? ", DLL slow" : "");
428 p += sprintf(p, "%s", (val>>14)&1 ? ", diff clock" :"");
429 p += sprintf(p, "%s", (val>>13)&1 ? ", DLL bypass" :"");
431 p += sprintf(p,"\n");
436 if (copy_to_user(buffer, buf, len))
444 if (!write && !first && left) {
445 if(put_user('\n', (char *) buffer))
463 filp->f_pos += *lenp;