cplbinfo.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * File: arch/blackfin/mach-common/cplbinfo.c
  3. * Based on:
  4. * Author: Sonic Zhang <sonic.zhang@analog.com>
  5. *
  6. * Created: Jan. 2005
  7. * Description: Display CPLB status
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/init.h>
  32. #include <linux/proc_fs.h>
  33. #include <asm/current.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/system.h>
  36. #include <asm/cplb.h>
  37. #include <asm/blackfin.h>
  38. #define CPLB_I 1
  39. #define CPLB_D 2
  40. #define SYNC_SYS SSYNC()
  41. #define SYNC_CORE CSYNC()
  42. #define CPLB_BIT_PAGESIZE 0x30000
  43. static int page_size_table[4] = {
  44. 0x00000400, /* 1K */
  45. 0x00001000, /* 4K */
  46. 0x00100000, /* 1M */
  47. 0x00400000 /* 4M */
  48. };
  49. static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
  50. static int cplb_find_entry(unsigned long *cplb_addr,
  51. unsigned long *cplb_data, unsigned long addr,
  52. unsigned long data)
  53. {
  54. int ii;
  55. for (ii = 0; ii < 16; ii++)
  56. if (addr >= cplb_addr[ii] && addr < cplb_addr[ii] +
  57. page_size_table[(cplb_data[ii] & CPLB_BIT_PAGESIZE) >> 16]
  58. && (cplb_data[ii] == data))
  59. return ii;
  60. return -1;
  61. }
  62. static char *cplb_print_entry(char *buf, int type)
  63. {
  64. unsigned long *p_addr = dpdt_table;
  65. unsigned long *p_data = dpdt_table + 1;
  66. unsigned long *p_icount = dpdt_swapcount_table;
  67. unsigned long *p_ocount = dpdt_swapcount_table + 1;
  68. unsigned long *cplb_addr = (unsigned long *)DCPLB_ADDR0;
  69. unsigned long *cplb_data = (unsigned long *)DCPLB_DATA0;
  70. int entry = 0, used_cplb = 0;
  71. if (type == CPLB_I) {
  72. buf += sprintf(buf, "Instrction CPLB entry:\n");
  73. p_addr = ipdt_table;
  74. p_data = ipdt_table + 1;
  75. p_icount = ipdt_swapcount_table;
  76. p_ocount = ipdt_swapcount_table + 1;
  77. cplb_addr = (unsigned long *)ICPLB_ADDR0;
  78. cplb_data = (unsigned long *)ICPLB_DATA0;
  79. } else
  80. buf += sprintf(buf, "Data CPLB entry:\n");
  81. buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\
  82. \tiCount\toCount\n");
  83. while (*p_addr != 0xffffffff) {
  84. entry = cplb_find_entry(cplb_addr, cplb_data, *p_addr, *p_data);
  85. if (entry >= 0)
  86. used_cplb |= 1 << entry;
  87. buf +=
  88. sprintf(buf,
  89. "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
  90. *p_addr, *p_data,
  91. page_size_string_table[(*p_data & 0x30000) >> 16],
  92. (*p_data & CPLB_VALID) ? 'Y' : 'N',
  93. (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
  94. *p_ocount);
  95. p_addr += 2;
  96. p_data += 2;
  97. p_icount += 2;
  98. p_ocount += 2;
  99. }
  100. if (used_cplb != 0xffff) {
  101. buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
  102. for (entry = 0; entry < 16; entry++)
  103. if (0 == ((1 << entry) & used_cplb)) {
  104. int flags = cplb_data[entry];
  105. buf +=
  106. sprintf(buf,
  107. "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
  108. entry, cplb_addr[entry], flags,
  109. page_size_string_table[(flags &
  110. 0x30000) >>
  111. 16],
  112. (flags & CPLB_VALID) ? 'Y' : 'N',
  113. (flags & CPLB_LOCK) ? 'Y' : 'N');
  114. }
  115. }
  116. buf += sprintf(buf, "\n");
  117. return buf;
  118. }
  119. static int cplbinfo_proc_output(char *buf)
  120. {
  121. char *p;
  122. p = buf;
  123. p += sprintf(p,
  124. "------------------ CPLB Information ------------------\n\n");
  125. if (bfin_read_IMEM_CONTROL() & ENICPLB)
  126. p = cplb_print_entry(p, CPLB_I);
  127. else
  128. p += sprintf(p, "Instruction CPLB is disabled.\n\n");
  129. if (bfin_read_DMEM_CONTROL() & ENDCPLB)
  130. p = cplb_print_entry(p, CPLB_D);
  131. else
  132. p += sprintf(p, "Data CPLB is disabled.\n");
  133. return p - buf;
  134. }
  135. static int cplbinfo_read_proc(char *page, char **start, off_t off,
  136. int count, int *eof, void *data)
  137. {
  138. int len;
  139. len = cplbinfo_proc_output(page);
  140. if (len <= off + count)
  141. *eof = 1;
  142. *start = page + off;
  143. len -= off;
  144. if (len > count)
  145. len = count;
  146. if (len < 0)
  147. len = 0;
  148. return len;
  149. }
  150. static int cplbinfo_write_proc(struct file *file, const char __user *buffer,
  151. unsigned long count, void *data)
  152. {
  153. printk(KERN_INFO "Reset the CPLB swap in/out counts.\n");
  154. memset(ipdt_swapcount_table, 0, MAX_SWITCH_I_CPLBS * sizeof(unsigned long));
  155. memset(dpdt_swapcount_table, 0, MAX_SWITCH_D_CPLBS * sizeof(unsigned long));
  156. return count;
  157. }
  158. static int __init cplbinfo_init(void)
  159. {
  160. struct proc_dir_entry *entry;
  161. if ((entry = create_proc_entry("cplbinfo", 0, NULL)) == NULL) {
  162. return -ENOMEM;
  163. }
  164. entry->read_proc = cplbinfo_read_proc;
  165. entry->write_proc = cplbinfo_write_proc;
  166. entry->data = NULL;
  167. return 0;
  168. }
  169. static void __exit cplbinfo_exit(void)
  170. {
  171. remove_proc_entry("cplbinfo", NULL);
  172. }
  173. module_init(cplbinfo_init);
  174. module_exit(cplbinfo_exit);