cplbinfo.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <linux/uaccess.h>
  34. #include <asm/current.h>
  35. #include <asm/system.h>
  36. #include <asm/cplb.h>
  37. #include <asm/cplbinit.h>
  38. #include <asm/blackfin.h>
  39. static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
  40. static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched)
  41. {
  42. int i;
  43. buf += sprintf(buf, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
  44. for (i = 0; i < MAX_CPLBS; i++) {
  45. unsigned long data = tbl[i].data;
  46. unsigned long addr = tbl[i].addr;
  47. if (!(data & CPLB_VALID))
  48. continue;
  49. buf +=
  50. sprintf(buf,
  51. "%d\t0x%08lx\t%06lx\t%s\t%c\t%c\t%c\t%c\n",
  52. i, addr, data,
  53. page_size_string_table[(data & 0x30000) >> 16],
  54. (data & CPLB_USER_RD) ? 'Y' : 'N',
  55. (data & CPLB_USER_WR) ? 'Y' : 'N',
  56. (data & CPLB_SUPV_WR) ? 'Y' : 'N',
  57. i < switched ? 'N' : 'Y');
  58. }
  59. buf += sprintf(buf, "\n");
  60. return buf;
  61. }
  62. int cplbinfo_proc_output(char *buf)
  63. {
  64. char *p;
  65. p = buf;
  66. p += sprintf(p, "------------------ CPLB Information ------------------\n\n");
  67. if (bfin_read_IMEM_CONTROL() & ENICPLB) {
  68. p += sprintf(p, "Instruction CPLB entry:\n");
  69. p = cplb_print_entry(p, icplb_tbl, first_switched_icplb);
  70. } else
  71. p += sprintf(p, "Instruction CPLB is disabled.\n\n");
  72. if (1 || bfin_read_DMEM_CONTROL() & ENDCPLB) {
  73. p += sprintf(p, "Data CPLB entry:\n");
  74. p = cplb_print_entry(p, dcplb_tbl, first_switched_dcplb);
  75. } else
  76. p += sprintf(p, "Data CPLB is disabled.\n");
  77. p += sprintf(p, "ICPLB miss: %d\nICPLB supervisor miss: %d\n",
  78. nr_icplb_miss, nr_icplb_supv_miss);
  79. p += sprintf(p, "DCPLB miss: %d\nDCPLB protection fault:%d\n",
  80. nr_dcplb_miss, nr_dcplb_prot);
  81. p += sprintf(p, "CPLB flushes: %d\n",
  82. nr_cplb_flush);
  83. return p - buf;
  84. }
  85. static int cplbinfo_read_proc(char *page, char **start, off_t off,
  86. int count, int *eof, void *data)
  87. {
  88. int len;
  89. len = cplbinfo_proc_output(page);
  90. if (len <= off + count)
  91. *eof = 1;
  92. *start = page + off;
  93. len -= off;
  94. if (len > count)
  95. len = count;
  96. if (len < 0)
  97. len = 0;
  98. return len;
  99. }
  100. static int __init cplbinfo_init(void)
  101. {
  102. struct proc_dir_entry *entry;
  103. entry = create_proc_entry("cplbinfo", 0, NULL);
  104. if (!entry)
  105. return -ENOMEM;
  106. entry->read_proc = cplbinfo_read_proc;
  107. entry->data = NULL;
  108. return 0;
  109. }
  110. static void __exit cplbinfo_exit(void)
  111. {
  112. remove_proc_entry("cplbinfo", NULL);
  113. }
  114. module_init(cplbinfo_init);
  115. module_exit(cplbinfo_exit);