cplbinfo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * arch/blackfin/kernel/cplbinfo.c - display CPLB status
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/ctype.h>
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/uaccess.h>
  15. #include <asm/cplbinit.h>
  16. #include <asm/blackfin.h>
  17. static char const page_strtbl[][4] = {
  18. "1K", "4K", "1M", "4M",
  19. #ifdef CONFIG_BF60x
  20. "16K", "64K", "16M", "64M",
  21. #endif
  22. };
  23. #define page(flags) (((flags) & 0x70000) >> 16)
  24. #define strpage(flags) page_strtbl[page(flags)]
  25. struct cplbinfo_data {
  26. loff_t pos;
  27. char cplb_type;
  28. u32 mem_control;
  29. struct cplb_entry *tbl;
  30. int switched;
  31. };
  32. static void cplbinfo_print_header(struct seq_file *m)
  33. {
  34. seq_printf(m, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
  35. }
  36. static int cplbinfo_nomore(struct cplbinfo_data *cdata)
  37. {
  38. return cdata->pos >= MAX_CPLBS;
  39. }
  40. static int cplbinfo_show(struct seq_file *m, void *p)
  41. {
  42. struct cplbinfo_data *cdata;
  43. unsigned long data, addr;
  44. loff_t pos;
  45. cdata = p;
  46. pos = cdata->pos;
  47. addr = cdata->tbl[pos].addr;
  48. data = cdata->tbl[pos].data;
  49. seq_printf(m,
  50. "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
  51. (int)pos, addr, data, strpage(data),
  52. (data & CPLB_USER_RD) ? 'Y' : 'N',
  53. (data & CPLB_USER_WR) ? 'Y' : 'N',
  54. (data & CPLB_SUPV_WR) ? 'Y' : 'N',
  55. pos < cdata->switched ? 'N' : 'Y');
  56. return 0;
  57. }
  58. static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
  59. {
  60. if (cdata->cplb_type == 'I') {
  61. cdata->mem_control = bfin_read_IMEM_CONTROL();
  62. cdata->tbl = icplb_tbl[cpu];
  63. cdata->switched = first_switched_icplb;
  64. } else {
  65. cdata->mem_control = bfin_read_DMEM_CONTROL();
  66. cdata->tbl = dcplb_tbl[cpu];
  67. cdata->switched = first_switched_dcplb;
  68. }
  69. }
  70. static void *cplbinfo_start(struct seq_file *m, loff_t *pos)
  71. {
  72. struct cplbinfo_data *cdata = m->private;
  73. if (!*pos) {
  74. seq_printf(m, "%cCPLBs are %sabled: 0x%x\n", cdata->cplb_type,
  75. (cdata->mem_control & ENDCPLB ? "en" : "dis"),
  76. cdata->mem_control);
  77. cplbinfo_print_header(m);
  78. } else if (cplbinfo_nomore(cdata))
  79. return NULL;
  80. get_cpu();
  81. return cdata;
  82. }
  83. static void *cplbinfo_next(struct seq_file *m, void *p, loff_t *pos)
  84. {
  85. struct cplbinfo_data *cdata = p;
  86. cdata->pos = ++(*pos);
  87. if (cplbinfo_nomore(cdata))
  88. return NULL;
  89. else
  90. return cdata;
  91. }
  92. static void cplbinfo_stop(struct seq_file *m, void *p)
  93. {
  94. put_cpu();
  95. }
  96. static const struct seq_operations cplbinfo_sops = {
  97. .start = cplbinfo_start,
  98. .next = cplbinfo_next,
  99. .stop = cplbinfo_stop,
  100. .show = cplbinfo_show,
  101. };
  102. #define CPLBINFO_DCPLB_FLAG 0x80000000
  103. static int cplbinfo_open(struct inode *inode, struct file *file)
  104. {
  105. char cplb_type;
  106. unsigned int cpu = (unsigned long)PDE_DATA(file_inode(file));
  107. int ret;
  108. struct seq_file *m;
  109. struct cplbinfo_data *cdata;
  110. cplb_type = cpu & CPLBINFO_DCPLB_FLAG ? 'D' : 'I';
  111. cpu &= ~CPLBINFO_DCPLB_FLAG;
  112. if (!cpu_online(cpu))
  113. return -ENODEV;
  114. ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
  115. if (ret)
  116. return ret;
  117. m = file->private_data;
  118. cdata = m->private;
  119. cdata->pos = 0;
  120. cdata->cplb_type = cplb_type;
  121. cplbinfo_seq_init(cdata, cpu);
  122. return 0;
  123. }
  124. static const struct file_operations cplbinfo_fops = {
  125. .open = cplbinfo_open,
  126. .read = seq_read,
  127. .llseek = seq_lseek,
  128. .release = seq_release_private,
  129. };
  130. static int __init cplbinfo_init(void)
  131. {
  132. struct proc_dir_entry *cplb_dir, *cpu_dir;
  133. char buf[10];
  134. unsigned int cpu;
  135. cplb_dir = proc_mkdir("cplbinfo", NULL);
  136. if (!cplb_dir)
  137. return -ENOMEM;
  138. for_each_possible_cpu(cpu) {
  139. sprintf(buf, "cpu%i", cpu);
  140. cpu_dir = proc_mkdir(buf, cplb_dir);
  141. if (!cpu_dir)
  142. return -ENOMEM;
  143. proc_create_data("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
  144. (void *)cpu);
  145. proc_create_data("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
  146. (void *)(cpu | CPLBINFO_DCPLB_FLAG));
  147. }
  148. return 0;
  149. }
  150. late_initcall(cplbinfo_init);