Merge branch 'for_rmk' of git://git.mnementh.co.uk/linux-2.6-im into devel
[sfrench/cifs-2.6.git] / arch / blackfin / kernel / cplb-mpu / 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/cplbinit.h>
40 #include <asm/blackfin.h>
41
42 static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
43
44 static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched)
45 {
46         int i;
47         buf += sprintf(buf, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
48         for (i = 0; i < MAX_CPLBS; i++) {
49                 unsigned long data = tbl[i].data;
50                 unsigned long addr = tbl[i].addr;
51                 if (!(data & CPLB_VALID))
52                         continue;
53
54                 buf +=
55                     sprintf(buf,
56                             "%d\t0x%08lx\t%06lx\t%s\t%c\t%c\t%c\t%c\n",
57                             i, addr, data,
58                             page_size_string_table[(data & 0x30000) >> 16],
59                             (data & CPLB_USER_RD) ? 'Y' : 'N',
60                             (data & CPLB_USER_WR) ? 'Y' : 'N',
61                             (data & CPLB_SUPV_WR) ? 'Y' : 'N',
62                             i < switched ? 'N' : 'Y');
63         }
64         buf += sprintf(buf, "\n");
65
66         return buf;
67 }
68
69 int cplbinfo_proc_output(char *buf)
70 {
71         char *p;
72
73         p = buf;
74
75         p += sprintf(p, "------------------ CPLB Information ------------------\n\n");
76
77         if (bfin_read_IMEM_CONTROL() & ENICPLB) {
78                 p += sprintf(p, "Instruction CPLB entry:\n");
79                 p = cplb_print_entry(p, icplb_tbl, first_switched_icplb);
80         } else
81                 p += sprintf(p, "Instruction CPLB is disabled.\n\n");
82
83         if (1 || bfin_read_DMEM_CONTROL() & ENDCPLB) {
84                 p += sprintf(p, "Data CPLB entry:\n");
85                 p = cplb_print_entry(p, dcplb_tbl, first_switched_dcplb);
86         } else
87                 p += sprintf(p, "Data CPLB is disabled.\n");
88
89         p += sprintf(p, "ICPLB miss: %d\nICPLB supervisor miss: %d\n",
90                      nr_icplb_miss, nr_icplb_supv_miss);
91         p += sprintf(p, "DCPLB miss: %d\nDCPLB protection fault:%d\n",
92                      nr_dcplb_miss, nr_dcplb_prot);
93         p += sprintf(p, "CPLB flushes: %d\n",
94                      nr_cplb_flush);
95
96         return p - buf;
97 }
98
99 static int cplbinfo_read_proc(char *page, char **start, off_t off,
100                               int count, int *eof, void *data)
101 {
102         int len;
103
104         len = cplbinfo_proc_output(page);
105         if (len <= off + count)
106                 *eof = 1;
107         *start = page + off;
108         len -= off;
109         if (len > count)
110                 len = count;
111         if (len < 0)
112                 len = 0;
113         return len;
114 }
115
116 static int __init cplbinfo_init(void)
117 {
118         struct proc_dir_entry *entry;
119
120         entry = create_proc_entry("cplbinfo", 0, NULL);
121         if (!entry)
122                 return -ENOMEM;
123
124         entry->read_proc = cplbinfo_read_proc;
125         entry->data = NULL;
126
127         return 0;
128 }
129
130 static void __exit cplbinfo_exit(void)
131 {
132         remove_proc_entry("cplbinfo", NULL);
133 }
134
135 module_init(cplbinfo_init);
136 module_exit(cplbinfo_exit);