]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/powerpc/mm/hash_low_32.S
m32r: fix build due to notify_cpu_starting() change
[linux-2.6-omap-h63xx.git] / arch / powerpc / mm / hash_low_32.S
1 /*
2  *  PowerPC version
3  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4  *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
5  *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
6  *  Adapted for Power Macintosh by Paul Mackerras.
7  *  Low-level exception handlers and MMU support
8  *  rewritten by Paul Mackerras.
9  *    Copyright (C) 1996 Paul Mackerras.
10  *
11  *  This file contains low-level assembler routines for managing
12  *  the PowerPC MMU hash table.  (PPC 8xx processors don't use a
13  *  hash table, so this file is not used on them.)
14  *
15  *  This program is free software; you can redistribute it and/or
16  *  modify it under the terms of the GNU General Public License
17  *  as published by the Free Software Foundation; either version
18  *  2 of the License, or (at your option) any later version.
19  *
20  */
21
22 #include <asm/reg.h>
23 #include <asm/page.h>
24 #include <asm/pgtable.h>
25 #include <asm/cputable.h>
26 #include <asm/ppc_asm.h>
27 #include <asm/thread_info.h>
28 #include <asm/asm-offsets.h>
29
30 #ifdef CONFIG_SMP
31         .section .bss
32         .align  2
33         .globl mmu_hash_lock
34 mmu_hash_lock:
35         .space  4
36 #endif /* CONFIG_SMP */
37
38 /*
39  * Sync CPUs with hash_page taking & releasing the hash
40  * table lock
41  */
42 #ifdef CONFIG_SMP
43         .text
44 _GLOBAL(hash_page_sync)
45         mfmsr   r10
46         rlwinm  r0,r10,0,17,15          /* clear bit 16 (MSR_EE) */
47         mtmsr   r0
48         lis     r8,mmu_hash_lock@h
49         ori     r8,r8,mmu_hash_lock@l
50         lis     r0,0x0fff
51         b       10f
52 11:     lwz     r6,0(r8)
53         cmpwi   0,r6,0
54         bne     11b
55 10:     lwarx   r6,0,r8
56         cmpwi   0,r6,0
57         bne-    11b
58         stwcx.  r0,0,r8
59         bne-    10b
60         isync
61         eieio
62         li      r0,0
63         stw     r0,0(r8)
64         mtmsr   r10
65         blr
66 #endif /* CONFIG_SMP */
67
68 /*
69  * Load a PTE into the hash table, if possible.
70  * The address is in r4, and r3 contains an access flag:
71  * _PAGE_RW (0x400) if a write.
72  * r9 contains the SRR1 value, from which we use the MSR_PR bit.
73  * SPRG3 contains the physical address of the current task's thread.
74  *
75  * Returns to the caller if the access is illegal or there is no
76  * mapping for the address.  Otherwise it places an appropriate PTE
77  * in the hash table and returns from the exception.
78  * Uses r0, r3 - r8, ctr, lr.
79  */
80         .text
81 _GLOBAL(hash_page)
82         tophys(r7,0)                    /* gets -KERNELBASE into r7 */
83 #ifdef CONFIG_SMP
84         addis   r8,r7,mmu_hash_lock@h
85         ori     r8,r8,mmu_hash_lock@l
86         lis     r0,0x0fff
87         b       10f
88 11:     lwz     r6,0(r8)
89         cmpwi   0,r6,0
90         bne     11b
91 10:     lwarx   r6,0,r8
92         cmpwi   0,r6,0
93         bne-    11b
94         stwcx.  r0,0,r8
95         bne-    10b
96         isync
97 #endif
98         /* Get PTE (linux-style) and check access */
99         lis     r0,KERNELBASE@h         /* check if kernel address */
100         cmplw   0,r4,r0
101         mfspr   r8,SPRN_SPRG3           /* current task's THREAD (phys) */
102         ori     r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
103         lwz     r5,PGDIR(r8)            /* virt page-table root */
104         blt+    112f                    /* assume user more likely */
105         lis     r5,swapper_pg_dir@ha    /* if kernel address, use */
106         addi    r5,r5,swapper_pg_dir@l  /* kernel page table */
107         rlwimi  r3,r9,32-12,29,29       /* MSR_PR -> _PAGE_USER */
108 112:    add     r5,r5,r7                /* convert to phys addr */
109         rlwimi  r5,r4,12,20,29          /* insert top 10 bits of address */
110         lwz     r8,0(r5)                /* get pmd entry */
111         rlwinm. r8,r8,0,0,19            /* extract address of pte page */
112 #ifdef CONFIG_SMP
113         beq-    hash_page_out           /* return if no mapping */
114 #else
115         /* XXX it seems like the 601 will give a machine fault on the
116            rfi if its alignment is wrong (bottom 4 bits of address are
117            8 or 0xc) and we have had a not-taken conditional branch
118            to the address following the rfi. */
119         beqlr-
120 #endif
121         rlwimi  r8,r4,22,20,29          /* insert next 10 bits of address */
122         rlwinm  r0,r3,32-3,24,24        /* _PAGE_RW access -> _PAGE_DIRTY */
123         ori     r0,r0,_PAGE_ACCESSED|_PAGE_HASHPTE
124
125         /*
126          * Update the linux PTE atomically.  We do the lwarx up-front
127          * because almost always, there won't be a permission violation
128          * and there won't already be an HPTE, and thus we will have
129          * to update the PTE to set _PAGE_HASHPTE.  -- paulus.
130          */
131 retry:
132         lwarx   r6,0,r8                 /* get linux-style pte */
133         andc.   r5,r3,r6                /* check access & ~permission */
134 #ifdef CONFIG_SMP
135         bne-    hash_page_out           /* return if access not permitted */
136 #else
137         bnelr-
138 #endif
139         or      r5,r0,r6                /* set accessed/dirty bits */
140         stwcx.  r5,0,r8                 /* attempt to update PTE */
141         bne-    retry                   /* retry if someone got there first */
142
143         mfsrin  r3,r4                   /* get segment reg for segment */
144         mfctr   r0
145         stw     r0,_CTR(r11)
146         bl      create_hpte             /* add the hash table entry */
147
148 #ifdef CONFIG_SMP
149         eieio
150         addis   r8,r7,mmu_hash_lock@ha
151         li      r0,0
152         stw     r0,mmu_hash_lock@l(r8)
153 #endif
154
155         /* Return from the exception */
156         lwz     r5,_CTR(r11)
157         mtctr   r5
158         lwz     r0,GPR0(r11)
159         lwz     r7,GPR7(r11)
160         lwz     r8,GPR8(r11)
161         b       fast_exception_return
162
163 #ifdef CONFIG_SMP
164 hash_page_out:
165         eieio
166         addis   r8,r7,mmu_hash_lock@ha
167         li      r0,0
168         stw     r0,mmu_hash_lock@l(r8)
169         blr
170 #endif /* CONFIG_SMP */
171
172 /*
173  * Add an entry for a particular page to the hash table.
174  *
175  * add_hash_page(unsigned context, unsigned long va, unsigned long pmdval)
176  *
177  * We assume any necessary modifications to the pte (e.g. setting
178  * the accessed bit) have already been done and that there is actually
179  * a hash table in use (i.e. we're not on a 603).
180  */
181 _GLOBAL(add_hash_page)
182         mflr    r0
183         stw     r0,4(r1)
184
185         /* Convert context and va to VSID */
186         mulli   r3,r3,897*16            /* multiply context by context skew */
187         rlwinm  r0,r4,4,28,31           /* get ESID (top 4 bits of va) */
188         mulli   r0,r0,0x111             /* multiply by ESID skew */
189         add     r3,r3,r0                /* note create_hpte trims to 24 bits */
190
191 #ifdef CONFIG_SMP
192         rlwinm  r8,r1,0,0,(31-THREAD_SHIFT) /* use cpu number to make tag */
193         lwz     r8,TI_CPU(r8)           /* to go in mmu_hash_lock */
194         oris    r8,r8,12
195 #endif /* CONFIG_SMP */
196
197         /*
198          * We disable interrupts here, even on UP, because we don't
199          * want to race with hash_page, and because we want the
200          * _PAGE_HASHPTE bit to be a reliable indication of whether
201          * the HPTE exists (or at least whether one did once).
202          * We also turn off the MMU for data accesses so that we
203          * we can't take a hash table miss (assuming the code is
204          * covered by a BAT).  -- paulus
205          */
206         mfmsr   r10
207         SYNC
208         rlwinm  r0,r10,0,17,15          /* clear bit 16 (MSR_EE) */
209         rlwinm  r0,r0,0,28,26           /* clear MSR_DR */
210         mtmsr   r0
211         SYNC_601
212         isync
213
214         tophys(r7,0)
215
216 #ifdef CONFIG_SMP
217         addis   r9,r7,mmu_hash_lock@ha
218         addi    r9,r9,mmu_hash_lock@l
219 10:     lwarx   r0,0,r9                 /* take the mmu_hash_lock */
220         cmpi    0,r0,0
221         bne-    11f
222         stwcx.  r8,0,r9
223         beq+    12f
224 11:     lwz     r0,0(r9)
225         cmpi    0,r0,0
226         beq     10b
227         b       11b
228 12:     isync
229 #endif
230
231         /*
232          * Fetch the linux pte and test and set _PAGE_HASHPTE atomically.
233          * If _PAGE_HASHPTE was already set, we don't replace the existing
234          * HPTE, so we just unlock and return.
235          */
236         mr      r8,r5
237         rlwimi  r8,r4,22,20,29
238 1:      lwarx   r6,0,r8
239         andi.   r0,r6,_PAGE_HASHPTE
240         bne     9f                      /* if HASHPTE already set, done */
241         ori     r5,r6,_PAGE_HASHPTE
242         stwcx.  r5,0,r8
243         bne-    1b
244
245         bl      create_hpte
246
247 9:
248 #ifdef CONFIG_SMP
249         eieio
250         li      r0,0
251         stw     r0,0(r9)                /* clear mmu_hash_lock */
252 #endif
253
254         /* reenable interrupts and DR */
255         mtmsr   r10
256         SYNC_601
257         isync
258
259         lwz     r0,4(r1)
260         mtlr    r0
261         blr
262
263 /*
264  * This routine adds a hardware PTE to the hash table.
265  * It is designed to be called with the MMU either on or off.
266  * r3 contains the VSID, r4 contains the virtual address,
267  * r5 contains the linux PTE, r6 contains the old value of the
268  * linux PTE (before setting _PAGE_HASHPTE) and r7 contains the
269  * offset to be added to addresses (0 if the MMU is on,
270  * -KERNELBASE if it is off).
271  * On SMP, the caller should have the mmu_hash_lock held.
272  * We assume that the caller has (or will) set the _PAGE_HASHPTE
273  * bit in the linux PTE in memory.  The value passed in r6 should
274  * be the old linux PTE value; if it doesn't have _PAGE_HASHPTE set
275  * this routine will skip the search for an existing HPTE.
276  * This procedure modifies r0, r3 - r6, r8, cr0.
277  *  -- paulus.
278  *
279  * For speed, 4 of the instructions get patched once the size and
280  * physical address of the hash table are known.  These definitions
281  * of Hash_base and Hash_bits below are just an example.
282  */
283 Hash_base = 0xc0180000
284 Hash_bits = 12                          /* e.g. 256kB hash table */
285 Hash_msk = (((1 << Hash_bits) - 1) * 64)
286
287 /* defines for the PTE format for 32-bit PPCs */
288 #define PTE_SIZE        8
289 #define PTEG_SIZE       64
290 #define LG_PTEG_SIZE    6
291 #define LDPTEu          lwzu
292 #define LDPTE           lwz
293 #define STPTE           stw
294 #define CMPPTE          cmpw
295 #define PTE_H           0x40
296 #define PTE_V           0x80000000
297 #define TST_V(r)        rlwinm. r,r,0,0,0
298 #define SET_V(r)        oris r,r,PTE_V@h
299 #define CLR_V(r,t)      rlwinm r,r,0,1,31
300
301 #define HASH_LEFT       31-(LG_PTEG_SIZE+Hash_bits-1)
302 #define HASH_RIGHT      31-LG_PTEG_SIZE
303
304 _GLOBAL(create_hpte)
305         /* Convert linux-style PTE (r5) to low word of PPC-style PTE (r8) */
306         rlwinm  r8,r5,32-10,31,31       /* _PAGE_RW -> PP lsb */
307         rlwinm  r0,r5,32-7,31,31        /* _PAGE_DIRTY -> PP lsb */
308         and     r8,r8,r0                /* writable if _RW & _DIRTY */
309         rlwimi  r5,r5,32-1,30,30        /* _PAGE_USER -> PP msb */
310         rlwimi  r5,r5,32-2,31,31        /* _PAGE_USER -> PP lsb */
311         ori     r8,r8,0xe14             /* clear out reserved bits and M */
312         andc    r8,r5,r8                /* PP = user? (rw&dirty? 2: 3): 0 */
313 BEGIN_FTR_SECTION
314         ori     r8,r8,_PAGE_COHERENT    /* set M (coherence required) */
315 END_FTR_SECTION_IFSET(CPU_FTR_NEED_COHERENT)
316
317         /* Construct the high word of the PPC-style PTE (r5) */
318         rlwinm  r5,r3,7,1,24            /* put VSID in 0x7fffff80 bits */
319         rlwimi  r5,r4,10,26,31          /* put in API (abbrev page index) */
320         SET_V(r5)                       /* set V (valid) bit */
321
322         /* Get the address of the primary PTE group in the hash table (r3) */
323 _GLOBAL(hash_page_patch_A)
324         addis   r0,r7,Hash_base@h       /* base address of hash table */
325         rlwimi  r0,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT    /* VSID -> hash */
326         rlwinm  r3,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
327         xor     r3,r3,r0                /* make primary hash */
328         li      r0,8                    /* PTEs/group */
329
330         /*
331          * Test the _PAGE_HASHPTE bit in the old linux PTE, and skip the search
332          * if it is clear, meaning that the HPTE isn't there already...
333          */
334         andi.   r6,r6,_PAGE_HASHPTE
335         beq+    10f                     /* no PTE: go look for an empty slot */
336         tlbie   r4
337
338         addis   r4,r7,htab_hash_searches@ha
339         lwz     r6,htab_hash_searches@l(r4)
340         addi    r6,r6,1                 /* count how many searches we do */
341         stw     r6,htab_hash_searches@l(r4)
342
343         /* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
344         mtctr   r0
345         addi    r4,r3,-PTE_SIZE
346 1:      LDPTEu  r6,PTE_SIZE(r4)         /* get next PTE */
347         CMPPTE  0,r6,r5
348         bdnzf   2,1b                    /* loop while ctr != 0 && !cr0.eq */
349         beq+    found_slot
350
351         /* Search the secondary PTEG for a matching PTE */
352         ori     r5,r5,PTE_H             /* set H (secondary hash) bit */
353 _GLOBAL(hash_page_patch_B)
354         xoris   r4,r3,Hash_msk>>16      /* compute secondary hash */
355         xori    r4,r4,(-PTEG_SIZE & 0xffff)
356         addi    r4,r4,-PTE_SIZE
357         mtctr   r0
358 2:      LDPTEu  r6,PTE_SIZE(r4)
359         CMPPTE  0,r6,r5
360         bdnzf   2,2b
361         beq+    found_slot
362         xori    r5,r5,PTE_H             /* clear H bit again */
363
364         /* Search the primary PTEG for an empty slot */
365 10:     mtctr   r0
366         addi    r4,r3,-PTE_SIZE         /* search primary PTEG */
367 1:      LDPTEu  r6,PTE_SIZE(r4)         /* get next PTE */
368         TST_V(r6)                       /* test valid bit */
369         bdnzf   2,1b                    /* loop while ctr != 0 && !cr0.eq */
370         beq+    found_empty
371
372         /* update counter of times that the primary PTEG is full */
373         addis   r4,r7,primary_pteg_full@ha
374         lwz     r6,primary_pteg_full@l(r4)
375         addi    r6,r6,1
376         stw     r6,primary_pteg_full@l(r4)
377
378         /* Search the secondary PTEG for an empty slot */
379         ori     r5,r5,PTE_H             /* set H (secondary hash) bit */
380 _GLOBAL(hash_page_patch_C)
381         xoris   r4,r3,Hash_msk>>16      /* compute secondary hash */
382         xori    r4,r4,(-PTEG_SIZE & 0xffff)
383         addi    r4,r4,-PTE_SIZE
384         mtctr   r0
385 2:      LDPTEu  r6,PTE_SIZE(r4)
386         TST_V(r6)
387         bdnzf   2,2b
388         beq+    found_empty
389         xori    r5,r5,PTE_H             /* clear H bit again */
390
391         /*
392          * Choose an arbitrary slot in the primary PTEG to overwrite.
393          * Since both the primary and secondary PTEGs are full, and we
394          * have no information that the PTEs in the primary PTEG are
395          * more important or useful than those in the secondary PTEG,
396          * and we know there is a definite (although small) speed
397          * advantage to putting the PTE in the primary PTEG, we always
398          * put the PTE in the primary PTEG.
399          *
400          * In addition, we skip any slot that is mapping kernel text in
401          * order to avoid a deadlock when not using BAT mappings if
402          * trying to hash in the kernel hash code itself after it has
403          * already taken the hash table lock. This works in conjunction
404          * with pre-faulting of the kernel text.
405          *
406          * If the hash table bucket is full of kernel text entries, we'll
407          * lockup here but that shouldn't happen
408          */
409
410 1:      addis   r4,r7,next_slot@ha              /* get next evict slot */
411         lwz     r6,next_slot@l(r4)
412         addi    r6,r6,PTE_SIZE                  /* search for candidate */
413         andi.   r6,r6,7*PTE_SIZE
414         stw     r6,next_slot@l(r4)
415         add     r4,r3,r6
416         LDPTE   r0,PTE_SIZE/2(r4)               /* get PTE second word */
417         clrrwi  r0,r0,12
418         lis     r6,etext@h
419         ori     r6,r6,etext@l                   /* get etext */
420         tophys(r6,r6)
421         cmpl    cr0,r0,r6                       /* compare and try again */
422         blt     1b
423
424 #ifndef CONFIG_SMP
425         /* Store PTE in PTEG */
426 found_empty:
427         STPTE   r5,0(r4)
428 found_slot:
429         STPTE   r8,PTE_SIZE/2(r4)
430
431 #else /* CONFIG_SMP */
432 /*
433  * Between the tlbie above and updating the hash table entry below,
434  * another CPU could read the hash table entry and put it in its TLB.
435  * There are 3 cases:
436  * 1. using an empty slot
437  * 2. updating an earlier entry to change permissions (i.e. enable write)
438  * 3. taking over the PTE for an unrelated address
439  *
440  * In each case it doesn't really matter if the other CPUs have the old
441  * PTE in their TLB.  So we don't need to bother with another tlbie here,
442  * which is convenient as we've overwritten the register that had the
443  * address. :-)  The tlbie above is mainly to make sure that this CPU comes
444  * and gets the new PTE from the hash table.
445  *
446  * We do however have to make sure that the PTE is never in an invalid
447  * state with the V bit set.
448  */
449 found_empty:
450 found_slot:
451         CLR_V(r5,r0)            /* clear V (valid) bit in PTE */
452         STPTE   r5,0(r4)
453         sync
454         TLBSYNC
455         STPTE   r8,PTE_SIZE/2(r4) /* put in correct RPN, WIMG, PP bits */
456         sync
457         SET_V(r5)
458         STPTE   r5,0(r4)        /* finally set V bit in PTE */
459 #endif /* CONFIG_SMP */
460
461         sync            /* make sure pte updates get to memory */
462         blr
463
464         .section .bss
465         .align  2
466 next_slot:
467         .space  4
468 primary_pteg_full:
469         .space  4
470 htab_hash_searches:
471         .space  4
472         .previous
473
474 /*
475  * Flush the entry for a particular page from the hash table.
476  *
477  * flush_hash_pages(unsigned context, unsigned long va, unsigned long pmdval,
478  *                  int count)
479  *
480  * We assume that there is a hash table in use (Hash != 0).
481  */
482 _GLOBAL(flush_hash_pages)
483         tophys(r7,0)
484
485         /*
486          * We disable interrupts here, even on UP, because we want
487          * the _PAGE_HASHPTE bit to be a reliable indication of
488          * whether the HPTE exists (or at least whether one did once).
489          * We also turn off the MMU for data accesses so that we
490          * we can't take a hash table miss (assuming the code is
491          * covered by a BAT).  -- paulus
492          */
493         mfmsr   r10
494         SYNC
495         rlwinm  r0,r10,0,17,15          /* clear bit 16 (MSR_EE) */
496         rlwinm  r0,r0,0,28,26           /* clear MSR_DR */
497         mtmsr   r0
498         SYNC_601
499         isync
500
501         /* First find a PTE in the range that has _PAGE_HASHPTE set */
502         rlwimi  r5,r4,22,20,29
503 1:      lwz     r0,0(r5)
504         cmpwi   cr1,r6,1
505         andi.   r0,r0,_PAGE_HASHPTE
506         bne     2f
507         ble     cr1,19f
508         addi    r4,r4,0x1000
509         addi    r5,r5,4
510         addi    r6,r6,-1
511         b       1b
512
513         /* Convert context and va to VSID */
514 2:      mulli   r3,r3,897*16            /* multiply context by context skew */
515         rlwinm  r0,r4,4,28,31           /* get ESID (top 4 bits of va) */
516         mulli   r0,r0,0x111             /* multiply by ESID skew */
517         add     r3,r3,r0                /* note code below trims to 24 bits */
518
519         /* Construct the high word of the PPC-style PTE (r11) */
520         rlwinm  r11,r3,7,1,24           /* put VSID in 0x7fffff80 bits */
521         rlwimi  r11,r4,10,26,31         /* put in API (abbrev page index) */
522         SET_V(r11)                      /* set V (valid) bit */
523
524 #ifdef CONFIG_SMP
525         addis   r9,r7,mmu_hash_lock@ha
526         addi    r9,r9,mmu_hash_lock@l
527         rlwinm  r8,r1,0,0,(31-THREAD_SHIFT)
528         add     r8,r8,r7
529         lwz     r8,TI_CPU(r8)
530         oris    r8,r8,9
531 10:     lwarx   r0,0,r9
532         cmpi    0,r0,0
533         bne-    11f
534         stwcx.  r8,0,r9
535         beq+    12f
536 11:     lwz     r0,0(r9)
537         cmpi    0,r0,0
538         beq     10b
539         b       11b
540 12:     isync
541 #endif
542
543         /*
544          * Check the _PAGE_HASHPTE bit in the linux PTE.  If it is
545          * already clear, we're done (for this pte).  If not,
546          * clear it (atomically) and proceed.  -- paulus.
547          */
548 33:     lwarx   r8,0,r5                 /* fetch the pte */
549         andi.   r0,r8,_PAGE_HASHPTE
550         beq     8f                      /* done if HASHPTE is already clear */
551         rlwinm  r8,r8,0,31,29           /* clear HASHPTE bit */
552         stwcx.  r8,0,r5                 /* update the pte */
553         bne-    33b
554
555         /* Get the address of the primary PTE group in the hash table (r3) */
556 _GLOBAL(flush_hash_patch_A)
557         addis   r8,r7,Hash_base@h       /* base address of hash table */
558         rlwimi  r8,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT    /* VSID -> hash */
559         rlwinm  r0,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
560         xor     r8,r0,r8                /* make primary hash */
561
562         /* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
563         li      r0,8                    /* PTEs/group */
564         mtctr   r0
565         addi    r12,r8,-PTE_SIZE
566 1:      LDPTEu  r0,PTE_SIZE(r12)        /* get next PTE */
567         CMPPTE  0,r0,r11
568         bdnzf   2,1b                    /* loop while ctr != 0 && !cr0.eq */
569         beq+    3f
570
571         /* Search the secondary PTEG for a matching PTE */
572         ori     r11,r11,PTE_H           /* set H (secondary hash) bit */
573         li      r0,8                    /* PTEs/group */
574 _GLOBAL(flush_hash_patch_B)
575         xoris   r12,r8,Hash_msk>>16     /* compute secondary hash */
576         xori    r12,r12,(-PTEG_SIZE & 0xffff)
577         addi    r12,r12,-PTE_SIZE
578         mtctr   r0
579 2:      LDPTEu  r0,PTE_SIZE(r12)
580         CMPPTE  0,r0,r11
581         bdnzf   2,2b
582         xori    r11,r11,PTE_H           /* clear H again */
583         bne-    4f                      /* should rarely fail to find it */
584
585 3:      li      r0,0
586         STPTE   r0,0(r12)               /* invalidate entry */
587 4:      sync
588         tlbie   r4                      /* in hw tlb too */
589         sync
590
591 8:      ble     cr1,9f                  /* if all ptes checked */
592 81:     addi    r6,r6,-1
593         addi    r5,r5,4                 /* advance to next pte */
594         addi    r4,r4,0x1000
595         lwz     r0,0(r5)                /* check next pte */
596         cmpwi   cr1,r6,1
597         andi.   r0,r0,_PAGE_HASHPTE
598         bne     33b
599         bgt     cr1,81b
600
601 9:
602 #ifdef CONFIG_SMP
603         TLBSYNC
604         li      r0,0
605         stw     r0,0(r9)                /* clear mmu_hash_lock */
606 #endif
607
608 19:     mtmsr   r10
609         SYNC_601
610         isync
611         blr