ppc_htab.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * PowerPC hash table management proc entry. Will show information
  3. * about the current hash table and will allow changes to it.
  4. *
  5. * Written by Cort Dougan (cort@cs.nmt.edu)
  6. *
  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.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/stat.h>
  17. #include <linux/sysctl.h>
  18. #include <linux/ctype.h>
  19. #include <linux/threads.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/init.h>
  23. #include <linux/bitops.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/mmu.h>
  26. #include <asm/residual.h>
  27. #include <asm/io.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/cputable.h>
  30. #include <asm/system.h>
  31. #include <asm/reg.h>
  32. static int ppc_htab_show(struct seq_file *m, void *v);
  33. static ssize_t ppc_htab_write(struct file * file, const char __user * buffer,
  34. size_t count, loff_t *ppos);
  35. extern PTE *Hash, *Hash_end;
  36. extern unsigned long Hash_size, Hash_mask;
  37. extern unsigned long _SDR1;
  38. extern unsigned long htab_reloads;
  39. extern unsigned long htab_preloads;
  40. extern unsigned long htab_evicts;
  41. extern unsigned long pte_misses;
  42. extern unsigned long pte_errors;
  43. extern unsigned int primary_pteg_full;
  44. extern unsigned int htab_hash_searches;
  45. static int ppc_htab_open(struct inode *inode, struct file *file)
  46. {
  47. return single_open(file, ppc_htab_show, NULL);
  48. }
  49. struct file_operations ppc_htab_operations = {
  50. .open = ppc_htab_open,
  51. .read = seq_read,
  52. .llseek = seq_lseek,
  53. .write = ppc_htab_write,
  54. .release = single_release,
  55. };
  56. static char *pmc1_lookup(unsigned long mmcr0)
  57. {
  58. switch ( mmcr0 & (0x7f<<7) )
  59. {
  60. case 0x0:
  61. return "none";
  62. case MMCR0_PMC1_CYCLES:
  63. return "cycles";
  64. case MMCR0_PMC1_ICACHEMISS:
  65. return "ic miss";
  66. case MMCR0_PMC1_DTLB:
  67. return "dtlb miss";
  68. default:
  69. return "unknown";
  70. }
  71. }
  72. static char *pmc2_lookup(unsigned long mmcr0)
  73. {
  74. switch ( mmcr0 & 0x3f )
  75. {
  76. case 0x0:
  77. return "none";
  78. case MMCR0_PMC2_CYCLES:
  79. return "cycles";
  80. case MMCR0_PMC2_DCACHEMISS:
  81. return "dc miss";
  82. case MMCR0_PMC2_ITLB:
  83. return "itlb miss";
  84. case MMCR0_PMC2_LOADMISSTIME:
  85. return "load miss time";
  86. default:
  87. return "unknown";
  88. }
  89. }
  90. /*
  91. * print some useful info about the hash table. This function
  92. * is _REALLY_ slow (see the nested for loops below) but nothing
  93. * in here should be really timing critical. -- Cort
  94. */
  95. static int ppc_htab_show(struct seq_file *m, void *v)
  96. {
  97. unsigned long mmcr0 = 0, pmc1 = 0, pmc2 = 0;
  98. #if defined(CONFIG_PPC_STD_MMU) && !defined(CONFIG_PPC64BRIDGE)
  99. unsigned int kptes = 0, uptes = 0;
  100. PTE *ptr;
  101. #endif /* CONFIG_PPC_STD_MMU */
  102. if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
  103. mmcr0 = mfspr(SPRN_MMCR0);
  104. pmc1 = mfspr(SPRN_PMC1);
  105. pmc2 = mfspr(SPRN_PMC2);
  106. seq_printf(m,
  107. "604 Performance Monitoring\n"
  108. "MMCR0\t\t: %08lx %s%s ",
  109. mmcr0,
  110. ( mmcr0>>28 & 0x2 ) ? "(user mode counted)" : "",
  111. ( mmcr0>>28 & 0x4 ) ? "(kernel mode counted)" : "");
  112. seq_printf(m,
  113. "\nPMC1\t\t: %08lx (%s)\n"
  114. "PMC2\t\t: %08lx (%s)\n",
  115. pmc1, pmc1_lookup(mmcr0),
  116. pmc2, pmc2_lookup(mmcr0));
  117. }
  118. #ifdef CONFIG_PPC_STD_MMU
  119. /* if we don't have a htab */
  120. if ( Hash_size == 0 ) {
  121. seq_printf(m, "No Hash Table used\n");
  122. return 0;
  123. }
  124. #ifndef CONFIG_PPC64BRIDGE
  125. for (ptr = Hash; ptr < Hash_end; ptr++) {
  126. unsigned int mctx, vsid;
  127. if (!ptr->v)
  128. continue;
  129. /* undo the esid skew */
  130. vsid = ptr->vsid;
  131. mctx = ((vsid - (vsid & 0xf) * 0x111) >> 4) & 0xfffff;
  132. if (mctx == 0)
  133. kptes++;
  134. else
  135. uptes++;
  136. }
  137. #endif
  138. seq_printf(m,
  139. "PTE Hash Table Information\n"
  140. "Size\t\t: %luKb\n"
  141. "Buckets\t\t: %lu\n"
  142. "Address\t\t: %08lx\n"
  143. "Entries\t\t: %lu\n"
  144. #ifndef CONFIG_PPC64BRIDGE
  145. "User ptes\t: %u\n"
  146. "Kernel ptes\t: %u\n"
  147. "Percent full\t: %lu%%\n"
  148. #endif
  149. , (unsigned long)(Hash_size>>10),
  150. (Hash_size/(sizeof(PTE)*8)),
  151. (unsigned long)Hash,
  152. Hash_size/sizeof(PTE)
  153. #ifndef CONFIG_PPC64BRIDGE
  154. , uptes,
  155. kptes,
  156. ((kptes+uptes)*100) / (Hash_size/sizeof(PTE))
  157. #endif
  158. );
  159. seq_printf(m,
  160. "Reloads\t\t: %lu\n"
  161. "Preloads\t: %lu\n"
  162. "Searches\t: %u\n"
  163. "Overflows\t: %u\n"
  164. "Evicts\t\t: %lu\n",
  165. htab_reloads, htab_preloads, htab_hash_searches,
  166. primary_pteg_full, htab_evicts);
  167. #endif /* CONFIG_PPC_STD_MMU */
  168. seq_printf(m,
  169. "Non-error misses: %lu\n"
  170. "Error misses\t: %lu\n",
  171. pte_misses, pte_errors);
  172. return 0;
  173. }
  174. /*
  175. * Allow user to define performance counters and resize the hash table
  176. */
  177. static ssize_t ppc_htab_write(struct file * file, const char __user * ubuffer,
  178. size_t count, loff_t *ppos)
  179. {
  180. #ifdef CONFIG_PPC_STD_MMU
  181. unsigned long tmp;
  182. char buffer[16];
  183. if (!capable(CAP_SYS_ADMIN))
  184. return -EACCES;
  185. if (strncpy_from_user(buffer, ubuffer, 15))
  186. return -EFAULT;
  187. buffer[15] = 0;
  188. /* don't set the htab size for now */
  189. if ( !strncmp( buffer, "size ", 5) )
  190. return -EBUSY;
  191. if ( !strncmp( buffer, "reset", 5) )
  192. {
  193. if (cpu_has_feature(CPU_FTR_604_PERF_MON)) {
  194. /* reset PMC1 and PMC2 */
  195. mtspr(SPRN_PMC1, 0);
  196. mtspr(SPRN_PMC2, 0);
  197. }
  198. htab_reloads = 0;
  199. htab_evicts = 0;
  200. pte_misses = 0;
  201. pte_errors = 0;
  202. }
  203. /* Everything below here requires the performance monitor feature. */
  204. if (!cpu_has_feature(CPU_FTR_604_PERF_MON))
  205. return count;
  206. /* turn off performance monitoring */
  207. if ( !strncmp( buffer, "off", 3) )
  208. {
  209. mtspr(SPRN_MMCR0, 0);
  210. mtspr(SPRN_PMC1, 0);
  211. mtspr(SPRN_PMC2, 0);
  212. }
  213. if ( !strncmp( buffer, "user", 4) )
  214. {
  215. /* setup mmcr0 and clear the correct pmc */
  216. tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x20000000;
  217. mtspr(SPRN_MMCR0, tmp);
  218. mtspr(SPRN_PMC1, 0);
  219. mtspr(SPRN_PMC2, 0);
  220. }
  221. if ( !strncmp( buffer, "kernel", 6) )
  222. {
  223. /* setup mmcr0 and clear the correct pmc */
  224. tmp = (mfspr(SPRN_MMCR0) & ~(0x60000000)) | 0x40000000;
  225. mtspr(SPRN_MMCR0, tmp);
  226. mtspr(SPRN_PMC1, 0);
  227. mtspr(SPRN_PMC2, 0);
  228. }
  229. /* PMC1 values */
  230. if ( !strncmp( buffer, "dtlb", 4) )
  231. {
  232. /* setup mmcr0 and clear the correct pmc */
  233. tmp = (mfspr(SPRN_MMCR0) & ~(0x7F << 7)) | MMCR0_PMC1_DTLB;
  234. mtspr(SPRN_MMCR0, tmp);
  235. mtspr(SPRN_PMC1, 0);
  236. }
  237. if ( !strncmp( buffer, "ic miss", 7) )
  238. {
  239. /* setup mmcr0 and clear the correct pmc */
  240. tmp = (mfspr(SPRN_MMCR0) & ~(0x7F<<7)) | MMCR0_PMC1_ICACHEMISS;
  241. mtspr(SPRN_MMCR0, tmp);
  242. mtspr(SPRN_PMC1, 0);
  243. }
  244. /* PMC2 values */
  245. if ( !strncmp( buffer, "load miss time", 14) )
  246. {
  247. /* setup mmcr0 and clear the correct pmc */
  248. asm volatile(
  249. "mfspr %0,%1\n\t" /* get current mccr0 */
  250. "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
  251. "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
  252. "mtspr %1,%0 \n\t" /* set new mccr0 */
  253. "mtspr %3,%4 \n\t" /* reset the pmc */
  254. : "=r" (tmp)
  255. : "i" (SPRN_MMCR0),
  256. "i" (MMCR0_PMC2_LOADMISSTIME),
  257. "i" (SPRN_PMC2), "r" (0) );
  258. }
  259. if ( !strncmp( buffer, "itlb", 4) )
  260. {
  261. /* setup mmcr0 and clear the correct pmc */
  262. asm volatile(
  263. "mfspr %0,%1\n\t" /* get current mccr0 */
  264. "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
  265. "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
  266. "mtspr %1,%0 \n\t" /* set new mccr0 */
  267. "mtspr %3,%4 \n\t" /* reset the pmc */
  268. : "=r" (tmp)
  269. : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_ITLB),
  270. "i" (SPRN_PMC2), "r" (0) );
  271. }
  272. if ( !strncmp( buffer, "dc miss", 7) )
  273. {
  274. /* setup mmcr0 and clear the correct pmc */
  275. asm volatile(
  276. "mfspr %0,%1\n\t" /* get current mccr0 */
  277. "rlwinm %0,%0,0,0,31-6\n\t" /* clear bits [26-31] */
  278. "ori %0,%0,%2 \n\t" /* or in mmcr0 settings */
  279. "mtspr %1,%0 \n\t" /* set new mccr0 */
  280. "mtspr %3,%4 \n\t" /* reset the pmc */
  281. : "=r" (tmp)
  282. : "i" (SPRN_MMCR0), "i" (MMCR0_PMC2_DCACHEMISS),
  283. "i" (SPRN_PMC2), "r" (0) );
  284. }
  285. return count;
  286. #else /* CONFIG_PPC_STD_MMU */
  287. return 0;
  288. #endif /* CONFIG_PPC_STD_MMU */
  289. }
  290. int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
  291. void __user *buffer_arg, size_t *lenp, loff_t *ppos)
  292. {
  293. int vleft, first=1, len, left, val;
  294. char __user *buffer = (char __user *) buffer_arg;
  295. #define TMPBUFLEN 256
  296. char buf[TMPBUFLEN], *p;
  297. static const char *sizestrings[4] = {
  298. "2MB", "256KB", "512KB", "1MB"
  299. };
  300. static const char *clockstrings[8] = {
  301. "clock disabled", "+1 clock", "+1.5 clock", "reserved(3)",
  302. "+2 clock", "+2.5 clock", "+3 clock", "reserved(7)"
  303. };
  304. static const char *typestrings[4] = {
  305. "flow-through burst SRAM", "reserved SRAM",
  306. "pipelined burst SRAM", "pipelined late-write SRAM"
  307. };
  308. static const char *holdstrings[4] = {
  309. "0.5", "1.0", "(reserved2)", "(reserved3)"
  310. };
  311. if (!cpu_has_feature(CPU_FTR_L2CR))
  312. return -EFAULT;
  313. if ( /*!table->maxlen ||*/ (*ppos && !write)) {
  314. *lenp = 0;
  315. return 0;
  316. }
  317. vleft = table->maxlen / sizeof(int);
  318. left = *lenp;
  319. for (; left /*&& vleft--*/; first=0) {
  320. if (write) {
  321. while (left) {
  322. char c;
  323. if(get_user(c, buffer))
  324. return -EFAULT;
  325. if (!isspace(c))
  326. break;
  327. left--;
  328. buffer++;
  329. }
  330. if (!left)
  331. break;
  332. len = left;
  333. if (len > TMPBUFLEN-1)
  334. len = TMPBUFLEN-1;
  335. if(copy_from_user(buf, buffer, len))
  336. return -EFAULT;
  337. buf[len] = 0;
  338. p = buf;
  339. if (*p < '0' || *p > '9')
  340. break;
  341. val = simple_strtoul(p, &p, 0);
  342. len = p-buf;
  343. if ((len < left) && *p && !isspace(*p))
  344. break;
  345. buffer += len;
  346. left -= len;
  347. _set_L2CR(val);
  348. } else {
  349. p = buf;
  350. if (!first)
  351. *p++ = '\t';
  352. val = _get_L2CR();
  353. p += sprintf(p, "0x%08x: ", val);
  354. p += sprintf(p, " %s", (val >> 31) & 1 ? "enabled" :
  355. "disabled");
  356. p += sprintf(p, ", %sparity", (val>>30)&1 ? "" : "no ");
  357. p += sprintf(p, ", %s", sizestrings[(val >> 28) & 3]);
  358. p += sprintf(p, ", %s", clockstrings[(val >> 25) & 7]);
  359. p += sprintf(p, ", %s", typestrings[(val >> 23) & 2]);
  360. p += sprintf(p, "%s", (val>>22)&1 ? ", data only" : "");
  361. p += sprintf(p, "%s", (val>>20)&1 ? ", ZZ enabled": "");
  362. p += sprintf(p, ", %s", (val>>19)&1 ? "write-through" :
  363. "copy-back");
  364. p += sprintf(p, "%s", (val>>18)&1 ? ", testing" : "");
  365. p += sprintf(p, ", %sns hold",holdstrings[(val>>16)&3]);
  366. p += sprintf(p, "%s", (val>>15)&1 ? ", DLL slow" : "");
  367. p += sprintf(p, "%s", (val>>14)&1 ? ", diff clock" :"");
  368. p += sprintf(p, "%s", (val>>13)&1 ? ", DLL bypass" :"");
  369. p += sprintf(p,"\n");
  370. len = strlen(buf);
  371. if (len > left)
  372. len = left;
  373. if (copy_to_user(buffer, buf, len))
  374. return -EFAULT;
  375. left -= len;
  376. buffer += len;
  377. break;
  378. }
  379. }
  380. if (!write && !first && left) {
  381. if(put_user('\n', (char __user *) buffer))
  382. return -EFAULT;
  383. left--, buffer++;
  384. }
  385. if (write) {
  386. char __user *s = (char __user *) buffer;
  387. while (left) {
  388. char c;
  389. if(get_user(c, s++))
  390. return -EFAULT;
  391. if (!isspace(c))
  392. break;
  393. left--;
  394. }
  395. }
  396. if (write && first)
  397. return -EINVAL;
  398. *lenp -= left;
  399. *ppos += *lenp;
  400. return 0;
  401. }
  402. #ifdef CONFIG_SYSCTL
  403. /*
  404. * Register our sysctl.
  405. */
  406. static ctl_table htab_ctl_table[]={
  407. {
  408. .ctl_name = KERN_PPC_L2CR,
  409. .procname = "l2cr",
  410. .mode = 0644,
  411. .proc_handler = &proc_dol2crvec,
  412. },
  413. { 0, },
  414. };
  415. static ctl_table htab_sysctl_root[] = {
  416. { 1, "kernel", NULL, 0, 0755, htab_ctl_table, },
  417. { 0,},
  418. };
  419. static int __init
  420. register_ppc_htab_sysctl(void)
  421. {
  422. register_sysctl_table(htab_sysctl_root, 0);
  423. return 0;
  424. }
  425. __initcall(register_ppc_htab_sysctl);
  426. #endif