2 * arch/blackfin/kernel/cplbinfo.c - display CPLB status
4 * Copyright 2004-2008 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
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>
16 #include <asm/cplbinit.h>
17 #include <asm/blackfin.h>
19 static char const page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
20 #define page(flags) (((flags) & 0x30000) >> 16)
21 #define strpage(flags) page_strtbl[page(flags)]
25 struct cplbinfo_data {
29 struct cplb_entry *tbl;
33 static void cplbinfo_print_header(struct seq_file *m)
35 seq_printf(m, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
38 static int cplbinfo_nomore(struct cplbinfo_data *cdata)
40 return cdata->pos >= MAX_CPLBS;
43 static int cplbinfo_show(struct seq_file *m, void *p)
45 struct cplbinfo_data *cdata;
46 unsigned long data, addr;
51 addr = cdata->tbl[pos].addr;
52 data = cdata->tbl[pos].data;
55 "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
56 (int)pos, addr, data, strpage(data),
57 (data & CPLB_USER_RD) ? 'Y' : 'N',
58 (data & CPLB_USER_WR) ? 'Y' : 'N',
59 (data & CPLB_SUPV_WR) ? 'Y' : 'N',
60 pos < cdata->switched ? 'N' : 'Y');
65 static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
67 if (cdata->cplb_type == 'I') {
68 cdata->mem_control = bfin_read_IMEM_CONTROL();
69 cdata->tbl = icplb_tbl[cpu];
70 cdata->switched = first_switched_icplb;
72 cdata->mem_control = bfin_read_DMEM_CONTROL();
73 cdata->tbl = dcplb_tbl[cpu];
74 cdata->switched = first_switched_dcplb;
80 struct cplbinfo_data {
84 unsigned long *pdt_tables, *pdt_swapcount;
85 unsigned long cplb_addr, cplb_data;
88 extern int page_size_table[];
90 static int cplb_find_entry(unsigned long addr_tbl, unsigned long data_tbl,
91 unsigned long addr_find, unsigned long data_find)
95 for (i = 0; i < 16; ++i) {
96 unsigned long cplb_addr = bfin_read32(addr_tbl + i * 4);
97 unsigned long cplb_data = bfin_read32(data_tbl + i * 4);
98 if (addr_find >= cplb_addr &&
99 addr_find < cplb_addr + page_size_table[page(cplb_data)] &&
100 cplb_data == data_find)
107 static void cplbinfo_print_header(struct seq_file *m)
109 seq_printf(m, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
112 static int cplbinfo_nomore(struct cplbinfo_data *cdata)
114 return cdata->pdt_tables[cdata->pos * 2] == 0xffffffff;
117 static int cplbinfo_show(struct seq_file *m, void *p)
119 struct cplbinfo_data *cdata;
120 unsigned long data, addr;
125 pos = cdata->pos * 2;
126 addr = cdata->pdt_tables[pos];
127 data = cdata->pdt_tables[pos + 1];
128 entry = cplb_find_entry(cdata->cplb_addr, cdata->cplb_data, addr, data);
131 "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
132 addr, data, strpage(data),
133 (data & CPLB_VALID) ? 'Y' : 'N',
134 (data & CPLB_LOCK) ? 'Y' : 'N', entry,
135 cdata->pdt_swapcount[pos],
136 cdata->pdt_swapcount[pos + 1]);
141 static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
143 if (cdata->cplb_type == 'I') {
144 cdata->mem_control = bfin_read_IMEM_CONTROL();
145 cdata->pdt_tables = ipdt_tables[cpu];
146 cdata->pdt_swapcount = ipdt_swapcount_tables[cpu];
147 cdata->cplb_addr = ICPLB_ADDR0;
148 cdata->cplb_data = ICPLB_DATA0;
150 cdata->mem_control = bfin_read_DMEM_CONTROL();
151 cdata->pdt_tables = dpdt_tables[cpu];
152 cdata->pdt_swapcount = dpdt_swapcount_tables[cpu];
153 cdata->cplb_addr = DCPLB_ADDR0;
154 cdata->cplb_data = DCPLB_DATA0;
160 static void *cplbinfo_start(struct seq_file *m, loff_t *pos)
162 struct cplbinfo_data *cdata = m->private;
165 seq_printf(m, "%cCPLBs are %sabled: 0x%x\n", cdata->cplb_type,
166 (cdata->mem_control & ENDCPLB ? "en" : "dis"),
168 cplbinfo_print_header(m);
169 } else if (cplbinfo_nomore(cdata))
176 static void *cplbinfo_next(struct seq_file *m, void *p, loff_t *pos)
178 struct cplbinfo_data *cdata = p;
179 cdata->pos = ++(*pos);
180 if (cplbinfo_nomore(cdata))
186 static void cplbinfo_stop(struct seq_file *m, void *p)
191 static const struct seq_operations cplbinfo_sops = {
192 .start = cplbinfo_start,
193 .next = cplbinfo_next,
194 .stop = cplbinfo_stop,
195 .show = cplbinfo_show,
198 static int cplbinfo_open(struct inode *inode, struct file *file)
200 char buf[256], *path, *p;
202 char *s_cpu, *s_cplb;
205 struct cplbinfo_data *cdata;
207 path = d_path(&file->f_path, buf, sizeof(buf));
209 return PTR_ERR(path);
210 s_cpu = strstr(path, "/cpu");
211 s_cplb = strrchr(path, '/');
212 if (!s_cpu || !s_cplb)
215 cpu = simple_strtoul(s_cpu + 4, &p, 10);
216 if (!cpu_online(cpu))
219 ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
222 m = file->private_data;
226 cdata->cplb_type = toupper(s_cplb[1]);
227 cplbinfo_seq_init(cdata, cpu);
232 static const struct file_operations cplbinfo_fops = {
233 .open = cplbinfo_open,
236 .release = seq_release_private,
239 static int __init cplbinfo_init(void)
241 struct proc_dir_entry *cplb_dir, *cpu_dir;
245 cplb_dir = proc_mkdir("cplbinfo", NULL);
249 for_each_possible_cpu(cpu) {
250 sprintf(buf, "cpu%i", cpu);
251 cpu_dir = proc_mkdir(buf, cplb_dir);
255 proc_create("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
256 proc_create("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
261 late_initcall(cplbinfo_init);