htab.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #define PS3_VERBOSE_RESULT
  28. #include "platform.h"
  29. /**
  30. * enum lpar_vas_id - id of LPAR virtual address space.
  31. * @lpar_vas_id_current: Current selected virtual address space
  32. *
  33. * Identify the target LPAR address space.
  34. */
  35. enum ps3_lpar_vas_id {
  36. PS3_LPAR_VAS_ID_CURRENT = 0,
  37. };
  38. static DEFINE_SPINLOCK(ps3_htab_lock);
  39. static long ps3_hpte_insert(unsigned long hpte_group, unsigned long vpn,
  40. unsigned long pa, unsigned long rflags, unsigned long vflags,
  41. int psize, int apsize, int ssize)
  42. {
  43. int result;
  44. u64 hpte_v, hpte_r;
  45. u64 inserted_index;
  46. u64 evicted_v, evicted_r;
  47. u64 hpte_v_array[4], hpte_rs;
  48. unsigned long flags;
  49. long ret = -1;
  50. /*
  51. * lv1_insert_htab_entry() will search for victim
  52. * entry in both primary and secondary pte group
  53. */
  54. vflags &= ~HPTE_V_SECONDARY;
  55. hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID;
  56. hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize, apsize) | rflags;
  57. spin_lock_irqsave(&ps3_htab_lock, flags);
  58. /* talk hvc to replace entries BOLTED == 0 */
  59. result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group,
  60. hpte_v, hpte_r,
  61. HPTE_V_BOLTED, 0,
  62. &inserted_index,
  63. &evicted_v, &evicted_r);
  64. if (result) {
  65. /* all entries bolted !*/
  66. pr_info("%s:result=%s vpn=%lx pa=%lx ix=%lx v=%llx r=%llx\n",
  67. __func__, ps3_result(result), vpn, pa, hpte_group,
  68. hpte_v, hpte_r);
  69. BUG();
  70. }
  71. /*
  72. * see if the entry is inserted into secondary pteg
  73. */
  74. result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT,
  75. inserted_index & ~0x3UL,
  76. &hpte_v_array[0], &hpte_v_array[1],
  77. &hpte_v_array[2], &hpte_v_array[3],
  78. &hpte_rs);
  79. BUG_ON(result);
  80. if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY)
  81. ret = (inserted_index & 7) | (1 << 3);
  82. else
  83. ret = inserted_index & 7;
  84. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  85. return ret;
  86. }
  87. static long ps3_hpte_remove(unsigned long hpte_group)
  88. {
  89. panic("ps3_hpte_remove() not implemented");
  90. return 0;
  91. }
  92. static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,
  93. unsigned long vpn, int psize, int apsize,
  94. int ssize, unsigned long inv_flags)
  95. {
  96. int result;
  97. u64 hpte_v, want_v, hpte_rs;
  98. u64 hpte_v_array[4];
  99. unsigned long flags;
  100. long ret;
  101. want_v = hpte_encode_avpn(vpn, psize, ssize);
  102. spin_lock_irqsave(&ps3_htab_lock, flags);
  103. result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL,
  104. &hpte_v_array[0], &hpte_v_array[1],
  105. &hpte_v_array[2], &hpte_v_array[3],
  106. &hpte_rs);
  107. if (result) {
  108. pr_info("%s: result=%s read vpn=%lx slot=%lx psize=%d\n",
  109. __func__, ps3_result(result), vpn, slot, psize);
  110. BUG();
  111. }
  112. hpte_v = hpte_v_array[slot % 4];
  113. /*
  114. * As lv1_read_htab_entries() does not give us the RPN, we can
  115. * not synthesize the new hpte_r value here, and therefore can
  116. * not update the hpte with lv1_insert_htab_entry(), so we
  117. * instead invalidate it and ask the caller to update it via
  118. * ps3_hpte_insert() by returning a -1 value.
  119. */
  120. if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {
  121. /* not found */
  122. ret = -1;
  123. } else {
  124. /* entry found, just invalidate it */
  125. result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT,
  126. slot, 0, 0);
  127. ret = -1;
  128. }
  129. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  130. return ret;
  131. }
  132. static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
  133. int psize, int ssize)
  134. {
  135. panic("ps3_hpte_updateboltedpp() not implemented");
  136. }
  137. static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
  138. int psize, int apsize, int ssize, int local)
  139. {
  140. unsigned long flags;
  141. int result;
  142. spin_lock_irqsave(&ps3_htab_lock, flags);
  143. result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0);
  144. if (result) {
  145. pr_info("%s: result=%s vpn=%lx slot=%lx psize=%d\n",
  146. __func__, ps3_result(result), vpn, slot, psize);
  147. BUG();
  148. }
  149. spin_unlock_irqrestore(&ps3_htab_lock, flags);
  150. }
  151. static void ps3_hpte_clear(void)
  152. {
  153. unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4;
  154. u64 i;
  155. for (i = 0; i < hpte_count; i++)
  156. lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0);
  157. ps3_mm_shutdown();
  158. ps3_mm_vas_destroy();
  159. }
  160. void __init ps3_hpte_init(unsigned long htab_size)
  161. {
  162. ppc_md.hpte_invalidate = ps3_hpte_invalidate;
  163. ppc_md.hpte_updatepp = ps3_hpte_updatepp;
  164. ppc_md.hpte_updateboltedpp = ps3_hpte_updateboltedpp;
  165. ppc_md.hpte_insert = ps3_hpte_insert;
  166. ppc_md.hpte_remove = ps3_hpte_remove;
  167. ppc_md.hpte_clear_all = ps3_hpte_clear;
  168. ppc64_pft_size = __ilog2(htab_size);
  169. }