sc-mips.c 3.3 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Copyright (C) 2006 Chris Dearman (chris@mips.com),
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>

9
#include <asm/cpu-type.h>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <asm/mipsregs.h>
#include <asm/bcache.h>
#include <asm/cacheops.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/mmu_context.h>
#include <asm/r4kcache.h>

/*
 * MIPS32/MIPS64 L2 cache handling
 */

/*
 * Writeback and invalidate the secondary cache before DMA.
 */
static void mips_sc_wback_inv(unsigned long addr, unsigned long size)
{
27
	blast_scache_range(addr, addr + size);
28 29 30 31 32 33 34
}

/*
 * Invalidate the secondary cache before DMA.
 */
static void mips_sc_inv(unsigned long addr, unsigned long size)
{
35 36 37 38 39
	unsigned long lsize = cpu_scache_line_size();
	unsigned long almask = ~(lsize - 1);

	cache_op(Hit_Writeback_Inv_SD, addr & almask);
	cache_op(Hit_Writeback_Inv_SD, (addr + size - 1) & almask);
40
	blast_inv_scache_range(addr, addr + size);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
}

static void mips_sc_enable(void)
{
	/* L2 cache is permanently enabled */
}

static void mips_sc_disable(void)
{
	/* L2 cache is permanently enabled */
}

static struct bcache_ops mips_sc_ops = {
	.bc_enable = mips_sc_enable,
	.bc_disable = mips_sc_disable,
	.bc_wback_inv = mips_sc_wback_inv,
	.bc_inv = mips_sc_inv
};

K
Kevin Cernekee 已提交
60 61 62 63 64 65 66 67 68 69 70
/*
 * Check if the L2 cache controller is activated on a particular platform.
 * MTI's L2 controller and the L2 cache controller of Broadcom's BMIPS
 * cores both use c0_config2's bit 12 as "L2 Bypass" bit, that is the
 * cache being disabled.  However there is no guarantee for this to be
 * true on all platforms.  In an act of stupidity the spec defined bits
 * 12..15 as implementation defined so below function will eventually have
 * to be replaced by a platform specific probe.
 */
static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
{
71 72 73
	unsigned int config2 = read_c0_config2();
	unsigned int tmp;

K
Kevin Cernekee 已提交
74
	/* Check the bypass bit (L2B) */
75
	switch (current_cpu_type()) {
K
Kevin Cernekee 已提交
76 77 78
	case CPU_34K:
	case CPU_74K:
	case CPU_1004K:
79
	case CPU_1074K:
80
	case CPU_INTERAPTIV:
81
	case CPU_PROAPTIV:
J
James Hogan 已提交
82
	case CPU_P5600:
K
Kevin Cernekee 已提交
83
	case CPU_BMIPS5000:
84
	case CPU_QEMU_GENERIC:
K
Kevin Cernekee 已提交
85 86 87 88 89 90 91 92 93
		if (config2 & (1 << 12))
			return 0;
	}

	tmp = (config2 >> 4) & 0x0f;
	if (0 < tmp && tmp <= 7)
		c->scache.linesz = 2 << tmp;
	else
		return 0;
94
	return 1;
K
Kevin Cernekee 已提交
95 96
}

97 98 99 100 101 102 103 104 105 106
static inline int __init mips_sc_probe(void)
{
	struct cpuinfo_mips *c = &current_cpu_data;
	unsigned int config1, config2;
	unsigned int tmp;

	/* Mark as not present until probe completed */
	c->scache.flags |= MIPS_CACHE_NOT_PRESENT;

	/* Ignore anything but MIPSxx processors */
107 108
	if (!(c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M32R2 |
			      MIPS_CPU_ISA_M64R1 | MIPS_CPU_ISA_M64R2)))
109 110 111 112 113 114 115 116
		return 0;

	/* Does this MIPS32/MIPS64 CPU have a config2 register? */
	config1 = read_c0_config1();
	if (!(config1 & MIPS_CONF_M))
		return 0;

	config2 = read_c0_config2();
K
Kevin Cernekee 已提交
117 118

	if (!mips_sc_is_activated(c))
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
		return 0;

	tmp = (config2 >> 8) & 0x0f;
	if (0 <= tmp && tmp <= 7)
		c->scache.sets = 64 << tmp;
	else
		return 0;

	tmp = (config2 >> 0) & 0x0f;
	if (0 <= tmp && tmp <= 7)
		c->scache.ways = tmp + 1;
	else
		return 0;

	c->scache.waysize = c->scache.sets * c->scache.linesz;
134
	c->scache.waybit = __ffs(c->scache.waysize);
135 136 137 138 139 140

	c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;

	return 1;
}

141
int mips_sc_init(void)
142
{
143
	int found = mips_sc_probe();
144 145 146 147 148 149
	if (found) {
		mips_sc_enable();
		bcops = &mips_sc_ops;
	}
	return found;
}