Blackfin arch: fix spurious newline in header
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / blackfin / mach-common / cplbinfo.c
bloba4f0b428a34da88f1bcd0543973f46f3bf5dbb34
1 /*
2 * File: arch/blackfin/mach-common/cplbinfo.c
3 * Based on:
4 * Author: Sonic Zhang <sonic.zhang@analog.com>
6 * Created: Jan. 2005
7 * Description: Display CPLB status
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
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>
36 #include <asm/current.h>
37 #include <asm/system.h>
38 #include <asm/cplb.h>
39 #include <asm/blackfin.h>
41 #define CPLB_I 1
42 #define CPLB_D 2
44 #define SYNC_SYS SSYNC()
45 #define SYNC_CORE CSYNC()
47 #define CPLB_BIT_PAGESIZE 0x30000
49 static int page_size_table[4] = {
50 0x00000400, /* 1K */
51 0x00001000, /* 4K */
52 0x00100000, /* 1M */
53 0x00400000 /* 4M */
56 static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
58 static int cplb_find_entry(unsigned long *cplb_addr,
59 unsigned long *cplb_data, unsigned long addr,
60 unsigned long data)
62 int ii;
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;
70 return -1;
73 static char *cplb_print_entry(char *buf, int type)
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;
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");
94 buf += sprintf(buf, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
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;
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);
110 p_addr += 2;
111 p_data += 2;
112 p_icount += 2;
113 p_ocount += 2;
116 if (used_cplb != 0xffff) {
117 buf += sprintf(buf, "Unused/mismatched CPLBs:\n");
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');
134 buf += sprintf(buf, "\n");
136 return buf;
139 static int cplbinfo_proc_output(char *buf)
141 char *p;
143 p = buf;
145 p += sprintf(p, "------------------ CPLB Information ------------------\n\n");
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");
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");
157 return p - buf;
160 static int cplbinfo_read_proc(char *page, char **start, off_t off,
161 int count, int *eof, void *data)
163 int len;
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;
177 static int cplbinfo_write_proc(struct file *file, const char __user *buffer,
178 unsigned long count, void *data)
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));
184 return count;
187 static int __init cplbinfo_init(void)
189 struct proc_dir_entry *entry;
191 entry = create_proc_entry("cplbinfo", 0, NULL);
192 if (!entry)
193 return -ENOMEM;
195 entry->read_proc = cplbinfo_read_proc;
196 entry->write_proc = cplbinfo_write_proc;
197 entry->data = NULL;
199 return 0;
202 static void __exit cplbinfo_exit(void)
204 remove_proc_entry("cplbinfo", NULL);
207 module_init(cplbinfo_init);
208 module_exit(cplbinfo_exit);