Blackfin arch: SMP supporting patchset: Blackfin CPLB related code
[safe/jmp/linux-2.6] / 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, void *data)
70 {
71         char *p;
72         unsigned int cpu = (unsigned int)data;;
73
74         p = buf;
75
76         p += sprintf(p, "------------- CPLB Information on CPU%u --------------\n\n", cpu);
77         if (bfin_read_IMEM_CONTROL() & ENICPLB) {
78                 p += sprintf(p, "Instruction CPLB entry:\n");
79                 p = cplb_print_entry(p, icplb_tbl[cpu], 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[cpu], 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[cpu], nr_icplb_supv_miss[cpu]);
91         p += sprintf(p, "DCPLB miss: %d\nDCPLB protection fault:%d\n",
92                      nr_dcplb_miss[cpu], nr_dcplb_prot[cpu]);
93         p += sprintf(p, "CPLB flushes: %d\n",
94                      nr_cplb_flush[cpu]);
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, data);
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 *parent, *entry;
119         unsigned int cpu;
120         unsigned char str[10];
121
122         parent = proc_mkdir("cplbinfo", NULL);
123
124         for_each_online_cpu(cpu) {
125                 sprintf(str, "cpu%u", cpu);
126                 entry = create_proc_entry(str, 0, parent);
127                 if (!entry)
128                         return -ENOMEM;
129
130                 entry->read_proc = cplbinfo_read_proc;
131                 entry->data = (void *)cpu;
132         }
133
134         return 0;
135 }
136
137 static void __exit cplbinfo_exit(void)
138 {
139         unsigned int cpu;
140         unsigned char str[20];
141         for_each_online_cpu(cpu) {
142                 sprintf(str, "cplbinfo/cpu%u", cpu);
143                 remove_proc_entry(str, NULL);
144         }
145         remove_proc_entry("cplbinfo", NULL);
146 }
147
148 module_init(cplbinfo_init);
149 module_exit(cplbinfo_exit);