cplbinfo.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. struct proc_dir_entry *pde = PDE(file_inode(file));
  106. char cplb_type;
  107. unsigned int cpu;
  108. int ret;
  109. struct seq_file *m;
  110. struct cplbinfo_data *cdata;
  111. cpu = (unsigned int)pde->data;
  112. cplb_type = cpu & CPLBINFO_DCPLB_FLAG ? 'D' : 'I';
  113. cpu &= ~CPLBINFO_DCPLB_FLAG;
  114. if (!cpu_online(cpu))
  115. return -ENODEV;
  116. ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
  117. if (ret)
  118. return ret;
  119. m = file->private_data;
  120. cdata = m->private;
  121. cdata->pos = 0;
  122. cdata->cplb_type = cplb_type;
  123. cplbinfo_seq_init(cdata, cpu);
  124. return 0;
  125. }
  126. static const struct file_operations cplbinfo_fops = {
  127. .open = cplbinfo_open,
  128. .read = seq_read,
  129. .llseek = seq_lseek,
  130. .release = seq_release_private,
  131. };
  132. static int __init cplbinfo_init(void)
  133. {
  134. struct proc_dir_entry *cplb_dir, *cpu_dir;
  135. char buf[10];
  136. unsigned int cpu;
  137. cplb_dir = proc_mkdir("cplbinfo", NULL);
  138. if (!cplb_dir)
  139. return -ENOMEM;
  140. for_each_possible_cpu(cpu) {
  141. sprintf(buf, "cpu%i", cpu);
  142. cpu_dir = proc_mkdir(buf, cplb_dir);
  143. if (!cpu_dir)
  144. return -ENOMEM;
  145. proc_create_data("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
  146. (void *)cpu);
  147. proc_create_data("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
  148. (void *)(cpu | CPLBINFO_DCPLB_FLAG));
  149. }
  150. return 0;
  151. }
  152. late_initcall(cplbinfo_init);