cplbinfo.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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/ctype.h>
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/seq_file.h>
  13. #include <linux/uaccess.h>
  14. #include <asm/cplbinit.h>
  15. #include <asm/blackfin.h>
  16. static char const page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
  17. #define page(flags) (((flags) & 0x30000) >> 16)
  18. #define strpage(flags) page_strtbl[page(flags)]
  19. struct cplbinfo_data {
  20. loff_t pos;
  21. char cplb_type;
  22. u32 mem_control;
  23. struct cplb_entry *tbl;
  24. int switched;
  25. };
  26. static void cplbinfo_print_header(struct seq_file *m)
  27. {
  28. seq_printf(m, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
  29. }
  30. static int cplbinfo_nomore(struct cplbinfo_data *cdata)
  31. {
  32. return cdata->pos >= MAX_CPLBS;
  33. }
  34. static int cplbinfo_show(struct seq_file *m, void *p)
  35. {
  36. struct cplbinfo_data *cdata;
  37. unsigned long data, addr;
  38. loff_t pos;
  39. cdata = p;
  40. pos = cdata->pos;
  41. addr = cdata->tbl[pos].addr;
  42. data = cdata->tbl[pos].data;
  43. seq_printf(m,
  44. "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
  45. (int)pos, addr, data, strpage(data),
  46. (data & CPLB_USER_RD) ? 'Y' : 'N',
  47. (data & CPLB_USER_WR) ? 'Y' : 'N',
  48. (data & CPLB_SUPV_WR) ? 'Y' : 'N',
  49. pos < cdata->switched ? 'N' : 'Y');
  50. return 0;
  51. }
  52. static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
  53. {
  54. if (cdata->cplb_type == 'I') {
  55. cdata->mem_control = bfin_read_IMEM_CONTROL();
  56. cdata->tbl = icplb_tbl[cpu];
  57. cdata->switched = first_switched_icplb;
  58. } else {
  59. cdata->mem_control = bfin_read_DMEM_CONTROL();
  60. cdata->tbl = dcplb_tbl[cpu];
  61. cdata->switched = first_switched_dcplb;
  62. }
  63. }
  64. static void *cplbinfo_start(struct seq_file *m, loff_t *pos)
  65. {
  66. struct cplbinfo_data *cdata = m->private;
  67. if (!*pos) {
  68. seq_printf(m, "%cCPLBs are %sabled: 0x%x\n", cdata->cplb_type,
  69. (cdata->mem_control & ENDCPLB ? "en" : "dis"),
  70. cdata->mem_control);
  71. cplbinfo_print_header(m);
  72. } else if (cplbinfo_nomore(cdata))
  73. return NULL;
  74. get_cpu();
  75. return cdata;
  76. }
  77. static void *cplbinfo_next(struct seq_file *m, void *p, loff_t *pos)
  78. {
  79. struct cplbinfo_data *cdata = p;
  80. cdata->pos = ++(*pos);
  81. if (cplbinfo_nomore(cdata))
  82. return NULL;
  83. else
  84. return cdata;
  85. }
  86. static void cplbinfo_stop(struct seq_file *m, void *p)
  87. {
  88. put_cpu();
  89. }
  90. static const struct seq_operations cplbinfo_sops = {
  91. .start = cplbinfo_start,
  92. .next = cplbinfo_next,
  93. .stop = cplbinfo_stop,
  94. .show = cplbinfo_show,
  95. };
  96. static int cplbinfo_open(struct inode *inode, struct file *file)
  97. {
  98. char buf[256], *path, *p;
  99. unsigned int cpu;
  100. char *s_cpu, *s_cplb;
  101. int ret;
  102. struct seq_file *m;
  103. struct cplbinfo_data *cdata;
  104. path = d_path(&file->f_path, buf, sizeof(buf));
  105. if (IS_ERR(path))
  106. return PTR_ERR(path);
  107. s_cpu = strstr(path, "/cpu");
  108. s_cplb = strrchr(path, '/');
  109. if (!s_cpu || !s_cplb)
  110. return -EINVAL;
  111. cpu = simple_strtoul(s_cpu + 4, &p, 10);
  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 = toupper(s_cplb[1]);
  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("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
  144. proc_create("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
  145. }
  146. return 0;
  147. }
  148. late_initcall(cplbinfo_init);