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/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/proc_fs.h>
12 #include <linux/uaccess.h>
14 #include <asm/cplbinit.h>
15 #include <asm/blackfin.h>
17 typedef enum { ICPLB, DCPLB } cplb_type;
19 static char page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
20 #define page(flags) (((flags) & 0x30000) >> 16)
21 #define strpage(flags) page_strtbl[page(flags)]
25 static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
27 struct cplb_entry *tbl;
33 switched = first_switched_icplb;
36 switched = first_switched_dcplb;
39 buf += sprintf(buf, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
40 for (i = 0; i < MAX_CPLBS; ++i) {
41 unsigned long data = tbl[i].data;
42 unsigned long addr = tbl[i].addr;
44 if (!(data & CPLB_VALID))
48 "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
49 i, addr, data, strpage(data),
50 (data & CPLB_USER_RD) ? 'Y' : 'N',
51 (data & CPLB_USER_WR) ? 'Y' : 'N',
52 (data & CPLB_SUPV_WR) ? 'Y' : 'N',
53 i < switched ? 'N' : 'Y');
55 buf += sprintf(buf, "\n");
62 static int page_size_table[4] = {
69 static int cplb_find_entry(unsigned long *cplb_addr,
70 unsigned long *cplb_data, unsigned long addr,
75 for (i = 0; i < 16; ++i)
76 if (addr >= cplb_addr[i] &&
77 addr < cplb_addr[i] + page_size_table[page(cplb_data[i])] &&
84 static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
86 unsigned long *p_addr, *p_data, *p_icount, *p_ocount;
87 unsigned long *cplb_addr, *cplb_data;
88 int entry = 0, used_cplb = 0;
91 p_addr = ipdt_tables[cpu];
92 p_data = ipdt_tables[cpu] + 1;
93 p_icount = ipdt_swapcount_tables[cpu];
94 p_ocount = ipdt_swapcount_tables[cpu] + 1;
95 cplb_addr = (unsigned long *)ICPLB_ADDR0;
96 cplb_data = (unsigned long *)ICPLB_DATA0;
98 p_addr = dpdt_tables[cpu];
99 p_data = dpdt_tables[cpu] + 1;
100 p_icount = dpdt_swapcount_tables[cpu];
101 p_ocount = dpdt_swapcount_tables[cpu] + 1;
102 cplb_addr = (unsigned long *)DCPLB_ADDR0;
103 cplb_data = (unsigned long *)DCPLB_DATA0;
106 buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
108 while (*p_addr != 0xffffffff) {
109 entry = cplb_find_entry(cplb_addr, cplb_data, *p_addr, *p_data);
111 used_cplb |= 1 << entry;
114 "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
115 *p_addr, *p_data, strpage(*p_data),
116 (*p_data & CPLB_VALID) ? 'Y' : 'N',
117 (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
126 if (used_cplb != 0xffff) {
127 buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
129 for (entry = 0; entry < 16; ++entry)
130 if (0 == ((1 << entry) & used_cplb)) {
131 int flags = cplb_data[entry];
133 "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
134 entry, cplb_addr[entry], flags, strpage(flags),
135 (flags & CPLB_VALID) ? 'Y' : 'N',
136 (flags & CPLB_LOCK) ? 'Y' : 'N');
140 buf += sprintf(buf, "\n");
147 static int cplbinfo_proc_output(char *buf, void *data)
149 unsigned int cpu = (unsigned int)data;
152 if (bfin_read_IMEM_CONTROL() & ENICPLB) {
153 p += sprintf(p, "Instruction CPLB entry:\n");
154 p = cplb_print_entry(p, ICPLB, cpu);
156 p += sprintf(p, "Instruction CPLB is disabled.\n\n");
158 if (bfin_read_DMEM_CONTROL() & ENDCPLB) {
159 p += sprintf(p, "Data CPLB entry:\n");
160 p = cplb_print_entry(p, DCPLB, cpu);
162 p += sprintf(p, "Data CPLB is disabled.\n\n");
167 static int cplbinfo_read_proc(char *page, char **start, off_t off,
168 int count, int *eof, void *data)
170 int len = cplbinfo_proc_output(page, data);
171 if (len <= off + count)
175 return max(min(len, count), 0);
178 static int __init cplbinfo_init(void)
180 struct proc_dir_entry *parent, *entry;
182 unsigned char str[10];
184 parent = proc_mkdir("cplbinfo", NULL);
188 for_each_online_cpu(cpu) {
189 sprintf(str, "cpu%u", cpu);
190 entry = create_proc_entry(str, 0, parent);
194 entry->read_proc = cplbinfo_read_proc;
195 entry->data = (void *)cpu;
200 late_initcall(cplbinfo_init);