cplbinfo.c 3.8 KB

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