cpu_init_early.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright 2009-2012 Freescale Semiconductor, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/processor.h>
  8. #include <asm/mmu.h>
  9. #include <asm/fsl_law.h>
  10. #include <asm/io.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. #ifdef CONFIG_A003399_NOR_WORKAROUND
  13. void setup_ifc(void)
  14. {
  15. struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR;
  16. u32 _mas0, _mas1, _mas2, _mas3, _mas7;
  17. phys_addr_t flash_phys = CONFIG_SYS_FLASH_BASE_PHYS;
  18. /*
  19. * Adjust the TLB we were running out of to match the phys addr of the
  20. * chip select we are adjusting and will return to.
  21. */
  22. flash_phys += (~CONFIG_SYS_AMASK0) + 1 - 4*1024*1024;
  23. _mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(15);
  24. _mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_IPROT |
  25. MAS1_TSIZE(BOOKE_PAGESZ_4M);
  26. _mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_TEXT_BASE, MAS2_I|MAS2_G);
  27. _mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
  28. _mas7 = FSL_BOOKE_MAS7(flash_phys);
  29. mtspr(MAS0, _mas0);
  30. mtspr(MAS1, _mas1);
  31. mtspr(MAS2, _mas2);
  32. mtspr(MAS3, _mas3);
  33. mtspr(MAS7, _mas7);
  34. asm volatile("isync;msync;tlbwe;isync");
  35. #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB)
  36. /*
  37. * TLB entry for debuggging in AS1
  38. * Create temporary TLB entry in AS0 to handle debug exception
  39. * As on debug exception MSR is cleared i.e. Address space is changed
  40. * to 0. A TLB entry (in AS0) is required to handle debug exception generated
  41. * in AS1.
  42. *
  43. * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
  44. * bacause flash's physical address is going to change as
  45. * CONFIG_SYS_FLASH_BASE_PHYS.
  46. */
  47. _mas0 = MAS0_TLBSEL(1) |
  48. MAS0_ESEL(CONFIG_SYS_PPC_E500_DEBUG_TLB);
  49. _mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_IPROT |
  50. MAS1_TSIZE(BOOKE_PAGESZ_4M);
  51. _mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_TEXT_BASE, MAS2_I|MAS2_G);
  52. _mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
  53. _mas7 = FSL_BOOKE_MAS7(flash_phys);
  54. mtspr(MAS0, _mas0);
  55. mtspr(MAS1, _mas1);
  56. mtspr(MAS2, _mas2);
  57. mtspr(MAS3, _mas3);
  58. mtspr(MAS7, _mas7);
  59. asm volatile("isync;msync;tlbwe;isync");
  60. #endif
  61. /* Change flash's physical address */
  62. out_be32(&(ifc_regs->cspr_cs[0].cspr), CONFIG_SYS_CSPR0);
  63. out_be32(&(ifc_regs->csor_cs[0].csor), CONFIG_SYS_CSOR0);
  64. out_be32(&(ifc_regs->amask_cs[0].amask), CONFIG_SYS_AMASK0);
  65. return ;
  66. }
  67. #endif
  68. /* We run cpu_init_early_f in AS = 1 */
  69. void cpu_init_early_f(void *fdt)
  70. {
  71. u32 mas0, mas1, mas2, mas3, mas7;
  72. int i;
  73. #ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
  74. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  75. #endif
  76. #ifdef CONFIG_A003399_NOR_WORKAROUND
  77. ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  78. u32 *dst, *src;
  79. void (*setup_ifc_sram)(void);
  80. #endif
  81. /* Pointer is writable since we allocated a register for it */
  82. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  83. /*
  84. * Clear initial global data
  85. * we don't use memset so we can share this code with NAND_SPL
  86. */
  87. for (i = 0; i < sizeof(gd_t); i++)
  88. ((char *)gd)[i] = 0;
  89. #ifdef CONFIG_QEMU_E500
  90. /*
  91. * CONFIG_SYS_CCSRBAR_PHYS below may use gd->fdt_blob on ePAPR systems,
  92. * so we need to populate it before it accesses it.
  93. */
  94. gd->fdt_blob = fdt;
  95. #endif
  96. mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(13);
  97. mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_1M);
  98. mas2 = FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, MAS2_I|MAS2_G);
  99. mas3 = FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS, 0, MAS3_SW|MAS3_SR);
  100. mas7 = FSL_BOOKE_MAS7(CONFIG_SYS_CCSRBAR_PHYS);
  101. write_tlb(mas0, mas1, mas2, mas3, mas7);
  102. /*
  103. * Work Around for IFC Erratum A-003549. This issue is P1010
  104. * specific. LCLK(a free running clk signal) is muxed with IFC_CS3 on P1010 SOC
  105. * Hence specifically selecting CS3.
  106. */
  107. #ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
  108. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_LCLK_IFC_CS3);
  109. #endif
  110. init_laws();
  111. /*
  112. * Work Around for IFC Erratum A003399, issue will hit only when execution
  113. * from NOR Flash
  114. */
  115. #ifdef CONFIG_A003399_NOR_WORKAROUND
  116. #define SRAM_BASE_ADDR (0x00000000)
  117. /* TLB for SRAM */
  118. mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(9);
  119. mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS |
  120. MAS1_TSIZE(BOOKE_PAGESZ_1M);
  121. mas2 = FSL_BOOKE_MAS2(SRAM_BASE_ADDR, MAS2_I);
  122. mas3 = FSL_BOOKE_MAS3(SRAM_BASE_ADDR, 0, MAS3_SX|MAS3_SW|MAS3_SR);
  123. mas7 = FSL_BOOKE_MAS7(0);
  124. write_tlb(mas0, mas1, mas2, mas3, mas7);
  125. out_be32(&l2cache->l2srbar0, SRAM_BASE_ADDR);
  126. out_be32(&l2cache->l2errdis,
  127. (MPC85xx_L2ERRDIS_MBECC | MPC85xx_L2ERRDIS_SBECC));
  128. out_be32(&l2cache->l2ctl,
  129. (MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2SRAM_ENTIRE));
  130. /*
  131. * Copy the code in setup_ifc to L2SRAM. Do a word copy
  132. * because NOR Flash on P1010 does not support byte
  133. * access (Erratum IFC-A002769)
  134. */
  135. setup_ifc_sram = (void *)SRAM_BASE_ADDR;
  136. dst = (u32 *) SRAM_BASE_ADDR;
  137. src = (u32 *) setup_ifc;
  138. for (i = 0; i < 1024; i++)
  139. *dst++ = *src++;
  140. setup_ifc_sram();
  141. /* CLEANUP */
  142. clrbits_be32(&l2cache->l2ctl,
  143. (MPC85xx_L2CTL_L2E |
  144. MPC85xx_L2CTL_L2SRAM_ENTIRE));
  145. out_be32(&l2cache->l2srbar0, 0x0);
  146. #endif
  147. invalidate_tlb(1);
  148. #if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && \
  149. !(defined(CONFIG_SPL_INIT_MINIMAL) && defined(CONFIG_SPL_BUILD)) && \
  150. !defined(CONFIG_NAND_SPL)
  151. disable_tlb(CONFIG_SYS_PPC_E500_DEBUG_TLB);
  152. #endif
  153. init_tlbs();
  154. }