1 /* *********************************************************************
2 * SB1250 Board Support Package
4 * L2 Cache initialization File: sb1250_l2cache.S
6 * This module contains code to initialize the L2 cache.
8 * Note: all the routines in this module rely on registers only,
9 * since DRAM may not be active yet.
11 * Author: Mitch Lichtenberg (mpl@broadcom.com)
13 *********************************************************************
15 * Copyright 2000,2001,2002,2003
16 * Broadcom Corporation. All rights reserved.
18 * This software is furnished under license and may be used and
19 * copied only in accordance with the following terms and
20 * conditions. Subject to these conditions, you may download,
21 * copy, install, use, modify and distribute modified or unmodified
22 * copies of this software in source and/or binary form. No title
23 * or ownership is transferred hereby.
25 * 1) Any source code used, modified or distributed must reproduce
26 * and retain this copyright notice and list of conditions
27 * as they appear in the source file.
29 * 2) No right is granted to use any trade name, trademark, or
30 * logo of Broadcom Corporation. The "Broadcom Corporation"
31 * name may not be used to endorse or promote products derived
32 * from this software without the prior written permission of
33 * Broadcom Corporation.
35 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47 * THE POSSIBILITY OF SUCH DAMAGE.
48 ********************************************************************* */
51 #include "mipsmacros.h"
52 #include "sb1250_regs.h"
53 #include "sb1250_l2c.h"
54 #include "sb1250_mc.h"
55 #include "sb1250_scd.h"
56 #include "sb1250_wid.h"
59 * This lets us override the WID by poking values into our PromICE
62 #undef A_SCD_SYSTEM_REVISION
63 #define A_SCD_SYSTEM_REVISION 0x1FC00508
70 /* *********************************************************************
72 ********************************************************************* */
74 /*#define PHYS_TO_XKPHYS(x) (0x9000000000000000|(x))*/
75 #define CACHE_LINE_SIZE 32
76 #define HAZARD ssnop ; ssnop ; ssnop ; ssnop ; ssnop ; ssnop ; ssnop
78 #define IF_BIN(binreg,binmask,label) \
80 andi AT,binreg,binmask ; \
84 /* In the WID register, 0=top/left, 1=bottom/left, 2=top/right, 3=bottom/right */
86 #define DISAB_TOP 0x800
87 #define DISAB_BOT 0x400
88 #define DISAB_RGT 0x200
89 #define DISAB_LFT 0x100
91 /* *********************************************************************
92 * SB1250_L2CACHE_DISABTABLE
94 * This table maps the WID l2 diagnostic bits onto the disable
95 * mask for the L2 disable register.
97 * There are 8 entries in the table, with the index as followS:
101 * H = 0 if only 1/4 of the cache is valid
102 * H = 1 if 1/2 of the cache is valid
103 * WW is the way number (or half number) that is valid
104 ********************************************************************* */
107 * This is how the quadrant numbers are actually organized:
113 sb1250_l2cache_disabtable:
115 .word DISAB_LFT /* Good=0(right) Disable: left */
116 .word DISAB_LFT /* Good=1(right) Disable: left */
117 .word DISAB_RGT /* Good=2(left) Disable: right */
118 .word DISAB_RGT /* Good=3(left) Disable: right */
120 .word DISAB_RGT|DISAB_TOP /* Good=0(bot/left), Disable: top,right */
121 .word DISAB_RGT|DISAB_BOT /* Good=1(top/left), Disable: bottom,right */
122 .word DISAB_LFT|DISAB_TOP /* Good=2(bot/right), Disable: top,left */
123 .word DISAB_LFT|DISAB_BOT /* Good=3(top/right), Disable: bottom,left */
126 // Old table for historical value, when we
127 // thought the quadrant numbers were:
132 // .word DISAB_RGT|DISAB_BOT /* Good=0(top/left), Disable: right,bottom */
133 // .word DISAB_RGT|DISAB_TOP /* Good=1(bot/left), Disable: right,top */
134 // .word DISAB_LFT|DISAB_BOT /* Good=2(top/right), Disable: left,bottom */
135 // .word DISAB_LFT|DISAB_TOP /* Good=3(bot/right), Disable: left,top */
138 /* *********************************************************************
139 * SB1250_L2CACHE_INIT()
141 * Initialize the L2 Cache tags to be "invalid"
151 ********************************************************************* */
154 LEAF(sb1250_l2cache_init)
156 # Do nothing (return immediately) if L2 has been disabled via JTAG.
158 li t0, PHYS_TO_K1(A_SCD_SYSTEM_CFG)
160 and t0, t0, M_SYS_L2C_RESET
165 # Save the old status register, and set the KX bit.
172 # Start the index at the base of the cache management
173 # area, but leave the address bit for "Valid" zero.
174 # Note that the management tags are at 00_D000_0000,
175 # which cannot be expressed with the PHYS_TO_K1 macro,
176 # so well need to use a 64-bit address to get to it.
178 dli t0,PHYS_TO_XKSEG_UNCACHED(A_L2C_MGMT_TAG_BASE)
180 # Loop through each entry and each way
185 li t1,L2C_ENTRIES_PER_WAY*L2C_NUM_WAYS
189 # Write a zero to the cache management register at each
194 sd zero,CACHE_LINE_SIZE(t0)
195 sd zero,2*CACHE_LINE_SIZE(t0)
196 sd zero,3*CACHE_LINE_SIZE(t0)
197 daddu t0,(4*CACHE_LINE_SIZE) # size of a cache line
202 # Restore old KX bit setting
210 * Test to see if we're running on a pre-production part with
211 * a defective L1 cache. We store information in the SCD
212 * SYSTEM_REVISION register that identifies what is
217 * First, check the part number
220 li t0,PHYS_TO_K1(A_SCD_SYSTEM_REVISION)
221 ld t1,0(t0) /* get SYSTEM_REVISION */
223 dsrl t1,t1,S_SYS_PART
224 andi t1,t1,(M_SYS_PART >> S_SYS_PART)
226 beq t1,0x1250,sb1250_l2cache_check_rev /* Go if real 1250 */
227 beq t1,0x1150,sb1250_l2cache_check_rev /* or 1250 in uni-cpu mode */
228 b sb1250_l2cache_init_good /* otherwise not a 1250, no WID check */
231 * Now, check the revision. Anything earlier than step A3
232 * does not need this check. Pass 3 does not need this check also.
234 * Exception: Step A6 parts return 0x04 in their revision field.
235 * These parts can can be verified as A6 by having a nonzero WID.
238 sb1250_l2cache_check_rev:
239 ld t1,0(t0) /* get the SYSTEM_REVISION again */
240 dsrl t1,t1,S_SYS_REVISION
241 andi t1,t1,(M_SYS_REVISION >> S_SYS_REVISION)
242 beq t1,0x04,sb1250_l2cache_check_wid
243 blt t1,0x05,sb1250_l2cache_init_good
244 bge t1,0x20,sb1250_l2cache_init_good
247 * Okay, we really need to check the WID now. If the WID is
248 * not programmed at all, assume the part is good.
249 * (yes, this includes the wafer/lot bits)
252 sb1250_l2cache_check_wid:
253 ld t1,0(t0) /* Get the WID bits back */
254 dsrl t1,t1,S_SYS_WID /* wafer ID to bits 0..31 */
255 li t2,(M_SYS_WID >> S_SYS_WID)
258 WID_UNCONVOLUTE(t1,t2,t3,t4)
260 beq t1,zero,sb1250_l2cache_init_good
263 * Get the bin number from the WID. This tells us many things.
264 * For the L1 cache we need to know which ways to use,
265 * and this is determined by what we put in the tag registers.
268 andi t0,t1,M_WID_BIN /* bin # into T0 */
269 li t2,1 /* make a bitmask */
270 sll t0,t2,t0 /* put '1' in correct place */
273 * t0 now contains a single bit set corresponding to the bin number
274 * that this chip belongs to.
275 * for example, if it is in bin 4, then the value is 1<<4
279 * Check for the case of a fully operational cache.
282 IF_BIN(t0,M_WID_BIN_F2,sb1250_l2cache_init_good)
285 * Get the WID register again and isolate the L2 cache bits. Combine
286 * this with the "1/2" attribute in the bin bitmask to form the
287 * offset of our table.
290 li t1,PHYS_TO_K1(A_SCD_SYSTEM_REVISION)
292 dsrl t1,t1,S_SYS_WID /* get WID bits */
294 WID_UNCONVOLUTE(t1,t2,t3,t4)
296 dsrl t1,t1,S_WID_L2QTR
297 andi t1,t1,(M_WID_L2QTR >> S_WID_L2QTR)
299 IF_BIN(t0,M_WID_BIN_H2,1f)
300 ori t1,t1,0x04 /* t1 = index into table */
303 sll t1,2 /* make 32-bit offset */
306 LOADREL(t0,sb1250_l2cache_disabtable)
308 move ra,t2 /* get address of table */
310 add t0,t0,t1 /* t0 = address of element in table */
311 lw t0,0(t0) /* t0 = address for WAY_DISABLE */
312 li t1,PHYS_TO_K1(A_L2_CACHE_DISABLE) /* Quadrant disable */
313 or t1,t1,t0 /* OR in the address bits */
315 sd t0,0(t1) /* do the memory reference */
318 sb1250_l2cache_init_good:
319 j ra # return to caller
321 END(sb1250_l2cache_init)
324 /* *********************************************************************
325 * SB1250_L2CACHE_DISABLE()
327 * Convert the entire L2 Cache into static memory, for use by
328 * the bootstrap loader. Actually, it only removes three of the
329 * ways, since you must leave at least one way active at all
340 ********************************************************************* */
343 LEAF(sb1250_l2cache_disable)
345 # Do nothing (return immediately) if L2 has been disabled via JTAG.
347 li t0, PHYS_TO_K1(A_SCD_SYSTEM_CFG)
349 and t0, t0, M_SYS_L2C_RESET
354 # Save the old status register, and set the KX bit.
355 # Configure the L2 cache as SRAM (all ways disabled except one)
356 # Do a memory reference at the "way_disable" address
358 # Warning: do NOT try to configure all of the ways off - you
359 # must leave at least one way active! This code leaves
360 # way #3 active and gives ways 0..2 to the program.
362 li t0,PHYS_TO_K1(A_L2_MAKEDISABLE(0x07))
365 # Use the result of the load to stall the pipe here.
367 # XXX is this necessary for global enable/disable operations?
371 # Re-write all the tags
373 b sb1250_l2cache_init
375 END(sb1250_l2cache_disable)
378 /* *********************************************************************
379 * SB1250_L2CACHE_ENABLE()
381 * Convert the L2 Cache memory into the actual L2 cache, enabling
382 * the cache for future memory accesses.
392 ********************************************************************* */
394 LEAF(sb1250_l2cache_enable)
396 # Do nothing (return immediately) if L2 has been disabled via JTAG.
398 li t0, PHYS_TO_K1(A_SCD_SYSTEM_CFG)
400 and t0, t0, M_SYS_L2C_RESET
405 # Save the old status register, and set the KX bit.
406 # Configure the L2 cache as Cache (all ways enabled)
407 # Do a memory reference at the "way_disable" address
410 li t0,PHYS_TO_K1(A_L2_MAKEDISABLE(0x0))
413 # Use the result of the load to stall the pipe here.
415 # XXX is this necessary for global enable/disable operations?
419 # Re-write all the tags
421 b sb1250_l2cache_init
423 END(sb1250_l2cache_enable)
426 /* *********************************************************************
427 * SB1250_L2CACHE_FLUSH()
429 * Flush the entire L2 cache. All dirty lines are written back
436 * v0 - number of lines flushed
439 * t0,t1,t2,t3,t4,t5,t6,t7,a0,s1,s2,s3,s4
440 ********************************************************************* */
442 LEAF(sb1250_l2cache_flush)
444 # Do nothing (return immediately) if L2 has been disabled via JTAG.
446 li t0, PHYS_TO_K1(A_SCD_SYSTEM_CFG)
448 and t0, t0, M_SYS_L2C_RESET
453 # Save the old status register, and set the KX bit.
461 # Set the BERR bits in both memory controllers. We're
462 # going to do cacheable reads where there is no memory.
465 # Note that on an 1125, we can still do this on MC 0 even
466 # though there is only one memory controller. The register
467 # is there, it just ignores the bits we're trying to write.
470 li t0,PHYS_TO_K1(A_MC_REGISTER(0,R_MC_CONFIG))
472 dli t1,(M_MC_BERR_DISABLE | M_MC_ECC_DISABLE)
476 li t0,PHYS_TO_K1(A_MC_REGISTER(1,R_MC_CONFIG))
478 dli t1,(M_MC_BERR_DISABLE | M_MC_ECC_DISABLE)
482 # Start the index at the base of the cache management area.
483 # Note that the management tags are at 00_D000_0000,
484 # which cannot be expressed with the PHYS_TO_K1 macro,
485 # so well need to use a 64-bit address to get to it.
487 # Set up the common values which may be massaged by WID info
489 li s1,PHYS_TO_K1(A_L2_READ_ADDRESS)
492 dli s3,PHYS_TO_XKSEG_UNCACHED(A_L2C_MGMT_TAG_BASE)
496 * Test to see if we're running on a pre-production part with
497 * a defective L1 cache. We store information in the SCD
498 * SYSTEM_REVISION register that identifies what is
503 * First, check the part number
506 li t0,PHYS_TO_K1(A_SCD_SYSTEM_REVISION)
507 ld t1,0(t0) /* get SYSTEM_REVISION */
509 dsrl t1,t1,S_SYS_PART
510 andi t1,t1,(M_SYS_PART >> S_SYS_PART)
512 beq t1,0x1250,1f /* Go if real 1250 */
513 beq t1,0x1150,1f /* or 1250 in uni-cpu mode */
514 b l2f_full /* otherwise not a 1250, no WID check */
517 * Now, check the revision. Anything earlier than step A3
518 * does not need this check.
520 * Exception: Step A6 parts return 0x04 in their revision field.
521 * These parts can can be verified as A6 by having a nonzero WID.
524 1: ld t1,0(t0) /* get the SYSTEM_REVISION again */
525 dsrl t1,t1,S_SYS_REVISION
526 andi t1,t1,(M_SYS_REVISION >> S_SYS_REVISION)
531 * Okay, we really need to check the WID now. If the WID is
532 * not programmed at all, assume the part is good.
533 * (yes, this includes the wafer/lot bits)
536 1: ld t1,0(t0) /* Get the WID bits back */
537 dsrl t1,t1,S_SYS_WID /* wafer ID to bits 0..31 */
538 li t2,(M_SYS_WID >> S_SYS_WID)
541 WID_UNCONVOLUTE(t1,t2,t3,t4)
546 * Get the bin number from the WID. This tells us many things.
547 * For the L1 cache we need to know which ways to use,
548 * and this is determined by what we put in the tag registers.
551 andi t0,t1,M_WID_BIN /* bin # into T0 */
552 li t2,1 /* make a bitmask */
553 sll t0,t2,t0 /* put '1' in correct place */
556 * t0 now contains a single bit set corresponding to the bin number
557 * that this chip belongs to.
558 * for example, if it is in bin 4, then the value is 1<<4
562 * Check for the case of a fully operational cache.
565 IF_BIN(t0,M_WID_BIN_F2,l2f_full)
568 * Get the WID register again and isolate the L2 cache bits. Combine
569 * this with the "1/2" attribute in the bin bitmask to form the
570 * offset of our table.
573 li t1,PHYS_TO_K1(A_SCD_SYSTEM_REVISION)
575 dsrl t1,t1,S_SYS_WID /* get WID bits */
577 WID_UNCONVOLUTE(t1,t2,t3,t4)
579 dsrl t1,t1,S_WID_L2QTR
580 andi t1,t1,(M_WID_L2QTR >> S_WID_L2QTR)
582 IF_BIN(t0,M_WID_BIN_H2,l2f_half)
584 l2f_quarter: li s4,L2C_ENTRIES_PER_WAY/4
585 dsll t1,S_L2C_MGMT_QUADRANT
589 l2f_half: li s4,L2C_ENTRIES_PER_WAY/2
592 dsll t1,S_L2C_MGMT_HALF
596 l2f_full: li s4,L2C_ENTRIES_PER_WAY
598 # Loop through each entry and each way
603 # Do a read at the cache management address to set the
604 # A_L2_READ_TAG register.
606 2: ld t3,0(t0) # this sets the register.
607 daddu t3,t3,0 # Do an ALU op to ensure ordering
608 ld t4,0(s1) # Get the tag
609 li t5,M_L2C_TAG_DIRTY
610 and t5,t4,t5 # Test the dirty bit
611 beq t5,zero,3f # don't flush this line
614 # The way that we're looking at now will be the victim, so all we
615 # need to do is a cacheable read at any address that does *not*
616 # match this tag. To do this, we're going to OR in some bits
617 # into the physical address to put it way outside the memory area.
618 # Then do a cacheable read. The current way will be replaced
619 # with the garbage data. We'll pick PA 30_0000_0000 in the middle
620 # of the 520GB memory expansion area for this purpose.
623 add v0,1 # count this line (debug)
625 dli t5,(M_L2C_TAG_TAG|M_L2C_TAG_INDEX)
626 and t4,t4,t5 # Have a physical address
627 dli t5,PHYS_TO_XKSEG_CACHED(0x3000000000)
629 ld t4,0(t4) # Do a read.
630 daddu t4,1 # Use it in an ALU op.
633 3: daddu t0,CACHE_LINE_SIZE # size of a cache line
637 daddu s3,V_L2C_MGMT_WAY(1)
643 # Now, reinit the entire cache. Of course, we could just
644 # reinit the lines we flushed, but this routine is mucking
645 # the entire cache anyway, so it doesn't matter.
649 dli t0,PHYS_TO_XKSEG_UNCACHED(A_L2C_MGMT_TAG_BASE)
650 li t1,L2C_ENTRIES_PER_WAY*L2C_NUM_WAYS
652 # Write a zero to the cache management register at each
656 sd zero,CACHE_LINE_SIZE(t0)
657 sd zero,2*CACHE_LINE_SIZE(t0)
658 sd zero,3*CACHE_LINE_SIZE(t0)
659 daddu t0,(4*CACHE_LINE_SIZE) # size of a cache line
664 # Restore the old MC register values
668 li t0,PHYS_TO_K1(A_MC_REGISTER(0,R_MC_CONFIG))
671 li t0,PHYS_TO_K1(A_MC_REGISTER(1,R_MC_CONFIG))
675 # Restore old KX bit setting
681 j ra # return to caller
683 END(sb1250_l2cache_flush)
688 /* *********************************************************************
690 ********************************************************************* */