cplbinfo.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * arch/blackfin/kernel/cplbinfo.c - display CPLB status
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/uaccess.h>
  12. #include <asm/cplbinit.h>
  13. #include <asm/blackfin.h>
  14. typedef enum { ICPLB, DCPLB } cplb_type;
  15. static char page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
  16. #define page(flags) (((flags) & 0x30000) >> 16)
  17. #define strpage(flags) page_strtbl[page(flags)]
  18. #ifdef CONFIG_MPU
  19. static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
  20. {
  21. struct cplb_entry *tbl;
  22. int switched;
  23. int i;
  24. if (type == ICPLB) {
  25. tbl = icplb_tbl[cpu];
  26. switched = first_switched_icplb;
  27. } else {
  28. tbl = dcplb_tbl[cpu];
  29. switched = first_switched_dcplb;
  30. }
  31. buf += sprintf(buf, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
  32. for (i = 0; i < MAX_CPLBS; ++i) {
  33. unsigned long data = tbl[i].data;
  34. unsigned long addr = tbl[i].addr;
  35. if (!(data & CPLB_VALID))
  36. continue;
  37. buf += sprintf(buf,
  38. "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
  39. i, addr, data, strpage(data),
  40. (data & CPLB_USER_RD) ? 'Y' : 'N',
  41. (data & CPLB_USER_WR) ? 'Y' : 'N',
  42. (data & CPLB_SUPV_WR) ? 'Y' : 'N',
  43. i < switched ? 'N' : 'Y');
  44. }
  45. buf += sprintf(buf, "\n");
  46. return buf;
  47. }
  48. #else
  49. extern int page_size_table[];
  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 i;
  55. for (i = 0; i < 16; ++i)
  56. if (addr >= cplb_addr[i] &&
  57. addr < cplb_addr[i] + page_size_table[page(cplb_data[i])] &&
  58. cplb_data[i] == data)
  59. return i;
  60. return -1;
  61. }
  62. static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
  63. {
  64. unsigned long *p_addr, *p_data, *p_icount, *p_ocount;
  65. unsigned long *cplb_addr, *cplb_data;
  66. int entry = 0, used_cplb = 0;
  67. if (type == ICPLB) {
  68. p_addr = ipdt_tables[cpu];
  69. p_data = ipdt_tables[cpu] + 1;
  70. p_icount = ipdt_swapcount_tables[cpu];
  71. p_ocount = ipdt_swapcount_tables[cpu] + 1;
  72. cplb_addr = (unsigned long *)ICPLB_ADDR0;
  73. cplb_data = (unsigned long *)ICPLB_DATA0;
  74. } else {
  75. p_addr = dpdt_tables[cpu];
  76. p_data = dpdt_tables[cpu] + 1;
  77. p_icount = dpdt_swapcount_tables[cpu];
  78. p_ocount = dpdt_swapcount_tables[cpu] + 1;
  79. cplb_addr = (unsigned long *)DCPLB_ADDR0;
  80. cplb_data = (unsigned long *)DCPLB_DATA0;
  81. }
  82. buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\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 += sprintf(buf,
  88. "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
  89. *p_addr, *p_data, strpage(*p_data),
  90. (*p_data & CPLB_VALID) ? 'Y' : 'N',
  91. (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
  92. *p_ocount);
  93. p_addr += 2;
  94. p_data += 2;
  95. p_icount += 2;
  96. p_ocount += 2;
  97. }
  98. if (used_cplb != 0xffff) {
  99. buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
  100. for (entry = 0; entry < 16; ++entry)
  101. if (0 == ((1 << entry) & used_cplb)) {
  102. int flags = cplb_data[entry];
  103. buf += sprintf(buf,
  104. "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
  105. entry, cplb_addr[entry], flags, strpage(flags),
  106. (flags & CPLB_VALID) ? 'Y' : 'N',
  107. (flags & CPLB_LOCK) ? 'Y' : 'N');
  108. }
  109. }
  110. buf += sprintf(buf, "\n");
  111. return buf;
  112. }
  113. #endif
  114. static int cplbinfo_proc_output(char *buf, void *data)
  115. {
  116. unsigned int cpu = (unsigned int)data;
  117. char *p = buf;
  118. if (bfin_read_IMEM_CONTROL() & ENICPLB) {
  119. p += sprintf(p, "Instruction CPLB entry:\n");
  120. p = cplb_print_entry(p, ICPLB, cpu);
  121. } else
  122. p += sprintf(p, "Instruction CPLB is disabled.\n\n");
  123. if (bfin_read_DMEM_CONTROL() & ENDCPLB) {
  124. p += sprintf(p, "Data CPLB entry:\n");
  125. p = cplb_print_entry(p, DCPLB, cpu);
  126. } else
  127. p += sprintf(p, "Data CPLB is disabled.\n\n");
  128. return p - buf;
  129. }
  130. static int cplbinfo_read_proc(char *page, char **start, off_t off,
  131. int count, int *eof, void *data)
  132. {
  133. int len = cplbinfo_proc_output(page, data);
  134. if (len <= off + count)
  135. *eof = 1;
  136. *start = page + off;
  137. len -= off;
  138. return max(min(len, count), 0);
  139. }
  140. static int __init cplbinfo_init(void)
  141. {
  142. struct proc_dir_entry *parent, *entry;
  143. unsigned int cpu;
  144. unsigned char str[10];
  145. parent = proc_mkdir("cplbinfo", NULL);
  146. if (!parent)
  147. return -ENOMEM;
  148. for_each_online_cpu(cpu) {
  149. sprintf(str, "cpu%u", cpu);
  150. entry = create_proc_entry(str, 0, parent);
  151. if (!entry)
  152. return -ENOMEM;
  153. entry->read_proc = cplbinfo_read_proc;
  154. entry->data = (void *)cpu;
  155. }
  156. return 0;
  157. }
  158. late_initcall(cplbinfo_init);