2 * arch/blackfin/kernel/cplbinfo.c - display CPLB status
4 * Copyright 2004-2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
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",
23 "16K", "64K", "16M", "64M",
26 #define page(flags) (((flags) & 0x70000) >> 16)
27 #define strpage(flags) page_strtbl[page(flags)]
29 struct cplbinfo_data
{
33 struct cplb_entry
*tbl
;
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
;
55 addr
= cdata
->tbl
[pos
].addr
;
56 data
= cdata
->tbl
[pos
].data
;
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');
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
;
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;
87 seq_printf(m
, "%cCPLBs are %sabled: 0x%x\n", cdata
->cplb_type
,
88 (cdata
->mem_control
& ENDCPLB
? "en" : "dis"),
90 cplbinfo_print_header(m
);
91 } else if (cplbinfo_nomore(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
))
108 static void cplbinfo_stop(struct seq_file
*m
, void *p
)
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
)
125 unsigned int cpu
= (unsigned long)PDE_DATA(file_inode(file
));
128 struct cplbinfo_data
*cdata
;
130 cplb_type
= cpu
& CPLBINFO_DCPLB_FLAG
? 'D' : 'I';
131 cpu
&= ~CPLBINFO_DCPLB_FLAG
;
133 if (!cpu_online(cpu
))
136 ret
= seq_open_private(file
, &cplbinfo_sops
, sizeof(*cdata
));
139 m
= file
->private_data
;
143 cdata
->cplb_type
= cplb_type
;
144 cplbinfo_seq_init(cdata
, cpu
);
149 static const struct file_operations cplbinfo_fops
= {
150 .open
= cplbinfo_open
,
153 .release
= seq_release_private
,
156 static int __init
cplbinfo_init(void)
158 struct proc_dir_entry
*cplb_dir
, *cpu_dir
;
162 cplb_dir
= proc_mkdir("cplbinfo", NULL
);
166 for_each_possible_cpu(cpu
) {
167 sprintf(buf
, "cpu%i", cpu
);
168 cpu_dir
= proc_mkdir(buf
, cplb_dir
);
172 proc_create_data("icplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
,
174 proc_create_data("dcplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
,
175 (void *)(cpu
| CPLBINFO_DCPLB_FLAG
));
180 late_initcall(cplbinfo_init
);