2006-02-01 05:29:18 +03:00
/ * tsb. S : S p a r c64 T S B t a b l e h a n d l i n g .
*
* Copyright ( C ) 2 0 0 6 D a v i d S . M i l l e r < d a v e m @davemloft.net>
* /
# include < a s m / t s b . h >
2006-02-10 04:21:53 +03:00
# include < a s m / h y p e r v i s o r . h >
2006-02-01 05:29:18 +03:00
.text
.align 32
/ * Invoked f r o m T L B m i s s h a n d l e r , w e a r e i n t h e
* MMU g l o b a l r e g i s t e r s a n d t h e y a r e s e t u p l i k e
* this :
*
* % g1 : TSB e n t r y p o i n t e r
* % g2 : available t e m p o r a r y
* % g3 : FAULT_ C O D E _ { D ,I } T L B
* % g4 : available t e m p o r a r y
* % g5 : available t e m p o r a r y
* % g6 : TAG T A R G E T
2006-02-07 10:44:37 +03:00
* % g7 : available t e m p o r a r y , w i l l b e l o a d e d b y u s w i t h
* the p h y s i c a l a d d r e s s b a s e o f t h e l i n u x p a g e
2006-02-01 05:29:18 +03:00
* tables f o r t h e c u r r e n t a d d r e s s s p a c e
* /
tsb_miss_dtlb :
mov T L B _ T A G _ A C C E S S , % g 4
ba,p t % x c c , t s b _ m i s s _ p a g e _ t a b l e _ w a l k
2006-02-11 11:29:34 +03:00
ldxa [ % g 4 ] A S I _ D M M U , % g 4
2006-02-01 05:29:18 +03:00
tsb_miss_itlb :
mov T L B _ T A G _ A C C E S S , % g 4
ba,p t % x c c , t s b _ m i s s _ p a g e _ t a b l e _ w a l k
2006-02-11 11:29:34 +03:00
ldxa [ % g 4 ] A S I _ I M M U , % g 4
2006-02-01 05:29:18 +03:00
2006-02-11 11:29:34 +03:00
/ * At t h i s p o i n t w e h a v e :
* % g4 - - m i s s i n g v i r t u a l a d d r e s s
* % g1 - - T S B e n t r y a d d r e s s
2006-02-18 05:01:02 +03:00
* % g6 - - T A G T A R G E T ( v a d d r > > 2 2 )
2006-02-07 10:44:37 +03:00
* /
2006-02-01 05:29:18 +03:00
tsb_miss_page_table_walk :
2006-02-03 08:55:10 +03:00
TRAP_ L O A D _ P G D _ P H Y S ( % g 7 , % g 5 )
2006-02-27 10:24:22 +03:00
2006-02-11 11:29:34 +03:00
/* And now we have the PGD base physical address in %g7. */
tsb_miss_page_table_walk_sun4v_fastpath :
2006-02-01 05:29:18 +03:00
USER_ P G T A B L E _ W A L K _ T L 1 ( % g 4 , % g 7 , % g 5 , % g 2 , t s b _ d o _ f a u l t )
tsb_reload :
2006-02-07 10:44:37 +03:00
TSB_ L O C K _ T A G ( % g 1 , % g 2 , % g 7 )
2006-02-01 05:29:18 +03:00
/* Load and check PTE. */
ldxa [ % g 5 ] A S I _ P H Y S _ U S E _ E C , % g 5
2006-02-18 05:01:02 +03:00
mov 1 , % g 7
sllx % g 7 , T S B _ T A G _ I N V A L I D _ B I T , % g 7
2006-02-01 05:29:18 +03:00
brgez,a ,p n % g 5 , t s b _ d o _ f a u l t
2006-02-18 05:01:02 +03:00
TSB_ S T O R E ( % g 1 , % g 7 )
2006-02-01 05:29:18 +03:00
2006-02-01 05:31:06 +03:00
/ * If i t i s l a r g e r t h a n t h e b a s e p a g e s i z e , d o n ' t
* bother p u t t i n g i t i n t o t h e T S B .
* /
2006-02-12 08:57:54 +03:00
sethi % h i ( _ P A G E _ A L L _ S Z _ B I T S ) , % g 7
ldx [ % g 7 + % l o ( _ P A G E _ A L L _ S Z _ B I T S ) ] , % g 7
and % g 5 , % g 7 , % g 2
sethi % h i ( _ P A G E _ S Z B I T S ) , % g 7
ldx [ % g 7 + % l o ( _ P A G E _ S Z B I T S ) ] , % g 7
2006-02-01 05:31:06 +03:00
cmp % g 2 , % g 7
2006-02-18 05:01:02 +03:00
mov 1 , % g 7
sllx % g 7 , T S B _ T A G _ I N V A L I D _ B I T , % g 7
2006-02-01 05:31:06 +03:00
bne,a ,p n % x c c , t s b _ t l b _ r e l o a d
2006-02-18 05:01:02 +03:00
TSB_ S T O R E ( % g 1 , % g 7 )
2006-02-01 05:31:06 +03:00
2006-02-01 05:29:18 +03:00
TSB_ W R I T E ( % g 1 , % g 5 , % g 6 )
/* Finally, load TLB and return from trap. */
tsb_tlb_reload :
cmp % g 3 , F A U L T _ C O D E _ D T L B
bne,p n % x c c , t s b _ i t l b _ l o a d
nop
tsb_dtlb_load :
2006-02-07 10:44:37 +03:00
661 : stxa % g 5 , [ % g 0 ] A S I _ D T L B _ D A T A _ I N
2006-02-01 05:29:18 +03:00
retry
2006-02-07 11:00:16 +03:00
.section .sun4v_2insn_patch , " ax"
2006-02-07 10:44:37 +03:00
.word 661b
nop
nop
.previous
/ * For s u n 4 v t h e A S I _ D T L B _ D A T A _ I N s t o r e a n d t h e r e t r y
* instruction g e t n o p ' d o u t a n d w e g e t h e r e t o b r a n c h
* to t h e s u n 4 v t l b l o a d c o d e . T h e r e g i s t e r s a r e s e t u p
* as f o l l o w s :
*
* % g4 : vaddr
* % g5 : PTE
* % g6 : TAG
*
* The s u n 4 v T L B l o a d w a n t s t h e P T E i n % g 3 s o w e f i x t h a t
* up h e r e .
* /
ba,p t % x c c , s u n 4 v _ d t l b _ l o a d
mov % g 5 , % g 3
2006-02-01 05:29:18 +03:00
tsb_itlb_load :
2006-02-07 10:44:37 +03:00
661 : stxa % g 5 , [ % g 0 ] A S I _ I T L B _ D A T A _ I N
2006-02-01 05:29:18 +03:00
retry
2006-02-07 11:00:16 +03:00
.section .sun4v_2insn_patch , " ax"
2006-02-07 10:44:37 +03:00
.word 661b
nop
nop
.previous
/ * For s u n 4 v t h e A S I _ I T L B _ D A T A _ I N s t o r e a n d t h e r e t r y
* instruction g e t n o p ' d o u t a n d w e g e t h e r e t o b r a n c h
* to t h e s u n 4 v t l b l o a d c o d e . T h e r e g i s t e r s a r e s e t u p
* as f o l l o w s :
*
* % g4 : vaddr
* % g5 : PTE
* % g6 : TAG
*
* The s u n 4 v T L B l o a d w a n t s t h e P T E i n % g 3 s o w e f i x t h a t
* up h e r e .
* /
ba,p t % x c c , s u n 4 v _ i t l b _ l o a d
mov % g 5 , % g 3
2006-02-01 05:29:18 +03:00
/ * No v a l i d e n t r y i n t h e p a g e t a b l e s , d o f u l l f a u l t
* processing.
* /
.globl tsb_do_fault
tsb_do_fault :
cmp % g 3 , F A U L T _ C O D E _ D T L B
2006-02-06 09:27:28 +03:00
661 : rdpr % p s t a t e , % g 5
wrpr % g 5 , P S T A T E _ A G | P S T A T E _ M G , % p s t a t e
2006-02-07 11:00:16 +03:00
.section .sun4v_2insn_patch , " ax"
2006-02-06 09:27:28 +03:00
.word 661b
2006-02-18 01:58:02 +03:00
SET_ G L ( 1 )
2006-02-18 05:01:02 +03:00
ldxa [ % g 0 ] A S I _ S C R A T C H P A D , % g 4
2006-02-06 09:27:28 +03:00
.previous
2006-02-01 05:29:18 +03:00
bne,p n % x c c , t s b _ d o _ i t l b _ f a u l t
2006-02-06 09:27:28 +03:00
nop
2006-02-01 05:29:18 +03:00
tsb_do_dtlb_fault :
2006-02-07 10:44:37 +03:00
rdpr % t l , % g 3
cmp % g 3 , 1
661 : mov T L B _ T A G _ A C C E S S , % g 4
2006-02-01 05:29:18 +03:00
ldxa [ % g 4 ] A S I _ D M M U , % g 5
2006-02-07 11:00:16 +03:00
.section .sun4v_2insn_patch , " ax"
2006-02-07 10:44:37 +03:00
.word 661b
2006-02-18 05:01:02 +03:00
ldx [ % g 4 + H V _ F A U L T _ D _ A D D R _ O F F S E T ] , % g 5
2006-02-07 10:44:37 +03:00
nop
.previous
2006-02-01 05:29:18 +03:00
be,p t % x c c , s p a r c64 _ r e a l f a u l t _ c o m m o n
mov F A U L T _ C O D E _ D T L B , % g 4
ba,p t % x c c , w i n f i x _ t r a m p o l i n e
nop
tsb_do_itlb_fault :
rdpr % t p c , % g 5
ba,p t % x c c , s p a r c64 _ r e a l f a u l t _ c o m m o n
mov F A U L T _ C O D E _ I T L B , % g 4
.globl sparc64_realfault_common
sparc64_realfault_common :
2006-02-01 05:34:21 +03:00
/ * fault c o d e i n % g 4 , f a u l t a d d r e s s i n % g 5 , e t r a p w i l l
* preserve t h e s e t w o v a l u e s i n % l 4 a n d % l 5 r e s p e c t i v e l y
* /
2006-02-01 05:29:18 +03:00
ba,p t % x c c , e t r a p ! S a v e t r a p s t a t e
1 : rd % p c , % g 7 ! . . .
2006-02-01 05:34:21 +03:00
stb % l 4 , [ % g 6 + T I _ F A U L T _ C O D E ] ! S a v e f a u l t c o d e
stx % l 5 , [ % g 6 + T I _ F A U L T _ A D D R ] ! S a v e f a u l t a d d r e s s
2006-02-01 05:29:18 +03:00
call d o _ s p a r c64 _ f a u l t ! C a l l f a u l t h a n d l e r
add % s p , P T R E G S _ O F F , % o 0 ! C o m p u t e p t _ r e g s a r g
ba,p t % x c c , r t r a p _ c l r _ l 6 ! R e s t o r e c p u s t a t e
nop ! D e l a y s l o t ( f i l l m e )
winfix_trampoline :
rdpr % t p c , % g 3 ! P r e p a r e w i n f i x u p T N P C
or % g 3 , 0 x7 c , % g 3 ! C o m p u t e b r a n c h o f f s e t
wrpr % g 3 , % t n p c ! W r i t e i t i n t o T N P C
done ! T r a p r e t u r n
2006-02-01 05:32:04 +03:00
/ * Insert a n e n t r y i n t o t h e T S B .
*
2006-02-02 02:55:21 +03:00
* % o0 : TSB e n t r y p o i n t e r ( v i r t o r p h y s a d d r e s s )
2006-02-01 05:32:04 +03:00
* % o1 : tag
* % o2 : pte
* /
.align 32
2006-02-02 02:55:21 +03:00
.globl __tsb_insert
__tsb_insert :
2006-02-01 05:32:04 +03:00
rdpr % p s t a t e , % o 5
wrpr % o 5 , P S T A T E _ I E , % p s t a t e
TSB_ L O C K _ T A G ( % o 0 , % g 2 , % g 3 )
TSB_ W R I T E ( % o 0 , % o 2 , % o 1 )
wrpr % o 5 , % p s t a t e
retl
nop
2006-02-02 02:55:21 +03:00
/ * Flush t h e g i v e n T S B e n t r y i f i t h a s t h e m a t c h i n g
* tag.
*
* % o0 : TSB e n t r y p o i n t e r ( v i r t o r p h y s a d d r e s s )
* % o1 : tag
* /
.align 32
.globl tsb_flush
tsb_flush :
sethi % h i ( T S B _ T A G _ L O C K _ H I G H ) , % g 2
1 : TSB_ L O A D _ T A G ( % o 0 , % g 1 )
srlx % g 1 , 3 2 , % o 3
andcc % o 3 , % g 2 , % g 0
bne,p n % i c c , 1 b
membar #L o a d L o a d
cmp % g 1 , % o 1
2006-02-18 05:01:02 +03:00
mov 1 , % o 3
2006-02-02 02:55:21 +03:00
bne,p t % x c c , 2 f
2006-02-18 05:01:02 +03:00
sllx % o 3 , T S B _ T A G _ I N V A L I D _ B I T , % o 3
2006-02-02 02:55:21 +03:00
TSB_ C A S _ T A G ( % o 0 , % g 1 , % o 3 )
cmp % g 1 , % o 3
bne,p n % x c c , 1 b
nop
2 : retl
TSB_ M E M B A R
2006-02-01 05:29:18 +03:00
/ * Reload M M U r e l a t e d c o n t e x t s w i t c h s t a t e a t
* schedule( ) t i m e .
*
* % o0 : page t a b l e p h y s i c a l a d d r e s s
2006-02-01 05:31:20 +03:00
* % o1 : TSB r e g i s t e r v a l u e
* % o2 : TSB v i r t u a l a d d r e s s
* % o3 : TSB m a p p i n g l o c k e d P T E
2006-02-10 04:21:53 +03:00
* % o4 : Hypervisor T S B d e s c r i p t o r p h y s i c a l a d d r e s s
2006-02-01 05:31:20 +03:00
*
* We h a v e t o r u n t h i s w h o l e t h i n g w i t h i n t e r r u p t s
* disabled s o t h a t t h e c u r r e n t c p u d o e s n ' t c h a n g e
* due t o p r e e m p t i o n .
2006-02-01 05:29:18 +03:00
* /
2006-02-27 10:24:22 +03:00
.align 32
2006-02-01 05:31:20 +03:00
.globl __tsb_context_switch
__tsb_context_switch :
2006-02-27 10:24:22 +03:00
rdpr % p s t a t e , % o 5
wrpr % o 5 , P S T A T E _ I E , % p s t a t e
2006-02-01 05:29:18 +03:00
2006-02-01 05:31:20 +03:00
ldub [ % g 6 + T I _ C P U ] , % g 1
sethi % h i ( t r a p _ b l o c k ) , % g 2
sllx % g 1 , T R A P _ B L O C K _ S Z _ S H I F T , % g 1
or % g 2 , % l o ( t r a p _ b l o c k ) , % g 2
add % g 2 , % g 1 , % g 2
stx % o 0 , [ % g 2 + T R A P _ P E R _ C P U _ P G D _ P A D D R ]
2006-02-01 05:29:18 +03:00
2006-02-10 04:21:53 +03:00
sethi % h i ( t l b _ t y p e ) , % g 1
lduw [ % g 1 + % l o ( t l b _ t y p e ) ] , % g 1
cmp % g 1 , 3
bne,p t % i c c , 1 f
nop
/* Hypervisor TSB switch. */
2006-02-07 10:44:37 +03:00
mov S C R A T C H P A D _ U T S B R E G 1 , % g 1
stxa % o 1 , [ % g 1 ] A S I _ S C R A T C H P A D
2006-02-10 04:21:53 +03:00
mov - 1 , % g 2
mov S C R A T C H P A D _ U T S B R E G 2 , % g 1
stxa % g 2 , [ % g 1 ] A S I _ S C R A T C H P A D
2006-02-07 10:44:37 +03:00
2006-02-16 08:16:42 +03:00
/ * Save a w a y % o 5 ' s % p s t a t e , w e h a v e t o u s e % o 5 f o r
* the h y p e r v i s o r c a l l .
* /
mov % o 5 , % g 1
2006-02-10 09:57:21 +03:00
mov H V _ F A S T _ M M U _ T S B _ C T X N O N 0 , % o 5
mov 1 , % o 0
mov % o 4 , % o 1
2006-02-10 04:21:53 +03:00
ta H V _ F A S T _ T R A P
2006-02-16 08:16:42 +03:00
/* Finish up and restore %o5. */
2006-02-10 04:21:53 +03:00
ba,p t % x c c , 9 f
2006-02-16 08:16:42 +03:00
mov % g 1 , % o 5
2006-02-01 05:29:18 +03:00
2006-02-10 04:21:53 +03:00
/* SUN4U TSB switch. */
1 : mov T S B _ R E G , % g 1
stxa % o 1 , [ % g 1 ] A S I _ D M M U
membar #S y n c
stxa % o 1 , [ % g 1 ] A S I _ I M M U
2006-02-01 05:29:18 +03:00
membar #S y n c
2006-02-10 04:21:53 +03:00
2 : brz % o 2 , 9 f
2006-02-01 05:31:20 +03:00
nop
2006-02-01 05:29:18 +03:00
2006-02-10 04:21:53 +03:00
sethi % h i ( s p a r c64 _ h i g h e s t _ u n l o c k e d _ t l b _ e n t ) , % g 2
2006-02-01 05:33:12 +03:00
mov T L B _ T A G _ A C C E S S , % g 1
2006-02-10 04:21:53 +03:00
lduw [ % g 2 + % l o ( s p a r c64 _ h i g h e s t _ u n l o c k e d _ t l b _ e n t ) ] , % g 2
2006-02-01 05:33:12 +03:00
stxa % o 2 , [ % g 1 ] A S I _ D M M U
membar #S y n c
sllx % g 2 , 3 , % g 2
stxa % o 3 , [ % g 2 ] A S I _ D T L B _ D A T A _ A C C E S S
membar #S y n c
2006-02-01 05:29:18 +03:00
9 :
2006-02-27 10:24:22 +03:00
wrpr % o 5 , % p s t a t e
2006-02-01 05:29:18 +03:00
retl
2006-02-01 05:31:20 +03:00
nop