@@ -560,6 +560,50 @@ flash_tlb:
560560 #endif
561561#endif /* ENABLE_DDR */
562562
563+ /* =========================================================================
564+ * CPC SRAM Initialization
565+ * Order: 1) CPC invalidate, 2) CPCSRCR config, 3) LAW, 4) TLB, 5) CPC enable
566+ * Note: TLB must be created BEFORE CPC enable (original working sequence)
567+ * ========================================================================= */
568+ #if defined(ENABLE_L2_CACHE) && defined(L2SRAM_ADDR) && (defined(CORE_E5500) || defined(CORE_E6500))
569+ cpc_setup_sram:
570+ /* T2080RM: 8.4.2.2 - CPC initialization sequence:
571+ * Step 1: Flash invalidate CPC and clear locks (CPCFI | CPCLFC)
572+ * Step 2: Poll until invalidate completes
573+ * Step 3: Configure SRAM control registers (CPCSRCR1, CPCSRCR0)
574+ * Step 4: Configure LAW for SRAM routing (done after this block)
575+ * Step 5: Enable CPC with parity (CPCE | CPCPE)
576+ * Step 6: Create TLB for SRAM access
577+ * The LAW (DDR_1) provides CoreNet routing; CPC intercepts before DDR. */
578+
579+ /* R1 = CPC base - preserve across LAW setup */
580+ LOAD_ADDR32(r1, CPC_BASE)
581+
582+ /* Step 1: Flash invalidate CPC and clear all locks */
583+ lis r0, (CPCCSR0_CPCFI | CPCCSR0_CPCLFC)@h
584+ ori r0, r0, (CPCCSR0_CPCFI | CPCCSR0_CPCLFC)@l
585+ stw r0, CPCCSR0(r1)
586+
587+ /* Step 2: Poll until CPCFI and CPCLFC clear */
588+ cpc_poll_invalidate:
589+ lwz r2, CPCCSR0(r1)
590+ and . r2, r2, r0
591+ bne cpc_poll_invalidate
592+ isync
593+
594+ /* Step 3: Configure CPC SRAM control registers */
595+ li r0, 0
596+ stw r0, CPCSRCR1(r1) /* SRAM high address = 0 */
597+ /* SRAM low address - use LOAD_ADDR32 on e6500 to avoid sign extension */
598+ LOAD_ADDR32(r0, L2SRAM_ADDR)
599+ /* Enable SRAM and set size (must match L2SRAM_SIZE = 512KB) */
600+ ori r0, r0, (CPCSRCR0_SRAMSZ_512 | CPCSRCR0_SRAMEN)
601+ stw r0, CPCSRCR0(r1)
602+ mbar
603+ isync
604+ #endif /* ENABLE_L2_CACHE && L2SRAM_ADDR */
605+
606+ /* Step 3: Configure LAW for SRAM */
563607#ifdef INITIAL_SRAM_ADDR
564608#ifndef INITIAL_SRAM_NO_LAW
565609init_sram_law:
@@ -570,60 +614,60 @@ init_sram_law:
570614 LOAD_ADDR32(r9, CCSRBAR + LAWBAR_BASE(2 ))
571615 li r0, 0 /* UPPER=0 */
572616 /* Use LOAD_ADDR32 on e6500 to avoid sign-extension for addresses >= 0x80000000 */
573- LOAD_ADDR32(r1 , INITIAL_SRAM_ADDR)
617+ LOAD_ADDR32(r3 , INITIAL_SRAM_ADDR)
574618 LOAD_ADDR32(r2, INITIAL_SRAM_LAW)
575619 stw r0, 0 (r9) /* LAWBARH */
576- stw r1 , 4 (r9) /* LAWBARL */
620+ stw r3 , 4 (r9) /* LAWBARL */
577621 sync
578622 stw r2, 8 (r9) /* LAWAR */
579623 /* read back LAWAR (per 2.3.2 Configuring Local Access Windows) */
580624 lwz r2, 8 (r9)
581625 isync
582626#endif /* !INITIAL_SRAM_NO_LAW */
627+ #endif /* INITIAL_SRAM_ADDR */
583628
629+ /* Step 4: Create TLB for SRAM - BEFORE CPC enable (original working order) */
630+ #ifdef INITIAL_SRAM_ADDR
584631init_sram_tlb:
585632 /* Initial SRAM: TLB 1, Entry 9, Supervisor X/R/W, M, TS=0, IPROT
586- * CPC SRAM uses cacheable memory-coherent (M) access.
587- * TLB is created BEFORE l2_setup_sram per old working code. */
633+ * Original working T2080 code (commit 11f46a51) used MAS2_M. */
588634 set_tlb(1 , 9 ,
589635 INITIAL_SRAM_ADDR, INITIAL_SRAM_ADDR, 0 ,
590636 MAS3_SX | MAS3_SW | MAS3_SR, MAS2_M, 0 ,
591637 INITIAL_SRAM_BOOKE_SZ, 1 , r3);
592- #endif
638+ #endif /* INITIAL_SRAM_ADDR */
593639
594- #ifdef ENABLE_L2_CACHE
595-
596- #if defined(CORE_E5500) || defined(CORE_E6500) /* --- L2 E5500/E6500 --- */
597- #ifdef L2SRAM_ADDR
598- l2_setup_sram:
599- /* T2080RM: 8.4.2.2 - CPC initialization
600- * Configure SRAM control registers, then enable CPC with parity.
601- * The LAW (DDR_1) provides CoreNet routing; CPC intercepts before DDR.
602- * SRAM is zeroed later via dcbz through cacheable TLB (MAS2_M). */
640+ /* Step 5: Enable CPC after TLB is configured */
641+ #if defined(ENABLE_L2_CACHE) && defined(L2SRAM_ADDR) && (defined(CORE_E5500) || defined(CORE_E6500))
642+ cpc_enable:
603643 /* R1 = CPC base */
604644 LOAD_ADDR32(r1, CPC_BASE)
605645
606- /* Configure CPC SRAM control registers */
607- li r0, 0
608- stw r0, CPCSRCR1(r1) /* SRAM high address = 0 */
609- /* SRAM low address - use LOAD_ADDR32 on e6500 to avoid sign extension */
610- LOAD_ADDR32(r0, L2SRAM_ADDR)
611- /* Enable SRAM and set size (must match L2SRAM_SIZE) */
612- ori r0, r0, (CPCSRCR0_SRAMSZ_1024 | CPCSRCR0_SRAMEN)
613- stw r0, CPCSRCR0(r1)
614-
615646 /* Enable CPC with parity */
616647 lis r0, (CPCCSR0_CPCE | CPCCSR0_CPCPE)@h
617648 mbar
618649 isync
619650 stw r0, CPCCSR0(r1)
620651 mbar
621652
653+ /* Verify CPC is enabled by reading back CPCCSR0 */
654+ cpc_poll_enable:
655+ lwz r2, CPCCSR0(r1)
656+ andis. r2, r2, CPCCSR0_CPCE@h /* check CPCE bit */
657+ beq cpc_poll_enable
658+ isync
659+
622660 /* Disable speculation (Errata A-006593) */
623661 lwz r0, CPCHDBCR0(r1)
624662 oris r0, r0, CPCHDBCR0_SPEC_DIS@h
625663 stw r0, CPCHDBCR0(r1)
626- #endif /* L2SRAM_ADDR */
664+ mbar
665+ isync
666+ #endif /* ENABLE_L2_CACHE && L2SRAM_ADDR */
667+
668+ #ifdef ENABLE_L2_CACHE
669+ #if defined(CORE_E5500) || defined(CORE_E6500) /* --- L2 E5500/E6500 --- */
670+ /* Note: CPC SRAM setup moved above for correct T2080RM sequence */
627671
628672#if defined(CORE_E6500) /* --- L2 E6500 --- */
629673l2_setup_cache:
@@ -653,6 +697,13 @@ l2_poll_invclear:
653697 isync
654698 LOAD_ADDR32(r4, (L2CSR0_L2E | L2CSR0_L2PE))
655699 stw r4, L2CSR0(r5)
700+ mbar
701+
702+ /* Verify L2 is enabled by reading back L2CSR0 */
703+ l2_poll_enable:
704+ lwz r3, L2CSR0(r5)
705+ andis. r3, r3, L2CSR0_L2E@h /* check bit 31 (L2E) */
706+ beq l2_poll_enable /* loop until enabled */
656707 isync
657708
658709#elif defined(CORE_E5500) /* --- L2 E5500 --- */
@@ -714,6 +765,17 @@ l2_setup_sram:
714765 stw r1, L2SRBAR0(r5)
715766 mbar
716767#endif /* L2SRAM_ADDR */
768+
769+ #ifdef INITIAL_SRAM_ADDR
770+ init_sram_tlb:
771+ /* Initial SRAM: TLB 1, Entry 9, Supervisor X/R/W, M, TS=0, IPROT
772+ * For e500, L2 SRAM uses cacheable memory-coherent (M) access.
773+ * TLB is created AFTER l2_setup_sram configures L2 as SRAM. */
774+ set_tlb(1 , 9 ,
775+ INITIAL_SRAM_ADDR, INITIAL_SRAM_ADDR, 0 ,
776+ MAS3_SX | MAS3_SW | MAS3_SR, MAS2_M, 0 ,
777+ INITIAL_SRAM_BOOKE_SZ, 1 , r3);
778+ #endif /* INITIAL_SRAM_ADDR */
717779#endif /* CORE_E500 */
718780#endif /* ENABLE_L2_CACHE */
719781
@@ -776,9 +838,9 @@ cache_sram_init_loop:
776838 bdnz cache_sram_init_loop
777839#elif defined(L2SRAM_ADDR)
778840cache_sram_init:
779- /* Zero CPC SRAM via cache (MAS2_M = cacheable, memory coherent) .
780- * dcbz allocates zeroed cache lines without reading from CPC,
781- * avoiding ECC/parity issues from uninitialized SRAM . */
841+ /* Zero CPC SRAM via dcbz .
842+ * With MAS2_M (memory-coherent), dcbz allocates zeroed cache lines.
843+ * This initializes SRAM and avoids ECC/parity issues from uninitialized data . */
782844 LOAD_ADDR32(r3, L2SRAM_ADDR)
783845 li r0, 0
784846 LOAD_ADDR32(r2, (L2SRAM_SIZE / CACHE_LINE_SIZE))
0 commit comments