MIPS L2 cache support
Subsystems (2)
v3 cover MIPS L2 cache support
This series introduces support for initialising & maintaining L2 caches on MIPS systems. This allows U-Boot to function correctly on systems where such caches are present, whereas without performing L2 maintenance it is likely to fail with cache coherence issues when writing code or performing DMA transfers. It also fixes up a few issues with the cache code in general, in particular ensuring that it clears execution hazards at appropriate points.
Paul Burton (14):
board_f: Add a mach_cpu_init callback
MIPS: ath79: Use mach_cpu_init instead of arch_cpu_init
MIPS: Probe cache line sizes once during boot
MIPS: Enable use of the instruction cache earlier
MIPS: Preserve Config implementation-defined bits
MIPS: If we don't need DDR for cache init, init cache first
MIPS: Define register names for cache init
MIPS: Map CM Global Control Registers
MIPS: L2 cache support
MIPS: Join the coherent domain when a CM is present
MIPS: Malta: Enable CM & L2 support
MIPS: Ensure Config.K0=2 applies before any memory accesses
MIPS: Clear hazard between TagLo writes & cache ops
MIPS: Ensure cache ops complete in mips_cache_reset
arch/mips/Kconfig | 24 ++++ arch/mips/cpu/Makefile | 2 + arch/mips/cpu/cm_init.S | 45 ++++++ arch/mips/cpu/cpu.c | 7 + arch/mips/cpu/start.S | 27 ++-- arch/mips/include/asm/cache.h | 9 ++ arch/mips/include/asm/cm.h | 62 +++++++++ arch/mips/include/asm/global_data.h | 7 + arch/mips/include/asm/mipsregs.h | 6 + arch/mips/lib/cache.c | 101 +++++++++++--- arch/mips/lib/cache_init.S | 271 +++++++++++++++++++++++++++++++++--- arch/mips/mach-ath79/cpu.c | 2 +- board/imgtec/malta/lowlevel_init.S | 6 - common/board_f.c | 6 + 14 files changed, 522 insertions(+), 53 deletions(-) create mode 100644 arch/mips/cpu/cm_init.S create mode 100644 arch/mips/include/asm/cm.h
Signature · 1 line
2.10.0
PATCH v3 1/14 board_f: Add a mach_cpu_init callback
Currently we have a mismash of architectures which use arch_cpu_init from architecture-wide code (arc, avr32, blackfin, mips, nios2, xtensa) and architectures which use arch_cpu_init from machine/SoC level code (arm, x86).
In order to clean this mess up & allow for both use cases, introduce a new mach_cpu_init callback which is run immediately after arch_cpu_init. This will allow for architectures to have arch-wide code without needing individual machines to all implement their own arch_cpu_init with a call to some common function.
---
Changes in v3: None
Changes in v2:
- Use a weak function, make it generic not MIPS-specific
common/board_f.c | 6 ++++++ 1 file changed, 6 insertions(+)
common/board_f.c +6 -0
@@ -290,6 +290,11 @@ __weak int arch_cpu_init(void)return 0 ; } +__weak int mach_cpu_init (void ) +{ +return 0 ; +} +#ifdef CONFIG_SANDBOX static int setup_ram_buf (void ) {
@@ -860,6 +865,7 @@ static init_fnc_t init_sequence_f[] = { x86_fsp_init, #endif arch_cpu_init,/* basic arch cpu dependent setup */ + mach_cpu_init,/* SoC/machine dependent CPU setup */ initf_dm, arch_cpu_init_dm, mark_bootstage, /* need timer, go after init dm */
Signature · 1 line
2.10.0
PATCH v3 2/14 MIPS: ath79: Use mach_cpu_init instead of arch_cpu_init
In reply to Paul BurtonIn order to prepare for MIPS arch code making use of arch_cpu_init in a later patch, stop using it from ath79 SoC code & instead use the new mach_cpu_init which is provided for this purpose.
---
Changes in v3: None
Changes in v2:
- Rebase atop changes in patch 1
arch/mips/mach-ath79/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/mach-ath79/cpu.c +1 -1
@@ -46,7 +46,7 @@ static const struct ath79_soc_desc desc[] = { {ATH79_SOC_QCA9561, "9561", REV_ID_MAJOR_QCA9561, 0}, }; -int arch_cpu_init (void ) +int mach_cpu_init (void ) {void __iomem *base;enum ath79_soc_type soc =ATH79_SOC_UNKNOWN ;
Signature · 1 line
2.10.0
PATCH v3 3/14 MIPS: Probe cache line sizes once during boot
In reply to Paul BurtonRather than probing the cache line sizes on every call of any cache maintenance function, probe them once during boot & store the values in the global data structure for later use. This will reduce the overhead of the cache maintenance functions, which isn't a big deal yet but becomes more important once L2 caches which may expose their properties via coprocessor 2 or the CM are supported.
---
Changes in v3: None
Changes in v2: None
arch/mips/cpu/cpu.c | 7 ++++++ arch/mips/include/asm/cache.h | 9 ++++++++ arch/mips/include/asm/global_data.h | 4 ++++ arch/mips/lib/cache.c | 43 +++++++++++++++++++++---------------- 4 files changed, 45 insertions(+), 18 deletions(-)
arch/mips/cpu/cpu.c +7 -0
@@ -8,6 +8,7 @@#include <common.h> #include <command.h> #include <linux/compiler.h> +#include <asm/cache.h> #include <asm/mipsregs.h> #include <asm/reboot.h>
@@ -35,3 +36,9 @@ void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1)write_c0_index (index);tlb_write_indexed (); } + +int arch_cpu_init (void ) +{ +mips_cache_probe (); +return 0 ; +}
arch/mips/include/asm/cache.h +9 -0
@@ -19,4 +19,13 @@*/ #define CONFIG_SYS_CACHELINE_SIZE ARCH_DMA_MINALIGN +/** +* mips_cache_probe() - Probe the properties of the caches +* +* Call this to probe the properties such as line sizes of the caches +* present in the system, if any. This must be done before cache maintenance +* functions such as flush_cache may be called. +*/ +void mips_cache_probe (void ); +#endif /* __MIPS_CACHE_H__ */
arch/mips/include/asm/global_data.h +4 -0
@@ -21,6 +21,10 @@ struct arch_global_data {unsigned long rev;unsigned long ver;#endif +#ifdef CONFIG_SYS_CACHE_SIZE_AUTO +unsigned short l1i_line_size; +unsigned short l1d_line_size; +#endif };#include <asm-generic/global_data.h>
arch/mips/lib/cache.c +25 -18
57 lines not on this page · raw message
Signature · 1 line
2.10.0
PATCH v3 4/14 MIPS: Enable use of the instruction cache earlier
In reply to Paul BurtonEnable use of the instruction cache immediately after it has been initialised. This will only take effect if U-Boot was linked to run from kseg0 rather than kseg1, but when this is the case the data cache initialisation code will run cached & thus significantly faster.
---
Changes in v3: None
Changes in v2: None
arch/mips/cpu/start.S | 8 -------- arch/mips/lib/cache_init.S | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-)
arch/mips/cpu/start.S +0 -8
@@ -12,10 +12,6 @@ #include <asm/regdef.h> #include <asm/mipsregs.h> -#ifndef CONFIG_SYS_MIPS_CACHE_MODE -#define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT -#endif - #ifndef CONFIG_SYS_INIT_SP_ADDR #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \ CONFIG_SYS_INIT_SP_OFFSET)
@@ -154,10 +150,6 @@ reset: PTR_LA t9, mips_cache_reset jalr t9 nop - - /* ... and enable them */ - li t0, CONFIG_SYS_MIPS_CACHE_MODE - mtc0 t0, CP0_CONFIG #endif /* Set up temporary stack */
arch/mips/lib/cache_init.S +13 -0
@@ -172,6 +172,19 @@ LEAF(mips_cache_reset) cache_loop t0, t1, t8, INDEX_STORE_TAG_I #endif + /* Enable use of the I-cache by setting Config.K0 */ + sync + mfc0 t0, CP0_CONFIG + li t1, CONFIG_SYS_MIPS_CACHE_MODE +#if __mips_isa_rev >= 2 + ins t0, t1, 0, 3 +#else + ori t0, t0, CONF_CM_CMASK + xori t0, t0, CONF_CM_CMASK + or t0, t0, t1 +#endif + mtc0 t0, CP0_CONFIG + /* * then initialize D-cache. */
Signature · 1 line
2.10.0
PATCH v3 5/14 MIPS: Preserve Config implementation-defined bits
In reply to Paul BurtonThe coprocessor 0 Config register includes 9 implementation defined bits, which in some processors do things like enable write combining or other functionality. We ought not to wipe them to 0 during boot. Rather than doing so, preserve their value & only clear the bits standardised by the MIPS architecture.
---
Changes in v3: None
Changes in v2: None
arch/mips/cpu/start.S | 5 +++-- arch/mips/include/asm/mipsregs.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-)
arch/mips/cpu/start.S +3 -2
@@ -123,8 +123,9 @@ reset: mtc0 zero, CP0_COMPARE #ifndef CONFIG_SKIP_LOWLEVEL_INIT - /* CONFIG0 register */ - li t0, CONF_CM_UNCACHED + mfc0 t0, CP0_CONFIG + and t0, t0, MIPS_CONF_IMPL + or t0, t0, CONF_CM_UNCACHED mtc0 t0, CP0_CONFIG #endif
arch/mips/include/asm/mipsregs.h +1 -0
@@ -450,6 +450,7 @@#define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)#define MIPS_CONF_AR (_ULCAST_(7) << 10)#define MIPS_CONF_AT (_ULCAST_(3) << 13) +#define MIPS_CONF_IMPL (_ULCAST_(0x1ff) << 16)#define MIPS_CONF_M (_ULCAST_(1) << 31)/*
Signature · 1 line
2.10.0
PATCH v3 6/14 MIPS: If we don't need DDR for cache init, init cache first
In reply to Paul BurtonOn systems where cache initialisation doesn't require zeroed memory (ie. systems where CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD is not defined) perform cache initialisation prior to lowlevel_init & DDR initialisation. This allows for DDR initialisation code to run cached & thus significantly faster.
---
Changes in v3: None
Changes in v2: None
arch/mips/cpu/start.S | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/mips/cpu/start.S +9 -0
@@ -142,15 +142,24 @@ reset: PTR_L gp, 0(ra) #ifndef CONFIG_SKIP_LOWLEVEL_INIT +# ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD /* Initialize any external memory */ PTR_LA t9, lowlevel_init jalr t9 nop +# endif /* Initialize caches... */ PTR_LA t9, mips_cache_reset jalr t9 nop + +# ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD + /* Initialize any external memory */ + PTR_LA t9, lowlevel_init + jalr t9 + nop +# endif #endif /* Set up temporary stack */
Signature · 1 line
2.10.0
PATCH v3 7/14 MIPS: Define register names for cache init
In reply to Paul BurtonDefine names for registers holding cache sizes throughout mips_cache_reset, in order to make the code easier to read & allow for changing register assignments more easily.
---
Changes in v3: None
Changes in v2: None
arch/mips/lib/cache_init.S | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)
arch/mips/lib/cache_init.S +23 -19
@@ -98,19 +98,23 @@ * RETURNS: N/A * */ +#define R_IC_SIZE t2 +#define R_IC_LINE t8 +#define R_DC_SIZE t3 +#define R_DC_LINE t9 LEAF(mips_cache_reset) #ifndef CONFIG_SYS_CACHE_SIZE_AUTO - li t2, CONFIG_SYS_ICACHE_SIZE - li t8, CONFIG_SYS_ICACHE_LINE_SIZE + li R_IC_SIZE, CONFIG_SYS_ICACHE_SIZE + li R_IC_LINE, CONFIG_SYS_ICACHE_LINE_SIZE #else - l1_info t2, t8, MIPS_CONF1_IA_SHF + l1_info R_IC_SIZE, R_IC_LINE, MIPS_CONF1_IA_SHF #endif #ifndef CONFIG_SYS_CACHE_SIZE_AUTO - li t3, CONFIG_SYS_DCACHE_SIZE - li t9, CONFIG_SYS_DCACHE_LINE_SIZE + li R_DC_SIZE, CONFIG_SYS_DCACHE_SIZE + li R_DC_LINE, CONFIG_SYS_DCACHE_LINE_SIZE #else - l1_info t3, t9, MIPS_CONF1_DA_SHF + l1_info R_DC_SIZE, R_DC_LINE, MIPS_CONF1_DA_SHF #endif #ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
@@ -123,9 +127,9 @@ LEAF(mips_cache_reset) li v0, CONFIG_SYS_DCACHE_SIZE #endif #else - move v0, t2 - sltu t1, t2, t3 - movn v0, t3, t1 + move v0, R_IC_SIZE + sltu t1, R_IC_SIZE, R_DC_SIZE + movn v0, R_DC_SIZE, t1 #endif /* * Now clear that much memory starting from zero.
@@ -158,18 +162,18 @@ LEAF(mips_cache_reset) /* * Initialize the I-cache first, */ - blez t2, 1f + blez R_IC_SIZE, 1f PTR_LI t0, INDEX_BASE - PTR_ADDU t1, t0, t2 + PTR_ADDU t1, t0, R_IC_SIZE /* clear tag to invalidate */ - cache_loop t0, t1, t8, INDEX_STORE_TAG_I + cache_loop t0, t1, R_IC_LINE, INDEX_STORE_TAG_I #ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD /* fill once, so data field parity is correct */ PTR_LI t0, INDEX_BASE - cache_loop t0, t1, t8, FILL + cache_loop t0, t1, R_IC_LINE, FILL /* invalidate again - prudent but not strictly neccessary */ PTR_LI t0, INDEX_BASE - cache_loop t0, t1, t8, INDEX_STORE_TAG_I + cache_loop t0, t1, R_IC_LINE, INDEX_STORE_TAG_I #endif /* Enable use of the I-cache by setting Config.K0 */
@@ -188,20 +192,20 @@ LEAF(mips_cache_reset) /* * then initialize D-cache. */ -1: blez t3, 3f +1: blez R_DC_SIZE, 3f PTR_LI t0, INDEX_BASE - PTR_ADDU t1, t0, t3 + PTR_ADDU t1, t0, R_DC_SIZE /* clear all tags */ - cache_loop t0, t1, t9, INDEX_STORE_TAG_D + cache_loop t0, t1, R_DC_LINE, INDEX_STORE_TAG_D #ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD /* load from each line (in cached space) */ PTR_LI t0, INDEX_BASE 2: LONG_L zero, 0(t0) - PTR_ADDU t0, t9 + PTR_ADDU t0, R_DC_LINE bne t0, t1, 2b /* clear all tags */ PTR_LI t0, INDEX_BASE - cache_loop t0, t1, t9, INDEX_STORE_TAG_D + cache_loop t0, t1, R_DC_LINE, INDEX_STORE_TAG_D #endif 3: jr ra
Signature · 1 line
2.10.0
PATCH v3 8/14 MIPS: Map CM Global Control Registers
In reply to Paul BurtonMap the Global Control Registers (GCRs) provided by the MIPS Coherence Manager (CM) in preparation for using some of them in later patches.
---
Changes in v3: None
Changes in v2: None
arch/mips/Kconfig | 16 ++++++++++++++++ arch/mips/cpu/Makefile | 2 ++ arch/mips/cpu/cm_init.S | 45 +++++++++++++++++++++++++++++++++++++++++++++ arch/mips/cpu/start.S | 6 ++++++ arch/mips/include/asm/cm.h | 19 +++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 arch/mips/cpu/cm_init.S create mode 100644 arch/mips/include/asm/cm.h
arch/mips/Kconfig +16 -0
@@ -303,6 +303,22 @@ config MIPS_L1_CACHE_SHIFT config DYNAMIC_IO_PORT_BASE bool +config MIPS_CM + bool + help + Select this if your system contains a MIPS Coherence Manager and you + wish U-Boot to configure it or make use of it to retrieve system + information such as cache configuration. + +config MIPS_CM_BASE + hex + default 0x1fbf8000 + help + The physical base address at which to map the MIPS Coherence Manager + Global Configuration Registers (GCRs). This should be set such that + the GCRs occupy a region of the physical address space which is + otherwise unused, or at minimum that software doesn't need to access. + endif endmenu
arch/mips/cpu/Makefile +2 -0
@@ -7,3 +7,5 @@ extra-y = start.o obj-y += time.o obj-y += interrupts.o obj-y += cpu.o + +obj-$(CONFIG_MIPS_CM) += cm_init.o
arch/mips/cpu/cm_init.S new file +45 -0
45 lines not on this page · raw message
arch/mips/cpu/start.S +6 -0
@@ -141,6 +141,12 @@ reset: 1: PTR_L gp, 0(ra) +#ifdef CONFIG_MIPS_CM + PTR_LA t9, mips_cm_map + jalr t9 + nop +#endif + #ifndef CONFIG_SKIP_LOWLEVEL_INIT # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD /* Initialize any external memory */
arch/mips/include/asm/cm.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* MIPS Coherence Manager (CM) Register Definitions +* +* Copyright (c) 2016 Imagination Technologies Ltd. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ +#ifndef __MIPS_ASM_CM_H__ +#define __MIPS_ASM_CM_H__ + +/* Global Control Register (GCR) offsets */ +#define GCR_BASE 0x0008 +#define GCR_BASE_UPPER 0x000c +#define GCR_REV 0x0030 + +/* GCR_REV CM versions */ +#define GCR_REV_CM3 0x0800 + +#endif /* __MIPS_ASM_CM_H__ */
Signature · 1 line
2.10.0
PATCH v3 9/14 MIPS: L2 cache support
In reply to Paul BurtonThis patch adds support for initialising & maintaining L2 caches on MIPS systems. The L2 cache configuration may be advertised through either coprocessor 0 or the MIPS Coherence Manager depending upon the system, and support for both is included.
If the L2 can be bypassed then we bypass it early in boot & initialise the L1 caches first, such that we can start making use of the L1 instruction cache as early as possible. Otherwise we initialise the L2 first such that the L1s have no opportunity to generate access to the uninitialised L2.
---
Changes in v3: None
Changes in v2: None
arch/mips/Kconfig | 6 ++ arch/mips/include/asm/cm.h | 38 ++++++++ arch/mips/include/asm/global_data.h | 3 + arch/mips/include/asm/mipsregs.h | 5 + arch/mips/lib/cache.c | 62 +++++++++++- arch/mips/lib/cache_init.S | 183 +++++++++++++++++++++++++++++++++++- 6 files changed, 291 insertions(+), 6 deletions(-)
arch/mips/Kconfig +6 -0
@@ -300,6 +300,12 @@ config MIPS_L1_CACHE_SHIFT default "4" if MIPS_L1_CACHE_SHIFT_4 default "5" +config MIPS_L2_CACHE + bool + help + Select this if your system includes an L2 cache and you want U-Boot + to initialise & maintain it. + config DYNAMIC_IO_PORT_BASE bool
arch/mips/include/asm/cm.h +38 -0
@@ -12,8 +12,46 @@#define GCR_BASE 0x0008#define GCR_BASE_UPPER 0x000c#define GCR_REV 0x0030 +#define GCR_L2_CONFIG 0x0130 +#define GCR_L2_TAG_ADDR 0x0600 +#define GCR_L2_TAG_ADDR_UPPER 0x0604 +#define GCR_L2_TAG_STATE 0x0608 +#define GCR_L2_TAG_STATE_UPPER 0x060c +#define GCR_L2_DATA 0x0610 +#define GCR_L2_DATA_UPPER 0x0614/* GCR_REV CM versions */ #define GCR_REV_CM3 0x0800 +/* GCR_L2_CONFIG fields */ +#define GCR_L2_CONFIG_ASSOC_SHIFT 0 +#define GCR_L2_CONFIG_ASSOC_BITS 8 +#define GCR_L2_CONFIG_LINESZ_SHIFT 8 +#define GCR_L2_CONFIG_LINESZ_BITS 4 +#define GCR_L2_CONFIG_SETSZ_SHIFT 12 +#define GCR_L2_CONFIG_SETSZ_BITS 4 +#define GCR_L2_CONFIG_BYPASS (1 << 20) + +#ifndef __ASSEMBLY__ + +#include <asm/io.h> + +static inline void *mips_cm_base (void ) +{ +return (void *)CKSEG1ADDR (CONFIG_MIPS_CM_BASE ); +} + +static inline unsigned long mips_cm_l2_line_size (void ) +{ +unsigned long l2conf, line_sz; + + l2conf =__raw_readl (mips_cm_base () +GCR_L2_CONFIG ); + + line_sz = l2conf >>GCR_L2_CONFIG_LINESZ_SHIFT ; + line_sz &=GENMASK (GCR_L2_CONFIG_LINESZ_BITS -1 ,0 ); +return line_sz ? (2 << line_sz) :0 ; +} + +#endif /* !__ASSEMBLY__ */ +#endif /* __MIPS_ASM_CM_H__ */
arch/mips/include/asm/global_data.h +3 -0
@@ -25,6 +25,9 @@ struct arch_global_data {unsigned short l1i_line_size;unsigned short l1d_line_size;#endif +#ifdef CONFIG_MIPS_L2_CACHE +unsigned short l2_line_size; +#endif };#include <asm-generic/global_data.h>
arch/mips/include/asm/mipsregs.h +5 -0
@@ -485,9 +485,13 @@#define MIPS_CONF1_TLBS_SIZE (6)#define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT) +#define MIPS_CONF2_SA_SHF 0#define MIPS_CONF2_SA (_ULCAST_(15) << 0) +#define MIPS_CONF2_SL_SHF 4#define MIPS_CONF2_SL (_ULCAST_(15) << 4) +#define MIPS_CONF2_SS_SHF 8#define MIPS_CONF2_SS (_ULCAST_(15) << 8) +#define MIPS_CONF2_L2B (_ULCAST_(1) << 12)#define MIPS_CONF2_SU (_ULCAST_(15) << 12)#define MIPS_CONF2_TA (_ULCAST_(15) << 16)#define MIPS_CONF2_TL (_ULCAST_(15) << 20)
@@ -551,6 +555,7 @@#define MIPS_CONF5_MVH (_ULCAST_(1) << 5)#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)#define MIPS_CONF5_UFE (_ULCAST_(1) << 9) +#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)#define MIPS_CONF5_CV (_ULCAST_(1) << 29)
arch/mips/lib/cache.c +61 -1
122 lines not on this page · raw message
arch/mips/lib/cache_init.S +178 -5
217 lines not on this page · raw message
Signature · 1 line
2.10.0
PATCH v3 10/14 MIPS: Join the coherent domain when a CM is present
In reply to Paul BurtonMIPS Linux expects the bootloader to leave the boot CPU a member of the coherent domain when running on a system with a CM, and we will need to do so if we wish to make use of IOCUs to have cache-coherent DMA in U-Boot (and on some systems there is no choice in that matter). When a CM is present, join the coherent domain after completing cache initialisation.
---
Changes in v3:
- New patch
Changes in v2: None
arch/mips/include/asm/cm.h | 5 +++++ arch/mips/lib/cache_init.S | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
arch/mips/include/asm/cm.h +5 -0
@@ -19,6 +19,7 @@#define GCR_L2_TAG_STATE_UPPER 0x060c#define GCR_L2_DATA 0x0610#define GCR_L2_DATA_UPPER 0x0614 +#define GCR_Cx_COHERENCE 0x2008/* GCR_REV CM versions */ #define GCR_REV_CM3 0x0800
@@ -32,6 +33,10 @@#define GCR_L2_CONFIG_SETSZ_BITS 4#define GCR_L2_CONFIG_BYPASS (1 << 20) +/* GCR_Cx_COHERENCE */ +#define GCR_Cx_COHERENCE_DOM_EN (0xff << 0) +#define GCR_Cx_COHERENCE_EN (0x1 << 0) +#ifndef __ASSEMBLY__#include <asm/io.h>
arch/mips/lib/cache_init.S +38 -0
@@ -378,6 +378,44 @@ l2_unbypass: ehb 2: +# ifdef CONFIG_MIPS_CM + /* Config3 must exist for a CM to be present */ + mfc0 t0, CP0_CONFIG, 1 + bgez t0, 2f + mfc0 t0, CP0_CONFIG, 2 + bgez t0, 2f + + /* Check Config3.CMGCR to determine CM presence */ + mfc0 t0, CP0_CONFIG, 3 + and t0, t0, MIPS_CONF3_CMGCR + beqz t0, 2f + + /* Change Config.K0 to a coherent CCA */ + mfc0 t0, CP0_CONFIG + li t1, CONF_CM_CACHABLE_COW +#if __mips_isa_rev >= 2 + ins t0, t1, 0, 3 +#else + ori t0, t0, CONF_CM_CMASK + xori t0, t0, CONF_CM_CMASK + or t0, t0, t1 +#endif + mtc0 t0, CP0_CONFIG + + /* + * Join the coherent domain such that the caches of this core are kept + * coherent with those of other cores. + */ + PTR_LI t0, CKSEG1ADDR(CONFIG_MIPS_CM_BASE) + lw t1, GCR_REV(t0) + li t2, GCR_REV_CM3 + li t3, GCR_Cx_COHERENCE_EN + bge t1, t2, 1f + li t3, GCR_Cx_COHERENCE_DOM_EN +1: sw t3, GCR_Cx_COHERENCE(t0) + ehb +2: +# endif #endif return:
Signature · 1 line
2.10.0
PATCH v3 11/14 MIPS: Malta: Enable CM & L2 support
In reply to Paul BurtonEnable support for the MIPS Coherence Manager & L2 caches on the MIPS Malta board, removing the need for us to attempt to bypass the L2 during boot (which would fail with recent CPUs that expose L2 config via the CM anyway).
---
Changes in v3: None
Changes in v2: None
arch/mips/Kconfig | 2 ++ board/imgtec/malta/lowlevel_init.S | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-)
arch/mips/Kconfig +2 -0
@@ -26,6 +26,8 @@ config TARGET_MALTA select DM select DM_SERIAL select DYNAMIC_IO_PORT_BASE + select MIPS_CM + select MIPS_L2_CACHE select OF_CONTROL select OF_ISA_BUS select SUPPORTS_BIG_ENDIAN
board/imgtec/malta/lowlevel_init.S +0 -6
@@ -28,12 +28,6 @@ .globl lowlevel_init lowlevel_init: - /* disable any L2 cache for now */ - sync - mfc0 t0, CP0_CONFIG, 2 - ori t0, t0, 0x1 << 12 - mtc0 t0, CP0_CONFIG, 2 - /* detect the core card */ PTR_LI t0, CKSEG1ADDR(MALTA_REVISION) lw t0, 0(t0)
Signature · 1 line
2.10.0
PATCH v3 12/14 MIPS: Ensure Config.K0=2 applies before any memory accesses
In reply to Paul BurtonDuring boot we set Config.K0=2 (uncached) such that any accesses to the kseg0 memory region are performed uncached before the caches are initialised. This write to the Config register introduces an execution hazard between it & any following memory accesses (such as the load of _gp), which we need to clear in order to ensure those memory accesses are actually performed uncached. Clear this execution hazard with the insertion of an ehb execution hazard barrier instruction.
---
Changes in v3:
- New patch
Changes in v2: None
arch/mips/cpu/start.S | 1 + 1 file changed, 1 insertion(+)
arch/mips/cpu/start.S +1 -0
@@ -127,6 +127,7 @@ reset: and t0, t0, MIPS_CONF_IMPL or t0, t0, CONF_CM_UNCACHED mtc0 t0, CP0_CONFIG + ehb #endif /*
Signature · 1 line
2.10.0
PATCH v3 13/14 MIPS: Clear hazard between TagLo writes & cache ops
In reply to Paul BurtonWriting to the coprocessor 0 TagLo registers introduces an execution hazard in that we need that write to complete before any cache instructions execute. Ensure that hazard is cleared by inserting an ehb instruction between the TagLo writes & cache op loop.
---
Changes in v3:
- New patch
Changes in v2: None
arch/mips/lib/cache_init.S | 1 + 1 file changed, 1 insertion(+)
arch/mips/lib/cache_init.S +1 -0
@@ -293,6 +293,7 @@ l2_init: l1_init: mtc0 zero, CP0_TAGLO mtc0 zero, CP0_TAGLO, 2 + ehb /* * The caches are probably in an indeterminate state, so we force good
Signature · 1 line
2.10.0
PATCH v3 14/14 MIPS: Ensure cache ops complete in mips_cache_reset
In reply to Paul BurtonEnsure that cache operations complete before returning from mips_cache_reset by placing a completion barrier (sync instruction) before the return. Without this there is no guarantee that the cache ops will complete before any subsequent memory accesses, since they are indexed cache ops & thus not implicitly ordered with memory accesses.
---
Changes in v3:
- New patch
Changes in v2: None
arch/mips/lib/cache_init.S | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/lib/cache_init.S +2 -0
@@ -420,6 +420,8 @@ l2_unbypass: #endif return: + /* Ensure all cache operations complete before returning */ + sync jr ra END(mips_cache_reset)
Signature · 1 line
2.10.0