cplbinfo.c 3.7 KB

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