Merge branches 'release', 'bugzilla-6217', 'bugzilla-6629', 'bugzilla-6933', 'bugzill...
[linux-2.6] / arch / blackfin / kernel / cplb-nompu / cplbinfo.c
1 /*
2  * File:         arch/blackfin/mach-common/cplbinfo.c
3  * Based on:
4  * Author:       Sonic Zhang <sonic.zhang@analog.com>
5  *
6  * Created:      Jan. 2005
7  * Description:  Display CPLB status
8  *
9  * Modified:
10  *               Copyright 2004-2006 Analog Devices Inc.
11  *
12  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, see the file COPYING, or write
26  * to the Free Software Foundation, Inc.,
27  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28  */
29
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <linux/proc_fs.h>
34 #include <linux/uaccess.h>
35
36 #include <asm/current.h>
37 #include <asm/system.h>
38 #include <asm/cplb.h>
39 #include <asm/blackfin.h>
40
41 #define CPLB_I 1
42 #define CPLB_D 2
43
44 #define SYNC_SYS    SSYNC()
45 #define SYNC_CORE   CSYNC()
46
47 #define CPLB_BIT_PAGESIZE 0x30000
48
49 static int page_size_table[4] = {
50         0x00000400,             /* 1K */
51         0x00001000,             /* 4K */
52         0x00100000,             /* 1M */
53         0x00400000              /* 4M */
54 };
55
56 static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
57
58 static int cplb_find_entry(unsigned long *cplb_addr,
59                            unsigned long *cplb_data, unsigned long addr,
60                            unsigned long data)
61 {
62         int ii;
63
64         for (ii = 0; ii < 16; ii++)
65                 if (addr >= cplb_addr[ii] && addr < cplb_addr[ii] +
66                     page_size_table[(cplb_data[ii] & CPLB_BIT_PAGESIZE) >> 16]
67                         && (cplb_data[ii] == data))
68                         return ii;
69
70         return -1;
71 }
72
73 static char *cplb_print_entry(char *buf, int type)
74 {
75         unsigned long *p_addr = dpdt_table;
76         unsigned long *p_data = dpdt_table + 1;
77         unsigned long *p_icount = dpdt_swapcount_table;
78         unsigned long *p_ocount = dpdt_swapcount_table + 1;
79         unsigned long *cplb_addr = (unsigned long *)DCPLB_ADDR0;
80         unsigned long *cplb_data = (unsigned long *)DCPLB_DATA0;
81         int entry = 0, used_cplb = 0;
82
83         if (type == CPLB_I) {
84                 buf += sprintf(buf, "Instruction CPLB entry:\n");
85                 p_addr = ipdt_table;
86                 p_data = ipdt_table + 1;
87                 p_icount = ipdt_swapcount_table;
88                 p_ocount = ipdt_swapcount_table + 1;
89                 cplb_addr = (unsigned long *)ICPLB_ADDR0;
90                 cplb_data = (unsigned long *)ICPLB_DATA0;
91         } else
92                 buf += sprintf(buf, "Data CPLB entry:\n");
93
94         buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
95
96         while (*p_addr != 0xffffffff) {
97                 entry = cplb_find_entry(cplb_addr, cplb_data, *p_addr, *p_data);
98                 if (entry >= 0)
99                         used_cplb |= 1 << entry;
100
101                 buf +=
102                     sprintf(buf,
103                             "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
104                             *p_addr, *p_data,
105                             page_size_string_table[(*p_data & 0x30000) >> 16],
106                             (*p_data & CPLB_VALID) ? 'Y' : 'N',
107                             (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
108                             *p_ocount);
109
110                 p_addr += 2;
111                 p_data += 2;
112                 p_icount += 2;
113                 p_ocount += 2;
114         }
115
116         if (used_cplb != 0xffff) {
117                 buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
118
119                 for (entry = 0; entry < 16; entry++)
120                         if (0 == ((1 << entry) & used_cplb)) {
121                                 int flags = cplb_data[entry];
122                                 buf +=
123                                     sprintf(buf,
124                                             "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
125                                             entry, cplb_addr[entry], flags,
126                                             page_size_string_table[(flags &
127                                                                     0x30000) >>
128                                                                    16],
129                                             (flags & CPLB_VALID) ? 'Y' : 'N',
130                                             (flags & CPLB_LOCK) ? 'Y' : 'N');
131                         }
132         }
133
134         buf += sprintf(buf, "\n");
135
136         return buf;
137 }
138
139 static int cplbinfo_proc_output(char *buf)
140 {
141         char *p;
142
143         p = buf;
144
145         p += sprintf(p, "------------------ CPLB Information ------------------\n\n");
146
147         if (bfin_read_IMEM_CONTROL() & ENICPLB)
148                 p = cplb_print_entry(p, CPLB_I);
149         else
150                 p += sprintf(p, "Instruction CPLB is disabled.\n\n");
151
152         if (bfin_read_DMEM_CONTROL() & ENDCPLB)
153                 p = cplb_print_entry(p, CPLB_D);
154         else
155                 p += sprintf(p, "Data CPLB is disabled.\n");
156
157         return p - buf;
158 }
159
160 static int cplbinfo_read_proc(char *page, char **start, off_t off,
161                               int count, int *eof, void *data)
162 {
163         int len;
164
165         len = cplbinfo_proc_output(page);
166         if (len <= off + count)
167                 *eof = 1;
168         *start = page + off;
169         len -= off;
170         if (len > count)
171                 len = count;
172         if (len < 0)
173                 len = 0;
174         return len;
175 }
176
177 static int cplbinfo_write_proc(struct file *file, const char __user *buffer,
178                                unsigned long count, void *data)
179 {
180         printk(KERN_INFO "Reset the CPLB swap in/out counts.\n");
181         memset(ipdt_swapcount_table, 0, MAX_SWITCH_I_CPLBS * sizeof(unsigned long));
182         memset(dpdt_swapcount_table, 0, MAX_SWITCH_D_CPLBS * sizeof(unsigned long));
183
184         return count;
185 }
186
187 static int __init cplbinfo_init(void)
188 {
189         struct proc_dir_entry *entry;
190
191         entry = create_proc_entry("cplbinfo", 0, NULL);
192         if (!entry)
193                 return -ENOMEM;
194
195         entry->read_proc = cplbinfo_read_proc;
196         entry->write_proc = cplbinfo_write_proc;
197         entry->data = NULL;
198
199         return 0;
200 }
201
202 static void __exit cplbinfo_exit(void)
203 {
204         remove_proc_entry("cplbinfo", NULL);
205 }
206
207 module_init(cplbinfo_init);
208 module_exit(cplbinfo_exit);