hash_native_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * native hashtable management.
  3. *
  4. * SMP scalability work:
  5. * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #undef DEBUG_LOW
  13. #include <linux/spinlock.h>
  14. #include <linux/bitops.h>
  15. #include <linux/of.h>
  16. #include <linux/threads.h>
  17. #include <linux/smp.h>
  18. #include <asm/machdep.h>
  19. #include <asm/mmu.h>
  20. #include <asm/mmu_context.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/tlbflush.h>
  23. #include <asm/tlb.h>
  24. #include <asm/cputable.h>
  25. #include <asm/udbg.h>
  26. #include <asm/kexec.h>
  27. #include <asm/ppc-opcode.h>
  28. #ifdef DEBUG_LOW
  29. #define DBG_LOW(fmt...) udbg_printf(fmt)
  30. #else
  31. #define DBG_LOW(fmt...)
  32. #endif
  33. #define HPTE_LOCK_BIT 3
  34. DEFINE_RAW_SPINLOCK(native_tlbie_lock);
  35. static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize)
  36. {
  37. unsigned long va;
  38. unsigned int penc;
  39. /*
  40. * We need 14 to 65 bits of va for a tlibe of 4K page
  41. * With vpn we ignore the lower VPN_SHIFT bits already.
  42. * And top two bits are already ignored because we can
  43. * only accomadate 76 bits in a 64 bit vpn with a VPN_SHIFT
  44. * of 12.
  45. */
  46. va = vpn << VPN_SHIFT;
  47. /*
  48. * clear top 16 bits of 64bit va, non SLS segment
  49. * Older versions of the architecture (2.02 and earler) require the
  50. * masking of the top 16 bits.
  51. */
  52. va &= ~(0xffffULL << 48);
  53. switch (psize) {
  54. case MMU_PAGE_4K:
  55. /* clear out bits after (52) [0....52.....63] */
  56. va &= ~((1ul << (64 - 52)) - 1);
  57. va |= ssize << 8;
  58. va |= mmu_psize_defs[apsize].sllp << 6;
  59. asm volatile(ASM_FTR_IFCLR("tlbie %0,0", PPC_TLBIE(%1,%0), %2)
  60. : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206)
  61. : "memory");
  62. break;
  63. default:
  64. /* We need 14 to 14 + i bits of va */
  65. penc = mmu_psize_defs[psize].penc[apsize];
  66. va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1);
  67. va |= penc << 12;
  68. va |= ssize << 8;
  69. /* Add AVAL part */
  70. if (psize != apsize) {
  71. /*
  72. * MPSS, 64K base page size and 16MB parge page size
  73. * We don't need all the bits, but rest of the bits
  74. * must be ignored by the processor.
  75. * vpn cover upto 65 bits of va. (0...65) and we need
  76. * 58..64 bits of va.
  77. */
  78. va |= (vpn & 0xfe);
  79. }
  80. va |= 1; /* L */
  81. asm volatile(ASM_FTR_IFCLR("tlbie %0,1", PPC_TLBIE(%1,%0), %2)
  82. : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206)
  83. : "memory");
  84. break;
  85. }
  86. }
  87. static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)
  88. {
  89. unsigned long va;
  90. unsigned int penc;
  91. /* VPN_SHIFT can be atmost 12 */
  92. va = vpn << VPN_SHIFT;
  93. /*
  94. * clear top 16 bits of 64 bit va, non SLS segment
  95. * Older versions of the architecture (2.02 and earler) require the
  96. * masking of the top 16 bits.
  97. */
  98. va &= ~(0xffffULL << 48);
  99. switch (psize) {
  100. case MMU_PAGE_4K:
  101. /* clear out bits after(52) [0....52.....63] */
  102. va &= ~((1ul << (64 - 52)) - 1);
  103. va |= ssize << 8;
  104. va |= mmu_psize_defs[apsize].sllp << 6;
  105. asm volatile(".long 0x7c000224 | (%0 << 11) | (0 << 21)"
  106. : : "r"(va) : "memory");
  107. break;
  108. default:
  109. /* We need 14 to 14 + i bits of va */
  110. penc = mmu_psize_defs[psize].penc[apsize];
  111. va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1);
  112. va |= penc << 12;
  113. va |= ssize << 8;
  114. /* Add AVAL part */
  115. if (psize != apsize) {
  116. /*
  117. * MPSS, 64K base page size and 16MB parge page size
  118. * We don't need all the bits, but rest of the bits
  119. * must be ignored by the processor.
  120. * vpn cover upto 65 bits of va. (0...65) and we need
  121. * 58..64 bits of va.
  122. */
  123. va |= (vpn & 0xfe);
  124. }
  125. va |= 1; /* L */
  126. asm volatile(".long 0x7c000224 | (%0 << 11) | (1 << 21)"
  127. : : "r"(va) : "memory");
  128. break;
  129. }
  130. }
  131. static inline void tlbie(unsigned long vpn, int psize, int apsize,
  132. int ssize, int local)
  133. {
  134. unsigned int use_local = local && mmu_has_feature(MMU_FTR_TLBIEL);
  135. int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
  136. if (use_local)
  137. use_local = mmu_psize_defs[psize].tlbiel;
  138. if (lock_tlbie && !use_local)
  139. raw_spin_lock(&native_tlbie_lock);
  140. asm volatile("ptesync": : :"memory");
  141. if (use_local) {
  142. __tlbiel(vpn, psize, apsize, ssize);
  143. asm volatile("ptesync": : :"memory");
  144. } else {
  145. __tlbie(vpn, psize, apsize, ssize);
  146. asm volatile("eieio; tlbsync; ptesync": : :"memory");
  147. }
  148. if (lock_tlbie && !use_local)
  149. raw_spin_unlock(&native_tlbie_lock);
  150. }
  151. static inline void native_lock_hpte(struct hash_pte *hptep)
  152. {
  153. unsigned long *word = &hptep->v;
  154. while (1) {
  155. if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word))
  156. break;
  157. while(test_bit(HPTE_LOCK_BIT, word))
  158. cpu_relax();
  159. }
  160. }
  161. static inline void native_unlock_hpte(struct hash_pte *hptep)
  162. {
  163. unsigned long *word = &hptep->v;
  164. clear_bit_unlock(HPTE_LOCK_BIT, word);
  165. }
  166. static long native_hpte_insert(unsigned long hpte_group, unsigned long vpn,
  167. unsigned long pa, unsigned long rflags,
  168. unsigned long vflags, int psize, int apsize, int ssize)
  169. {
  170. struct hash_pte *hptep = htab_address + hpte_group;
  171. unsigned long hpte_v, hpte_r;
  172. int i;
  173. if (!(vflags & HPTE_V_BOLTED)) {
  174. DBG_LOW(" insert(group=%lx, vpn=%016lx, pa=%016lx,"
  175. " rflags=%lx, vflags=%lx, psize=%d)\n",
  176. hpte_group, vpn, pa, rflags, vflags, psize);
  177. }
  178. for (i = 0; i < HPTES_PER_GROUP; i++) {
  179. if (! (hptep->v & HPTE_V_VALID)) {
  180. /* retry with lock held */
  181. native_lock_hpte(hptep);
  182. if (! (hptep->v & HPTE_V_VALID))
  183. break;
  184. native_unlock_hpte(hptep);
  185. }
  186. hptep++;
  187. }
  188. if (i == HPTES_PER_GROUP)
  189. return -1;
  190. hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID;
  191. hpte_r = hpte_encode_r(pa, psize, apsize) | rflags;
  192. if (!(vflags & HPTE_V_BOLTED)) {
  193. DBG_LOW(" i=%x hpte_v=%016lx, hpte_r=%016lx\n",
  194. i, hpte_v, hpte_r);
  195. }
  196. hptep->r = hpte_r;
  197. /* Guarantee the second dword is visible before the valid bit */
  198. eieio();
  199. /*
  200. * Now set the first dword including the valid bit
  201. * NOTE: this also unlocks the hpte
  202. */
  203. hptep->v = hpte_v;
  204. __asm__ __volatile__ ("ptesync" : : : "memory");
  205. return i | (!!(vflags & HPTE_V_SECONDARY) << 3);
  206. }
  207. static long native_hpte_remove(unsigned long hpte_group)
  208. {
  209. struct hash_pte *hptep;
  210. int i;
  211. int slot_offset;
  212. unsigned long hpte_v;
  213. DBG_LOW(" remove(group=%lx)\n", hpte_group);
  214. /* pick a random entry to start at */
  215. slot_offset = mftb() & 0x7;
  216. for (i = 0; i < HPTES_PER_GROUP; i++) {
  217. hptep = htab_address + hpte_group + slot_offset;
  218. hpte_v = hptep->v;
  219. if ((hpte_v & HPTE_V_VALID) && !(hpte_v & HPTE_V_BOLTED)) {
  220. /* retry with lock held */
  221. native_lock_hpte(hptep);
  222. hpte_v = hptep->v;
  223. if ((hpte_v & HPTE_V_VALID)
  224. && !(hpte_v & HPTE_V_BOLTED))
  225. break;
  226. native_unlock_hpte(hptep);
  227. }
  228. slot_offset++;
  229. slot_offset &= 0x7;
  230. }
  231. if (i == HPTES_PER_GROUP)
  232. return -1;
  233. /* Invalidate the hpte. NOTE: this also unlocks it */
  234. hptep->v = 0;
  235. return i;
  236. }
  237. static inline int __hpte_actual_psize(unsigned int lp, int psize)
  238. {
  239. int i, shift;
  240. unsigned int mask;
  241. /* start from 1 ignoring MMU_PAGE_4K */
  242. for (i = 1; i < MMU_PAGE_COUNT; i++) {
  243. /* invalid penc */
  244. if (mmu_psize_defs[psize].penc[i] == -1)
  245. continue;
  246. /*
  247. * encoding bits per actual page size
  248. * PTE LP actual page size
  249. * rrrr rrrz >=8KB
  250. * rrrr rrzz >=16KB
  251. * rrrr rzzz >=32KB
  252. * rrrr zzzz >=64KB
  253. * .......
  254. */
  255. shift = mmu_psize_defs[i].shift - LP_SHIFT;
  256. if (shift > LP_BITS)
  257. shift = LP_BITS;
  258. mask = (1 << shift) - 1;
  259. if ((lp & mask) == mmu_psize_defs[psize].penc[i])
  260. return i;
  261. }
  262. return -1;
  263. }
  264. static inline int hpte_actual_psize(struct hash_pte *hptep, int psize)
  265. {
  266. /* Look at the 8 bit LP value */
  267. unsigned int lp = (hptep->r >> LP_SHIFT) & ((1 << LP_BITS) - 1);
  268. if (!(hptep->v & HPTE_V_VALID))
  269. return -1;
  270. /* First check if it is large page */
  271. if (!(hptep->v & HPTE_V_LARGE))
  272. return MMU_PAGE_4K;
  273. return __hpte_actual_psize(lp, psize);
  274. }
  275. static long native_hpte_updatepp(unsigned long slot, unsigned long newpp,
  276. unsigned long vpn, int psize, int ssize,
  277. int local)
  278. {
  279. struct hash_pte *hptep = htab_address + slot;
  280. unsigned long hpte_v, want_v;
  281. int ret = 0;
  282. int actual_psize;
  283. want_v = hpte_encode_avpn(vpn, psize, ssize);
  284. DBG_LOW(" update(vpn=%016lx, avpnv=%016lx, group=%lx, newpp=%lx)",
  285. vpn, want_v & HPTE_V_AVPN, slot, newpp);
  286. native_lock_hpte(hptep);
  287. hpte_v = hptep->v;
  288. actual_psize = hpte_actual_psize(hptep, psize);
  289. /*
  290. * We need to invalidate the TLB always because hpte_remove doesn't do
  291. * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less
  292. * random entry from it. When we do that we don't invalidate the TLB
  293. * (hpte_remove) because we assume the old translation is still
  294. * technically "valid".
  295. */
  296. if (actual_psize < 0) {
  297. actual_psize = psize;
  298. ret = -1;
  299. goto err_out;
  300. }
  301. if (!HPTE_V_COMPARE(hpte_v, want_v)) {
  302. DBG_LOW(" -> miss\n");
  303. ret = -1;
  304. } else {
  305. DBG_LOW(" -> hit\n");
  306. /* Update the HPTE */
  307. hptep->r = (hptep->r & ~(HPTE_R_PP | HPTE_R_N)) |
  308. (newpp & (HPTE_R_PP | HPTE_R_N | HPTE_R_C));
  309. }
  310. err_out:
  311. native_unlock_hpte(hptep);
  312. /* Ensure it is out of the tlb too. */
  313. tlbie(vpn, psize, actual_psize, ssize, local);
  314. return ret;
  315. }
  316. static long native_hpte_find(unsigned long vpn, int psize, int ssize)
  317. {
  318. struct hash_pte *hptep;
  319. unsigned long hash;
  320. unsigned long i;
  321. long slot;
  322. unsigned long want_v, hpte_v;
  323. hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize);
  324. want_v = hpte_encode_avpn(vpn, psize, ssize);
  325. /* Bolted mappings are only ever in the primary group */
  326. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  327. for (i = 0; i < HPTES_PER_GROUP; i++) {
  328. hptep = htab_address + slot;
  329. hpte_v = hptep->v;
  330. if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID))
  331. /* HPTE matches */
  332. return slot;
  333. ++slot;
  334. }
  335. return -1;
  336. }
  337. /*
  338. * Update the page protection bits. Intended to be used to create
  339. * guard pages for kernel data structures on pages which are bolted
  340. * in the HPT. Assumes pages being operated on will not be stolen.
  341. *
  342. * No need to lock here because we should be the only user.
  343. */
  344. static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
  345. int psize, int ssize)
  346. {
  347. int actual_psize;
  348. unsigned long vpn;
  349. unsigned long vsid;
  350. long slot;
  351. struct hash_pte *hptep;
  352. vsid = get_kernel_vsid(ea, ssize);
  353. vpn = hpt_vpn(ea, vsid, ssize);
  354. slot = native_hpte_find(vpn, psize, ssize);
  355. if (slot == -1)
  356. panic("could not find page to bolt\n");
  357. hptep = htab_address + slot;
  358. actual_psize = hpte_actual_psize(hptep, psize);
  359. if (actual_psize < 0)
  360. actual_psize = psize;
  361. /* Update the HPTE */
  362. hptep->r = (hptep->r & ~(HPTE_R_PP | HPTE_R_N)) |
  363. (newpp & (HPTE_R_PP | HPTE_R_N));
  364. /* Ensure it is out of the tlb too. */
  365. tlbie(vpn, psize, actual_psize, ssize, 0);
  366. }
  367. static void native_hpte_invalidate(unsigned long slot, unsigned long vpn,
  368. int psize, int ssize, int local)
  369. {
  370. struct hash_pte *hptep = htab_address + slot;
  371. unsigned long hpte_v;
  372. unsigned long want_v;
  373. unsigned long flags;
  374. int actual_psize;
  375. local_irq_save(flags);
  376. DBG_LOW(" invalidate(vpn=%016lx, hash: %lx)\n", vpn, slot);
  377. want_v = hpte_encode_avpn(vpn, psize, ssize);
  378. native_lock_hpte(hptep);
  379. hpte_v = hptep->v;
  380. actual_psize = hpte_actual_psize(hptep, psize);
  381. /*
  382. * We need to invalidate the TLB always because hpte_remove doesn't do
  383. * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less
  384. * random entry from it. When we do that we don't invalidate the TLB
  385. * (hpte_remove) because we assume the old translation is still
  386. * technically "valid".
  387. */
  388. if (actual_psize < 0) {
  389. actual_psize = psize;
  390. native_unlock_hpte(hptep);
  391. goto err_out;
  392. }
  393. if (!HPTE_V_COMPARE(hpte_v, want_v))
  394. native_unlock_hpte(hptep);
  395. else
  396. /* Invalidate the hpte. NOTE: this also unlocks it */
  397. hptep->v = 0;
  398. err_out:
  399. /* Invalidate the TLB */
  400. tlbie(vpn, psize, actual_psize, ssize, local);
  401. local_irq_restore(flags);
  402. }
  403. static void hpte_decode(struct hash_pte *hpte, unsigned long slot,
  404. int *psize, int *apsize, int *ssize, unsigned long *vpn)
  405. {
  406. unsigned long avpn, pteg, vpi;
  407. unsigned long hpte_v = hpte->v;
  408. unsigned long vsid, seg_off;
  409. int size, a_size, shift;
  410. /* Look at the 8 bit LP value */
  411. unsigned int lp = (hpte->r >> LP_SHIFT) & ((1 << LP_BITS) - 1);
  412. if (!(hpte_v & HPTE_V_LARGE)) {
  413. size = MMU_PAGE_4K;
  414. a_size = MMU_PAGE_4K;
  415. } else {
  416. for (size = 0; size < MMU_PAGE_COUNT; size++) {
  417. /* valid entries have a shift value */
  418. if (!mmu_psize_defs[size].shift)
  419. continue;
  420. a_size = __hpte_actual_psize(lp, size);
  421. if (a_size != -1)
  422. break;
  423. }
  424. }
  425. /* This works for all page sizes, and for 256M and 1T segments */
  426. *ssize = hpte_v >> HPTE_V_SSIZE_SHIFT;
  427. shift = mmu_psize_defs[size].shift;
  428. avpn = (HPTE_V_AVPN_VAL(hpte_v) & ~mmu_psize_defs[size].avpnm);
  429. pteg = slot / HPTES_PER_GROUP;
  430. if (hpte_v & HPTE_V_SECONDARY)
  431. pteg = ~pteg;
  432. switch (*ssize) {
  433. case MMU_SEGSIZE_256M:
  434. /* We only have 28 - 23 bits of seg_off in avpn */
  435. seg_off = (avpn & 0x1f) << 23;
  436. vsid = avpn >> 5;
  437. /* We can find more bits from the pteg value */
  438. if (shift < 23) {
  439. vpi = (vsid ^ pteg) & htab_hash_mask;
  440. seg_off |= vpi << shift;
  441. }
  442. *vpn = vsid << (SID_SHIFT - VPN_SHIFT) | seg_off >> VPN_SHIFT;
  443. case MMU_SEGSIZE_1T:
  444. /* We only have 40 - 23 bits of seg_off in avpn */
  445. seg_off = (avpn & 0x1ffff) << 23;
  446. vsid = avpn >> 17;
  447. if (shift < 23) {
  448. vpi = (vsid ^ (vsid << 25) ^ pteg) & htab_hash_mask;
  449. seg_off |= vpi << shift;
  450. }
  451. *vpn = vsid << (SID_SHIFT_1T - VPN_SHIFT) | seg_off >> VPN_SHIFT;
  452. default:
  453. *vpn = size = 0;
  454. }
  455. *psize = size;
  456. *apsize = a_size;
  457. }
  458. /*
  459. * clear all mappings on kexec. All cpus are in real mode (or they will
  460. * be when they isi), and we are the only one left. We rely on our kernel
  461. * mapping being 0xC0's and the hardware ignoring those two real bits.
  462. *
  463. * TODO: add batching support when enabled. remember, no dynamic memory here,
  464. * athough there is the control page available...
  465. */
  466. static void native_hpte_clear(void)
  467. {
  468. unsigned long vpn = 0;
  469. unsigned long slot, slots, flags;
  470. struct hash_pte *hptep = htab_address;
  471. unsigned long hpte_v;
  472. unsigned long pteg_count;
  473. int psize, apsize, ssize;
  474. pteg_count = htab_hash_mask + 1;
  475. local_irq_save(flags);
  476. /* we take the tlbie lock and hold it. Some hardware will
  477. * deadlock if we try to tlbie from two processors at once.
  478. */
  479. raw_spin_lock(&native_tlbie_lock);
  480. slots = pteg_count * HPTES_PER_GROUP;
  481. for (slot = 0; slot < slots; slot++, hptep++) {
  482. /*
  483. * we could lock the pte here, but we are the only cpu
  484. * running, right? and for crash dump, we probably
  485. * don't want to wait for a maybe bad cpu.
  486. */
  487. hpte_v = hptep->v;
  488. /*
  489. * Call __tlbie() here rather than tlbie() since we
  490. * already hold the native_tlbie_lock.
  491. */
  492. if (hpte_v & HPTE_V_VALID) {
  493. hpte_decode(hptep, slot, &psize, &apsize, &ssize, &vpn);
  494. hptep->v = 0;
  495. __tlbie(vpn, psize, apsize, ssize);
  496. }
  497. }
  498. asm volatile("eieio; tlbsync; ptesync":::"memory");
  499. raw_spin_unlock(&native_tlbie_lock);
  500. local_irq_restore(flags);
  501. }
  502. /*
  503. * Batched hash table flush, we batch the tlbie's to avoid taking/releasing
  504. * the lock all the time
  505. */
  506. static void native_flush_hash_range(unsigned long number, int local)
  507. {
  508. unsigned long vpn;
  509. unsigned long hash, index, hidx, shift, slot;
  510. struct hash_pte *hptep;
  511. unsigned long hpte_v;
  512. unsigned long want_v;
  513. unsigned long flags;
  514. real_pte_t pte;
  515. struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
  516. unsigned long psize = batch->psize;
  517. int ssize = batch->ssize;
  518. int i;
  519. local_irq_save(flags);
  520. for (i = 0; i < number; i++) {
  521. vpn = batch->vpn[i];
  522. pte = batch->pte[i];
  523. pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) {
  524. hash = hpt_hash(vpn, shift, ssize);
  525. hidx = __rpte_to_hidx(pte, index);
  526. if (hidx & _PTEIDX_SECONDARY)
  527. hash = ~hash;
  528. slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
  529. slot += hidx & _PTEIDX_GROUP_IX;
  530. hptep = htab_address + slot;
  531. want_v = hpte_encode_avpn(vpn, psize, ssize);
  532. native_lock_hpte(hptep);
  533. hpte_v = hptep->v;
  534. if (!HPTE_V_COMPARE(hpte_v, want_v) ||
  535. !(hpte_v & HPTE_V_VALID))
  536. native_unlock_hpte(hptep);
  537. else
  538. hptep->v = 0;
  539. } pte_iterate_hashed_end();
  540. }
  541. if (mmu_has_feature(MMU_FTR_TLBIEL) &&
  542. mmu_psize_defs[psize].tlbiel && local) {
  543. asm volatile("ptesync":::"memory");
  544. for (i = 0; i < number; i++) {
  545. vpn = batch->vpn[i];
  546. pte = batch->pte[i];
  547. pte_iterate_hashed_subpages(pte, psize,
  548. vpn, index, shift) {
  549. __tlbiel(vpn, psize, psize, ssize);
  550. } pte_iterate_hashed_end();
  551. }
  552. asm volatile("ptesync":::"memory");
  553. } else {
  554. int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE);
  555. if (lock_tlbie)
  556. raw_spin_lock(&native_tlbie_lock);
  557. asm volatile("ptesync":::"memory");
  558. for (i = 0; i < number; i++) {
  559. vpn = batch->vpn[i];
  560. pte = batch->pte[i];
  561. pte_iterate_hashed_subpages(pte, psize,
  562. vpn, index, shift) {
  563. __tlbie(vpn, psize, psize, ssize);
  564. } pte_iterate_hashed_end();
  565. }
  566. asm volatile("eieio; tlbsync; ptesync":::"memory");
  567. if (lock_tlbie)
  568. raw_spin_unlock(&native_tlbie_lock);
  569. }
  570. local_irq_restore(flags);
  571. }
  572. void __init hpte_init_native(void)
  573. {
  574. ppc_md.hpte_invalidate = native_hpte_invalidate;
  575. ppc_md.hpte_updatepp = native_hpte_updatepp;
  576. ppc_md.hpte_updateboltedpp = native_hpte_updateboltedpp;
  577. ppc_md.hpte_insert = native_hpte_insert;
  578. ppc_md.hpte_remove = native_hpte_remove;
  579. ppc_md.hpte_clear_all = native_hpte_clear;
  580. ppc_md.flush_hash_range = native_flush_hash_range;
  581. }