aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel/cplbinfo.c
blob: 1d3bbec1a195dfb7e54eecb0e2519362e322c383 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
 * arch/blackfin/kernel/cplbinfo.c - display CPLB status
 *
 * Copyright 2004-2008 Analog Devices Inc.
 * Licensed under the GPL-2 or later.
 */

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

#include <asm/cplbinit.h>
#include <asm/blackfin.h>

static char const page_strtbl[][3] = { "1K", "4K", "1M", "4M" };
#define page(flags)    (((flags) & 0x30000) >> 16)
#define strpage(flags) page_strtbl[page(flags)]

#ifdef CONFIG_MPU

struct cplbinfo_data {
	loff_t pos;
	char cplb_type;
	u32 mem_control;
	struct cplb_entry *tbl;
	int switched;
};

static void cplbinfo_print_header(struct seq_file *m)
{
	seq_printf(m, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
}

static int cplbinfo_nomore(struct cplbinfo_data *cdata)
{
	return cdata->pos >= MAX_CPLBS;
}

static int cplbinfo_show(struct seq_file *m, void *p)
{
	struct cplbinfo_data *cdata;
	unsigned long data, addr;
	loff_t pos;

	cdata = p;
	pos = cdata->pos;
	addr = cdata->tbl[pos].addr;
	data = cdata->tbl[pos].data;

	seq_printf(m,
		"%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
		(int)pos, addr, data, strpage(data),
		(data & CPLB_USER_RD) ? 'Y' : 'N',
		(data & CPLB_USER_WR) ? 'Y' : 'N',
		(data & CPLB_SUPV_WR) ? 'Y' : 'N',
		pos < cdata->switched ? 'N' : 'Y');

	return 0;
}

static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
{
	if (cdata->cplb_type == 'I') {
		cdata->mem_control = bfin_read_IMEM_CONTROL();
		cdata->tbl = icplb_tbl[cpu];
		cdata->switched = first_switched_icplb;
	} else {
		cdata->mem_control = bfin_read_DMEM_CONTROL();
		cdata->tbl = dcplb_tbl[cpu];
		cdata->switched = first_switched_dcplb;
	}
}

#else

struct cplbinfo_data {
	loff_t pos;
	char cplb_type;
	u32 mem_control;
	unsigned long *pdt_tables, *pdt_swapcount;
	unsigned long cplb_addr, cplb_data;
};

extern int page_size_table[];

static int cplb_find_entry(unsigned long addr_tbl, unsigned long data_tbl,
                           unsigned long addr_find, unsigned long data_find)
{
	int i;

	for (i = 0; i < 16; ++i) {
		unsigned long cplb_addr = bfin_read32(addr_tbl + i * 4);
		unsigned long cplb_data = bfin_read32(data_tbl + i * 4);
		if (addr_find >= cplb_addr &&
		    addr_find < cplb_addr + page_size_table[page(cplb_data)] &&
		    cplb_data == data_find)
			return i;
	}

	return -1;
}

static void cplbinfo_print_header(struct seq_file *m)
{
	seq_printf(m, "Address\t\tData\tSize\tValid\tLocked\tSwapin\tiCount\toCount\n");
}

static int cplbinfo_nomore(struct cplbinfo_data *cdata)
{
	return cdata->pdt_tables[cdata->pos * 2] == 0xffffffff;
}

static int cplbinfo_show(struct seq_file *m, void *p)
{
	struct cplbinfo_data *cdata;
	unsigned long data, addr;
	int entry;
	loff_t pos;

	cdata = p;
	pos = cdata->pos * 2;
	addr = cdata->pdt_tables[pos];
	data = cdata->pdt_tables[pos + 1];
	entry = cplb_find_entry(cdata->cplb_addr, cdata->cplb_data, addr, data);

	seq_printf(m,
		"0x%08lx\t0x%05lx\t%s\t%c\t%c\t%2d\t%ld\t%ld\n",
		addr, data, strpage(data),
		(data & CPLB_VALID) ? 'Y' : 'N',
		(data & CPLB_LOCK) ? 'Y' : 'N', entry,
		cdata->pdt_swapcount[pos],
		cdata->pdt_swapcount[pos + 1]);

	return 0;
}

static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
{
	if (cdata->cplb_type == 'I') {
		cdata->mem_control = bfin_read_IMEM_CONTROL();
		cdata->pdt_tables = ipdt_tables[cpu];
		cdata->pdt_swapcount = ipdt_swapcount_tables[cpu];
		cdata->cplb_addr = ICPLB_ADDR0;
		cdata->cplb_data = ICPLB_DATA0;
	} else {
		cdata->mem_control = bfin_read_DMEM_CONTROL();
		cdata->pdt_tables = dpdt_tables[cpu];
		cdata->pdt_swapcount = dpdt_swapcount_tables[cpu];
		cdata->cplb_addr = DCPLB_ADDR0;
		cdata->cplb_data = DCPLB_DATA0;
	}
}

#endif

static void *cplbinfo_start(struct seq_file *m, loff_t *pos)
{
	struct cplbinfo_data *cdata = m->private;

	if (!*pos) {
		seq_printf(m, "%cCPLBs are %sabled: 0x%x\n", cdata->cplb_type,
			(cdata->mem_control & ENDCPLB ? "en" : "dis"),
			cdata->mem_control);
		cplbinfo_print_header(m);
	} else if (cplbinfo_nomore(cdata))
		return NULL;

	get_cpu();
	return cdata;
}

static void *cplbinfo_next(struct seq_file *m, void *p, loff_t *pos)
{
	struct cplbinfo_data *cdata = p;
	cdata->pos = ++(*pos);
	if (cplbinfo_nomore(cdata))
		return NULL;
	else
		return cdata;
}

static void cplbinfo_stop(struct seq_file *m, void *p)
{
	put_cpu();
}

static const struct seq_operations cplbinfo_sops = {
	.start = cplbinfo_start,
	.next  = cplbinfo_next,
	.stop  = cplbinfo_stop,
	.show  = cplbinfo_show,
};

static int cplbinfo_open(struct inode *inode, struct file *file)
{
	char buf[256], *path, *p;
	unsigned int cpu;
	char *s_cpu, *s_cplb;
	int ret;
	struct seq_file *m;
	struct cplbinfo_data *cdata;

	path = d_path(&file->f_path, buf, sizeof(buf));
	if (IS_ERR(path))
		return PTR_ERR(path);
	s_cpu = strstr(path, "/cpu");
	s_cplb = strrchr(path, '/');
	if (!s_cpu || !s_cplb)
		return -EINVAL;

	cpu = simple_strtoul(s_cpu + 4, &p, 10);
	if (!cpu_online(cpu))
		return -ENODEV;

	ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
	if (ret)
		return ret;
	m = file->private_data;
	cdata = m->private;

	cdata->pos = 0;
	cdata->cplb_type = toupper(s_cplb[1]);
	cplbinfo_seq_init(cdata, cpu);

	return 0;
}

static const struct file_operations cplbinfo_fops = {
	.open    = cplbinfo_open,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = seq_release_private,
};

static int __init cplbinfo_init(void)
{
	struct proc_dir_entry *cplb_dir, *cpu_dir;
	char buf[10];
	unsigned int cpu;

	cplb_dir = proc_mkdir("cplbinfo", NULL);
	if (!cplb_dir)
		return -ENOMEM;

	for_each_possible_cpu(cpu) {
		sprintf(buf, "cpu%i", cpu);
		cpu_dir = proc_mkdir(buf, cplb_dir);
		if (!cpu_dir)
			return -ENOMEM;

		proc_create("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
		proc_create("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops);
	}

	return 0;
}
late_initcall(cplbinfo_init);