ppc_htab.c 12 KB

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