2005-04-16 15:20:36 -07:00
/ *
* We n e e d c o n s t a n t s . h f o r :
* VMA_ V M _ M M
* VMA_ V M _ F L A G S
* VM_ E X E C
* /
2005-09-09 21:08:59 +02:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-16 15:20:36 -07:00
# include < a s m / t h r e a d _ i n f o . h >
/ *
* vma_ v m _ m m - g e t m m p o i n t e r f r o m v m a p o i n t e r ( v m a - > v m _ m m )
* /
.macro vma_ v m _ m m , r d , r n
ldr \ r d , [ \ r n , #V M A _ V M _ M M ]
.endm
/ *
* vma_ v m _ f l a g s - g e t v m a - > v m _ f l a g s
* /
.macro vma_ v m _ f l a g s , r d , r n
ldr \ r d , [ \ r n , #V M A _ V M _ F L A G S ]
.endm
.macro tsk_ m m , r d , r n
ldr \ r d , [ \ r n , #T I _ T A S K ]
ldr \ r d , [ \ r d , #T S K _ A C T I V E _ M M ]
.endm
/ *
* act_ m m - g e t c u r r e n t - > a c t i v e _ m m
* /
.macro act_ m m , r d
bic \ r d , s p , #8128
bic \ r d , \ r d , #63
ldr \ r d , [ \ r d , #T I _ T A S K ]
ldr \ r d , [ \ r d , #T S K _ A C T I V E _ M M ]
.endm
/ *
* mmid - g e t c o n t e x t i d f r o m m m p o i n t e r ( m m - > c o n t e x t . i d )
2013-02-11 12:25:06 +01:00
* note, t h i s f i e l d i s 6 4 b i t , s o i n b i g - e n d i a n t h e t w o w o r d s a r e s w a p p e d t o o .
2005-04-16 15:20:36 -07:00
* /
.macro mmid, r d , r n
2013-02-11 12:25:06 +01:00
# ifdef _ _ A R M E B _ _
ldr \ r d , [ \ r n , #M M _ C O N T E X T _ I D + 4 ]
# else
2005-04-16 15:20:36 -07:00
ldr \ r d , [ \ r n , #M M _ C O N T E X T _ I D ]
2013-02-11 12:25:06 +01:00
# endif
2005-04-16 15:20:36 -07:00
.endm
/ *
* mask_ a s i d - m a s k t h e A S I D f r o m t h e c o n t e x t I D
* /
.macro asid, r d , r n
and \ r d , \ r n , #255
.endm
2006-06-29 15:09:57 +01:00
.macro crval, c l e a r , m m u s e t , u c s e t
# ifdef C O N F I G _ M M U
.word \ clear
.word \ mmuset
# else
.word \ clear
.word \ ucset
# endif
.endm
2007-05-08 22:27:46 +01:00
/ *
2010-12-07 16:52:04 +01:00
* dcache_ l i n e _ s i z e - g e t t h e m i n i m u m D - c a c h e l i n e s i z e f r o m t h e C T R r e g i s t e r
* on A R M v7 .
2007-05-08 22:27:46 +01:00
* /
.macro dcache_ l i n e _ s i z e , r e g , t m p
2010-12-07 16:52:04 +01:00
mrc p15 , 0 , \ t m p , c0 , c0 , 1 @ read ctr
lsr \ t m p , \ t m p , #16
and \ t m p , \ t m p , #0xf @ cache line size encoding
mov \ r e g , #4 @ bytes per word
2007-05-08 22:27:46 +01:00
mov \ r e g , \ r e g , l s l \ t m p @ actual cache line size
.endm
2008-09-06 17:19:08 +01:00
2010-12-07 16:56:29 +01:00
/ *
* icache_ l i n e _ s i z e - g e t t h e m i n i m u m I - c a c h e l i n e s i z e f r o m t h e C T R r e g i s t e r
* on A R M v7 .
* /
.macro icache_ l i n e _ s i z e , r e g , t m p
mrc p15 , 0 , \ t m p , c0 , c0 , 1 @ read ctr
and \ t m p , \ t m p , #0xf @ cache line size encoding
mov \ r e g , #4 @ bytes per word
mov \ r e g , \ r e g , l s l \ t m p @ actual cache line size
.endm
2008-09-06 17:19:08 +01:00
/ *
* Sanity c h e c k t h e P T E c o n f i g u r a t i o n f o r t h e c o d e b e l o w - w h i c h m a k e s
2011-03-30 22:57:33 -03:00
* certain a s s u m p t i o n s a b o u t h o w t h e s e b i t s a r e l a i d o u t .
2008-09-06 17:19:08 +01:00
* /
2009-07-24 12:35:04 +01:00
# ifdef C O N F I G _ M M U
2008-09-06 17:19:08 +01:00
# if L _ P T E _ S H A R E D ! = P T E _ E X T _ S H A R E D
# error P T E s h a r e d b i t m i s m a t c h
# endif
2011-11-22 17:30:29 +00:00
# if ! d e f i n e d ( C O N F I G _ A R M _ L P A E ) & & \
( L_ P T E _ X N + L _ P T E _ U S E R + L _ P T E _ R D O N L Y + L _ P T E _ D I R T Y + L _ P T E _ Y O U N G + \
L_ P T E _ F I L E + L _ P T E _ P R E S E N T ) > L _ P T E _ S H A R E D
2008-09-06 17:19:08 +01:00
# error I n v a l i d L i n u x P T E b i t s e t t i n g s
# endif
2009-07-24 12:35:04 +01:00
# endif / * C O N F I G _ M M U * /
2008-09-06 17:19:08 +01:00
/ *
* The A R M v6 a n d A R M v7 s e t _ p t e _ e x t t r a n s l a t i o n f u n c t i o n .
*
* Permission t r a n s l a t i o n :
* YUWD A P X A P 1 A P 0 S V C U s e r
* 0 xxx 0 0 0 n o a c c n o a c c
* 1 0 0 x 1 0 1 r / o n o a c c
* 1 0 x0 1 0 1 r / o n o a c c
* 1 0 1 1 0 0 1 r/ w n o a c c
* 1 1 0 x 0 1 0 r / w r / o
* 1 1 x0 0 1 0 r / w r / o
* 1 1 1 1 0 1 1 r/ w r / w
2010-09-13 16:03:21 +01:00
*
* If ! C O N F I G _ C P U _ U S E _ D O M A I N S , t h e f o l l o w i n g p e r m i s s i o n s a r e c h a n g e d :
* 1 1 0 x 1 1 1 r / o r / o
* 1 1 x0 1 1 1 r / o r / o
2008-09-06 17:19:08 +01:00
* /
2008-09-06 21:07:45 +01:00
.macro armv6_mt_table pfx
\ pfx\ ( ) _ m t _ t a b l e :
.long 0x00 @ L_PTE_MT_UNCACHED
.long PTE_ E X T _ T E X ( 1 ) @ L_PTE_MT_BUFFERABLE
.long PTE_CACHEABLE @ L_PTE_MT_WRITETHROUGH
.long PTE_CACHEABLE | PTE_ B U F F E R A B L E @ L_PTE_MT_WRITEBACK
.long PTE_BUFFERABLE @ L_PTE_MT_DEV_SHARED
.long 0x00 @ unused
.long 0x00 @ L_PTE_MT_MINICACHE (not present)
.long PTE_ E X T _ T E X ( 1 ) | P T E _ C A C H E A B L E | P T E _ B U F F E R A B L E @ L_PTE_MT_WRITEALLOC
.long 0x00 @ unused
.long PTE_ E X T _ T E X ( 1 ) @ L_PTE_MT_DEV_WC
.long 0x00 @ unused
.long PTE_CACHEABLE | PTE_ B U F F E R A B L E @ L_PTE_MT_DEV_CACHED
.long PTE_ E X T _ T E X ( 2 ) @ L_PTE_MT_DEV_NONSHARED
2008-09-07 12:42:51 +01:00
.long 0x00 @ unused
2008-09-06 21:07:45 +01:00
.long 0x00 @ unused
.long 0x00 @ unused
.endm
.macro armv6_set_pte_ext pfx
2010-11-16 00:16:01 +00:00
str r1 , [ r0 ] , #2048 @ linux version
2008-09-06 17:19:08 +01:00
2008-09-06 21:07:45 +01:00
bic r3 , r1 , #0x000003fc
2008-09-06 17:19:08 +01:00
bic r3 , r3 , #P T E _ T Y P E _ M A S K
orr r3 , r3 , r2
orr r3 , r3 , #P T E _ E X T _ A P 0 | 2
2008-09-06 21:07:45 +01:00
adr i p , \ p f x \ ( ) _ m t _ t a b l e
and r2 , r1 , #L _ P T E _ M T _ M A S K
ldr r2 , [ i p , r2 ]
2010-11-16 08:40:36 +00:00
eor r1 , r1 , #L _ P T E _ D I R T Y
tst r1 , #L _ P T E _ D I R T Y | L _ P T E _ R D O N L Y
orrne r3 , r3 , #P T E _ E X T _ A P X
2008-09-06 17:19:08 +01:00
tst r1 , #L _ P T E _ U S E R
orrne r3 , r3 , #P T E _ E X T _ A P 1
2010-09-13 16:03:21 +01:00
# ifdef C O N F I G _ C P U _ U S E _ D O M A I N S
@ allow kernel read/write access to read-only user pages
2008-09-06 17:19:08 +01:00
tstne r3 , #P T E _ E X T _ A P X
bicne r3 , r3 , #P T E _ E X T _ A P X | P T E _ E X T _ A P 0
2010-09-13 16:03:21 +01:00
# endif
2008-09-06 17:19:08 +01:00
2010-11-16 00:23:31 +00:00
tst r1 , #L _ P T E _ X N
orrne r3 , r3 , #P T E _ E X T _ X N
2008-09-06 17:19:08 +01:00
2008-09-06 21:07:45 +01:00
orr r3 , r3 , r2
2008-09-06 17:19:08 +01:00
tst r1 , #L _ P T E _ Y O U N G
tstne r1 , #L _ P T E _ P R E S E N T
moveq r3 , #0
2012-09-01 05:22:12 +01:00
# ifndef C O N F I G _ C P U _ U S E _ D O M A I N S
tstne r1 , #L _ P T E _ N O N E
movne r3 , #0
# endif
2008-09-06 17:19:08 +01:00
str r3 , [ r0 ]
mcr p15 , 0 , r0 , c7 , c10 , 1 @ flush_pte
.endm
/ *
* The A R M v3 , A R M v4 a n d A R M v5 s e t _ p t e _ e x t t r a n s l a t i o n f u n c t i o n ,
* covering m o s t C P U s e x c e p t X s c a l e a n d X s c a l e 3 .
*
* Permission t r a n s l a t i o n :
* YUWD A P S V C U s e r
* 0 xxx 0 x00 n o a c c n o a c c
* 1 0 0 x 0 x00 r / o n o a c c
* 1 0 x0 0 x00 r / o n o a c c
* 1 0 1 1 0 x5 5 r / w n o a c c
* 1 1 0 x 0 x a a r / w r / o
* 1 1 x0 0 x a a r / w r / o
* 1 1 1 1 0 xff r / w r / w
* /
.macro armv3_set_pte_ext wc_ d i s a b l e =1
2010-11-16 00:16:01 +00:00
str r1 , [ r0 ] , #2048 @ linux version
2008-09-06 17:19:08 +01:00
2010-11-16 08:40:36 +00:00
eor r3 , r1 , #L _ P T E _ P R E S E N T | L _ P T E _ Y O U N G | L _ P T E _ D I R T Y
2008-09-06 17:19:08 +01:00
bic r2 , r1 , #P T E _ S M A L L _ A P _ M A S K @ k e e p C , B b i t s
bic r2 , r2 , #P T E _ T Y P E _ M A S K
orr r2 , r2 , #P T E _ T Y P E _ S M A L L
tst r3 , #L _ P T E _ U S E R @ u s e r ?
orrne r2 , r2 , #P T E _ S M A L L _ A P _ U R O _ S R W
2010-11-16 08:40:36 +00:00
tst r3 , #L _ P T E _ R D O N L Y | L _ P T E _ D I R T Y @ w r i t e a n d d i r t y ?
2008-09-06 17:19:08 +01:00
orreq r2 , r2 , #P T E _ S M A L L _ A P _ U N O _ S R W
tst r3 , #L _ P T E _ P R E S E N T | L _ P T E _ Y O U N G @ p r e s e n t a n d y o u n g ?
movne r2 , #0
.if \ wc_ d i s a b l e
# ifdef C O N F I G _ C P U _ D C A C H E _ W R I T E T H R O U G H
tst r2 , #P T E _ C A C H E A B L E
bicne r2 , r2 , #P T E _ B U F F E R A B L E
# endif
.endif
2010-11-16 00:16:01 +00:00
str r2 , [ r0 ] @ hardware version
2008-09-06 17:19:08 +01:00
.endm
/ *
* Xscale s e t _ p t e _ e x t t r a n s l a t i o n , s p l i t i n t o t w o h a l v e s t o c o p e
* with w o r k - a r o u n d s . r3 m u s t b e p r e s e r v e d b y c o d e b e t w e e n t h e s e
* two m a c r o s .
*
* Permission t r a n s l a t i o n :
* YUWD A P S V C U s e r
* 0 xxx 0 0 n o a c c n o a c c
* 1 0 0 x 0 0 r / o n o a c c
* 1 0 x0 0 0 r / o n o a c c
* 1 0 1 1 0 1 r/ w n o a c c
* 1 1 0 x 1 0 r / w r / o
* 1 1 x0 1 0 r / w r / o
* 1 1 1 1 1 1 r/ w r / w
* /
.macro xscale_set_pte_ext_prologue
2010-11-16 00:16:01 +00:00
str r1 , [ r0 ] @ linux version
2008-09-06 17:19:08 +01:00
2010-11-16 08:40:36 +00:00
eor r3 , r1 , #L _ P T E _ P R E S E N T | L _ P T E _ Y O U N G | L _ P T E _ D I R T Y
2008-09-06 17:19:08 +01:00
bic r2 , r1 , #P T E _ S M A L L _ A P _ M A S K @ k e e p C , B b i t s
orr r2 , r2 , #P T E _ T Y P E _ E X T @ e x t e n d e d p a g e
tst r3 , #L _ P T E _ U S E R @ u s e r ?
orrne r2 , r2 , #P T E _ E X T _ A P _ U R O _ S R W @ y e s - > u s e r r / o , s y s t e m r / w
2010-11-16 08:40:36 +00:00
tst r3 , #L _ P T E _ R D O N L Y | L _ P T E _ D I R T Y @ w r i t e a n d d i r t y ?
2008-09-06 17:19:08 +01:00
orreq r2 , r2 , #P T E _ E X T _ A P _ U N O _ S R W @ y e s - > u s e r n / a , s y s t e m r / w
@ combined with user -> user r/w
.endm
.macro xscale_set_pte_ext_epilogue
tst r3 , #L _ P T E _ P R E S E N T | L _ P T E _ Y O U N G @ p r e s e n t a n d y o u n g ?
movne r2 , #0 @ no -> fault
2010-11-16 00:16:01 +00:00
str r2 , [ r0 , #2048 ] ! @ hardware version
2008-09-06 17:19:08 +01:00
mov i p , #0
mcr p15 , 0 , r0 , c7 , c10 , 1 @ clean L1 D line
mcr p15 , 0 , i p , c7 , c10 , 4 @ data write barrier
.endm
2011-06-23 17:07:40 +01:00
.macro define_processor_functions name : req, d a b o r t : r e q , p a b o r t : r e q , n o m m u =0 , s u s p e n d =0
.type \ name\ ( ) _ p r o c e s s o r _ f u n c t i o n s , #o b j e c t
.align 2
ENTRY( \ n a m e \ ( ) _ p r o c e s s o r _ f u n c t i o n s )
.word \ dabort
.word \ pabort
.word cpu_ \ n a m e \ ( ) _ p r o c _ i n i t
.word cpu_ \ n a m e \ ( ) _ p r o c _ f i n
.word cpu_ \ n a m e \ ( ) _ r e s e t
.word cpu_ \ n a m e \ ( ) _ d o _ i d l e
.word cpu_ \ n a m e \ ( ) _ d c a c h e _ c l e a n _ a r e a
.word cpu_ \ n a m e \ ( ) _ s w i t c h _ m m
.if \ nommu
.word 0
.else
.word cpu_ \ n a m e \ ( ) _ s e t _ p t e _ e x t
.endif
.if \ suspend
.word cpu_ \ n a m e \ ( ) _ s u s p e n d _ s i z e
2011-07-21 14:42:40 +01:00
# ifdef C O N F I G _ P M _ S L E E P
2011-06-23 17:07:40 +01:00
.word cpu_ \ n a m e \ ( ) _ d o _ s u s p e n d
.word cpu_ \ n a m e \ ( ) _ d o _ r e s u m e
2011-07-21 14:42:40 +01:00
# else
.word 0
.word 0
# endif
2011-06-23 17:07:40 +01:00
.else
.word 0
.word 0
.word 0
.endif
.size \ name\ ( ) _ p r o c e s s o r _ f u n c t i o n s , . - \ n a m e \ ( ) _ p r o c e s s o r _ f u n c t i o n s
.endm
.macro define_cache_functions name : req
.align 2
.type \ name\ ( ) _ c a c h e _ f n s , #o b j e c t
ENTRY( \ n a m e \ ( ) _ c a c h e _ f n s )
.long \ name\ ( ) _ f l u s h _ i c a c h e _ a l l
.long \ name\ ( ) _ f l u s h _ k e r n _ c a c h e _ a l l
2012-09-06 18:35:13 +05:30
.long \ name\ ( ) _ f l u s h _ k e r n _ c a c h e _ l o u i s
2011-06-23 17:07:40 +01:00
.long \ name\ ( ) _ f l u s h _ u s e r _ c a c h e _ a l l
.long \ name\ ( ) _ f l u s h _ u s e r _ c a c h e _ r a n g e
.long \ name\ ( ) _ c o h e r e n t _ k e r n _ r a n g e
.long \ name\ ( ) _ c o h e r e n t _ u s e r _ r a n g e
.long \ name\ ( ) _ f l u s h _ k e r n _ d c a c h e _ a r e a
.long \ name\ ( ) _ d m a _ m a p _ a r e a
.long \ name\ ( ) _ d m a _ u n m a p _ a r e a
.long \ name\ ( ) _ d m a _ f l u s h _ r a n g e
.size \ name\ ( ) _ c a c h e _ f n s , . - \ n a m e \ ( ) _ c a c h e _ f n s
.endm
.macro define_tlb_functions name : req, f l a g s _ u p : r e q , f l a g s _ s m p
.type \ name\ ( ) _ t l b _ f n s , #o b j e c t
ENTRY( \ n a m e \ ( ) _ t l b _ f n s )
.long \ name\ ( ) _ f l u s h _ u s e r _ t l b _ r a n g e
.long \ name\ ( ) _ f l u s h _ k e r n _ t l b _ r a n g e
.ifnb \ flags_ s m p
ALT_ S M P ( . l o n g \ f l a g s _ s m p )
ALT_ U P ( . l o n g \ f l a g s _ u p )
.else
.long \ flags_ u p
.endif
.size \ name\ ( ) _ t l b _ f n s , . - \ n a m e \ ( ) _ t l b _ f n s
.endm
2013-06-23 10:17:11 +01:00
.macro globl_equ x, y
.globl \ x
.equ \ x, \ y
.endm