blob: 723839da14a101c0f21d3053fc4e5d124e3750fd [file] [log] [blame]
Mike Frysingerff4c02e2008-11-18 17:48:22 +08001/*
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
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>
13
14#include <asm/cplbinit.h>
15#include <asm/blackfin.h>
16
17typedef enum { ICPLB, DCPLB } cplb_type;
18
19static char page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
20#define page(flags) (((flags) & 0x30000) >> 16)
21#define strpage(flags) page_strtbl[page(flags)]
22
23#ifdef CONFIG_MPU
24
25static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
26{
27 struct cplb_entry *tbl;
28 int switched;
29 int i;
30
31 if (type == ICPLB) {
32 tbl = icplb_tbl[cpu];
33 switched = first_switched_icplb;
34 } else {
35 tbl = dcplb_tbl[cpu];
36 switched = first_switched_dcplb;
37 }
38
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;
43
44 if (!(data & CPLB_VALID))
45 continue;
46
47 buf += sprintf(buf,
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');
54 }
55 buf += sprintf(buf, "\n");
56
57 return buf;
58}
59
60#else
61
Mike Frysingercb15e572008-11-18 17:48:22 +080062extern int page_size_table[];
Mike Frysingerff4c02e2008-11-18 17:48:22 +080063
64static int cplb_find_entry(unsigned long *cplb_addr,
65 unsigned long *cplb_data, unsigned long addr,
66 unsigned long data)
67{
68 int i;
69
70 for (i = 0; i < 16; ++i)
71 if (addr >= cplb_addr[i] &&
72 addr < cplb_addr[i] + page_size_table[page(cplb_data[i])] &&
73 cplb_data[i] == data)
74 return i;
75
76 return -1;
77}
78
79static char *cplb_print_entry(char *buf, cplb_type type, unsigned int cpu)
80{
81 unsigned long *p_addr, *p_data, *p_icount, *p_ocount;
82 unsigned long *cplb_addr, *cplb_data;
83 int entry = 0, used_cplb = 0;
84
85 if (type == ICPLB) {
86 p_addr = ipdt_tables[cpu];
87 p_data = ipdt_tables[cpu] + 1;
88 p_icount = ipdt_swapcount_tables[cpu];
89 p_ocount = ipdt_swapcount_tables[cpu] + 1;
90 cplb_addr = (unsigned long *)ICPLB_ADDR0;
91 cplb_data = (unsigned long *)ICPLB_DATA0;
92 } else {
93 p_addr = dpdt_tables[cpu];
94 p_data = dpdt_tables[cpu] + 1;
95 p_icount = dpdt_swapcount_tables[cpu];
96 p_ocount = dpdt_swapcount_tables[cpu] + 1;
97 cplb_addr = (unsigned long *)DCPLB_ADDR0;
98 cplb_data = (unsigned long *)DCPLB_DATA0;
99 }
100
101 buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
102
103 while (*p_addr != 0xffffffff) {
104 entry = cplb_find_entry(cplb_addr, cplb_data, *p_addr, *p_data);
105 if (entry >= 0)
106 used_cplb |= 1 << entry;
107
108 buf += sprintf(buf,
109 "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
110 *p_addr, *p_data, strpage(*p_data),
111 (*p_data & CPLB_VALID) ? 'Y' : 'N',
112 (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
113 *p_ocount);
114
115 p_addr += 2;
116 p_data += 2;
117 p_icount += 2;
118 p_ocount += 2;
119 }
120
121 if (used_cplb != 0xffff) {
122 buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
123
124 for (entry = 0; entry < 16; ++entry)
125 if (0 == ((1 << entry) & used_cplb)) {
126 int flags = cplb_data[entry];
127 buf += sprintf(buf,
128 "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
129 entry, cplb_addr[entry], flags, strpage(flags),
130 (flags & CPLB_VALID) ? 'Y' : 'N',
131 (flags & CPLB_LOCK) ? 'Y' : 'N');
132 }
133 }
134
135 buf += sprintf(buf, "\n");
136
137 return buf;
138}
139
140#endif
141
142static int cplbinfo_proc_output(char *buf, void *data)
143{
144 unsigned int cpu = (unsigned int)data;
145 char *p = buf;
146
147 if (bfin_read_IMEM_CONTROL() & ENICPLB) {
148 p += sprintf(p, "Instruction CPLB entry:\n");
149 p = cplb_print_entry(p, ICPLB, cpu);
150 } else
151 p += sprintf(p, "Instruction CPLB is disabled.\n\n");
152
153 if (bfin_read_DMEM_CONTROL() & ENDCPLB) {
154 p += sprintf(p, "Data CPLB entry:\n");
155 p = cplb_print_entry(p, DCPLB, cpu);
156 } else
157 p += sprintf(p, "Data CPLB is disabled.\n\n");
158
159 return p - buf;
160}
161
162static int cplbinfo_read_proc(char *page, char **start, off_t off,
163 int count, int *eof, void *data)
164{
165 int len = cplbinfo_proc_output(page, data);
166 if (len <= off + count)
167 *eof = 1;
168 *start = page + off;
169 len -= off;
170 return max(min(len, count), 0);
171}
172
173static int __init cplbinfo_init(void)
174{
175 struct proc_dir_entry *parent, *entry;
176 unsigned int cpu;
177 unsigned char str[10];
178
179 parent = proc_mkdir("cplbinfo", NULL);
180 if (!parent)
181 return -ENOMEM;
182
183 for_each_online_cpu(cpu) {
184 sprintf(str, "cpu%u", cpu);
185 entry = create_proc_entry(str, 0, parent);
186 if (!entry)
187 return -ENOMEM;
188
189 entry->read_proc = cplbinfo_read_proc;
190 entry->data = (void *)cpu;
191 }
192
193 return 0;
194}
195late_initcall(cplbinfo_init);