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
[][3] = { "1K", "4K", "1M", "4M" };
21 #define page(flags) (((flags) & 0x30000) >> 16)
22 #define strpage(flags) page_strtbl[page(flags)]
24 struct cplbinfo_data
{
28 struct cplb_entry
*tbl
;
32 static void cplbinfo_print_header(struct seq_file
*m
)
34 seq_printf(m
, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
37 static int cplbinfo_nomore(struct cplbinfo_data
*cdata
)
39 return cdata
->pos
>= MAX_CPLBS
;
42 static int cplbinfo_show(struct seq_file
*m
, void *p
)
44 struct cplbinfo_data
*cdata
;
45 unsigned long data
, addr
;
50 addr
= cdata
->tbl
[pos
].addr
;
51 data
= cdata
->tbl
[pos
].data
;
54 "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
55 (int)pos
, addr
, data
, strpage(data
),
56 (data
& CPLB_USER_RD
) ? 'Y' : 'N',
57 (data
& CPLB_USER_WR
) ? 'Y' : 'N',
58 (data
& CPLB_SUPV_WR
) ? 'Y' : 'N',
59 pos
< cdata
->switched
? 'N' : 'Y');
64 static void cplbinfo_seq_init(struct cplbinfo_data
*cdata
, unsigned int cpu
)
66 if (cdata
->cplb_type
== 'I') {
67 cdata
->mem_control
= bfin_read_IMEM_CONTROL();
68 cdata
->tbl
= icplb_tbl
[cpu
];
69 cdata
->switched
= first_switched_icplb
;
71 cdata
->mem_control
= bfin_read_DMEM_CONTROL();
72 cdata
->tbl
= dcplb_tbl
[cpu
];
73 cdata
->switched
= first_switched_dcplb
;
77 static void *cplbinfo_start(struct seq_file
*m
, loff_t
*pos
)
79 struct cplbinfo_data
*cdata
= m
->private;
82 seq_printf(m
, "%cCPLBs are %sabled: 0x%x\n", cdata
->cplb_type
,
83 (cdata
->mem_control
& ENDCPLB
? "en" : "dis"),
85 cplbinfo_print_header(m
);
86 } else if (cplbinfo_nomore(cdata
))
93 static void *cplbinfo_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
95 struct cplbinfo_data
*cdata
= p
;
96 cdata
->pos
= ++(*pos
);
97 if (cplbinfo_nomore(cdata
))
103 static void cplbinfo_stop(struct seq_file
*m
, void *p
)
108 static const struct seq_operations cplbinfo_sops
= {
109 .start
= cplbinfo_start
,
110 .next
= cplbinfo_next
,
111 .stop
= cplbinfo_stop
,
112 .show
= cplbinfo_show
,
115 #define CPLBINFO_DCPLB_FLAG 0x80000000
117 static int cplbinfo_open(struct inode
*inode
, struct file
*file
)
119 struct proc_dir_entry
*pde
= PDE(file
->f_path
.dentry
->d_inode
);
124 struct cplbinfo_data
*cdata
;
126 cpu
= (unsigned int)pde
->data
;
127 cplb_type
= cpu
& CPLBINFO_DCPLB_FLAG
? 'D' : 'I';
128 cpu
&= ~CPLBINFO_DCPLB_FLAG
;
130 if (!cpu_online(cpu
))
133 ret
= seq_open_private(file
, &cplbinfo_sops
, sizeof(*cdata
));
136 m
= file
->private_data
;
140 cdata
->cplb_type
= cplb_type
;
141 cplbinfo_seq_init(cdata
, cpu
);
146 static const struct file_operations cplbinfo_fops
= {
147 .open
= cplbinfo_open
,
150 .release
= seq_release_private
,
153 static int __init
cplbinfo_init(void)
155 struct proc_dir_entry
*cplb_dir
, *cpu_dir
;
159 cplb_dir
= proc_mkdir("cplbinfo", NULL
);
163 for_each_possible_cpu(cpu
) {
164 sprintf(buf
, "cpu%i", cpu
);
165 cpu_dir
= proc_mkdir(buf
, cplb_dir
);
169 proc_create_data("icplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
,
171 proc_create_data("dcplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
,
172 (void *)(cpu
| CPLBINFO_DCPLB_FLAG
));
177 late_initcall(cplbinfo_init
);