aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel/cplb-mpu/cplbinfo.c
blob: 00cb2cf3a42053ab4125b145bfede8945f9d0583 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * File:         arch/blackfin/mach-common/cplbinfo.c
 * Based on:
 * Author:       Sonic Zhang <sonic.zhang@analog.com>
 *
 * Created:      Jan. 2005
 * Description:  Display CPLB status
 *
 * Modified:
 *               Copyright 2004-2006 Analog Devices Inc.
 *
 * Bugs:         Enter bugs at http://blackfin.uclinux.org/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see the file COPYING, or write
 * to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>

#include <asm/current.h>
#include <asm/system.h>
#include <asm/cplb.h>
#include <asm/cplbinit.h>
#include <asm/blackfin.h>

static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };

static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched)
{
	int i;
	buf += sprintf(buf, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
	for (i = 0; i < MAX_CPLBS; i++) {
		unsigned long data = tbl[i].data;
		unsigned long addr = tbl[i].addr;
		if (!(data & CPLB_VALID))
			continue;

		buf +=
		    sprintf(buf,
			    "%d\t0x%08lx\t%06lx\t%s\t%c\t%c\t%c\t%c\n",
			    i, addr, data,
			    page_size_string_table[(data & 0x30000) >> 16],
			    (data & CPLB_USER_RD) ? 'Y' : 'N',
			    (data & CPLB_USER_WR) ? 'Y' : 'N',
			    (data & CPLB_SUPV_WR) ? 'Y' : 'N',
			    i < switched ? 'N' : 'Y');
	}
	buf += sprintf(buf, "\n");

	return buf;
}

int cplbinfo_proc_output(char *buf, void *data)
{
	char *p;
	unsigned int cpu = (unsigned int)data;;

	p = buf;

	p += sprintf(p, "------------- CPLB Information on CPU%u --------------\n\n", cpu);
	if (bfin_read_IMEM_CONTROL() & ENICPLB) {
		p += sprintf(p, "Instruction CPLB entry:\n");
		p = cplb_print_entry(p, icplb_tbl[cpu], first_switched_icplb);
	} else
		p += sprintf(p, "Instruction CPLB is disabled.\n\n");

	if (1 || bfin_read_DMEM_CONTROL() & ENDCPLB) {
		p += sprintf(p, "Data CPLB entry:\n");
		p = cplb_print_entry(p, dcplb_tbl[cpu], first_switched_dcplb);
	} else
		p += sprintf(p, "Data CPLB is disabled.\n");

	p += sprintf(p, "ICPLB miss: %d\nICPLB supervisor miss: %d\n",
		     nr_icplb_miss[cpu], nr_icplb_supv_miss[cpu]);
	p += sprintf(p, "DCPLB miss: %d\nDCPLB protection fault:%d\n",
		     nr_dcplb_miss[cpu], nr_dcplb_prot[cpu]);
	p += sprintf(p, "CPLB flushes: %d\n",
		     nr_cplb_flush[cpu]);

	return p - buf;
}

static int cplbinfo_read_proc(char *page, char **start, off_t off,
			      int count, int *eof, void *data)
{
	int len;

	len = cplbinfo_proc_output(page, data);
	if (len <= off + count)
		*eof = 1;
	*start = page + off;
	len -= off;
	if (len > count)
		len = count;
	if (len < 0)
		len = 0;
	return len;
}

static int __init cplbinfo_init(void)
{
	struct proc_dir_entry *parent, *entry;
	unsigned int cpu;
	unsigned char str[10];

	parent = proc_mkdir("cplbinfo", NULL);

	for_each_online_cpu(cpu) {
		sprintf(str, "cpu%u", cpu);
		entry = create_proc_entry(str, 0, parent);
		if (!entry)
			return -ENOMEM;

		entry->read_proc = cplbinfo_read_proc;
		entry->data = (void *)cpu;
	}

	return 0;
}

static void __exit cplbinfo_exit(void)
{
	unsigned int cpu;
	unsigned char str[20];
	for_each_online_cpu(cpu) {
		sprintf(str, "cplbinfo/cpu%u", cpu);
		remove_proc_entry(str, NULL);
	}
	remove_proc_entry("cplbinfo", NULL);
}

module_init(cplbinfo_init);
module_exit(cplbinfo_exit);