2 * PARISC TLB and cache flushing support
3 * Copyright (C) 2000-2001 Hewlett-Packard (John Marvin)
4 * Copyright (C) 2001 Matthew Wilcox (willy at parisc-linux.org)
5 * Copyright (C) 2002 Richard Hirst (rhirst with parisc-linux.org)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * NOTE: fdc,fic, and pdc instructions that use base register modification
24 * should only use index and base registers that are not shadowed,
25 * so that the fast path emulation in the non access miss handler
36 #include <asm/assembly.h>
37 #include <asm/pgtable.h>
38 #include <asm/cache.h>
39 #include <linux/linkage.h>
40 #include <linux/init.h>
45 ENTRY(flush_tlb_all_local)
51 * The pitlbe and pdtlbe instructions should only be used to
52 * flush the entire tlb. Also, there needs to be no intervening
53 * tlb operations, e.g. tlb misses, so the operation needs
54 * to happen in real mode with all interruptions disabled.
57 /* pcxt_ssm_bug - relied upon translation! PA 2.0 Arch. F-4 and F-5 */
58 rsm PSW_SM_I, %r19 /* save I-bit state */
66 rsm PSW_SM_Q, %r0 /* prep to load iia queue */
67 mtctl %r0, %cr17 /* Clear IIASQ tail */
68 mtctl %r0, %cr17 /* Clear IIASQ head */
69 mtctl %r1, %cr18 /* IIAOQ head */
71 mtctl %r1, %cr18 /* IIAOQ tail */
72 load32 REAL_MODE_PSW, %r1
77 1: load32 PA(cache_info), %r1
79 /* Flush Instruction Tlb */
81 LDREG ITLB_SID_BASE(%r1), %r20
82 LDREG ITLB_SID_STRIDE(%r1), %r21
83 LDREG ITLB_SID_COUNT(%r1), %r22
84 LDREG ITLB_OFF_BASE(%r1), %arg0
85 LDREG ITLB_OFF_STRIDE(%r1), %arg1
86 LDREG ITLB_OFF_COUNT(%r1), %arg2
87 LDREG ITLB_LOOP(%r1), %arg3
89 ADDIB= -1, %arg3, fitoneloop /* Preadjust and test */
90 movb,<,n %arg3, %r31, fitdone /* If loop < 0, skip */
91 copy %arg0, %r28 /* Init base addr */
93 fitmanyloop: /* Loop if LOOP >= 2 */
95 add %r21, %r20, %r20 /* increment space */
96 copy %arg2, %r29 /* Init middle loop count */
98 fitmanymiddle: /* Loop if LOOP >= 2 */
99 ADDIB> -1, %r31, fitmanymiddle /* Adjusted inner loop decr */
101 pitlbe,m %arg1(%sr1, %r28) /* Last pitlbe and addr adjust */
102 ADDIB> -1, %r29, fitmanymiddle /* Middle loop decr */
103 copy %arg3, %r31 /* Re-init inner loop count */
105 movb,tr %arg0, %r28, fitmanyloop /* Re-init base addr */
106 ADDIB<=,n -1, %r22, fitdone /* Outer loop count decr */
108 fitoneloop: /* Loop if LOOP = 1 */
110 copy %arg0, %r28 /* init base addr */
111 copy %arg2, %r29 /* init middle loop count */
113 fitonemiddle: /* Loop if LOOP = 1 */
114 ADDIB> -1, %r29, fitonemiddle /* Middle loop count decr */
115 pitlbe,m %arg1(%sr1, %r28) /* pitlbe for one loop */
117 ADDIB> -1, %r22, fitoneloop /* Outer loop count decr */
118 add %r21, %r20, %r20 /* increment space */
124 LDREG DTLB_SID_BASE(%r1), %r20
125 LDREG DTLB_SID_STRIDE(%r1), %r21
126 LDREG DTLB_SID_COUNT(%r1), %r22
127 LDREG DTLB_OFF_BASE(%r1), %arg0
128 LDREG DTLB_OFF_STRIDE(%r1), %arg1
129 LDREG DTLB_OFF_COUNT(%r1), %arg2
130 LDREG DTLB_LOOP(%r1), %arg3
132 ADDIB= -1, %arg3, fdtoneloop /* Preadjust and test */
133 movb,<,n %arg3, %r31, fdtdone /* If loop < 0, skip */
134 copy %arg0, %r28 /* Init base addr */
136 fdtmanyloop: /* Loop if LOOP >= 2 */
138 add %r21, %r20, %r20 /* increment space */
139 copy %arg2, %r29 /* Init middle loop count */
141 fdtmanymiddle: /* Loop if LOOP >= 2 */
142 ADDIB> -1, %r31, fdtmanymiddle /* Adjusted inner loop decr */
144 pdtlbe,m %arg1(%sr1, %r28) /* Last pdtlbe and addr adjust */
145 ADDIB> -1, %r29, fdtmanymiddle /* Middle loop decr */
146 copy %arg3, %r31 /* Re-init inner loop count */
148 movb,tr %arg0, %r28, fdtmanyloop /* Re-init base addr */
149 ADDIB<=,n -1, %r22,fdtdone /* Outer loop count decr */
151 fdtoneloop: /* Loop if LOOP = 1 */
153 copy %arg0, %r28 /* init base addr */
154 copy %arg2, %r29 /* init middle loop count */
156 fdtonemiddle: /* Loop if LOOP = 1 */
157 ADDIB> -1, %r29, fdtonemiddle /* Middle loop count decr */
158 pdtlbe,m %arg1(%sr1, %r28) /* pdtlbe for one loop */
160 ADDIB> -1, %r22, fdtoneloop /* Outer loop count decr */
161 add %r21, %r20, %r20 /* increment space */
166 * Switch back to virtual mode
177 rsm PSW_SM_Q, %r0 /* prep to load iia queue */
178 mtctl %r0, %cr17 /* Clear IIASQ tail */
179 mtctl %r0, %cr17 /* Clear IIASQ head */
180 mtctl %r1, %cr18 /* IIAOQ head */
182 mtctl %r1, %cr18 /* IIAOQ tail */
183 load32 KERNEL_PSW, %r1
184 or %r1, %r19, %r1 /* I-bit to state on entry */
185 mtctl %r1, %ipsw /* restore I-bit (entire PSW) */
194 ENDPROC(flush_tlb_all_local)
196 .import cache_info,data
198 ENTRY(flush_instruction_cache_local)
204 load32 cache_info, %r1
206 /* Flush Instruction Cache */
208 LDREG ICACHE_BASE(%r1), %arg0
209 LDREG ICACHE_STRIDE(%r1), %arg1
210 LDREG ICACHE_COUNT(%r1), %arg2
211 LDREG ICACHE_LOOP(%r1), %arg3
212 rsm PSW_SM_I, %r22 /* No mmgt ops during loop*/
213 ADDIB= -1, %arg3, fioneloop /* Preadjust and test */
214 movb,<,n %arg3, %r31, fisync /* If loop < 0, do sync */
216 fimanyloop: /* Loop if LOOP >= 2 */
217 ADDIB> -1, %r31, fimanyloop /* Adjusted inner loop decr */
218 fice %r0(%sr1, %arg0)
219 fice,m %arg1(%sr1, %arg0) /* Last fice and addr adjust */
220 movb,tr %arg3, %r31, fimanyloop /* Re-init inner loop count */
221 ADDIB<=,n -1, %arg2, fisync /* Outer loop decr */
223 fioneloop: /* Loop if LOOP = 1 */
224 ADDIB> -1, %arg2, fioneloop /* Outer loop count decr */
225 fice,m %arg1(%sr1, %arg0) /* Fice for one loop */
229 mtsm %r22 /* restore I-bit */
235 ENDPROC(flush_instruction_cache_local)
238 .import cache_info, data
239 ENTRY(flush_data_cache_local)
245 load32 cache_info, %r1
247 /* Flush Data Cache */
249 LDREG DCACHE_BASE(%r1), %arg0
250 LDREG DCACHE_STRIDE(%r1), %arg1
251 LDREG DCACHE_COUNT(%r1), %arg2
252 LDREG DCACHE_LOOP(%r1), %arg3
254 ADDIB= -1, %arg3, fdoneloop /* Preadjust and test */
255 movb,<,n %arg3, %r31, fdsync /* If loop < 0, do sync */
257 fdmanyloop: /* Loop if LOOP >= 2 */
258 ADDIB> -1, %r31, fdmanyloop /* Adjusted inner loop decr */
259 fdce %r0(%sr1, %arg0)
260 fdce,m %arg1(%sr1, %arg0) /* Last fdce and addr adjust */
261 movb,tr %arg3, %r31, fdmanyloop /* Re-init inner loop count */
262 ADDIB<=,n -1, %arg2, fdsync /* Outer loop decr */
264 fdoneloop: /* Loop if LOOP = 1 */
265 ADDIB> -1, %arg2, fdoneloop /* Outer loop count decr */
266 fdce,m %arg1(%sr1, %arg0) /* Fdce for one loop */
271 mtsm %r22 /* restore I-bit */
277 ENDPROC(flush_data_cache_local)
281 ENTRY(copy_user_page_asm)
287 /* PA8x00 CPUs can consume 2 loads or 1 store per cycle.
288 * Unroll the loop by hand and arrange insn appropriately.
289 * GCC probably can do this just as well.
293 ldi (PAGE_SIZE / 128), %r1
295 ldw 64(%r25), %r0 /* prefetch 1 cacheline ahead */
296 ldw 128(%r25), %r0 /* prefetch 2 */
299 ldw 192(%r25), %r0 /* prefetch 3 */
300 ldw 256(%r25), %r0 /* prefetch 4 */
342 /* conditional branches nullify on forward taken branch, and on
343 * non-taken backward branch. Note that .+4 is a backwards branch.
344 * The ldd should only get executed if the branch is taken.
346 ADDIB>,n -1, %r1, 1b /* bundle 10 */
347 ldd 0(%r25), %r19 /* start next loads */
352 * This loop is optimized for PCXL/PCXL2 ldw/ldw and stw/stw
353 * bundles (very restricted rules for bundling).
354 * Note that until (if) we start saving
355 * the full 64 bit register values on interrupt, we can't
356 * use ldd/std on a 32 bit kernel.
359 ldi (PAGE_SIZE / 64), %r1
403 ENDPROC(copy_user_page_asm)
406 * NOTE: Code in clear_user_page has a hard coded dependency on the
407 * maximum alias boundary being 4 Mb. We've been assured by the
408 * parisc chip designers that there will not ever be a parisc
409 * chip with a larger alias boundary (Never say never :-) ).
411 * Subtle: the dtlb miss handlers support the temp alias region by
412 * "knowing" that if a dtlb miss happens within the temp alias
413 * region it must have occurred while in clear_user_page. Since
414 * this routine makes use of processor local translations, we
415 * don't want to insert them into the kernel page table. Instead,
416 * we load up some general registers (they need to be registers
417 * which aren't shadowed) with the physical page numbers (preshifted
418 * for tlb insertion) needed to insert the translations. When we
419 * miss on the translation, the dtlb miss handler inserts the
420 * translation into the tlb using these values:
422 * %r26 physical page (shifted for tlb insert) of "to" translation
423 * %r23 physical page (shifted for tlb insert) of "from" translation
429 * We can't do this since copy_user_page is used to bring in
430 * file data that might have instructions. Since the data would
431 * then need to be flushed out so the i-fetch can see it, it
432 * makes more sense to just copy through the kernel translation
435 * I'm still keeping this around because it may be possible to
436 * use it if more information is passed into copy_user_page().
437 * Have to do some measurements to see if it is worthwhile to
438 * lobby for such a change.
441 ENTRY(copy_user_page_asm)
446 ldil L%(__PAGE_OFFSET), %r1
448 sub %r25, %r1, %r23 /* move physical addr into non shadowed reg */
450 ldil L%(TMPALIAS_MAP_START), %r28
451 /* FIXME for different page sizes != 4k */
453 extrd,u %r26,56,32, %r26 /* convert phys addr to tlb insert format */
454 extrd,u %r23,56,32, %r23 /* convert phys addr to tlb insert format */
455 depd %r24,63,22, %r28 /* Form aliased virtual address 'to' */
456 depdi 0, 63,12, %r28 /* Clear any offset bits */
458 depdi 1, 41,1, %r29 /* Form aliased virtual address 'from' */
460 extrw,u %r26, 24,25, %r26 /* convert phys addr to tlb insert format */
461 extrw,u %r23, 24,25, %r23 /* convert phys addr to tlb insert format */
462 depw %r24, 31,22, %r28 /* Form aliased virtual address 'to' */
463 depwi 0, 31,12, %r28 /* Clear any offset bits */
465 depwi 1, 9,1, %r29 /* Form aliased virtual address 'from' */
468 /* Purge any old translations */
476 * This loop is optimized for PCXL/PCXL2 ldw/ldw and stw/stw
477 * bundles (very restricted rules for bundling). It probably
478 * does OK on PCXU and better, but we could do better with
479 * ldd/std instructions. Note that until (if) we start saving
480 * the full 64 bit register values on interrupt, we can't
481 * use ldd/std on a 32 bit kernel.
527 ENDPROC(copy_user_page_asm)
530 ENTRY(__clear_user_page_asm)
537 ldil L%(TMPALIAS_MAP_START), %r28
539 #if (TMPALIAS_MAP_START >= 0x80000000)
540 depdi 0, 31,32, %r28 /* clear any sign extension */
541 /* FIXME: page size dependend */
543 extrd,u %r26, 56,32, %r26 /* convert phys addr to tlb insert format */
544 depd %r25, 63,22, %r28 /* Form aliased virtual address 'to' */
545 depdi 0, 63,12, %r28 /* Clear any offset bits */
547 extrw,u %r26, 24,25, %r26 /* convert phys addr to tlb insert format */
548 depw %r25, 31,22, %r28 /* Form aliased virtual address 'to' */
549 depwi 0, 31,12, %r28 /* Clear any offset bits */
552 /* Purge any old translation */
557 ldi (PAGE_SIZE / 128), %r1
559 /* PREFETCH (Write) has not (yet) been proven to help here */
560 /* #define PREFETCHW_OP ldd 256(%0), %r0 */
581 #else /* ! CONFIG_64BIT */
582 ldi (PAGE_SIZE / 64), %r1
603 #endif /* CONFIG_64BIT */
610 ENDPROC(__clear_user_page_asm)
612 ENTRY(flush_kernel_dcache_page_asm)
617 ldil L%dcache_stride, %r1
618 ldw R%dcache_stride(%r1), %r23
621 depdi,z 1, 63-PAGE_SHIFT,1, %r25
623 depwi,z 1, 31-PAGE_SHIFT,1, %r25
653 ENDPROC(flush_kernel_dcache_page_asm)
655 ENTRY(flush_user_dcache_page)
660 ldil L%dcache_stride, %r1
661 ldw R%dcache_stride(%r1), %r23
664 depdi,z 1,63-PAGE_SHIFT,1, %r25
666 depwi,z 1,31-PAGE_SHIFT,1, %r25
672 1: fdc,m %r23(%sr3, %r26)
673 fdc,m %r23(%sr3, %r26)
674 fdc,m %r23(%sr3, %r26)
675 fdc,m %r23(%sr3, %r26)
676 fdc,m %r23(%sr3, %r26)
677 fdc,m %r23(%sr3, %r26)
678 fdc,m %r23(%sr3, %r26)
679 fdc,m %r23(%sr3, %r26)
680 fdc,m %r23(%sr3, %r26)
681 fdc,m %r23(%sr3, %r26)
682 fdc,m %r23(%sr3, %r26)
683 fdc,m %r23(%sr3, %r26)
684 fdc,m %r23(%sr3, %r26)
685 fdc,m %r23(%sr3, %r26)
686 fdc,m %r23(%sr3, %r26)
688 fdc,m %r23(%sr3, %r26)
696 ENDPROC(flush_user_dcache_page)
698 ENTRY(flush_user_icache_page)
703 ldil L%dcache_stride, %r1
704 ldw R%dcache_stride(%r1), %r23
707 depdi,z 1, 63-PAGE_SHIFT,1, %r25
709 depwi,z 1, 31-PAGE_SHIFT,1, %r25
715 1: fic,m %r23(%sr3, %r26)
716 fic,m %r23(%sr3, %r26)
717 fic,m %r23(%sr3, %r26)
718 fic,m %r23(%sr3, %r26)
719 fic,m %r23(%sr3, %r26)
720 fic,m %r23(%sr3, %r26)
721 fic,m %r23(%sr3, %r26)
722 fic,m %r23(%sr3, %r26)
723 fic,m %r23(%sr3, %r26)
724 fic,m %r23(%sr3, %r26)
725 fic,m %r23(%sr3, %r26)
726 fic,m %r23(%sr3, %r26)
727 fic,m %r23(%sr3, %r26)
728 fic,m %r23(%sr3, %r26)
729 fic,m %r23(%sr3, %r26)
731 fic,m %r23(%sr3, %r26)
739 ENDPROC(flush_user_icache_page)
742 ENTRY(purge_kernel_dcache_page)
747 ldil L%dcache_stride, %r1
748 ldw R%dcache_stride(%r1), %r23
751 depdi,z 1, 63-PAGE_SHIFT,1, %r25
753 depwi,z 1, 31-PAGE_SHIFT,1, %r25
773 CMPB<< %r26, %r25, 1b
782 ENDPROC(purge_kernel_dcache_page)
785 /* Currently not used, but it still is a possible alternate
789 ENTRY(flush_alias_page)
796 ldil L%(TMPALIAS_MAP_START), %r28
798 extrd,u %r26, 56,32, %r26 /* convert phys addr to tlb insert format */
799 depd %r25, 63,22, %r28 /* Form aliased virtual address 'to' */
800 depdi 0, 63,12, %r28 /* Clear any offset bits */
802 extrw,u %r26, 24,25, %r26 /* convert phys addr to tlb insert format */
803 depw %r25, 31,22, %r28 /* Form aliased virtual address 'to' */
804 depwi 0, 31,12, %r28 /* Clear any offset bits */
807 /* Purge any old translation */
811 ldil L%dcache_stride, %r1
812 ldw R%dcache_stride(%r1), %r23
815 depdi,z 1, 63-PAGE_SHIFT,1, %r29
817 depwi,z 1, 31-PAGE_SHIFT,1, %r29
837 CMPB<< %r28, %r29, 1b
848 .export flush_user_dcache_range_asm
850 flush_user_dcache_range_asm:
855 ldil L%dcache_stride, %r1
856 ldw R%dcache_stride(%r1), %r23
858 ANDCM %r26, %r21, %r26
860 1: CMPB<<,n %r26, %r25, 1b
861 fdc,m %r23(%sr3, %r26)
869 ENDPROC(flush_alias_page)
871 ENTRY(flush_kernel_dcache_range_asm)
876 ldil L%dcache_stride, %r1
877 ldw R%dcache_stride(%r1), %r23
879 ANDCM %r26, %r21, %r26
881 1: CMPB<<,n %r26, %r25,1b
891 ENDPROC(flush_kernel_dcache_range_asm)
893 ENTRY(flush_user_icache_range_asm)
898 ldil L%icache_stride, %r1
899 ldw R%icache_stride(%r1), %r23
901 ANDCM %r26, %r21, %r26
903 1: CMPB<<,n %r26, %r25,1b
904 fic,m %r23(%sr3, %r26)
912 ENDPROC(flush_user_icache_range_asm)
914 ENTRY(flush_kernel_icache_page)
919 ldil L%icache_stride, %r1
920 ldw R%icache_stride(%r1), %r23
923 depdi,z 1, 63-PAGE_SHIFT,1, %r25
925 depwi,z 1, 31-PAGE_SHIFT,1, %r25
931 1: fic,m %r23(%sr4, %r26)
932 fic,m %r23(%sr4, %r26)
933 fic,m %r23(%sr4, %r26)
934 fic,m %r23(%sr4, %r26)
935 fic,m %r23(%sr4, %r26)
936 fic,m %r23(%sr4, %r26)
937 fic,m %r23(%sr4, %r26)
938 fic,m %r23(%sr4, %r26)
939 fic,m %r23(%sr4, %r26)
940 fic,m %r23(%sr4, %r26)
941 fic,m %r23(%sr4, %r26)
942 fic,m %r23(%sr4, %r26)
943 fic,m %r23(%sr4, %r26)
944 fic,m %r23(%sr4, %r26)
945 fic,m %r23(%sr4, %r26)
946 CMPB<< %r26, %r25, 1b
947 fic,m %r23(%sr4, %r26)
955 ENDPROC(flush_kernel_icache_page)
957 ENTRY(flush_kernel_icache_range_asm)
962 ldil L%icache_stride, %r1
963 ldw R%icache_stride(%r1), %r23
965 ANDCM %r26, %r21, %r26
967 1: CMPB<<,n %r26, %r25, 1b
968 fic,m %r23(%sr4, %r26)
975 ENDPROC(flush_kernel_icache_range_asm)
977 /* align should cover use of rfi in disable_sr_hashing_asm and
981 ENTRY(disable_sr_hashing_asm)
987 * Switch to real mode
998 rsm PSW_SM_Q, %r0 /* prep to load iia queue */
999 mtctl %r0, %cr17 /* Clear IIASQ tail */
1000 mtctl %r0, %cr17 /* Clear IIASQ head */
1001 mtctl %r1, %cr18 /* IIAOQ head */
1003 mtctl %r1, %cr18 /* IIAOQ tail */
1004 load32 REAL_MODE_PSW, %r1
1009 1: cmpib,=,n SRHASH_PCXST, %r26,srdis_pcxs
1010 cmpib,=,n SRHASH_PCXL, %r26,srdis_pcxl
1011 cmpib,=,n SRHASH_PA20, %r26,srdis_pa20
1016 /* Disable Space Register Hashing for PCXS,PCXT,PCXT' */
1018 .word 0x141c1a00 /* mfdiag %dr0, %r28 */
1019 .word 0x141c1a00 /* must issue twice */
1020 depwi 0,18,1, %r28 /* Clear DHE (dcache hash enable) */
1021 depwi 0,20,1, %r28 /* Clear IHE (icache hash enable) */
1022 .word 0x141c1600 /* mtdiag %r28, %dr0 */
1023 .word 0x141c1600 /* must issue twice */
1028 /* Disable Space Register Hashing for PCXL */
1030 .word 0x141c0600 /* mfdiag %dr0, %r28 */
1031 depwi 0,28,2, %r28 /* Clear DHASH_EN & IHASH_EN */
1032 .word 0x141c0240 /* mtdiag %r28, %dr0 */
1037 /* Disable Space Register Hashing for PCXU,PCXU+,PCXW,PCXW+,PCXW2 */
1039 .word 0x144008bc /* mfdiag %dr2, %r28 */
1040 depdi 0, 54,1, %r28 /* clear DIAG_SPHASH_ENAB (bit 54) */
1041 .word 0x145c1840 /* mtdiag %r28, %dr2 */
1045 /* Switch back to virtual mode */
1046 rsm PSW_SM_I, %r0 /* prep to load iia queue */
1054 rsm PSW_SM_Q, %r0 /* prep to load iia queue */
1055 mtctl %r0, %cr17 /* Clear IIASQ tail */
1056 mtctl %r0, %cr17 /* Clear IIASQ head */
1057 mtctl %r1, %cr18 /* IIAOQ head */
1059 mtctl %r1, %cr18 /* IIAOQ tail */
1060 load32 KERNEL_PSW, %r1
1070 ENDPROC(disable_sr_hashing_asm)