3f0080954e6f17bd15e3a69f40152f29fd2003c7
[linux-2.6.git] / 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/cplbinit.h>
37 #include <asm/blackfin.h>
38
39 #define CPLB_I 1
40 #define CPLB_D 2
41
42 #define SYNC_SYS    SSYNC()
43 #define SYNC_CORE   CSYNC()
44
45 #define CPLB_BIT_PAGESIZE 0x30000
46
47 static int page_size_table[4] = {
48         0x00000400,             /* 1K */
49         0x00001000,             /* 4K */
50         0x00100000,             /* 1M */
51         0x00400000              /* 4M */
52 };
53
54 static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
55
56 static int cplb_find_entry(unsigned long *cplb_addr,
57                            unsigned long *cplb_data, unsigned long addr,
58                            unsigned long data)
59 {
60         int ii;
61
62         for (ii = 0; ii < 16; ii++)
63                 if (addr >= cplb_addr[ii] && addr < cplb_addr[ii] +
64                     page_size_table[(cplb_data[ii] & CPLB_BIT_PAGESIZE) >> 16]
65                         && (cplb_data[ii] == data))
66                         return ii;
67
68         return -1;
69 }
70
71 static char *cplb_print_entry(char *buf, int type, unsigned int cpu)
72 {
73         unsigned long *p_addr = dpdt_tables[cpu];
74         unsigned long *p_data = dpdt_tables[cpu] + 1;
75         unsigned long *p_icount = dpdt_swapcount_tables[cpu];
76         unsigned long *p_ocount = dpdt_swapcount_tables[cpu] + 1;
77         unsigned long *cplb_addr = (unsigned long *)DCPLB_ADDR0;
78         unsigned long *cplb_data = (unsigned long *)DCPLB_DATA0;
79         int entry = 0, used_cplb = 0;
80
81         if (type == CPLB_I) {
82                 buf += sprintf(buf, "Instruction CPLB entry:\n");
83                 p_addr = ipdt_tables[cpu];
84                 p_data = ipdt_tables[cpu] + 1;
85                 p_icount = ipdt_swapcount_tables[cpu];
86                 p_ocount = ipdt_swapcount_tables[cpu] + 1;
87                 cplb_addr = (unsigned long *)ICPLB_ADDR0;
88                 cplb_data = (unsigned long *)ICPLB_DATA0;
89         } else
90                 buf += sprintf(buf, "Data CPLB entry:\n");
91
92         buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
93
94         while (*p_addr != 0xffffffff) {
95                 entry = cplb_find_entry(cplb_addr, cplb_data, *p_addr, *p_data);
96                 if (entry >= 0)
97                         used_cplb |= 1 << entry;
98
99                 buf +=
100                     sprintf(buf,
101                             "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
102                             *p_addr, *p_data,
103                             page_size_string_table[(*p_data & 0x30000) >> 16],
104                             (*p_data & CPLB_VALID) ? 'Y' : 'N',
105                             (*p_data & CPLB_LOCK) ? 'Y' : 'N', entry, *p_icount,
106                             *p_ocount);
107
108                 p_addr += 2;
109                 p_data += 2;
110                 p_icount += 2;
111                 p_ocount += 2;
112         }
113
114         if (used_cplb != 0xffff) {
115                 buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
116
117                 for (entry = 0; entry < 16; entry++)
118                         if (0 == ((1 << entry) & used_cplb)) {
119                                 int flags = cplb_data[entry];
120                                 buf +=
121                                     sprintf(buf,
122                                             "%2d: 0x%08lx\t0x%05x\t%s\t%c\t%c\n",
123                                             entry, cplb_addr[entry], flags,
124                                             page_size_string_table[(flags &
125                                                                     0x30000) >>
126                                                                    16],
127                                             (flags & CPLB_VALID) ? 'Y' : 'N',
128                                             (flags & CPLB_LOCK) ? 'Y' : 'N');
129                         }
130         }
131
132         buf += sprintf(buf, "\n");
133
134         return buf;
135 }
136
137 static int cplbinfo_proc_output(char *buf, void *data)
138 {
139         unsigned int cpu = (unsigned int)data;
140         char *p;
141
142         p = buf;
143
144         p += sprintf(p, "------------- CPLB Information on CPU%u--------------\n\n", cpu);
145
146         if (bfin_read_IMEM_CONTROL() & ENICPLB)
147                 p = cplb_print_entry(p, CPLB_I, cpu);
148         else
149                 p += sprintf(p, "Instruction CPLB is disabled.\n\n");
150
151         if (bfin_read_DMEM_CONTROL() & ENDCPLB)
152                 p = cplb_print_entry(p, CPLB_D, cpu);
153         else
154                 p += sprintf(p, "Data CPLB is disabled.\n");
155         return p - buf;
156 }
157
158 static int cplbinfo_read_proc(char *page, char **start, off_t off,
159                               int count, int *eof, void *data)
160 {
161         int len;
162
163         len = cplbinfo_proc_output(page, data);
164         if (len <= off + count)
165                 *eof = 1;
166         *start = page + off;
167         len -= off;
168         if (len > count)
169                 len = count;
170         if (len < 0)
171                 len = 0;
172         return len;
173 }
174
175 static int __init cplbinfo_init(void)
176 {
177         struct proc_dir_entry *parent, *entry;
178         unsigned int cpu;
179         unsigned char str[10];
180
181         parent = proc_mkdir("cplbinfo", NULL);
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 }
195
196 static void __exit cplbinfo_exit(void)
197 {
198         unsigned int cpu;
199         unsigned char str[20];
200         for_each_online_cpu(cpu) {
201                 sprintf(str, "cplbinfo/cpu%u", cpu);
202                 remove_proc_entry(str, NULL);
203         }
204         remove_proc_entry("cplbinfo", NULL);
205 }
206
207 module_init(cplbinfo_init);
208 module_exit(cplbinfo_exit);