2 * File: arch/blackfin/mach-common/cplbinfo.c
4 * Author: Sonic Zhang <sonic.zhang@analog.com>
7 * Description: Display CPLB status
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>
39 #include <asm/blackfin.h>
44 #define SYNC_SYS SSYNC()
45 #define SYNC_CORE CSYNC()
47 #define CPLB_BIT_PAGESIZE 0x30000
49 static int page_size_table
[4] = {
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
,
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
))
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;
84 buf
+= sprintf(buf
, "Instruction CPLB entry:\n");
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
;
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
);
99 used_cplb
|= 1 << entry
;
103 "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
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
,
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
];
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
&
129 (flags
& CPLB_VALID
) ? 'Y' : 'N',
130 (flags
& CPLB_LOCK
) ? 'Y' : 'N');
134 buf
+= sprintf(buf
, "\n");
139 static int cplbinfo_proc_output(char *buf
)
145 p
+= sprintf(p
, "------------------ CPLB Information ------------------\n\n");
147 if (bfin_read_IMEM_CONTROL() & ENICPLB
)
148 p
= cplb_print_entry(p
, CPLB_I
);
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
);
155 p
+= sprintf(p
, "Data CPLB is disabled.\n");
160 static int cplbinfo_read_proc(char *page
, char **start
, off_t off
,
161 int count
, int *eof
, void *data
)
165 len
= cplbinfo_proc_output(page
);
166 if (len
<= off
+ count
)
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));
187 static int __init
cplbinfo_init(void)
189 struct proc_dir_entry
*entry
;
191 entry
= create_proc_entry("cplbinfo", 0, NULL
);
195 entry
->read_proc
= cplbinfo_read_proc
;
196 entry
->write_proc
= cplbinfo_write_proc
;
202 static void __exit
cplbinfo_exit(void)
204 remove_proc_entry("cplbinfo", NULL
);
207 module_init(cplbinfo_init
);
208 module_exit(cplbinfo_exit
);