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/cplbinit.h>
37 #include <asm/blackfin.h>
42 #define SYNC_SYS SSYNC()
43 #define SYNC_CORE CSYNC()
45 #define CPLB_BIT_PAGESIZE 0x30000
47 static int page_size_table
[4] = {
54 static char page_size_string_table
[][4] = { "1K", "4K", "1M", "4M" };
56 static int cplb_find_entry(unsigned long *cplb_addr
,
57 unsigned long *cplb_data
, unsigned long addr
,
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
))
71 static char *cplb_print_entry(char *buf
, int type
)
73 unsigned long *p_addr
= dpdt_table
;
74 unsigned long *p_data
= dpdt_table
+ 1;
75 unsigned long *p_icount
= dpdt_swapcount_table
;
76 unsigned long *p_ocount
= dpdt_swapcount_table
+ 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;
82 buf
+= sprintf(buf
, "Instruction CPLB entry:\n");
84 p_data
= ipdt_table
+ 1;
85 p_icount
= ipdt_swapcount_table
;
86 p_ocount
= ipdt_swapcount_table
+ 1;
87 cplb_addr
= (unsigned long *)ICPLB_ADDR0
;
88 cplb_data
= (unsigned long *)ICPLB_DATA0
;
90 buf
+= sprintf(buf
, "Data CPLB entry:\n");
92 buf
+= sprintf(buf
, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
94 while (*p_addr
!= 0xffffffff) {
95 entry
= cplb_find_entry(cplb_addr
, cplb_data
, *p_addr
, *p_data
);
97 used_cplb
|= 1 << entry
;
101 "0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
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
,
114 if (used_cplb
!= 0xffff) {
115 buf
+= sprintf(buf
, "Unused/mismatched CPLBs:\n");
117 for (entry
= 0; entry
< 16; entry
++)
118 if (0 == ((1 << entry
) & used_cplb
)) {
119 int flags
= cplb_data
[entry
];
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
&
127 (flags
& CPLB_VALID
) ? 'Y' : 'N',
128 (flags
& CPLB_LOCK
) ? 'Y' : 'N');
132 buf
+= sprintf(buf
, "\n");
137 static int cplbinfo_proc_output(char *buf
)
143 p
+= sprintf(p
, "------------------ CPLB Information ------------------\n\n");
145 if (bfin_read_IMEM_CONTROL() & ENICPLB
)
146 p
= cplb_print_entry(p
, CPLB_I
);
148 p
+= sprintf(p
, "Instruction CPLB is disabled.\n\n");
150 if (bfin_read_DMEM_CONTROL() & ENDCPLB
)
151 p
= cplb_print_entry(p
, CPLB_D
);
153 p
+= sprintf(p
, "Data CPLB is disabled.\n");
158 static int cplbinfo_read_proc(char *page
, char **start
, off_t off
,
159 int count
, int *eof
, void *data
)
163 len
= cplbinfo_proc_output(page
);
164 if (len
<= off
+ count
)
175 static int __init
cplbinfo_init(void)
177 struct proc_dir_entry
*entry
;
179 entry
= create_proc_entry("cplbinfo", 0, NULL
);
183 entry
->read_proc
= cplbinfo_read_proc
;
189 static void __exit
cplbinfo_exit(void)
191 remove_proc_entry("cplbinfo", NULL
);
194 module_init(cplbinfo_init
);
195 module_exit(cplbinfo_exit
);