3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 2011-2012 by Broadcom Corporation
10 * Used to init second core in dual core 5000's.
13 #include <linux/init.h>
16 #include <asm/asmmacro.h>
17 #include <asm/cacheops.h>
18 #include <asm/regdef.h>
19 #include <asm/mipsregs.h>
20 #include <asm/stackframe.h>
21 #include <asm/addrspace.h>
22 #include <asm/hazards.h>
23 #include <asm/bmips.h>
25 #ifdef CONFIG_CPU_BMIPS5000
28 #define cacheop(kva, size, linesize, op) \
30 addu t1, kva, size ; \
31 subu t2, linesize, 1 ; \
36 9: cache op, 0(t0) ; \
55 #define ICE_MASK 0x80000000
56 #define DCE_MASK 0x40000000
58 #define CP0_BRCM_CONFIG0 $22, 0
59 #define CP0_BRCM_MODE $22, 1
60 #define CP0_CONFIG_K0_MASK 7
62 #define CP0_ICACHE_TAG_LO $28
63 #define CP0_ICACHE_DATA_LO $28, 1
64 #define CP0_DCACHE_TAG_LO $28, 2
65 #define CP0_D_SEC_CACHE_DATA_LO $28, 3
66 #define CP0_ICACHE_TAG_HI $29
67 #define CP0_ICACHE_DATA_HI $29, 1
68 #define CP0_DCACHE_TAG_HI $29, 2
70 #define CP0_BRCM_MODE_Luc_MASK (1 << 11)
71 #define CP0_BRCM_CONFIG0_CWF_MASK (1 << 20)
72 #define CP0_BRCM_CONFIG0_TSE_MASK (1 << 19)
73 #define CP0_BRCM_MODE_SET_MASK (1 << 7)
74 #define CP0_BRCM_MODE_ClkRATIO_MASK (7 << 4)
75 #define CP0_BRCM_MODE_BrPRED_MASK (3 << 24)
76 #define CP0_BRCM_MODE_BrPRED_SHIFT 24
77 #define CP0_BRCM_MODE_BrHIST_MASK (0x1f << 20)
78 #define CP0_BRCM_MODE_BrHIST_SHIFT 20
80 /* ZSC L2 Cache Register Access Register Definitions */
81 #define BRCM_ZSC_ALL_REGS_SELECT 0x7 << 24
83 #define BRCM_ZSC_CONFIG_REG 0 << 3
84 #define BRCM_ZSC_REQ_BUFFER_REG 2 << 3
85 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG0 4 << 3
86 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG1 6 << 3
87 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG2 8 << 3
89 #define BRCM_ZSC_SCB0_ADDR_MAPPING_REG0 0xa << 3
90 #define BRCM_ZSC_SCB0_ADDR_MAPPING_REG1 0xc << 3
92 #define BRCM_ZSC_SCB1_ADDR_MAPPING_REG0 0xe << 3
93 #define BRCM_ZSC_SCB1_ADDR_MAPPING_REG1 0x10 << 3
95 #define BRCM_ZSC_CONFIG_LMB1En 1 << (15)
96 #define BRCM_ZSC_CONFIG_LMB0En 1 << (14)
98 /* branch predition values */
100 #define BRCM_BrPRED_ALL_TAKEN (0x0)
101 #define BRCM_BrPRED_ALL_NOT_TAKEN (0x1)
102 #define BRCM_BrPRED_BHT_ENABLE (0x2)
103 #define BRCM_BrPRED_PREDICT_BACKWARD (0x3)
109 * Function: size_i_cache
111 * Returns: v0 = i cache size, v1 = I cache line size
112 * Description: compute the I-cache size and I-cache line size
113 * Trashes: v0, v1, a0, t0
122 mfc0 a0, CP0_CONFIG, 1
126 * Determine sets per way: IS
128 * This field contains the number of sets (i.e., indices) per way of
129 * the instruction cache:
130 * i) 0x0: 64, ii) 0x1: 128, iii) 0x2: 256, iv) 0x3: 512, v) 0x4: 1k
131 * vi) 0x5 - 0x7: Reserved.
137 /* sets per way = (64<<IS) */
143 * Determine line size
145 * This field contains the line size of the instruction cache:
146 * i) 0x0: No I-cache present, i) 0x3: 16 bytes, ii) 0x4: 32 bytes, iii)
147 * 0x5: 64 bytes, iv) the rest: Reserved.
158 /* line size = 2 ^ (IL+1) */
164 /* v0 now have sets per way, multiply it by line size now
165 * that will give the set size
171 * Determine set associativity
173 * This field contains the set associativity of the instruction cache.
174 * i) 0x0: Direct mapped, ii) 0x1: 2-way, iii) 0x2: 3-way, iv) 0x3:
175 * 4-way, v) 0x4 - 0x7: Reserved.
184 /* v0 has the set size, multiply it by
185 * set associativiy, to get the cache size
188 multu v0, a0 /*multu is interlocked, so no need to insert nops */
204 * Function: size_d_cache
206 * Returns: v0 = d cache size, v1 = d cache line size
207 * Description: compute the D-cache size and D-cache line size.
208 * Trashes: v0, v1, a0, t0
215 mfc0 a0, CP0_CONFIG, 1
219 * Determine sets per way: IS
221 * This field contains the number of sets (i.e., indices) per way of
222 * the instruction cache:
223 * i) 0x0: 64, ii) 0x1: 128, iii) 0x2: 256, iv) 0x3: 512, v) 0x4: 1k
224 * vi) 0x5 - 0x7: Reserved.
230 /* sets per way = (64<<IS) */
236 * Determine line size
238 * This field contains the line size of the instruction cache:
239 * i) 0x0: No I-cache present, i) 0x3: 16 bytes, ii) 0x4: 32 bytes, iii)
240 * 0x5: 64 bytes, iv) the rest: Reserved.
250 /* line size = 2 ^ (IL+1) */
256 /* v0 now have sets per way, multiply it by line size now
257 * that will give the set size
262 /* determine set associativity
264 * This field contains the set associativity of the instruction cache.
265 * i) 0x0: Direct mapped, ii) 0x1: 2-way, iii) 0x2: 3-way, iv) 0x3:
266 * 4-way, v) 0x4 - 0x7: Reserved.
275 /* v0 has the set size, multiply it by
276 * set associativiy, to get the cache size
279 multu v0, a0 /*multu is interlocked, so no need to insert nops */
297 * Function: enable_ID
300 * Description: Enable I and D caches, initialize I and D-caches, also set
301 * hardware delay for d-cache (TP0).
309 mfc0 t0, CP0_BRCM_CONFIG0
310 or t0, t0, (ICE_MASK | DCE_MASK)
311 mtc0 t0, CP0_BRCM_CONFIG0
323 * Description: Enable I and D caches, and initialize I and D-caches
324 * Trashes: a0, v0, v1, t0, t1, t2, t8
332 /* save return address */
336 /* initialize I and D cache Data and Tag registers. */
337 mtc0 zero, CP0_ICACHE_TAG_LO
338 mtc0 zero, CP0_ICACHE_TAG_HI
339 mtc0 zero, CP0_ICACHE_DATA_LO
340 mtc0 zero, CP0_ICACHE_DATA_HI
341 mtc0 zero, CP0_DCACHE_TAG_LO
342 mtc0 zero, CP0_DCACHE_TAG_HI
344 /* Enable Caches before Clearing. If the caches are disabled
345 * then the cache operations to clear the cache will be ignored
351 jal size_i_cache /* v0 = i-cache size, v1 = i-cache line size */
354 /* run uncached in kseg 1 */
367 and t0, t0, ~CP0_CONFIG_K0_MASK
368 or t0, t0, 3 /* Write Back mode */
372 * Initialize instruction cache.
376 cacheop(a0, v0, v1, Index_Store_Tag_I)
379 * Now we can run from I-$, kseg 0
389 * Initialize data cache.
392 jal size_d_cache /* v0 = d-cache size, v1 = d-cache line size */
397 cacheop(a0, v0, v1, Index_Store_Tag_D)
407 * Function: set_other_config
410 * Description: initialize other remainder configuration to defaults.
416 LEAF(set_other_config)
419 /* enable Bus error for I-fetch */
420 mfc0 t0, CP0_CACHEERR, 0
423 mtc0 t0, CP0_CACHEERR, 0
425 /* enable Bus error for Load */
426 mfc0 t0, CP0_CACHEERR, 1
429 mtc0 t0, CP0_CACHEERR, 1
431 /* enable Bus Error for Store */
432 mfc0 t0, CP0_CACHEERR, 2
435 mtc0 t0, CP0_CACHEERR, 2
440 END(set_other_config)
443 * Function: set_branch_pred
453 LEAF(set_branch_pred)
455 mfc0 t0, CP0_BRCM_MODE
456 li t1, ~(CP0_BRCM_MODE_BrPRED_MASK | CP0_BRCM_MODE_BrHIST_MASK )
459 /* enable Branch prediction */
460 li t1, BRCM_BrPRED_BHT_ENABLE
461 sll t1, CP0_BRCM_MODE_BrPRED_SHIFT
464 /* set history count to 8 */
466 sll t1, CP0_BRCM_MODE_BrHIST_SHIFT
469 mtc0 t0, CP0_BRCM_MODE
478 * Arguments: set link uncached.
486 mfc0 t0, CP0_BRCM_MODE
487 li t1, ~(CP0_BRCM_MODE_Luc_MASK)
491 ori t0, t0, CP0_BRCM_MODE_Luc_MASK
493 mtc0 t0, CP0_BRCM_MODE
500 * Function: set_cwf_tse
501 * Arguments: set CWF and TSE bits
509 mfc0 t0, CP0_BRCM_CONFIG0
510 li t1, (CP0_BRCM_CONFIG0_CWF_MASK | CP0_BRCM_CONFIG0_TSE_MASK)
513 mtc0 t0, CP0_BRCM_CONFIG0
520 * Function: set_clock_ratio
521 * Arguments: set clock ratio specified by a0
524 * Trashes: v0, v1, a0, a1
529 LEAF(set_clock_ratio)
532 mfc0 t0, CP0_BRCM_MODE
533 li t1, ~(CP0_BRCM_MODE_SET_MASK | CP0_BRCM_MODE_ClkRATIO_MASK)
535 li t1, CP0_BRCM_MODE_SET_MASK
538 mtc0 t0, CP0_BRCM_MODE
544 * Function: set_zephyr
547 * Description: Set any zephyr bits
554 /* enable read/write of CP0 #22 sel. 8 */
556 .word 0x4088b00f /* mtc0 t0, $22, 15 */
558 .word 0x4008b008 /* mfc0 t0, $22, 8 */
559 li t1, 0x09008000 /* turn off pref, jtb */
561 .word 0x4088b008 /* mtc0 t0, $22, 8 */
564 /* disable read/write of CP0 #22 sel 8 */
566 .word 0x4088b00f /* mtc0 t0, $22, 15 */
578 * Arguments: a0=0 disable llmb, a0=1 enables llmb
581 * Trashes: t0, t1, t2
589 li t2, 0x90000000 | BRCM_ZSC_ALL_REGS_SELECT | BRCM_ZSC_CONFIG_REG
593 mfc0 t0, CP0_D_SEC_CACHE_DATA_LO
594 li t1, ~(BRCM_ZSC_CONFIG_LMB1En | BRCM_ZSC_CONFIG_LMB0En)
601 li t1, (BRCM_ZSC_CONFIG_LMB1En | BRCM_ZSC_CONFIG_LMB0En)
605 mtc0 t0, CP0_D_SEC_CACHE_DATA_LO
616 * Function: core_init
619 * Description: initialize core related configuration
620 * Trashes: v0,v1,a0,a1,t8
631 /* set Zephyr bits. */
636 /* initialize the Floating point unit (both TPs) */
641 /* set low latency memory bus */
646 /* set branch prediction (TP0 only) */
650 /* set link uncached */
654 /* set CWF and TSE */
659 *set clock ratio by setting 1 to 'set'
660 * and 0 to ClkRatio, (TP0 only)
666 /* set other configuration to defaults */
678 * Function: clear_jump_target_buffer
682 * Trashes: t0, t1, t2
685 #define RESET_CALL_RETURN_STACK_THIS_THREAD (0x06<<16)
686 #define RESET_JUMP_TARGET_BUFFER_THIS_THREAD (0x04<<16)
687 #define JTB_CS_CNTL_MASK (0xFF<<16)
689 .globl clear_jump_target_buffer
690 .ent clear_jump_target_buffer
692 clear_jump_target_buffer:
698 li t1, ~JTB_CS_CNTL_MASK
700 li t2, RESET_CALL_RETURN_STACK_THIS_THREAD
707 li t2, RESET_JUMP_TARGET_BUFFER_THIS_THREAD
715 .end clear_jump_target_buffer
718 * Function: bmips_cache_init
721 * Description: Enable I and D caches, and initialize I and D-caches
722 * Trashes: v0, v1, t0, t1, t2, t5, t7, t8
725 .globl bmips_5xxx_init
730 /* save return address and A0 */
740 jal clear_jump_target_buffer