xref: /openbmc/linux/arch/sh/mm/cache-debugfs.c (revision f8bade6c9a6213c2c5ba6e5bf32415ecab6e41e5)
115f57a29SPaul Mundt /*
215f57a29SPaul Mundt  * debugfs ops for the L1 cache
315f57a29SPaul Mundt  *
415f57a29SPaul Mundt  *  Copyright (C) 2006  Paul Mundt
515f57a29SPaul Mundt  *
615f57a29SPaul Mundt  * This file is subject to the terms and conditions of the GNU General Public
715f57a29SPaul Mundt  * License.  See the file "COPYING" in the main directory of this archive
815f57a29SPaul Mundt  * for more details.
915f57a29SPaul Mundt  */
1015f57a29SPaul Mundt #include <linux/init.h>
1115f57a29SPaul Mundt #include <linux/module.h>
1215f57a29SPaul Mundt #include <linux/debugfs.h>
1315f57a29SPaul Mundt #include <linux/seq_file.h>
1415f57a29SPaul Mundt #include <asm/processor.h>
157c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
1615f57a29SPaul Mundt #include <asm/cache.h>
1715f57a29SPaul Mundt #include <asm/io.h>
1815f57a29SPaul Mundt 
1915f57a29SPaul Mundt enum cache_type {
2015f57a29SPaul Mundt 	CACHE_TYPE_ICACHE,
2115f57a29SPaul Mundt 	CACHE_TYPE_DCACHE,
2215f57a29SPaul Mundt 	CACHE_TYPE_UNIFIED,
2315f57a29SPaul Mundt };
2415f57a29SPaul Mundt 
cache_debugfs_show(struct seq_file * file,void * iter)25*a1153636SQinglang Miao static int cache_debugfs_show(struct seq_file *file, void *iter)
2615f57a29SPaul Mundt {
2715f57a29SPaul Mundt 	unsigned int cache_type = (unsigned int)file->private;
2815f57a29SPaul Mundt 	struct cache_info *cache;
29298c48a8SSrinivas KANDAGATLA 	unsigned int waysize, way;
30298c48a8SSrinivas KANDAGATLA 	unsigned long ccr;
31298c48a8SSrinivas KANDAGATLA 	unsigned long addrstart = 0;
3215f57a29SPaul Mundt 
3315f57a29SPaul Mundt 	/*
3415f57a29SPaul Mundt 	 * Go uncached immediately so we don't skew the results any
3515f57a29SPaul Mundt 	 * more than we already are..
3615f57a29SPaul Mundt 	 */
37cbaa118eSStuart Menefy 	jump_to_uncached();
3815f57a29SPaul Mundt 
39a5f6ea29SGeert Uytterhoeven 	ccr = __raw_readl(SH_CCR);
4015f57a29SPaul Mundt 	if ((ccr & CCR_CACHE_ENABLE) == 0) {
41cbaa118eSStuart Menefy 		back_to_cached();
4215f57a29SPaul Mundt 
4315f57a29SPaul Mundt 		seq_printf(file, "disabled\n");
4415f57a29SPaul Mundt 		return 0;
4515f57a29SPaul Mundt 	}
4615f57a29SPaul Mundt 
4715f57a29SPaul Mundt 	if (cache_type == CACHE_TYPE_DCACHE) {
48298c48a8SSrinivas KANDAGATLA 		addrstart = CACHE_OC_ADDRESS_ARRAY;
4911c19656SPaul Mundt 		cache = &current_cpu_data.dcache;
5015f57a29SPaul Mundt 	} else {
51298c48a8SSrinivas KANDAGATLA 		addrstart = CACHE_IC_ADDRESS_ARRAY;
5211c19656SPaul Mundt 		cache = &current_cpu_data.icache;
5315f57a29SPaul Mundt 	}
5415f57a29SPaul Mundt 
5515f57a29SPaul Mundt 	waysize = cache->sets;
5615f57a29SPaul Mundt 
5715f57a29SPaul Mundt 	/*
5815f57a29SPaul Mundt 	 * If the OC is already in RAM mode, we only have
5915f57a29SPaul Mundt 	 * half of the entries to consider..
6015f57a29SPaul Mundt 	 */
6115f57a29SPaul Mundt 	if ((ccr & CCR_CACHE_ORA) && cache_type == CACHE_TYPE_DCACHE)
6215f57a29SPaul Mundt 		waysize >>= 1;
6315f57a29SPaul Mundt 
6415f57a29SPaul Mundt 	waysize <<= cache->entry_shift;
6515f57a29SPaul Mundt 
6615f57a29SPaul Mundt 	for (way = 0; way < cache->ways; way++) {
6715f57a29SPaul Mundt 		unsigned long addr;
6815f57a29SPaul Mundt 		unsigned int line;
6915f57a29SPaul Mundt 
7015f57a29SPaul Mundt 		seq_printf(file, "-----------------------------------------\n");
7115f57a29SPaul Mundt 		seq_printf(file, "Way %d\n", way);
7215f57a29SPaul Mundt 		seq_printf(file, "-----------------------------------------\n");
7315f57a29SPaul Mundt 
7415f57a29SPaul Mundt 		for (addr = addrstart, line = 0;
7515f57a29SPaul Mundt 		     addr < addrstart + waysize;
7615f57a29SPaul Mundt 		     addr += cache->linesz, line++) {
779d56dd3bSPaul Mundt 			unsigned long data = __raw_readl(addr);
7815f57a29SPaul Mundt 
7915f57a29SPaul Mundt 			/* Check the V bit, ignore invalid cachelines */
8015f57a29SPaul Mundt 			if ((data & 1) == 0)
8115f57a29SPaul Mundt 				continue;
8215f57a29SPaul Mundt 
8315f57a29SPaul Mundt 			/* U: Dirty, cache tag is 10 bits up */
8415f57a29SPaul Mundt 			seq_printf(file, "%3d: %c 0x%lx\n",
8515f57a29SPaul Mundt 				   line, data & 2 ? 'U' : ' ',
8615f57a29SPaul Mundt 				   data & 0x1ffffc00);
8715f57a29SPaul Mundt 		}
8815f57a29SPaul Mundt 
8915f57a29SPaul Mundt 		addrstart += cache->way_incr;
9015f57a29SPaul Mundt 	}
9115f57a29SPaul Mundt 
92cbaa118eSStuart Menefy 	back_to_cached();
9315f57a29SPaul Mundt 
9415f57a29SPaul Mundt 	return 0;
9515f57a29SPaul Mundt }
9615f57a29SPaul Mundt 
97*a1153636SQinglang Miao DEFINE_SHOW_ATTRIBUTE(cache_debugfs);
9815f57a29SPaul Mundt 
cache_debugfs_init(void)9915f57a29SPaul Mundt static int __init cache_debugfs_init(void)
10015f57a29SPaul Mundt {
10103eb2a08SGreg Kroah-Hartman 	debugfs_create_file("dcache", S_IRUSR, arch_debugfs_dir,
10203eb2a08SGreg Kroah-Hartman 			    (void *)CACHE_TYPE_DCACHE, &cache_debugfs_fops);
10303eb2a08SGreg Kroah-Hartman 	debugfs_create_file("icache", S_IRUSR, arch_debugfs_dir,
10403eb2a08SGreg Kroah-Hartman 			    (void *)CACHE_TYPE_ICACHE, &cache_debugfs_fops);
10515f57a29SPaul Mundt 	return 0;
10615f57a29SPaul Mundt }
10715f57a29SPaul Mundt module_init(cache_debugfs_init);
10815f57a29SPaul Mundt 
10915f57a29SPaul Mundt MODULE_LICENSE("GPL v2");
110