hash_low_64.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * ppc64 MMU hashtable management routines
  3. *
  4. * (c) Copyright IBM Corp. 2003, 2005
  5. *
  6. * Maintained by: Benjamin Herrenschmidt
  7. * <benh@kernel.crashing.org>
  8. *
  9. * This file is covered by the GNU Public Licence v2 as
  10. * described in the kernel's COPYING file.
  11. */
  12. #include <linux/config.h>
  13. #include <asm/reg.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/mmu.h>
  16. #include <asm/page.h>
  17. #include <asm/types.h>
  18. #include <asm/ppc_asm.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/cputable.h>
  21. .text
  22. /*
  23. * Stackframe:
  24. *
  25. * +-> Back chain (SP + 256)
  26. * | General register save area (SP + 112)
  27. * | Parameter save area (SP + 48)
  28. * | TOC save area (SP + 40)
  29. * | link editor doubleword (SP + 32)
  30. * | compiler doubleword (SP + 24)
  31. * | LR save area (SP + 16)
  32. * | CR save area (SP + 8)
  33. * SP ---> +-- Back chain (SP + 0)
  34. */
  35. #define STACKFRAMESIZE 256
  36. /* Save parameters offsets */
  37. #define STK_PARM(i) (STACKFRAMESIZE + 48 + ((i)-3)*8)
  38. /* Save non-volatile offsets */
  39. #define STK_REG(i) (112 + ((i)-14)*8)
  40. #ifndef CONFIG_PPC_64K_PAGES
  41. /*****************************************************************************
  42. * *
  43. * 4K SW & 4K HW pages implementation *
  44. * *
  45. *****************************************************************************/
  46. /*
  47. * _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
  48. * pte_t *ptep, unsigned long trap, int local)
  49. *
  50. * Adds a 4K page to the hash table in a segment of 4K pages only
  51. */
  52. _GLOBAL(__hash_page_4K)
  53. mflr r0
  54. std r0,16(r1)
  55. stdu r1,-STACKFRAMESIZE(r1)
  56. /* Save all params that we need after a function call */
  57. std r6,STK_PARM(r6)(r1)
  58. std r8,STK_PARM(r8)(r1)
  59. /* Add _PAGE_PRESENT to access */
  60. ori r4,r4,_PAGE_PRESENT
  61. /* Save non-volatile registers.
  62. * r31 will hold "old PTE"
  63. * r30 is "new PTE"
  64. * r29 is "va"
  65. * r28 is a hash value
  66. * r27 is hashtab mask (maybe dynamic patched instead ?)
  67. */
  68. std r27,STK_REG(r27)(r1)
  69. std r28,STK_REG(r28)(r1)
  70. std r29,STK_REG(r29)(r1)
  71. std r30,STK_REG(r30)(r1)
  72. std r31,STK_REG(r31)(r1)
  73. /* Step 1:
  74. *
  75. * Check permissions, atomically mark the linux PTE busy
  76. * and hashed.
  77. */
  78. 1:
  79. ldarx r31,0,r6
  80. /* Check access rights (access & ~(pte_val(*ptep))) */
  81. andc. r0,r4,r31
  82. bne- htab_wrong_access
  83. /* Check if PTE is busy */
  84. andi. r0,r31,_PAGE_BUSY
  85. /* If so, just bail out and refault if needed. Someone else
  86. * is changing this PTE anyway and might hash it.
  87. */
  88. bne- htab_bail_ok
  89. /* Prepare new PTE value (turn access RW into DIRTY, then
  90. * add BUSY,HASHPTE and ACCESSED)
  91. */
  92. rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
  93. or r30,r30,r31
  94. ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
  95. /* Write the linux PTE atomically (setting busy) */
  96. stdcx. r30,0,r6
  97. bne- 1b
  98. isync
  99. /* Step 2:
  100. *
  101. * Insert/Update the HPTE in the hash table. At this point,
  102. * r4 (access) is re-useable, we use it for the new HPTE flags
  103. */
  104. /* Calc va and put it in r29 */
  105. rldicr r29,r5,28,63-28
  106. rldicl r3,r3,0,36
  107. or r29,r3,r29
  108. /* Calculate hash value for primary slot and store it in r28 */
  109. rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
  110. rldicl r0,r3,64-12,48 /* (ea >> 12) & 0xffff */
  111. xor r28,r5,r0
  112. /* Convert linux PTE bits into HW equivalents */
  113. andi. r3,r30,0x1fe /* Get basic set of flags */
  114. xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
  115. rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
  116. rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
  117. and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
  118. andc r0,r30,r0 /* r0 = pte & ~r0 */
  119. rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
  120. /* We eventually do the icache sync here (maybe inline that
  121. * code rather than call a C function...)
  122. */
  123. BEGIN_FTR_SECTION
  124. mr r4,r30
  125. mr r5,r7
  126. bl .hash_page_do_lazy_icache
  127. END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
  128. /* At this point, r3 contains new PP bits, save them in
  129. * place of "access" in the param area (sic)
  130. */
  131. std r3,STK_PARM(r4)(r1)
  132. /* Get htab_hash_mask */
  133. ld r4,htab_hash_mask@got(2)
  134. ld r27,0(r4) /* htab_hash_mask -> r27 */
  135. /* Check if we may already be in the hashtable, in this case, we
  136. * go to out-of-line code to try to modify the HPTE
  137. */
  138. andi. r0,r31,_PAGE_HASHPTE
  139. bne htab_modify_pte
  140. htab_insert_pte:
  141. /* Clear hpte bits in new pte (we also clear BUSY btw) and
  142. * add _PAGE_HASHPTE
  143. */
  144. lis r0,_PAGE_HPTEFLAGS@h
  145. ori r0,r0,_PAGE_HPTEFLAGS@l
  146. andc r30,r30,r0
  147. ori r30,r30,_PAGE_HASHPTE
  148. /* physical address r5 */
  149. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  150. sldi r5,r5,PAGE_SHIFT
  151. /* Calculate primary group hash */
  152. and r0,r28,r27
  153. rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
  154. /* Call ppc_md.hpte_insert */
  155. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  156. mr r4,r29 /* Retreive va */
  157. li r7,0 /* !bolted, !secondary */
  158. li r8,MMU_PAGE_4K /* page size */
  159. _GLOBAL(htab_call_hpte_insert1)
  160. bl . /* Patched by htab_finish_init() */
  161. cmpdi 0,r3,0
  162. bge htab_pte_insert_ok /* Insertion successful */
  163. cmpdi 0,r3,-2 /* Critical failure */
  164. beq- htab_pte_insert_failure
  165. /* Now try secondary slot */
  166. /* physical address r5 */
  167. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  168. sldi r5,r5,PAGE_SHIFT
  169. /* Calculate secondary group hash */
  170. andc r0,r27,r28
  171. rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
  172. /* Call ppc_md.hpte_insert */
  173. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  174. mr r4,r29 /* Retreive va */
  175. li r7,HPTE_V_SECONDARY /* !bolted, secondary */
  176. li r8,MMU_PAGE_4K /* page size */
  177. _GLOBAL(htab_call_hpte_insert2)
  178. bl . /* Patched by htab_finish_init() */
  179. cmpdi 0,r3,0
  180. bge+ htab_pte_insert_ok /* Insertion successful */
  181. cmpdi 0,r3,-2 /* Critical failure */
  182. beq- htab_pte_insert_failure
  183. /* Both are full, we need to evict something */
  184. mftb r0
  185. /* Pick a random group based on TB */
  186. andi. r0,r0,1
  187. mr r5,r28
  188. bne 2f
  189. not r5,r5
  190. 2: and r0,r5,r27
  191. rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  192. /* Call ppc_md.hpte_remove */
  193. _GLOBAL(htab_call_hpte_remove)
  194. bl . /* Patched by htab_finish_init() */
  195. /* Try all again */
  196. b htab_insert_pte
  197. htab_bail_ok:
  198. li r3,0
  199. b htab_bail
  200. htab_pte_insert_ok:
  201. /* Insert slot number & secondary bit in PTE */
  202. rldimi r30,r3,12,63-15
  203. /* Write out the PTE with a normal write
  204. * (maybe add eieio may be good still ?)
  205. */
  206. htab_write_out_pte:
  207. ld r6,STK_PARM(r6)(r1)
  208. std r30,0(r6)
  209. li r3, 0
  210. htab_bail:
  211. ld r27,STK_REG(r27)(r1)
  212. ld r28,STK_REG(r28)(r1)
  213. ld r29,STK_REG(r29)(r1)
  214. ld r30,STK_REG(r30)(r1)
  215. ld r31,STK_REG(r31)(r1)
  216. addi r1,r1,STACKFRAMESIZE
  217. ld r0,16(r1)
  218. mtlr r0
  219. blr
  220. htab_modify_pte:
  221. /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
  222. mr r4,r3
  223. rlwinm r3,r31,32-12,29,31
  224. /* Secondary group ? if yes, get a inverted hash value */
  225. mr r5,r28
  226. andi. r0,r31,_PAGE_SECONDARY
  227. beq 1f
  228. not r5,r5
  229. 1:
  230. /* Calculate proper slot value for ppc_md.hpte_updatepp */
  231. and r0,r5,r27
  232. rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  233. add r3,r0,r3 /* add slot idx */
  234. /* Call ppc_md.hpte_updatepp */
  235. mr r5,r29 /* va */
  236. li r6,MMU_PAGE_4K /* page size */
  237. ld r7,STK_PARM(r8)(r1) /* get "local" param */
  238. _GLOBAL(htab_call_hpte_updatepp)
  239. bl . /* Patched by htab_finish_init() */
  240. /* if we failed because typically the HPTE wasn't really here
  241. * we try an insertion.
  242. */
  243. cmpdi 0,r3,-1
  244. beq- htab_insert_pte
  245. /* Clear the BUSY bit and Write out the PTE */
  246. li r0,_PAGE_BUSY
  247. andc r30,r30,r0
  248. b htab_write_out_pte
  249. htab_wrong_access:
  250. /* Bail out clearing reservation */
  251. stdcx. r31,0,r6
  252. li r3,1
  253. b htab_bail
  254. htab_pte_insert_failure:
  255. /* Bail out restoring old PTE */
  256. ld r6,STK_PARM(r6)(r1)
  257. std r31,0(r6)
  258. li r3,-1
  259. b htab_bail
  260. #else /* CONFIG_PPC_64K_PAGES */
  261. /*****************************************************************************
  262. * *
  263. * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
  264. * *
  265. *****************************************************************************/
  266. /* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
  267. * pte_t *ptep, unsigned long trap, int local)
  268. */
  269. /*
  270. * For now, we do NOT implement Admixed pages
  271. */
  272. _GLOBAL(__hash_page_4K)
  273. mflr r0
  274. std r0,16(r1)
  275. stdu r1,-STACKFRAMESIZE(r1)
  276. /* Save all params that we need after a function call */
  277. std r6,STK_PARM(r6)(r1)
  278. std r8,STK_PARM(r8)(r1)
  279. /* Add _PAGE_PRESENT to access */
  280. ori r4,r4,_PAGE_PRESENT
  281. /* Save non-volatile registers.
  282. * r31 will hold "old PTE"
  283. * r30 is "new PTE"
  284. * r29 is "va"
  285. * r28 is a hash value
  286. * r27 is hashtab mask (maybe dynamic patched instead ?)
  287. * r26 is the hidx mask
  288. * r25 is the index in combo page
  289. */
  290. std r25,STK_REG(r25)(r1)
  291. std r26,STK_REG(r26)(r1)
  292. std r27,STK_REG(r27)(r1)
  293. std r28,STK_REG(r28)(r1)
  294. std r29,STK_REG(r29)(r1)
  295. std r30,STK_REG(r30)(r1)
  296. std r31,STK_REG(r31)(r1)
  297. /* Step 1:
  298. *
  299. * Check permissions, atomically mark the linux PTE busy
  300. * and hashed.
  301. */
  302. 1:
  303. ldarx r31,0,r6
  304. /* Check access rights (access & ~(pte_val(*ptep))) */
  305. andc. r0,r4,r31
  306. bne- htab_wrong_access
  307. /* Check if PTE is busy */
  308. andi. r0,r31,_PAGE_BUSY
  309. /* If so, just bail out and refault if needed. Someone else
  310. * is changing this PTE anyway and might hash it.
  311. */
  312. bne- htab_bail_ok
  313. /* Prepare new PTE value (turn access RW into DIRTY, then
  314. * add BUSY and ACCESSED)
  315. */
  316. rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
  317. or r30,r30,r31
  318. ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
  319. /* Write the linux PTE atomically (setting busy) */
  320. stdcx. r30,0,r6
  321. bne- 1b
  322. isync
  323. /* Step 2:
  324. *
  325. * Insert/Update the HPTE in the hash table. At this point,
  326. * r4 (access) is re-useable, we use it for the new HPTE flags
  327. */
  328. /* Load the hidx index */
  329. rldicl r25,r3,64-12,60
  330. /* Calc va and put it in r29 */
  331. rldicr r29,r5,28,63-28 /* r29 = (vsid << 28) */
  332. rldicl r3,r3,0,36 /* r3 = (ea & 0x0fffffff) */
  333. or r29,r3,r29 /* r29 = va
  334. /* Calculate hash value for primary slot and store it in r28 */
  335. rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
  336. rldicl r0,r3,64-12,48 /* (ea >> 12) & 0xffff */
  337. xor r28,r5,r0
  338. /* Convert linux PTE bits into HW equivalents */
  339. andi. r3,r30,0x1fe /* Get basic set of flags */
  340. xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
  341. rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
  342. rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
  343. and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
  344. andc r0,r30,r0 /* r0 = pte & ~r0 */
  345. rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
  346. /* We eventually do the icache sync here (maybe inline that
  347. * code rather than call a C function...)
  348. */
  349. BEGIN_FTR_SECTION
  350. mr r4,r30
  351. mr r5,r7
  352. bl .hash_page_do_lazy_icache
  353. END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
  354. /* At this point, r3 contains new PP bits, save them in
  355. * place of "access" in the param area (sic)
  356. */
  357. std r3,STK_PARM(r4)(r1)
  358. /* Get htab_hash_mask */
  359. ld r4,htab_hash_mask@got(2)
  360. ld r27,0(r4) /* htab_hash_mask -> r27 */
  361. /* Check if we may already be in the hashtable, in this case, we
  362. * go to out-of-line code to try to modify the HPTE. We look for
  363. * the bit at (1 >> (index + 32))
  364. */
  365. andi. r0,r31,_PAGE_HASHPTE
  366. li r26,0 /* Default hidx */
  367. beq htab_insert_pte
  368. ld r6,STK_PARM(r6)(r1)
  369. ori r26,r6,0x8000 /* Load the hidx mask */
  370. ld r26,0(r26)
  371. addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
  372. rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
  373. bne htab_modify_pte
  374. htab_insert_pte:
  375. /* real page number in r5, PTE RPN value + index */
  376. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  377. sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
  378. add r5,r5,r25
  379. sldi r5,r5,HW_PAGE_SHIFT
  380. /* Calculate primary group hash */
  381. and r0,r28,r27
  382. rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  383. /* Call ppc_md.hpte_insert */
  384. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  385. mr r4,r29 /* Retreive va */
  386. li r7,0 /* !bolted, !secondary */
  387. li r8,MMU_PAGE_4K /* page size */
  388. _GLOBAL(htab_call_hpte_insert1)
  389. bl . /* patched by htab_finish_init() */
  390. cmpdi 0,r3,0
  391. bge htab_pte_insert_ok /* Insertion successful */
  392. cmpdi 0,r3,-2 /* Critical failure */
  393. beq- htab_pte_insert_failure
  394. /* Now try secondary slot */
  395. /* real page number in r5, PTE RPN value + index */
  396. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  397. sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
  398. add r5,r5,r25
  399. sldi r5,r5,HW_PAGE_SHIFT
  400. /* Calculate secondary group hash */
  401. andc r0,r27,r28
  402. rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
  403. /* Call ppc_md.hpte_insert */
  404. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  405. mr r4,r29 /* Retreive va */
  406. li r7,HPTE_V_SECONDARY /* !bolted, secondary */
  407. li r8,MMU_PAGE_4K /* page size */
  408. _GLOBAL(htab_call_hpte_insert2)
  409. bl . /* patched by htab_finish_init() */
  410. cmpdi 0,r3,0
  411. bge+ htab_pte_insert_ok /* Insertion successful */
  412. cmpdi 0,r3,-2 /* Critical failure */
  413. beq- htab_pte_insert_failure
  414. /* Both are full, we need to evict something */
  415. mftb r0
  416. /* Pick a random group based on TB */
  417. andi. r0,r0,1
  418. mr r5,r28
  419. bne 2f
  420. not r5,r5
  421. 2: and r0,r5,r27
  422. rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  423. /* Call ppc_md.hpte_remove */
  424. _GLOBAL(htab_call_hpte_remove)
  425. bl . /* patched by htab_finish_init() */
  426. /* Try all again */
  427. b htab_insert_pte
  428. htab_bail_ok:
  429. li r3,0
  430. b htab_bail
  431. htab_pte_insert_ok:
  432. /* Insert slot number & secondary bit in PTE second half,
  433. * clear _PAGE_BUSY and set approriate HPTE slot bit
  434. */
  435. ld r6,STK_PARM(r6)(r1)
  436. li r0,_PAGE_BUSY
  437. andc r30,r30,r0
  438. /* HPTE SUB bit */
  439. li r0,1
  440. subfic r5,r25,27 /* Must match bit position in */
  441. sld r0,r0,r5 /* pgtable.h */
  442. or r30,r30,r0
  443. /* hindx */
  444. sldi r5,r25,2
  445. sld r3,r3,r5
  446. li r4,0xf
  447. sld r4,r4,r5
  448. andc r26,r26,r4
  449. or r26,r26,r3
  450. ori r5,r6,0x8000
  451. std r26,0(r5)
  452. lwsync
  453. std r30,0(r6)
  454. li r3, 0
  455. htab_bail:
  456. ld r25,STK_REG(r25)(r1)
  457. ld r26,STK_REG(r26)(r1)
  458. ld r27,STK_REG(r27)(r1)
  459. ld r28,STK_REG(r28)(r1)
  460. ld r29,STK_REG(r29)(r1)
  461. ld r30,STK_REG(r30)(r1)
  462. ld r31,STK_REG(r31)(r1)
  463. addi r1,r1,STACKFRAMESIZE
  464. ld r0,16(r1)
  465. mtlr r0
  466. blr
  467. htab_modify_pte:
  468. /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
  469. mr r4,r3
  470. sldi r5,r25,2
  471. srd r3,r26,r5
  472. /* Secondary group ? if yes, get a inverted hash value */
  473. mr r5,r28
  474. andi. r0,r3,0x8 /* page secondary ? */
  475. beq 1f
  476. not r5,r5
  477. 1: andi. r3,r3,0x7 /* extract idx alone */
  478. /* Calculate proper slot value for ppc_md.hpte_updatepp */
  479. and r0,r5,r27
  480. rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  481. add r3,r0,r3 /* add slot idx */
  482. /* Call ppc_md.hpte_updatepp */
  483. mr r5,r29 /* va */
  484. li r6,MMU_PAGE_4K /* page size */
  485. ld r7,STK_PARM(r8)(r1) /* get "local" param */
  486. _GLOBAL(htab_call_hpte_updatepp)
  487. bl . /* patched by htab_finish_init() */
  488. /* if we failed because typically the HPTE wasn't really here
  489. * we try an insertion.
  490. */
  491. cmpdi 0,r3,-1
  492. beq- htab_insert_pte
  493. /* Clear the BUSY bit and Write out the PTE */
  494. li r0,_PAGE_BUSY
  495. andc r30,r30,r0
  496. ld r6,STK_PARM(r6)(r1)
  497. std r30,0(r6)
  498. li r3,0
  499. b htab_bail
  500. htab_wrong_access:
  501. /* Bail out clearing reservation */
  502. stdcx. r31,0,r6
  503. li r3,1
  504. b htab_bail
  505. htab_pte_insert_failure:
  506. /* Bail out restoring old PTE */
  507. ld r6,STK_PARM(r6)(r1)
  508. std r31,0(r6)
  509. li r3,-1
  510. b htab_bail
  511. /*****************************************************************************
  512. * *
  513. * 64K SW & 64K HW in a 64K segment pages implementation *
  514. * *
  515. *****************************************************************************/
  516. _GLOBAL(__hash_page_64K)
  517. mflr r0
  518. std r0,16(r1)
  519. stdu r1,-STACKFRAMESIZE(r1)
  520. /* Save all params that we need after a function call */
  521. std r6,STK_PARM(r6)(r1)
  522. std r8,STK_PARM(r8)(r1)
  523. /* Add _PAGE_PRESENT to access */
  524. ori r4,r4,_PAGE_PRESENT
  525. /* Save non-volatile registers.
  526. * r31 will hold "old PTE"
  527. * r30 is "new PTE"
  528. * r29 is "va"
  529. * r28 is a hash value
  530. * r27 is hashtab mask (maybe dynamic patched instead ?)
  531. */
  532. std r27,STK_REG(r27)(r1)
  533. std r28,STK_REG(r28)(r1)
  534. std r29,STK_REG(r29)(r1)
  535. std r30,STK_REG(r30)(r1)
  536. std r31,STK_REG(r31)(r1)
  537. /* Step 1:
  538. *
  539. * Check permissions, atomically mark the linux PTE busy
  540. * and hashed.
  541. */
  542. 1:
  543. ldarx r31,0,r6
  544. /* Check access rights (access & ~(pte_val(*ptep))) */
  545. andc. r0,r4,r31
  546. bne- ht64_wrong_access
  547. /* Check if PTE is busy */
  548. andi. r0,r31,_PAGE_BUSY
  549. /* If so, just bail out and refault if needed. Someone else
  550. * is changing this PTE anyway and might hash it.
  551. */
  552. bne- ht64_bail_ok
  553. /* Prepare new PTE value (turn access RW into DIRTY, then
  554. * add BUSY,HASHPTE and ACCESSED)
  555. */
  556. rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
  557. or r30,r30,r31
  558. ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
  559. /* Write the linux PTE atomically (setting busy) */
  560. stdcx. r30,0,r6
  561. bne- 1b
  562. isync
  563. /* Step 2:
  564. *
  565. * Insert/Update the HPTE in the hash table. At this point,
  566. * r4 (access) is re-useable, we use it for the new HPTE flags
  567. */
  568. /* Calc va and put it in r29 */
  569. rldicr r29,r5,28,63-28
  570. rldicl r3,r3,0,36
  571. or r29,r3,r29
  572. /* Calculate hash value for primary slot and store it in r28 */
  573. rldicl r5,r5,0,25 /* vsid & 0x0000007fffffffff */
  574. rldicl r0,r3,64-16,52 /* (ea >> 16) & 0xfff */
  575. xor r28,r5,r0
  576. /* Convert linux PTE bits into HW equivalents */
  577. andi. r3,r30,0x1fe /* Get basic set of flags */
  578. xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
  579. rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
  580. rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
  581. and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
  582. andc r0,r30,r0 /* r0 = pte & ~r0 */
  583. rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
  584. /* We eventually do the icache sync here (maybe inline that
  585. * code rather than call a C function...)
  586. */
  587. BEGIN_FTR_SECTION
  588. mr r4,r30
  589. mr r5,r7
  590. bl .hash_page_do_lazy_icache
  591. END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
  592. /* At this point, r3 contains new PP bits, save them in
  593. * place of "access" in the param area (sic)
  594. */
  595. std r3,STK_PARM(r4)(r1)
  596. /* Get htab_hash_mask */
  597. ld r4,htab_hash_mask@got(2)
  598. ld r27,0(r4) /* htab_hash_mask -> r27 */
  599. /* Check if we may already be in the hashtable, in this case, we
  600. * go to out-of-line code to try to modify the HPTE
  601. */
  602. andi. r0,r31,_PAGE_HASHPTE
  603. bne ht64_modify_pte
  604. ht64_insert_pte:
  605. /* Clear hpte bits in new pte (we also clear BUSY btw) and
  606. * add _PAGE_HASHPTE
  607. */
  608. lis r0,_PAGE_HPTEFLAGS@h
  609. ori r0,r0,_PAGE_HPTEFLAGS@l
  610. andc r30,r30,r0
  611. ori r30,r30,_PAGE_HASHPTE
  612. /* Phyical address in r5 */
  613. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  614. sldi r5,r5,PAGE_SHIFT
  615. /* Calculate primary group hash */
  616. and r0,r28,r27
  617. rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  618. /* Call ppc_md.hpte_insert */
  619. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  620. mr r4,r29 /* Retreive va */
  621. li r7,0 /* !bolted, !secondary */
  622. li r8,MMU_PAGE_64K
  623. _GLOBAL(ht64_call_hpte_insert1)
  624. bl . /* patched by htab_finish_init() */
  625. cmpdi 0,r3,0
  626. bge ht64_pte_insert_ok /* Insertion successful */
  627. cmpdi 0,r3,-2 /* Critical failure */
  628. beq- ht64_pte_insert_failure
  629. /* Now try secondary slot */
  630. /* Phyical address in r5 */
  631. rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
  632. sldi r5,r5,PAGE_SHIFT
  633. /* Calculate secondary group hash */
  634. andc r0,r27,r28
  635. rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
  636. /* Call ppc_md.hpte_insert */
  637. ld r6,STK_PARM(r4)(r1) /* Retreive new pp bits */
  638. mr r4,r29 /* Retreive va */
  639. li r7,HPTE_V_SECONDARY /* !bolted, secondary */
  640. li r8,MMU_PAGE_64K
  641. _GLOBAL(ht64_call_hpte_insert2)
  642. bl . /* patched by htab_finish_init() */
  643. cmpdi 0,r3,0
  644. bge+ ht64_pte_insert_ok /* Insertion successful */
  645. cmpdi 0,r3,-2 /* Critical failure */
  646. beq- ht64_pte_insert_failure
  647. /* Both are full, we need to evict something */
  648. mftb r0
  649. /* Pick a random group based on TB */
  650. andi. r0,r0,1
  651. mr r5,r28
  652. bne 2f
  653. not r5,r5
  654. 2: and r0,r5,r27
  655. rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  656. /* Call ppc_md.hpte_remove */
  657. _GLOBAL(ht64_call_hpte_remove)
  658. bl . /* patched by htab_finish_init() */
  659. /* Try all again */
  660. b ht64_insert_pte
  661. ht64_bail_ok:
  662. li r3,0
  663. b ht64_bail
  664. ht64_pte_insert_ok:
  665. /* Insert slot number & secondary bit in PTE */
  666. rldimi r30,r3,12,63-15
  667. /* Write out the PTE with a normal write
  668. * (maybe add eieio may be good still ?)
  669. */
  670. ht64_write_out_pte:
  671. ld r6,STK_PARM(r6)(r1)
  672. std r30,0(r6)
  673. li r3, 0
  674. ht64_bail:
  675. ld r27,STK_REG(r27)(r1)
  676. ld r28,STK_REG(r28)(r1)
  677. ld r29,STK_REG(r29)(r1)
  678. ld r30,STK_REG(r30)(r1)
  679. ld r31,STK_REG(r31)(r1)
  680. addi r1,r1,STACKFRAMESIZE
  681. ld r0,16(r1)
  682. mtlr r0
  683. blr
  684. ht64_modify_pte:
  685. /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
  686. mr r4,r3
  687. rlwinm r3,r31,32-12,29,31
  688. /* Secondary group ? if yes, get a inverted hash value */
  689. mr r5,r28
  690. andi. r0,r31,_PAGE_F_SECOND
  691. beq 1f
  692. not r5,r5
  693. 1:
  694. /* Calculate proper slot value for ppc_md.hpte_updatepp */
  695. and r0,r5,r27
  696. rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
  697. add r3,r0,r3 /* add slot idx */
  698. /* Call ppc_md.hpte_updatepp */
  699. mr r5,r29 /* va */
  700. li r6,MMU_PAGE_64K
  701. ld r7,STK_PARM(r8)(r1) /* get "local" param */
  702. _GLOBAL(ht64_call_hpte_updatepp)
  703. bl . /* patched by htab_finish_init() */
  704. /* if we failed because typically the HPTE wasn't really here
  705. * we try an insertion.
  706. */
  707. cmpdi 0,r3,-1
  708. beq- ht64_insert_pte
  709. /* Clear the BUSY bit and Write out the PTE */
  710. li r0,_PAGE_BUSY
  711. andc r30,r30,r0
  712. b ht64_write_out_pte
  713. ht64_wrong_access:
  714. /* Bail out clearing reservation */
  715. stdcx. r31,0,r6
  716. li r3,1
  717. b ht64_bail
  718. ht64_pte_insert_failure:
  719. /* Bail out restoring old PTE */
  720. ld r6,STK_PARM(r6)(r1)
  721. std r31,0(r6)
  722. li r3,-1
  723. b ht64_bail
  724. #endif /* CONFIG_PPC_64K_PAGES */
  725. /*****************************************************************************
  726. * *
  727. * Huge pages implementation is in hugetlbpage.c *
  728. * *
  729. *****************************************************************************/