htab.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * PS3 pagetable management routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006, 2007 Sony Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/memblock.h>
  22. #include <asm/machdep.h>
  23. #include <asm/prom.h>
  24. #include <asm/udbg.h>
  25. #include <asm/lv1call.h>
  26. #include <asm/ps3fb.h>
  27. #include "platform.h"
  28. /**
  29. * enum lpar_vas_id - id of LPAR virtual address space.
  30. * @lpar_vas_id_current: Current selected virtual address space
  31. *
  32. * Identify the target LPAR address space.
  33. */
  34. enum ps3_lpar_vas_id {
  35. PS3_LPAR_VAS_ID_CURRENT = 0,
  36. };
  37. static DEFINE_SPINLOCK(ps3_htab_lock);
  38. static long ps3_hpte_insert(unsigned long hpte_group, unsigned long va,
  39. unsigned long pa, unsigned long rflags, unsigned long vflags,
  40. int psize, int ssize)
  41. {
  42. int result;
  43. u64 hpte_v, hpte_r;
  44. u64 inserted_index;
  45. u64 evicted_v, evicted_r;
  46. u64 hpte_v_array[4], hpte_rs;
  47. unsigned long flags;
  48. long ret = -1;
  49. /*
  50. * lv1_insert_htab_entry() will search for victim
  51. * entry in both primary and secondary pte group
  52. */
  53. vflags &= ~HPTE_V_SECONDARY;
  54. hpte_v = hpte_encode_v(va, psize, ssize) | vflags | HPTE_V_VALID;
  55. hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize) | rflags;
  56. spin_lock_irqsave(&ps3_htab_lock, flags);
  57. /* talk hvc to replace entries BOLTED == 0 */
  58. result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group,
  59. hpte_v, hpte_r,
  60. HPTE_V_BOLTED, 0,
  61. &inserted_index,
  62. &evicted_v, &evicted_r);
  63. if (result) {
  64. /* all entries bolted !*/
  65. pr_info("%s:result=%d va=%lx pa=%lx ix=%lx v=%llx r=%llx\n",
  66. __func__, result, va, pa, hpte_group, hpte_v, hpte_r);
  67. BUG();
  68. }
  69. /*
  70. * see if the entry is inserted into secondary pteg
  71. */
  72. result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT,
  73. inserted_index & ~0x3UL,
  74. &hpte_v_array[0], &hpte_v_array[1],
  75. &hpte_v_array[2], &hpte_v_array[3],
  76. &hpte_rs);
  77. BUG_ON(result);
  78. if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY)
  79. ret = (inserted_index & 7) | (1 << 3);
  80. else
  81. ret = inserted_index & 7;
  82. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  83. return ret;
  84. }
  85. static long ps3_hpte_remove(unsigned long hpte_group)
  86. {
  87. panic("ps3_hpte_remove() not implemented");
  88. return 0;
  89. }
  90. static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,
  91. unsigned long va, int psize, int ssize, int local)
  92. {
  93. int result;
  94. u64 hpte_v, want_v, hpte_rs;
  95. u64 hpte_v_array[4];
  96. unsigned long flags;
  97. long ret;
  98. want_v = hpte_encode_v(va, psize, ssize);
  99. spin_lock_irqsave(&ps3_htab_lock, flags);
  100. result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL,
  101. &hpte_v_array[0], &hpte_v_array[1],
  102. &hpte_v_array[2], &hpte_v_array[3],
  103. &hpte_rs);
  104. if (result) {
  105. pr_info("%s: res=%d read va=%lx slot=%lx psize=%d\n",
  106. __func__, result, va, slot, psize);
  107. BUG();
  108. }
  109. hpte_v = hpte_v_array[slot % 4];
  110. /*
  111. * As lv1_read_htab_entries() does not give us the RPN, we can
  112. * not synthesize the new hpte_r value here, and therefore can
  113. * not update the hpte with lv1_insert_htab_entry(), so we
  114. * instead invalidate it and ask the caller to update it via
  115. * ps3_hpte_insert() by returning a -1 value.
  116. */
  117. if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {
  118. /* not found */
  119. ret = -1;
  120. } else {
  121. /* entry found, just invalidate it */
  122. result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT,
  123. slot, 0, 0);
  124. ret = -1;
  125. }
  126. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  127. return ret;
  128. }
  129. static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
  130. int psize, int ssize)
  131. {
  132. panic("ps3_hpte_updateboltedpp() not implemented");
  133. }
  134. static void ps3_hpte_invalidate(unsigned long slot, unsigned long va,
  135. int psize, int ssize, int local)
  136. {
  137. unsigned long flags;
  138. int result;
  139. spin_lock_irqsave(&ps3_htab_lock, flags);
  140. result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0);
  141. if (result) {
  142. pr_info("%s: res=%d va=%lx slot=%lx psize=%d\n",
  143. __func__, result, va, slot, psize);
  144. BUG();
  145. }
  146. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  147. }
  148. static void ps3_hpte_clear(void)
  149. {
  150. unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4;
  151. u64 i;
  152. for (i = 0; i < hpte_count; i++)
  153. lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0);
  154. ps3_mm_shutdown();
  155. ps3_mm_vas_destroy();
  156. }
  157. void __init ps3_hpte_init(unsigned long htab_size)
  158. {
  159. ppc_md.hpte_invalidate = ps3_hpte_invalidate;
  160. ppc_md.hpte_updatepp = ps3_hpte_updatepp;
  161. ppc_md.hpte_updateboltedpp = ps3_hpte_updateboltedpp;
  162. ppc_md.hpte_insert = ps3_hpte_insert;
  163. ppc_md.hpte_remove = ps3_hpte_remove;
  164. ppc_md.hpte_clear_all = ps3_hpte_clear;
  165. ppc64_pft_size = __ilog2(htab_size);
  166. }