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. static int cplbinfo_open(struct inode *inode, struct file *file)
  98. {
  99. char buf[256], *path, *p;
  100. unsigned int cpu;
  101. char *s_cpu, *s_cplb;
  102. int ret;
  103. struct seq_file *m;
  104. struct cplbinfo_data *cdata;
  105. path = d_path(&file->f_path, buf, sizeof(buf));
  106. if (IS_ERR(path))
  107. return PTR_ERR(path);
  108. s_cpu = strstr(path, "/cpu");
  109. s_cplb = strrchr(path, '/');
  110. if (!s_cpu || !s_cplb)
  111. return -EINVAL;
  112. cpu = simple_strtoul(s_cpu + 4, &p, 10);
  113. if (!cpu_online(cpu))
  114. return -ENODEV;
  115. ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
  116. if (ret)
  117. return ret;
  118. m = file->private_data;
  119. cdata = m->private;
  120. cdata->pos = 0;
  121. cdata->cplb_type = toupper(s_cplb[1]);
  122. cplbinfo_seq_init(cdata, cpu);
  123. return 0;
  124. }
  125. static const struct file_operations cplbinfo_fops = {
  126. .open = cplbinfo_open,
  127. .read = seq_read,
  128. .llseek = seq_lseek,
  129. .release = seq_release_private,
  130. };
  131. static int __init cplbinfo_init(void)
  132. {
  133. struct proc_dir_entry *cplb_dir, *cpu_dir;
  134. char buf[10];
  135. unsigned int cpu;
  136. cplb_dir = proc_mkdir("cplbinfo", NULL);
  137. if (!cplb_dir)
  138. return -ENOMEM;
  139. for_each_possible_cpu(cpu) {
  140. sprintf(buf, "cpu%i", cpu);
  141. cpu_dir = proc_mkdir(buf, cplb_dir);
  142. if (!cpu_dir)
  143. return -ENOMEM;
  144. proc_create("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
  145. proc_create("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
  146. }
  147. return 0;
  148. }
  149. late_initcall(cplbinfo_init);