tlb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2000
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #ifdef CONFIG_ADDR_MAP
  29. #include <addr_map.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. void set_tlb(u8 tlb, u32 epn, u64 rpn,
  33. u8 perms, u8 wimge,
  34. u8 ts, u8 esel, u8 tsize, u8 iprot)
  35. {
  36. u32 _mas0, _mas1, _mas2, _mas3, _mas7;
  37. _mas0 = FSL_BOOKE_MAS0(tlb, esel, 0);
  38. _mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize);
  39. _mas2 = FSL_BOOKE_MAS2(epn, wimge);
  40. _mas3 = FSL_BOOKE_MAS3(rpn, 0, perms);
  41. _mas7 = rpn >> 32;
  42. mtspr(MAS0, _mas0);
  43. mtspr(MAS1, _mas1);
  44. mtspr(MAS2, _mas2);
  45. mtspr(MAS3, _mas3);
  46. #ifdef CONFIG_ENABLE_36BIT_PHYS
  47. mtspr(MAS7, _mas7);
  48. #endif
  49. asm volatile("isync;msync;tlbwe;isync");
  50. #ifdef CONFIG_ADDR_MAP
  51. if ((tlb == 1) && (gd->flags & GD_FLG_RELOC))
  52. addrmap_set_entry(epn, rpn, (1UL << ((tsize * 2) + 10)), esel);
  53. #endif
  54. }
  55. void disable_tlb(u8 esel)
  56. {
  57. u32 _mas0, _mas1, _mas2, _mas3, _mas7;
  58. _mas0 = FSL_BOOKE_MAS0(1, esel, 0);
  59. _mas1 = 0;
  60. _mas2 = 0;
  61. _mas3 = 0;
  62. _mas7 = 0;
  63. mtspr(MAS0, _mas0);
  64. mtspr(MAS1, _mas1);
  65. mtspr(MAS2, _mas2);
  66. mtspr(MAS3, _mas3);
  67. #ifdef CONFIG_ENABLE_36BIT_PHYS
  68. mtspr(MAS7, _mas7);
  69. #endif
  70. asm volatile("isync;msync;tlbwe;isync");
  71. #ifdef CONFIG_ADDR_MAP
  72. if (gd->flags & GD_FLG_RELOC)
  73. addrmap_set_entry(0, 0, 0, esel);
  74. #endif
  75. }
  76. void invalidate_tlb(u8 tlb)
  77. {
  78. if (tlb == 0)
  79. mtspr(MMUCSR0, 0x4);
  80. if (tlb == 1)
  81. mtspr(MMUCSR0, 0x2);
  82. }
  83. void init_tlbs(void)
  84. {
  85. int i;
  86. for (i = 0; i < num_tlb_entries; i++) {
  87. set_tlb(tlb_table[i].tlb, tlb_table[i].epn, tlb_table[i].rpn,
  88. tlb_table[i].perms, tlb_table[i].wimge,
  89. tlb_table[i].ts, tlb_table[i].esel, tlb_table[i].tsize,
  90. tlb_table[i].iprot);
  91. }
  92. return ;
  93. }
  94. #ifdef CONFIG_ADDR_MAP
  95. void init_addr_map(void)
  96. {
  97. int i;
  98. for (i = 0; i < num_tlb_entries; i++) {
  99. if (tlb_table[i].tlb == 0)
  100. continue;
  101. addrmap_set_entry(tlb_table[i].epn,
  102. tlb_table[i].rpn,
  103. (1UL << ((tlb_table[i].tsize * 2) + 10)),
  104. tlb_table[i].esel);
  105. }
  106. return ;
  107. }
  108. #endif
  109. unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
  110. {
  111. unsigned int tlb_size;
  112. unsigned int ram_tlb_index;
  113. unsigned int ram_tlb_address;
  114. /*
  115. * Determine size of each TLB1 entry.
  116. */
  117. switch (memsize_in_meg) {
  118. case 16:
  119. case 32:
  120. tlb_size = BOOKE_PAGESZ_16M;
  121. break;
  122. case 64:
  123. case 128:
  124. tlb_size = BOOKE_PAGESZ_64M;
  125. break;
  126. case 256:
  127. case 512:
  128. tlb_size = BOOKE_PAGESZ_256M;
  129. break;
  130. case 1024:
  131. case 2048:
  132. if (PVR_VER(get_pvr()) > PVR_VER(PVR_85xx))
  133. tlb_size = BOOKE_PAGESZ_1G;
  134. else
  135. tlb_size = BOOKE_PAGESZ_256M;
  136. break;
  137. default:
  138. puts("DDR: only 16M, 32M, 64M, 128M, 256M, 512M, 1G"
  139. " and 2G are supported.\n");
  140. /*
  141. * The memory was not able to be mapped.
  142. * Default to a small size.
  143. */
  144. tlb_size = BOOKE_PAGESZ_64M;
  145. memsize_in_meg = 64;
  146. break;
  147. }
  148. /*
  149. * Configure DDR TLB1 entries.
  150. * Starting at TLB1 8, use no more than 8 TLB1 entries.
  151. */
  152. ram_tlb_index = 8;
  153. ram_tlb_address = (unsigned int)CONFIG_SYS_DDR_SDRAM_BASE;
  154. while (ram_tlb_address < (memsize_in_meg * 1024 * 1024)
  155. && ram_tlb_index < 16) {
  156. set_tlb(1, ram_tlb_address, ram_tlb_address,
  157. MAS3_SX|MAS3_SW|MAS3_SR, 0,
  158. 0, ram_tlb_index, tlb_size, 1);
  159. ram_tlb_address += (0x1000 << ((tlb_size - 1) * 2));
  160. ram_tlb_index++;
  161. }
  162. /*
  163. * Confirm that the requested amount of memory was mapped.
  164. */
  165. return memsize_in_meg;
  166. }