2006-06-20 18:15:20 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Chris Dearman (chris@mips.com),
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
2013-09-17 10:25:47 +02:00
|
|
|
#include <asm/cpu-type.h>
|
2006-06-20 18:15:20 +02:00
|
|
|
#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>
|
2015-07-09 11:40:42 +02:00
|
|
|
#include <asm/mips-cm.h>
|
2006-06-20 18:15:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2006-06-22 12:42:43 +02:00
|
|
|
blast_scache_range(addr, addr + size);
|
2006-06-20 18:15:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invalidate the secondary cache before DMA.
|
|
|
|
*/
|
|
|
|
static void mips_sc_inv(unsigned long addr, unsigned long size)
|
|
|
|
{
|
2009-09-19 04:12:45 +02:00
|
|
|
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);
|
2006-06-22 12:42:43 +02:00
|
|
|
blast_inv_scache_range(addr, addr + size);
|
2006-06-20 18:15:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mips_sc_enable(void)
|
|
|
|
{
|
|
|
|
/* L2 cache is permanently enabled */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mips_sc_disable(void)
|
|
|
|
{
|
|
|
|
/* L2 cache is permanently enabled */
|
|
|
|
}
|
|
|
|
|
2015-09-22 19:10:54 +02:00
|
|
|
static void mips_sc_prefetch_enable(void)
|
|
|
|
{
|
|
|
|
unsigned long pftctl;
|
|
|
|
|
|
|
|
if (mips_cm_revision() < CM_REV_CM2_5)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is one or more L2 prefetch unit present then enable
|
|
|
|
* prefetching for both code & data, for all ports.
|
|
|
|
*/
|
|
|
|
pftctl = read_gcr_l2_pft_control();
|
|
|
|
if (pftctl & CM_GCR_L2_PFT_CONTROL_NPFT_MSK) {
|
|
|
|
pftctl &= ~CM_GCR_L2_PFT_CONTROL_PAGEMASK_MSK;
|
|
|
|
pftctl |= PAGE_MASK & CM_GCR_L2_PFT_CONTROL_PAGEMASK_MSK;
|
|
|
|
pftctl |= CM_GCR_L2_PFT_CONTROL_PFTEN_MSK;
|
|
|
|
write_gcr_l2_pft_control(pftctl);
|
|
|
|
|
|
|
|
pftctl = read_gcr_l2_pft_control_b();
|
|
|
|
pftctl |= CM_GCR_L2_PFT_CONTROL_B_PORTID_MSK;
|
|
|
|
pftctl |= CM_GCR_L2_PFT_CONTROL_B_CEN_MSK;
|
|
|
|
write_gcr_l2_pft_control_b(pftctl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mips_sc_prefetch_disable(void)
|
|
|
|
{
|
|
|
|
unsigned long pftctl;
|
|
|
|
|
|
|
|
if (mips_cm_revision() < CM_REV_CM2_5)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pftctl = read_gcr_l2_pft_control();
|
|
|
|
pftctl &= ~CM_GCR_L2_PFT_CONTROL_PFTEN_MSK;
|
|
|
|
write_gcr_l2_pft_control(pftctl);
|
|
|
|
|
|
|
|
pftctl = read_gcr_l2_pft_control_b();
|
|
|
|
pftctl &= ~CM_GCR_L2_PFT_CONTROL_B_PORTID_MSK;
|
|
|
|
pftctl &= ~CM_GCR_L2_PFT_CONTROL_B_CEN_MSK;
|
|
|
|
write_gcr_l2_pft_control_b(pftctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool mips_sc_prefetch_is_enabled(void)
|
|
|
|
{
|
|
|
|
unsigned long pftctl;
|
|
|
|
|
|
|
|
if (mips_cm_revision() < CM_REV_CM2_5)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pftctl = read_gcr_l2_pft_control();
|
|
|
|
if (!(pftctl & CM_GCR_L2_PFT_CONTROL_NPFT_MSK))
|
|
|
|
return false;
|
|
|
|
return !!(pftctl & CM_GCR_L2_PFT_CONTROL_PFTEN_MSK);
|
|
|
|
}
|
|
|
|
|
2006-06-20 18:15:20 +02:00
|
|
|
static struct bcache_ops mips_sc_ops = {
|
|
|
|
.bc_enable = mips_sc_enable,
|
|
|
|
.bc_disable = mips_sc_disable,
|
|
|
|
.bc_wback_inv = mips_sc_wback_inv,
|
2015-09-22 19:10:54 +02:00
|
|
|
.bc_inv = mips_sc_inv,
|
|
|
|
.bc_prefetch_enable = mips_sc_prefetch_enable,
|
|
|
|
.bc_prefetch_disable = mips_sc_prefetch_disable,
|
|
|
|
.bc_prefetch_is_enabled = mips_sc_prefetch_is_enabled,
|
2006-06-20 18:15:20 +02:00
|
|
|
};
|
|
|
|
|
2010-10-21 05:05:42 +02:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
2010-11-03 06:28:01 +01:00
|
|
|
unsigned int config2 = read_c0_config2();
|
|
|
|
unsigned int tmp;
|
|
|
|
|
2010-10-21 05:05:42 +02:00
|
|
|
/* Check the bypass bit (L2B) */
|
2013-09-17 10:25:47 +02:00
|
|
|
switch (current_cpu_type()) {
|
2010-10-21 05:05:42 +02:00
|
|
|
case CPU_34K:
|
|
|
|
case CPU_74K:
|
|
|
|
case CPU_1004K:
|
2014-01-17 22:03:50 +01:00
|
|
|
case CPU_1074K:
|
2013-11-27 11:07:53 +01:00
|
|
|
case CPU_INTERAPTIV:
|
2013-11-14 17:12:27 +01:00
|
|
|
case CPU_PROAPTIV:
|
2014-01-22 17:19:38 +01:00
|
|
|
case CPU_P5600:
|
2010-10-21 05:05:42 +02:00
|
|
|
case CPU_BMIPS5000:
|
2014-11-24 13:59:01 +01:00
|
|
|
case CPU_QEMU_GENERIC:
|
2016-02-03 04:26:38 +01:00
|
|
|
case CPU_P6600:
|
2010-10-21 05:05:42 +02:00
|
|
|
if (config2 & (1 << 12))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = (config2 >> 4) & 0x0f;
|
|
|
|
if (0 < tmp && tmp <= 7)
|
|
|
|
c->scache.linesz = 2 << tmp;
|
|
|
|
else
|
|
|
|
return 0;
|
2010-11-03 06:28:01 +01:00
|
|
|
return 1;
|
2010-10-21 05:05:42 +02:00
|
|
|
}
|
|
|
|
|
2015-07-09 11:40:42 +02:00
|
|
|
static int __init mips_sc_probe_cm3(void)
|
|
|
|
{
|
|
|
|
struct cpuinfo_mips *c = ¤t_cpu_data;
|
|
|
|
unsigned long cfg = read_gcr_l2_config();
|
|
|
|
unsigned long sets, line_sz, assoc;
|
|
|
|
|
|
|
|
if (cfg & CM_GCR_L2_CONFIG_BYPASS_MSK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sets = cfg & CM_GCR_L2_CONFIG_SET_SIZE_MSK;
|
|
|
|
sets >>= CM_GCR_L2_CONFIG_SET_SIZE_SHF;
|
2016-02-29 12:41:20 +01:00
|
|
|
if (sets)
|
|
|
|
c->scache.sets = 64 << sets;
|
2015-07-09 11:40:42 +02:00
|
|
|
|
|
|
|
line_sz = cfg & CM_GCR_L2_CONFIG_LINE_SIZE_MSK;
|
|
|
|
line_sz >>= CM_GCR_L2_CONFIG_LINE_SIZE_SHF;
|
2016-02-29 12:41:20 +01:00
|
|
|
if (line_sz)
|
|
|
|
c->scache.linesz = 2 << line_sz;
|
2015-07-09 11:40:42 +02:00
|
|
|
|
|
|
|
assoc = cfg & CM_GCR_L2_CONFIG_ASSOC_MSK;
|
|
|
|
assoc >>= CM_GCR_L2_CONFIG_ASSOC_SHF;
|
|
|
|
c->scache.ways = assoc + 1;
|
|
|
|
c->scache.waysize = c->scache.sets * c->scache.linesz;
|
|
|
|
c->scache.waybit = __ffs(c->scache.waysize);
|
|
|
|
|
2016-02-29 12:41:20 +01:00
|
|
|
if (c->scache.linesz) {
|
|
|
|
c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
|
2016-08-19 19:13:36 +02:00
|
|
|
c->options |= MIPS_CPU_INCLUSIVE_CACHES;
|
2016-02-29 12:41:20 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2015-07-09 11:40:42 +02:00
|
|
|
|
2016-02-29 12:41:20 +01:00
|
|
|
return 0;
|
2015-07-09 11:40:42 +02:00
|
|
|
}
|
|
|
|
|
2006-06-20 18:15:20 +02:00
|
|
|
static inline int __init mips_sc_probe(void)
|
|
|
|
{
|
|
|
|
struct cpuinfo_mips *c = ¤t_cpu_data;
|
|
|
|
unsigned int config1, config2;
|
|
|
|
unsigned int tmp;
|
|
|
|
|
|
|
|
/* Mark as not present until probe completed */
|
|
|
|
c->scache.flags |= MIPS_CACHE_NOT_PRESENT;
|
|
|
|
|
2015-07-09 11:40:42 +02:00
|
|
|
if (mips_cm_revision() >= CM_REV_CM3)
|
|
|
|
return mips_sc_probe_cm3();
|
|
|
|
|
2006-06-20 18:15:20 +02:00
|
|
|
/* Ignore anything but MIPSxx processors */
|
2013-04-01 20:14:28 +02:00
|
|
|
if (!(c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M32R2 |
|
2015-01-15 11:28:29 +01:00
|
|
|
MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R1 |
|
|
|
|
MIPS_CPU_ISA_M64R2 | MIPS_CPU_ISA_M64R6)))
|
2006-06-20 18:15:20 +02:00
|
|
|
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();
|
2010-10-21 05:05:42 +02:00
|
|
|
|
|
|
|
if (!mips_sc_is_activated(c))
|
2006-06-20 18:15:20 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
tmp = (config2 >> 8) & 0x0f;
|
2015-09-21 15:34:08 +02:00
|
|
|
if (tmp <= 7)
|
2006-06-20 18:15:20 +02:00
|
|
|
c->scache.sets = 64 << tmp;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tmp = (config2 >> 0) & 0x0f;
|
2015-09-21 15:34:08 +02:00
|
|
|
if (tmp <= 7)
|
2006-06-20 18:15:20 +02:00
|
|
|
c->scache.ways = tmp + 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
c->scache.waysize = c->scache.sets * c->scache.linesz;
|
2006-06-22 12:42:43 +02:00
|
|
|
c->scache.waybit = __ffs(c->scache.waysize);
|
2006-06-20 18:15:20 +02:00
|
|
|
|
|
|
|
c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 15:38:59 +02:00
|
|
|
int mips_sc_init(void)
|
2006-06-20 18:15:20 +02:00
|
|
|
{
|
2007-10-12 00:46:15 +02:00
|
|
|
int found = mips_sc_probe();
|
2006-06-20 18:15:20 +02:00
|
|
|
if (found) {
|
|
|
|
mips_sc_enable();
|
2015-09-22 19:10:54 +02:00
|
|
|
mips_sc_prefetch_enable();
|
2006-06-20 18:15:20 +02:00
|
|
|
bcops = &mips_sc_ops;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|