bfin cache: dcplb map: add 16M dcplb map for BF60x
[linux-2.6.git] / arch / blackfin / kernel / cplbinfo.c
blob49b28ed29737e0f4fd137532740e87b7054f24b2
1 /*
2 * arch/blackfin/kernel/cplbinfo.c - display CPLB status
4 * Copyright 2004-2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
7 */
9 #include <linux/ctype.h>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/proc_fs.h>
14 #include <linux/seq_file.h>
15 #include <linux/uaccess.h>
17 #include <asm/cplbinit.h>
18 #include <asm/blackfin.h>
20 static char const page_strtbl[][4] = {
21 "1K", "4K", "1M", "4M",
22 #ifdef CONFIG_BF60x
23 "16K", "64K", "16M", "64M",
24 #endif
26 #define page(flags) (((flags) & 0x70000) >> 16)
27 #define strpage(flags) page_strtbl[page(flags)]
29 struct cplbinfo_data {
30 loff_t pos;
31 char cplb_type;
32 u32 mem_control;
33 struct cplb_entry *tbl;
34 int switched;
37 static void cplbinfo_print_header(struct seq_file *m)
39 seq_printf(m, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
42 static int cplbinfo_nomore(struct cplbinfo_data *cdata)
44 return cdata->pos >= MAX_CPLBS;
47 static int cplbinfo_show(struct seq_file *m, void *p)
49 struct cplbinfo_data *cdata;
50 unsigned long data, addr;
51 loff_t pos;
53 cdata = p;
54 pos = cdata->pos;
55 addr = cdata->tbl[pos].addr;
56 data = cdata->tbl[pos].data;
58 seq_printf(m,
59 "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
60 (int)pos, addr, data, strpage(data),
61 (data & CPLB_USER_RD) ? 'Y' : 'N',
62 (data & CPLB_USER_WR) ? 'Y' : 'N',
63 (data & CPLB_SUPV_WR) ? 'Y' : 'N',
64 pos < cdata->switched ? 'N' : 'Y');
66 return 0;
69 static void cplbinfo_seq_init(struct cplbinfo_data *cdata, unsigned int cpu)
71 if (cdata->cplb_type == 'I') {
72 cdata->mem_control = bfin_read_IMEM_CONTROL();
73 cdata->tbl = icplb_tbl[cpu];
74 cdata->switched = first_switched_icplb;
75 } else {
76 cdata->mem_control = bfin_read_DMEM_CONTROL();
77 cdata->tbl = dcplb_tbl[cpu];
78 cdata->switched = first_switched_dcplb;
82 static void *cplbinfo_start(struct seq_file *m, loff_t *pos)
84 struct cplbinfo_data *cdata = m->private;
86 if (!*pos) {
87 seq_printf(m, "%cCPLBs are %sabled: 0x%x\n", cdata->cplb_type,
88 (cdata->mem_control & ENDCPLB ? "en" : "dis"),
89 cdata->mem_control);
90 cplbinfo_print_header(m);
91 } else if (cplbinfo_nomore(cdata))
92 return NULL;
94 get_cpu();
95 return cdata;
98 static void *cplbinfo_next(struct seq_file *m, void *p, loff_t *pos)
100 struct cplbinfo_data *cdata = p;
101 cdata->pos = ++(*pos);
102 if (cplbinfo_nomore(cdata))
103 return NULL;
104 else
105 return cdata;
108 static void cplbinfo_stop(struct seq_file *m, void *p)
110 put_cpu();
113 static const struct seq_operations cplbinfo_sops = {
114 .start = cplbinfo_start,
115 .next = cplbinfo_next,
116 .stop = cplbinfo_stop,
117 .show = cplbinfo_show,
120 #define CPLBINFO_DCPLB_FLAG 0x80000000
122 static int cplbinfo_open(struct inode *inode, struct file *file)
124 struct proc_dir_entry *pde = PDE(file_inode(file));
125 char cplb_type;
126 unsigned int cpu;
127 int ret;
128 struct seq_file *m;
129 struct cplbinfo_data *cdata;
131 cpu = (unsigned int)pde->data;
132 cplb_type = cpu & CPLBINFO_DCPLB_FLAG ? 'D' : 'I';
133 cpu &= ~CPLBINFO_DCPLB_FLAG;
135 if (!cpu_online(cpu))
136 return -ENODEV;
138 ret = seq_open_private(file, &cplbinfo_sops, sizeof(*cdata));
139 if (ret)
140 return ret;
141 m = file->private_data;
142 cdata = m->private;
144 cdata->pos = 0;
145 cdata->cplb_type = cplb_type;
146 cplbinfo_seq_init(cdata, cpu);
148 return 0;
151 static const struct file_operations cplbinfo_fops = {
152 .open = cplbinfo_open,
153 .read = seq_read,
154 .llseek = seq_lseek,
155 .release = seq_release_private,
158 static int __init cplbinfo_init(void)
160 struct proc_dir_entry *cplb_dir, *cpu_dir;
161 char buf[10];
162 unsigned int cpu;
164 cplb_dir = proc_mkdir("cplbinfo", NULL);
165 if (!cplb_dir)
166 return -ENOMEM;
168 for_each_possible_cpu(cpu) {
169 sprintf(buf, "cpu%i", cpu);
170 cpu_dir = proc_mkdir(buf, cplb_dir);
171 if (!cpu_dir)
172 return -ENOMEM;
174 proc_create_data("icplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
175 (void *)cpu);
176 proc_create_data("dcplb", S_IRUGO, cpu_dir, &cplbinfo_fops,
177 (void *)(cpu | CPLBINFO_DCPLB_FLAG));
180 return 0;
182 late_initcall(cplbinfo_init);