blob: 1136d26a95ae02ac075914e13f54720864b71fea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ppc64 MMU hashtable management routines
3 *
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +11004 * (c) Copyright IBM Corp. 2003, 2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Paul Mackerrasab1f9da2005-10-10 21:58:35 +100013#include <asm/reg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#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>
Sam Ravnborg0013a852005-09-09 20:57:26 +020019#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/cputable.h>
21
22 .text
23
24/*
25 * Stackframe:
26 *
27 * +-> Back chain (SP + 256)
28 * | General register save area (SP + 112)
29 * | Parameter save area (SP + 48)
30 * | TOC save area (SP + 40)
31 * | link editor doubleword (SP + 32)
32 * | compiler doubleword (SP + 24)
33 * | LR save area (SP + 16)
34 * | CR save area (SP + 8)
35 * SP ---> +-- Back chain (SP + 0)
36 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110037
38#ifndef CONFIG_PPC_64K_PAGES
39
40/*****************************************************************************
41 * *
42 * 4K SW & 4K HW pages implementation *
43 * *
44 *****************************************************************************/
45
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110048 * _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
Paul Mackerras1189be62007-10-11 20:37:10 +100049 * pte_t *ptep, unsigned long trap, int local, int ssize)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 *
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110051 * Adds a 4K page to the hash table in a segment of 4K pages only
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 */
53
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110054_GLOBAL(__hash_page_4K)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 mflr r0
56 std r0,16(r1)
57 stdu r1,-STACKFRAMESIZE(r1)
58 /* Save all params that we need after a function call */
Michael Neuling44ce6a52012-06-25 13:33:14 +000059 std r6,STK_PARAM(R6)(r1)
60 std r8,STK_PARAM(R8)(r1)
61 std r9,STK_PARAM(R9)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /* Save non-volatile registers.
64 * r31 will hold "old PTE"
65 * r30 is "new PTE"
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +000066 * r29 is vpn
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 * r28 is a hash value
68 * r27 is hashtab mask (maybe dynamic patched instead ?)
69 */
Michael Neulingc75df6f2012-06-25 13:33:10 +000070 std r27,STK_REG(R27)(r1)
71 std r28,STK_REG(R28)(r1)
72 std r29,STK_REG(R29)(r1)
73 std r30,STK_REG(R30)(r1)
74 std r31,STK_REG(R31)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 /* Step 1:
77 *
78 * Check permissions, atomically mark the linux PTE busy
79 * and hashed.
80 */
811:
82 ldarx r31,0,r6
83 /* Check access rights (access & ~(pte_val(*ptep))) */
84 andc. r0,r4,r31
85 bne- htab_wrong_access
86 /* Check if PTE is busy */
87 andi. r0,r31,_PAGE_BUSY
Olof Johanssond03853d2005-05-01 08:58:45 -070088 /* If so, just bail out and refault if needed. Someone else
89 * is changing this PTE anyway and might hash it.
90 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110091 bne- htab_bail_ok
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 /* Prepare new PTE value (turn access RW into DIRTY, then
94 * add BUSY,HASHPTE and ACCESSED)
95 */
96 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
97 or r30,r30,r31
98 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED | _PAGE_HASHPTE
99 /* Write the linux PTE atomically (setting busy) */
100 stdcx. r30,0,r6
101 bne- 1b
102 isync
103
104 /* Step 2:
105 *
106 * Insert/Update the HPTE in the hash table. At this point,
107 * r4 (access) is re-useable, we use it for the new HPTE flags
108 */
109
Paul Mackerras1189be62007-10-11 20:37:10 +1000110BEGIN_FTR_SECTION
111 cmpdi r9,0 /* check segment size */
112 bne 3f
Matt Evans44ae3ab2011-04-06 19:48:50 +0000113END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000114 /* Calc vpn and put it in r29 */
115 sldi r29,r5,SID_SHIFT - VPN_SHIFT
116 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
117 or r29,r28,r29
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000118 /*
119 * Calculate hash value for primary slot and store it in r28
120 * r3 = va, r5 = vsid
121 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
122 */
123 rldicl r0,r3,64-12,48
124 xor r28,r5,r0 /* hash */
Paul Mackerras1189be62007-10-11 20:37:10 +1000125 b 4f
126
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +00001273: /* Calc vpn and put it in r29 */
128 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
129 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
130 or r29,r28,r29
131
132 /*
133 * calculate hash value for primary slot and
134 * store it in r28 for 1T segment
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000135 * r3 = va, r5 = vsid
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000136 */
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000137 sldi r28,r5,25 /* vsid << 25 */
138 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
139 rldicl r0,r3,64-12,36
140 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
Paul Mackerras1189be62007-10-11 20:37:10 +1000141 xor r28,r28,r0 /* hash */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* Convert linux PTE bits into HW equivalents */
Paul Mackerras1189be62007-10-11 20:37:10 +10001444: andi. r3,r30,0x1fe /* Get basic set of flags */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100145 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
147 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100148 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 andc r0,r30,r0 /* r0 = pte & ~r0 */
150 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
Aneesh Kumar K.Vc8c06f52013-11-18 14:58:10 +0530151 /*
152 * Always add "C" bit for perf. Memory coherence is always enabled
153 */
154 ori r3,r3,HPTE_R_C | HPTE_R_M
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 /* We eventually do the icache sync here (maybe inline that
157 * code rather than call a C function...)
158 */
159BEGIN_FTR_SECTION
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 mr r4,r30
161 mr r5,r7
162 bl .hash_page_do_lazy_icache
David Gibson8913ca12005-07-27 15:47:23 +1000163END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 /* At this point, r3 contains new PP bits, save them in
166 * place of "access" in the param area (sic)
167 */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000168 std r3,STK_PARAM(R4)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* Get htab_hash_mask */
171 ld r4,htab_hash_mask@got(2)
172 ld r27,0(r4) /* htab_hash_mask -> r27 */
173
174 /* Check if we may already be in the hashtable, in this case, we
175 * go to out-of-line code to try to modify the HPTE
176 */
177 andi. r0,r31,_PAGE_HASHPTE
178 bne htab_modify_pte
179
180htab_insert_pte:
181 /* Clear hpte bits in new pte (we also clear BUSY btw) and
182 * add _PAGE_HASHPTE
183 */
184 lis r0,_PAGE_HPTEFLAGS@h
185 ori r0,r0,_PAGE_HPTEFLAGS@l
186 andc r30,r30,r0
187 ori r30,r30,_PAGE_HASHPTE
188
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100189 /* physical address r5 */
190 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
191 sldi r5,r5,PAGE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* Calculate primary group hash */
194 and r0,r28,r27
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100195 rldicr r3,r0,3,63-3 /* r3 = (hash & mask) << 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000198 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000199 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100200 li r7,0 /* !bolted, !secondary */
201 li r8,MMU_PAGE_4K /* page size */
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000202 li r9,MMU_PAGE_4K /* actual page size */
203 ld r10,STK_PARAM(R9)(r1) /* segment size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204_GLOBAL(htab_call_hpte_insert1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100205 bl . /* Patched by htab_finish_init() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 cmpdi 0,r3,0
207 bge htab_pte_insert_ok /* Insertion successful */
208 cmpdi 0,r3,-2 /* Critical failure */
209 beq- htab_pte_insert_failure
210
211 /* Now try secondary slot */
212
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100213 /* physical address r5 */
214 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
215 sldi r5,r5,PAGE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* Calculate secondary group hash */
218 andc r0,r27,r28
219 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
220
221 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000222 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000223 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100224 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
225 li r8,MMU_PAGE_4K /* page size */
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000226 li r9,MMU_PAGE_4K /* actual page size */
227 ld r10,STK_PARAM(R9)(r1) /* segment size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228_GLOBAL(htab_call_hpte_insert2)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100229 bl . /* Patched by htab_finish_init() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 cmpdi 0,r3,0
231 bge+ htab_pte_insert_ok /* Insertion successful */
232 cmpdi 0,r3,-2 /* Critical failure */
233 beq- htab_pte_insert_failure
234
235 /* Both are full, we need to evict something */
236 mftb r0
237 /* Pick a random group based on TB */
238 andi. r0,r0,1
239 mr r5,r28
240 bne 2f
241 not r5,r5
2422: and r0,r5,r27
243 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
244 /* Call ppc_md.hpte_remove */
245_GLOBAL(htab_call_hpte_remove)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100246 bl . /* Patched by htab_finish_init() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 /* Try all again */
249 b htab_insert_pte
250
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100251htab_bail_ok:
Olof Johanssond03853d2005-05-01 08:58:45 -0700252 li r3,0
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100253 b htab_bail
Olof Johanssond03853d2005-05-01 08:58:45 -0700254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255htab_pte_insert_ok:
256 /* Insert slot number & secondary bit in PTE */
257 rldimi r30,r3,12,63-15
258
259 /* Write out the PTE with a normal write
260 * (maybe add eieio may be good still ?)
261 */
262htab_write_out_pte:
Michael Neuling44ce6a52012-06-25 13:33:14 +0000263 ld r6,STK_PARAM(R6)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 std r30,0(r6)
265 li r3, 0
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100266htab_bail:
Michael Neulingc75df6f2012-06-25 13:33:10 +0000267 ld r27,STK_REG(R27)(r1)
268 ld r28,STK_REG(R28)(r1)
269 ld r29,STK_REG(R29)(r1)
270 ld r30,STK_REG(R30)(r1)
271 ld r31,STK_REG(R31)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 addi r1,r1,STACKFRAMESIZE
273 ld r0,16(r1)
274 mtlr r0
275 blr
276
277htab_modify_pte:
278 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
279 mr r4,r3
280 rlwinm r3,r31,32-12,29,31
281
282 /* Secondary group ? if yes, get a inverted hash value */
283 mr r5,r28
284 andi. r0,r31,_PAGE_SECONDARY
285 beq 1f
286 not r5,r5
2871:
288 /* Calculate proper slot value for ppc_md.hpte_updatepp */
289 and r0,r5,r27
290 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
291 add r3,r0,r3 /* add slot idx */
292
293 /* Call ppc_md.hpte_updatepp */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000294 mr r5,r29 /* vpn */
Aneesh Kumar K.Vdb3d8532013-06-20 14:30:13 +0530295 li r6,MMU_PAGE_4K /* base page size */
296 li r7,MMU_PAGE_4K /* actual page size */
297 ld r8,STK_PARAM(R9)(r1) /* segment size */
298 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299_GLOBAL(htab_call_hpte_updatepp)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100300 bl . /* Patched by htab_finish_init() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 /* if we failed because typically the HPTE wasn't really here
303 * we try an insertion.
304 */
305 cmpdi 0,r3,-1
306 beq- htab_insert_pte
307
308 /* Clear the BUSY bit and Write out the PTE */
309 li r0,_PAGE_BUSY
310 andc r30,r30,r0
311 b htab_write_out_pte
312
313htab_wrong_access:
314 /* Bail out clearing reservation */
315 stdcx. r31,0,r6
316 li r3,1
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100317 b htab_bail
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319htab_pte_insert_failure:
320 /* Bail out restoring old PTE */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000321 ld r6,STK_PARAM(R6)(r1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 std r31,0(r6)
323 li r3,-1
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100324 b htab_bail
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100327#else /* CONFIG_PPC_64K_PAGES */
328
329
330/*****************************************************************************
331 * *
332 * 64K SW & 4K or 64K HW in a 4K segment pages implementation *
333 * *
334 *****************************************************************************/
335
336/* _hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
Paul Mackerrasfa282372008-01-24 08:35:13 +1100337 * pte_t *ptep, unsigned long trap, int local, int ssize,
338 * int subpg_prot)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100339 */
340
341/*
342 * For now, we do NOT implement Admixed pages
343 */
344_GLOBAL(__hash_page_4K)
345 mflr r0
346 std r0,16(r1)
347 stdu r1,-STACKFRAMESIZE(r1)
348 /* Save all params that we need after a function call */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000349 std r6,STK_PARAM(R6)(r1)
350 std r8,STK_PARAM(R8)(r1)
351 std r9,STK_PARAM(R9)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100352
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100353 /* Save non-volatile registers.
354 * r31 will hold "old PTE"
355 * r30 is "new PTE"
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000356 * r29 is vpn
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100357 * r28 is a hash value
358 * r27 is hashtab mask (maybe dynamic patched instead ?)
359 * r26 is the hidx mask
360 * r25 is the index in combo page
361 */
Michael Neulingc75df6f2012-06-25 13:33:10 +0000362 std r25,STK_REG(R25)(r1)
363 std r26,STK_REG(R26)(r1)
364 std r27,STK_REG(R27)(r1)
365 std r28,STK_REG(R28)(r1)
366 std r29,STK_REG(R29)(r1)
367 std r30,STK_REG(R30)(r1)
368 std r31,STK_REG(R31)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100369
370 /* Step 1:
371 *
372 * Check permissions, atomically mark the linux PTE busy
373 * and hashed.
374 */
3751:
376 ldarx r31,0,r6
377 /* Check access rights (access & ~(pte_val(*ptep))) */
378 andc. r0,r4,r31
379 bne- htab_wrong_access
380 /* Check if PTE is busy */
381 andi. r0,r31,_PAGE_BUSY
382 /* If so, just bail out and refault if needed. Someone else
383 * is changing this PTE anyway and might hash it.
384 */
385 bne- htab_bail_ok
386 /* Prepare new PTE value (turn access RW into DIRTY, then
387 * add BUSY and ACCESSED)
388 */
389 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
390 or r30,r30,r31
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000391 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000392 oris r30,r30,_PAGE_COMBO@h
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100393 /* Write the linux PTE atomically (setting busy) */
394 stdcx. r30,0,r6
395 bne- 1b
396 isync
397
398 /* Step 2:
399 *
400 * Insert/Update the HPTE in the hash table. At this point,
401 * r4 (access) is re-useable, we use it for the new HPTE flags
402 */
403
404 /* Load the hidx index */
405 rldicl r25,r3,64-12,60
406
Paul Mackerras1189be62007-10-11 20:37:10 +1000407BEGIN_FTR_SECTION
408 cmpdi r9,0 /* check segment size */
409 bne 3f
Matt Evans44ae3ab2011-04-06 19:48:50 +0000410END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000411 /* Calc vpn and put it in r29 */
412 sldi r29,r5,SID_SHIFT - VPN_SHIFT
413 /*
414 * clrldi r3,r3,64 - SID_SHIFT --> ea & 0xfffffff
415 * srdi r28,r3,VPN_SHIFT
416 */
417 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
418 or r29,r28,r29
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000419 /*
420 * Calculate hash value for primary slot and store it in r28
421 * r3 = va, r5 = vsid
422 * r0 = (va >> 12) & ((1ul << (28 - 12)) -1)
423 */
424 rldicl r0,r3,64-12,48
425 xor r28,r5,r0 /* hash */
Paul Mackerras1189be62007-10-11 20:37:10 +1000426 b 4f
427
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +00004283: /* Calc vpn and put it in r29 */
429 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
430 /*
431 * clrldi r3,r3,64 - SID_SHIFT_1T --> ea & 0xffffffffff
432 * srdi r28,r3,VPN_SHIFT
433 */
434 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
435 or r29,r28,r29
436
437 /*
438 * Calculate hash value for primary slot and
439 * store it in r28 for 1T segment
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000440 * r3 = va, r5 = vsid
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000441 */
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000442 sldi r28,r5,25 /* vsid << 25 */
443 /* r0 = (va >> 12) & ((1ul << (40 - 12)) -1) */
444 rldicl r0,r3,64-12,36
445 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
Paul Mackerras1189be62007-10-11 20:37:10 +1000446 xor r28,r28,r0 /* hash */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100447
448 /* Convert linux PTE bits into HW equivalents */
Paul Mackerrasfa282372008-01-24 08:35:13 +11004494:
450#ifdef CONFIG_PPC_SUBPAGE_PROT
451 andc r10,r30,r10
452 andi. r3,r10,0x1fe /* Get basic set of flags */
453 rlwinm r0,r10,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
454#else
455 andi. r3,r30,0x1fe /* Get basic set of flags */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100456 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
Paul Mackerrasfa282372008-01-24 08:35:13 +1100457#endif
458 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100459 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
460 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
Paul Mackerrasfa282372008-01-24 08:35:13 +1100461 andc r0,r3,r0 /* r0 = pte & ~r0 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100462 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
Aneesh Kumar K.Vc8c06f52013-11-18 14:58:10 +0530463 /*
464 * Always add "C" bit for perf. Memory coherence is always enabled
465 */
466 ori r3,r3,HPTE_R_C | HPTE_R_M
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100467
468 /* We eventually do the icache sync here (maybe inline that
469 * code rather than call a C function...)
470 */
471BEGIN_FTR_SECTION
472 mr r4,r30
473 mr r5,r7
474 bl .hash_page_do_lazy_icache
475END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
476
477 /* At this point, r3 contains new PP bits, save them in
478 * place of "access" in the param area (sic)
479 */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000480 std r3,STK_PARAM(R4)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100481
482 /* Get htab_hash_mask */
483 ld r4,htab_hash_mask@got(2)
484 ld r27,0(r4) /* htab_hash_mask -> r27 */
485
486 /* Check if we may already be in the hashtable, in this case, we
487 * go to out-of-line code to try to modify the HPTE. We look for
488 * the bit at (1 >> (index + 32))
489 */
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000490 rldicl. r0,r31,64-12,48
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100491 li r26,0 /* Default hidx */
492 beq htab_insert_pte
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000493
494 /*
495 * Check if the pte was already inserted into the hash table
496 * as a 64k HW page, and invalidate the 64k HPTE if so.
497 */
498 andis. r0,r31,_PAGE_COMBO@h
499 beq htab_inval_old_hpte
500
Michael Neuling44ce6a52012-06-25 13:33:14 +0000501 ld r6,STK_PARAM(R6)(r1)
Aneesh Kumar K.Vcc3665a2013-04-28 09:37:27 +0000502 ori r26,r6,PTE_PAGE_HIDX_OFFSET /* Load the hidx mask. */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100503 ld r26,0(r26)
504 addi r5,r25,36 /* Check actual HPTE_SUB bit, this */
505 rldcr. r0,r31,r5,0 /* must match pgtable.h definition */
506 bne htab_modify_pte
507
508htab_insert_pte:
509 /* real page number in r5, PTE RPN value + index */
Paul Mackerras721151d2007-04-03 21:24:02 +1000510 andis. r0,r31,_PAGE_4K_PFN@h
511 srdi r5,r31,PTE_RPN_SHIFT
512 bne- htab_special_pfn
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100513 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
514 add r5,r5,r25
Paul Mackerras721151d2007-04-03 21:24:02 +1000515htab_special_pfn:
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100516 sldi r5,r5,HW_PAGE_SHIFT
517
518 /* Calculate primary group hash */
519 and r0,r28,r27
520 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
521
522 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000523 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000524 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100525 li r7,0 /* !bolted, !secondary */
526 li r8,MMU_PAGE_4K /* page size */
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000527 li r9,MMU_PAGE_4K /* actual page size */
528 ld r10,STK_PARAM(R9)(r1) /* segment size */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100529_GLOBAL(htab_call_hpte_insert1)
530 bl . /* patched by htab_finish_init() */
531 cmpdi 0,r3,0
532 bge htab_pte_insert_ok /* Insertion successful */
533 cmpdi 0,r3,-2 /* Critical failure */
534 beq- htab_pte_insert_failure
535
536 /* Now try secondary slot */
537
538 /* real page number in r5, PTE RPN value + index */
Paul Mackerras430404e2007-08-03 19:16:11 +1000539 andis. r0,r31,_PAGE_4K_PFN@h
540 srdi r5,r31,PTE_RPN_SHIFT
541 bne- 3f
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100542 sldi r5,r5,PAGE_SHIFT-HW_PAGE_SHIFT
543 add r5,r5,r25
Paul Mackerras430404e2007-08-03 19:16:11 +10005443: sldi r5,r5,HW_PAGE_SHIFT
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100545
546 /* Calculate secondary group hash */
547 andc r0,r27,r28
548 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
549
550 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000551 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000552 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100553 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
554 li r8,MMU_PAGE_4K /* page size */
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000555 li r9,MMU_PAGE_4K /* actual page size */
556 ld r10,STK_PARAM(R9)(r1) /* segment size */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100557_GLOBAL(htab_call_hpte_insert2)
558 bl . /* patched by htab_finish_init() */
559 cmpdi 0,r3,0
560 bge+ htab_pte_insert_ok /* Insertion successful */
561 cmpdi 0,r3,-2 /* Critical failure */
562 beq- htab_pte_insert_failure
563
564 /* Both are full, we need to evict something */
565 mftb r0
566 /* Pick a random group based on TB */
567 andi. r0,r0,1
568 mr r5,r28
569 bne 2f
570 not r5,r5
5712: and r0,r5,r27
572 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
573 /* Call ppc_md.hpte_remove */
574_GLOBAL(htab_call_hpte_remove)
575 bl . /* patched by htab_finish_init() */
576
577 /* Try all again */
578 b htab_insert_pte
579
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000580 /*
581 * Call out to C code to invalidate an 64k HW HPTE that is
582 * useless now that the segment has been switched to 4k pages.
583 */
584htab_inval_old_hpte:
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000585 mr r3,r29 /* vpn */
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000586 mr r4,r31 /* PTE.pte */
587 li r5,0 /* PTE.hidx */
588 li r6,MMU_PAGE_64K /* psize */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000589 ld r7,STK_PARAM(R9)(r1) /* ssize */
590 ld r8,STK_PARAM(R8)(r1) /* local */
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000591 bl .flush_hash_page
Paul Mackerras65ba6cd2008-06-18 16:40:35 +1000592 /* Clear out _PAGE_HPTE_SUB bits in the new linux PTE */
593 lis r0,_PAGE_HPTE_SUB@h
594 ori r0,r0,_PAGE_HPTE_SUB@l
595 andc r30,r30,r0
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000596 b htab_insert_pte
597
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100598htab_bail_ok:
599 li r3,0
600 b htab_bail
601
602htab_pte_insert_ok:
603 /* Insert slot number & secondary bit in PTE second half,
604 * clear _PAGE_BUSY and set approriate HPTE slot bit
605 */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000606 ld r6,STK_PARAM(R6)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100607 li r0,_PAGE_BUSY
608 andc r30,r30,r0
609 /* HPTE SUB bit */
610 li r0,1
611 subfic r5,r25,27 /* Must match bit position in */
612 sld r0,r0,r5 /* pgtable.h */
613 or r30,r30,r0
614 /* hindx */
615 sldi r5,r25,2
616 sld r3,r3,r5
617 li r4,0xf
618 sld r4,r4,r5
619 andc r26,r26,r4
620 or r26,r26,r3
Aneesh Kumar K.Vcc3665a2013-04-28 09:37:27 +0000621 ori r5,r6,PTE_PAGE_HIDX_OFFSET
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100622 std r26,0(r5)
623 lwsync
624 std r30,0(r6)
625 li r3, 0
626htab_bail:
Michael Neulingc75df6f2012-06-25 13:33:10 +0000627 ld r25,STK_REG(R25)(r1)
628 ld r26,STK_REG(R26)(r1)
629 ld r27,STK_REG(R27)(r1)
630 ld r28,STK_REG(R28)(r1)
631 ld r29,STK_REG(R29)(r1)
632 ld r30,STK_REG(R30)(r1)
633 ld r31,STK_REG(R31)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100634 addi r1,r1,STACKFRAMESIZE
635 ld r0,16(r1)
636 mtlr r0
637 blr
638
639htab_modify_pte:
640 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
641 mr r4,r3
642 sldi r5,r25,2
643 srd r3,r26,r5
644
645 /* Secondary group ? if yes, get a inverted hash value */
646 mr r5,r28
647 andi. r0,r3,0x8 /* page secondary ? */
648 beq 1f
649 not r5,r5
6501: andi. r3,r3,0x7 /* extract idx alone */
651
652 /* Calculate proper slot value for ppc_md.hpte_updatepp */
653 and r0,r5,r27
654 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
655 add r3,r0,r3 /* add slot idx */
656
657 /* Call ppc_md.hpte_updatepp */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000658 mr r5,r29 /* vpn */
Aneesh Kumar K.Vdb3d8532013-06-20 14:30:13 +0530659 li r6,MMU_PAGE_4K /* base page size */
660 li r7,MMU_PAGE_4K /* actual page size */
661 ld r8,STK_PARAM(R9)(r1) /* segment size */
662 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100663_GLOBAL(htab_call_hpte_updatepp)
664 bl . /* patched by htab_finish_init() */
665
666 /* if we failed because typically the HPTE wasn't really here
667 * we try an insertion.
668 */
669 cmpdi 0,r3,-1
670 beq- htab_insert_pte
671
672 /* Clear the BUSY bit and Write out the PTE */
673 li r0,_PAGE_BUSY
674 andc r30,r30,r0
Michael Neuling44ce6a52012-06-25 13:33:14 +0000675 ld r6,STK_PARAM(R6)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100676 std r30,0(r6)
677 li r3,0
678 b htab_bail
679
680htab_wrong_access:
681 /* Bail out clearing reservation */
682 stdcx. r31,0,r6
683 li r3,1
684 b htab_bail
685
686htab_pte_insert_failure:
687 /* Bail out restoring old PTE */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000688 ld r6,STK_PARAM(R6)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100689 std r31,0(r6)
690 li r3,-1
691 b htab_bail
692
Benjamin Herrenschmidt16c2d472007-05-08 16:27:28 +1000693#endif /* CONFIG_PPC_64K_PAGES */
694
695#ifdef CONFIG_PPC_HAS_HASH_64K
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100696
697/*****************************************************************************
698 * *
699 * 64K SW & 64K HW in a 64K segment pages implementation *
700 * *
701 *****************************************************************************/
702
703_GLOBAL(__hash_page_64K)
704 mflr r0
705 std r0,16(r1)
706 stdu r1,-STACKFRAMESIZE(r1)
707 /* Save all params that we need after a function call */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000708 std r6,STK_PARAM(R6)(r1)
709 std r8,STK_PARAM(R8)(r1)
710 std r9,STK_PARAM(R9)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100711
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100712 /* Save non-volatile registers.
713 * r31 will hold "old PTE"
714 * r30 is "new PTE"
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000715 * r29 is vpn
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100716 * r28 is a hash value
717 * r27 is hashtab mask (maybe dynamic patched instead ?)
718 */
Michael Neulingc75df6f2012-06-25 13:33:10 +0000719 std r27,STK_REG(R27)(r1)
720 std r28,STK_REG(R28)(r1)
721 std r29,STK_REG(R29)(r1)
722 std r30,STK_REG(R30)(r1)
723 std r31,STK_REG(R31)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100724
725 /* Step 1:
726 *
727 * Check permissions, atomically mark the linux PTE busy
728 * and hashed.
729 */
7301:
731 ldarx r31,0,r6
732 /* Check access rights (access & ~(pte_val(*ptep))) */
733 andc. r0,r4,r31
734 bne- ht64_wrong_access
735 /* Check if PTE is busy */
736 andi. r0,r31,_PAGE_BUSY
737 /* If so, just bail out and refault if needed. Someone else
738 * is changing this PTE anyway and might hash it.
739 */
740 bne- ht64_bail_ok
Paul Mackerrasbf72aeb2006-06-15 10:45:18 +1000741BEGIN_FTR_SECTION
742 /* Check if PTE has the cache-inhibit bit set */
743 andi. r0,r31,_PAGE_NO_CACHE
744 /* If so, bail out and refault as a 4k page */
745 bne- ht64_bail_ok
Matt Evans44ae3ab2011-04-06 19:48:50 +0000746END_MMU_FTR_SECTION_IFCLR(MMU_FTR_CI_LARGE_PAGE)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100747 /* Prepare new PTE value (turn access RW into DIRTY, then
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000748 * add BUSY and ACCESSED)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100749 */
750 rlwinm r30,r4,32-9+7,31-7,31-7 /* _PAGE_RW -> _PAGE_DIRTY */
751 or r30,r30,r31
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000752 ori r30,r30,_PAGE_BUSY | _PAGE_ACCESSED
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100753 /* Write the linux PTE atomically (setting busy) */
754 stdcx. r30,0,r6
755 bne- 1b
756 isync
757
758 /* Step 2:
759 *
760 * Insert/Update the HPTE in the hash table. At this point,
761 * r4 (access) is re-useable, we use it for the new HPTE flags
762 */
763
Paul Mackerras1189be62007-10-11 20:37:10 +1000764BEGIN_FTR_SECTION
765 cmpdi r9,0 /* check segment size */
766 bne 3f
Matt Evans44ae3ab2011-04-06 19:48:50 +0000767END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000768 /* Calc vpn and put it in r29 */
769 sldi r29,r5,SID_SHIFT - VPN_SHIFT
770 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT - VPN_SHIFT)
771 or r29,r28,r29
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100772
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000773 /* Calculate hash value for primary slot and store it in r28
774 * r3 = va, r5 = vsid
775 * r0 = (va >> 16) & ((1ul << (28 - 16)) -1)
776 */
777 rldicl r0,r3,64-16,52
778 xor r28,r5,r0 /* hash */
Paul Mackerras1189be62007-10-11 20:37:10 +1000779 b 4f
780
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +00007813: /* Calc vpn and put it in r29 */
782 sldi r29,r5,SID_SHIFT_1T - VPN_SHIFT
783 rldicl r28,r3,64 - VPN_SHIFT,64 - (SID_SHIFT_1T - VPN_SHIFT)
784 or r29,r28,r29
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000785 /*
786 * calculate hash value for primary slot and
787 * store it in r28 for 1T segment
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000788 * r3 = va, r5 = vsid
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000789 */
Aneesh Kumar K.Veda8eeb2013-01-29 19:40:42 +0000790 sldi r28,r5,25 /* vsid << 25 */
791 /* r0 = (va >> 16) & ((1ul << (40 - 16)) -1) */
792 rldicl r0,r3,64-16,40
793 xor r28,r28,r5 /* vsid ^ ( vsid << 25) */
Paul Mackerras1189be62007-10-11 20:37:10 +1000794 xor r28,r28,r0 /* hash */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100795
796 /* Convert linux PTE bits into HW equivalents */
Paul Mackerras1189be62007-10-11 20:37:10 +10007974: andi. r3,r30,0x1fe /* Get basic set of flags */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100798 xori r3,r3,HPTE_R_N /* _PAGE_EXEC -> NOEXEC */
799 rlwinm r0,r30,32-9+1,30,30 /* _PAGE_RW -> _PAGE_USER (r0) */
800 rlwinm r4,r30,32-7+1,30,30 /* _PAGE_DIRTY -> _PAGE_USER (r4) */
801 and r0,r0,r4 /* _PAGE_RW & _PAGE_DIRTY ->r0 bit 30*/
802 andc r0,r30,r0 /* r0 = pte & ~r0 */
803 rlwimi r3,r0,32-1,31,31 /* Insert result into PP lsb */
Aneesh Kumar K.Vc8c06f52013-11-18 14:58:10 +0530804 /*
805 * Always add "C" bit for perf. Memory coherence is always enabled
806 */
807 ori r3,r3,HPTE_R_C | HPTE_R_M
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100808
809 /* We eventually do the icache sync here (maybe inline that
810 * code rather than call a C function...)
811 */
812BEGIN_FTR_SECTION
813 mr r4,r30
814 mr r5,r7
815 bl .hash_page_do_lazy_icache
816END_FTR_SECTION(CPU_FTR_NOEXECUTE|CPU_FTR_COHERENT_ICACHE, CPU_FTR_NOEXECUTE)
817
818 /* At this point, r3 contains new PP bits, save them in
819 * place of "access" in the param area (sic)
820 */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000821 std r3,STK_PARAM(R4)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100822
823 /* Get htab_hash_mask */
824 ld r4,htab_hash_mask@got(2)
825 ld r27,0(r4) /* htab_hash_mask -> r27 */
826
827 /* Check if we may already be in the hashtable, in this case, we
828 * go to out-of-line code to try to modify the HPTE
829 */
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000830 rldicl. r0,r31,64-12,48
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100831 bne ht64_modify_pte
832
833ht64_insert_pte:
834 /* Clear hpte bits in new pte (we also clear BUSY btw) and
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000835 * add _PAGE_HPTE_SUB0
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100836 */
837 lis r0,_PAGE_HPTEFLAGS@h
838 ori r0,r0,_PAGE_HPTEFLAGS@l
839 andc r30,r30,r0
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000840#ifdef CONFIG_PPC_64K_PAGES
841 oris r30,r30,_PAGE_HPTE_SUB0@h
842#else
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100843 ori r30,r30,_PAGE_HASHPTE
Benjamin Herrenschmidt41743a42008-06-11 15:37:10 +1000844#endif
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100845 /* Phyical address in r5 */
846 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
847 sldi r5,r5,PAGE_SHIFT
848
849 /* Calculate primary group hash */
850 and r0,r28,r27
851 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
852
853 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000854 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000855 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100856 li r7,0 /* !bolted, !secondary */
857 li r8,MMU_PAGE_64K
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000858 li r9,MMU_PAGE_64K /* actual page size */
859 ld r10,STK_PARAM(R9)(r1) /* segment size */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100860_GLOBAL(ht64_call_hpte_insert1)
861 bl . /* patched by htab_finish_init() */
862 cmpdi 0,r3,0
863 bge ht64_pte_insert_ok /* Insertion successful */
864 cmpdi 0,r3,-2 /* Critical failure */
865 beq- ht64_pte_insert_failure
866
867 /* Now try secondary slot */
868
869 /* Phyical address in r5 */
870 rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT
871 sldi r5,r5,PAGE_SHIFT
872
873 /* Calculate secondary group hash */
874 andc r0,r27,r28
875 rldicr r3,r0,3,63-3 /* r0 = (~hash & mask) << 3 */
876
877 /* Call ppc_md.hpte_insert */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000878 ld r6,STK_PARAM(R4)(r1) /* Retrieve new pp bits */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000879 mr r4,r29 /* Retrieve vpn */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100880 li r7,HPTE_V_SECONDARY /* !bolted, secondary */
881 li r8,MMU_PAGE_64K
Aneesh Kumar K.Vb1022fb2013-04-28 09:37:35 +0000882 li r9,MMU_PAGE_64K /* actual page size */
883 ld r10,STK_PARAM(R9)(r1) /* segment size */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100884_GLOBAL(ht64_call_hpte_insert2)
885 bl . /* patched by htab_finish_init() */
886 cmpdi 0,r3,0
887 bge+ ht64_pte_insert_ok /* Insertion successful */
888 cmpdi 0,r3,-2 /* Critical failure */
889 beq- ht64_pte_insert_failure
890
891 /* Both are full, we need to evict something */
892 mftb r0
893 /* Pick a random group based on TB */
894 andi. r0,r0,1
895 mr r5,r28
896 bne 2f
897 not r5,r5
8982: and r0,r5,r27
899 rldicr r3,r0,3,63-3 /* r0 = (hash & mask) << 3 */
900 /* Call ppc_md.hpte_remove */
901_GLOBAL(ht64_call_hpte_remove)
902 bl . /* patched by htab_finish_init() */
903
904 /* Try all again */
905 b ht64_insert_pte
906
907ht64_bail_ok:
908 li r3,0
909 b ht64_bail
910
911ht64_pte_insert_ok:
912 /* Insert slot number & secondary bit in PTE */
913 rldimi r30,r3,12,63-15
914
915 /* Write out the PTE with a normal write
916 * (maybe add eieio may be good still ?)
917 */
918ht64_write_out_pte:
Michael Neuling44ce6a52012-06-25 13:33:14 +0000919 ld r6,STK_PARAM(R6)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100920 std r30,0(r6)
921 li r3, 0
922ht64_bail:
Michael Neulingc75df6f2012-06-25 13:33:10 +0000923 ld r27,STK_REG(R27)(r1)
924 ld r28,STK_REG(R28)(r1)
925 ld r29,STK_REG(R29)(r1)
926 ld r30,STK_REG(R30)(r1)
927 ld r31,STK_REG(R31)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100928 addi r1,r1,STACKFRAMESIZE
929 ld r0,16(r1)
930 mtlr r0
931 blr
932
933ht64_modify_pte:
934 /* Keep PP bits in r4 and slot idx from the PTE around in r3 */
935 mr r4,r3
936 rlwinm r3,r31,32-12,29,31
937
938 /* Secondary group ? if yes, get a inverted hash value */
939 mr r5,r28
940 andi. r0,r31,_PAGE_F_SECOND
941 beq 1f
942 not r5,r5
9431:
944 /* Calculate proper slot value for ppc_md.hpte_updatepp */
945 and r0,r5,r27
946 rldicr r0,r0,3,63-3 /* r0 = (hash & mask) << 3 */
947 add r3,r0,r3 /* add slot idx */
948
949 /* Call ppc_md.hpte_updatepp */
Aneesh Kumar K.V5524a272012-09-10 02:52:50 +0000950 mr r5,r29 /* vpn */
Aneesh Kumar K.Vdb3d8532013-06-20 14:30:13 +0530951 li r6,MMU_PAGE_64K /* base page size */
952 li r7,MMU_PAGE_64K /* actual page size */
953 ld r8,STK_PARAM(R9)(r1) /* segment size */
954 ld r9,STK_PARAM(R8)(r1) /* get "local" param */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100955_GLOBAL(ht64_call_hpte_updatepp)
956 bl . /* patched by htab_finish_init() */
957
958 /* if we failed because typically the HPTE wasn't really here
959 * we try an insertion.
960 */
961 cmpdi 0,r3,-1
962 beq- ht64_insert_pte
963
964 /* Clear the BUSY bit and Write out the PTE */
965 li r0,_PAGE_BUSY
966 andc r30,r30,r0
967 b ht64_write_out_pte
968
969ht64_wrong_access:
970 /* Bail out clearing reservation */
971 stdcx. r31,0,r6
972 li r3,1
973 b ht64_bail
974
975ht64_pte_insert_failure:
976 /* Bail out restoring old PTE */
Michael Neuling44ce6a52012-06-25 13:33:14 +0000977 ld r6,STK_PARAM(R6)(r1)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100978 std r31,0(r6)
979 li r3,-1
980 b ht64_bail
981
982
Benjamin Herrenschmidt16c2d472007-05-08 16:27:28 +1000983#endif /* CONFIG_PPC_HAS_HASH_64K */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100984
985
986/*****************************************************************************
987 * *
988 * Huge pages implementation is in hugetlbpage.c *
989 * *
990 *****************************************************************************/