cpu_init_early.c 5.5 KB

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