2 * arch/blackfin/kernel/cplbinfo.c - display CPLB status
4 * Copyright 2004-2008 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
8 #include <linux/ctype.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/proc_fs.h>
13 #include <linux/seq_file.h>
14 #include <linux/uaccess.h>
16 #include <asm/cplbinit.h>
17 #include <asm/blackfin.h>
19 static char const page_strtbl
[][3] = { "1K", "4K", "1M", "4M" };
20 #define page(flags) (((flags) & 0x30000) >> 16)
21 #define strpage(flags) page_strtbl[page(flags)]
23 struct cplbinfo_data
{
27 struct cplb_entry
*tbl
;
31 static void cplbinfo_print_header(struct seq_file
*m
)
33 seq_printf(m
, "Index\tAddress\t\tData\tSize\tU/RD\tU/WR\tS/WR\tSwitch\n");
36 static int cplbinfo_nomore(struct cplbinfo_data
*cdata
)
38 return cdata
->pos
>= MAX_CPLBS
;
41 static int cplbinfo_show(struct seq_file
*m
, void *p
)
43 struct cplbinfo_data
*cdata
;
44 unsigned long data
, addr
;
49 addr
= cdata
->tbl
[pos
].addr
;
50 data
= cdata
->tbl
[pos
].data
;
53 "%d\t0x%08lx\t%05lx\t%s\t%c\t%c\t%c\t%c\n",
54 (int)pos
, addr
, data
, strpage(data
),
55 (data
& CPLB_USER_RD
) ? 'Y' : 'N',
56 (data
& CPLB_USER_WR
) ? 'Y' : 'N',
57 (data
& CPLB_SUPV_WR
) ? 'Y' : 'N',
58 pos
< cdata
->switched
? 'N' : 'Y');
63 static void cplbinfo_seq_init(struct cplbinfo_data
*cdata
, unsigned int cpu
)
65 if (cdata
->cplb_type
== 'I') {
66 cdata
->mem_control
= bfin_read_IMEM_CONTROL();
67 cdata
->tbl
= icplb_tbl
[cpu
];
68 cdata
->switched
= first_switched_icplb
;
70 cdata
->mem_control
= bfin_read_DMEM_CONTROL();
71 cdata
->tbl
= dcplb_tbl
[cpu
];
72 cdata
->switched
= first_switched_dcplb
;
76 static void *cplbinfo_start(struct seq_file
*m
, loff_t
*pos
)
78 struct cplbinfo_data
*cdata
= m
->private;
81 seq_printf(m
, "%cCPLBs are %sabled: 0x%x\n", cdata
->cplb_type
,
82 (cdata
->mem_control
& ENDCPLB
? "en" : "dis"),
84 cplbinfo_print_header(m
);
85 } else if (cplbinfo_nomore(cdata
))
92 static void *cplbinfo_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
94 struct cplbinfo_data
*cdata
= p
;
95 cdata
->pos
= ++(*pos
);
96 if (cplbinfo_nomore(cdata
))
102 static void cplbinfo_stop(struct seq_file
*m
, void *p
)
107 static const struct seq_operations cplbinfo_sops
= {
108 .start
= cplbinfo_start
,
109 .next
= cplbinfo_next
,
110 .stop
= cplbinfo_stop
,
111 .show
= cplbinfo_show
,
114 static int cplbinfo_open(struct inode
*inode
, struct file
*file
)
116 char buf
[256], *path
, *p
;
118 char *s_cpu
, *s_cplb
;
121 struct cplbinfo_data
*cdata
;
123 path
= d_path(&file
->f_path
, buf
, sizeof(buf
));
125 return PTR_ERR(path
);
126 s_cpu
= strstr(path
, "/cpu");
127 s_cplb
= strrchr(path
, '/');
128 if (!s_cpu
|| !s_cplb
)
131 cpu
= simple_strtoul(s_cpu
+ 4, &p
, 10);
132 if (!cpu_online(cpu
))
135 ret
= seq_open_private(file
, &cplbinfo_sops
, sizeof(*cdata
));
138 m
= file
->private_data
;
142 cdata
->cplb_type
= toupper(s_cplb
[1]);
143 cplbinfo_seq_init(cdata
, cpu
);
148 static const struct file_operations cplbinfo_fops
= {
149 .open
= cplbinfo_open
,
152 .release
= seq_release_private
,
155 static int __init
cplbinfo_init(void)
157 struct proc_dir_entry
*cplb_dir
, *cpu_dir
;
161 cplb_dir
= proc_mkdir("cplbinfo", NULL
);
165 for_each_possible_cpu(cpu
) {
166 sprintf(buf
, "cpu%i", cpu
);
167 cpu_dir
= proc_mkdir(buf
, cplb_dir
);
171 proc_create("icplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
);
172 proc_create("dcplb", S_IRUGO
, cpu_dir
, &cplbinfo_fops
);
177 late_initcall(cplbinfo_init
);