2005-04-16 15:20:36 -07:00
/ *
* Low- l e v e l S L B r o u t i n e s
*
* Copyright ( C ) 2 0 0 4 D a v i d G i b s o n < d w g @au.ibm.com>, IBM
*
* Based o n e a r l i e r C v e r s i o n :
* Dave E n g e b r e t s e n a n d M i k e C o r r i g a n { e n g e b r e t | m i k e j c } @us.ibm.com
* Copyright ( c ) 2 0 0 1 D a v e E n g e b r e t s e n
* Copyright ( C ) 2 0 0 2 A n t o n B l a n c h a r d < a n t o n @au.ibm.com>, IBM
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
* /
# include < a s m / p r o c e s s o r . h >
# include < a s m / p p c _ a s m . h >
2005-09-09 20:57:26 +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 / c p u t a b l e . h >
2005-11-07 11:06:55 +11:00
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
2006-09-25 18:19:00 +10:00
# include < a s m / f i r m w a r e . h >
2005-04-16 15:20:36 -07:00
2005-11-07 11:06:55 +11:00
/ * void s l b _ a l l o c a t e _ r e a l m o d e ( u n s i g n e d l o n g e a ) ;
2005-04-16 15:20:36 -07:00
*
* Create a n S L B e n t r y f o r t h e g i v e n E A ( u s e r o r k e r n e l ) .
* r3 = f a u l t i n g a d d r e s s , r13 = P A C A
* r9 , r10 , r11 a r e c l o b b e r e d b y t h i s f u n c t i o n
* No o t h e r r e g i s t e r s a r e e x a m i n e d o r c h a n g e d .
* /
2005-11-07 11:06:55 +11:00
_ GLOBAL( s l b _ a l l o c a t e _ r e a l m o d e )
/* r3 = faulting address */
2005-04-16 15:20:36 -07:00
srdi r9 ,r3 ,6 0 / * g e t r e g i o n * /
2005-11-07 11:06:55 +11:00
srdi r10 ,r3 ,2 8 / * g e t e s i d * /
2005-12-05 10:24:33 -06:00
cmpldi c r7 ,r9 ,0 x c / * c m p P A G E _ O F F S E T f o r l a t e r u s e * /
2005-04-16 15:20:36 -07:00
2005-12-05 10:24:33 -06:00
/* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */
2005-04-16 15:20:36 -07:00
blt c r7 ,0 f / * u s e r o r k e r n e l ? * /
/* kernel address: proto-VSID = ESID */
/ * WARNING - M A G I C : w e d o n ' t u s e t h e V S I D 0 x f f f f f f f f f , b u t
* this c o d e w i l l g e n e r a t e t h e p r o t o V S I D 0 x f f f f f f f f f f o r t h e
* top s e g m e n t . T h a t ' s o k , t h e s c r a m b l e b e l o w w i l l t r a n s l a t e
* it t o V S I D 0 , w h i c h i s r e s e r v e d a s a b a d V S I D - o n e w h i c h
* will n e v e r h a v e a n y p a g e s i n i t . * /
2005-11-07 11:06:55 +11:00
/ * Check i f h i t t i n g t h e l i n e a r m a p p i n g o f t h e v m a l l o c / i o r e m a p
* kernel s p a c e
* /
bne c r7 ,1 f
/ * Linear m a p p i n g e n c o d i n g b i t s , t h e " l i " i n s t r u c t i o n b e l o w w i l l
* be p a t c h e d b y t h e k e r n e l a t b o o t
* /
_ GLOBAL( s l b _ m i s s _ k e r n e l _ l o a d _ l i n e a r )
li r11 ,0
b s l b _ f i n i s h _ l o a d
2006-06-15 10:45:18 +10:00
1 : / * vmalloc/ i o r e m a p m a p p i n g e n c o d i n g b i t s , t h e " l i " i n s t r u c t i o n s b e l o w
2005-11-07 11:06:55 +11:00
* will b e p a t c h e d b y t h e k e r n e l a t b o o t
* /
2006-06-15 10:45:18 +10:00
BEGIN_ F T R _ S E C T I O N
/* check whether this is in vmalloc or ioremap space */
clrldi r11 ,r10 ,4 8
cmpldi r11 ,( V M A L L O C _ S I Z E > > 2 8 ) - 1
bgt 5 f
lhz r11 ,P A C A V M A L L O C S L L P ( r13 )
b s l b _ f i n i s h _ l o a d
5 :
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ C I _ L A R G E _ P A G E )
_ GLOBAL( s l b _ m i s s _ k e r n e l _ l o a d _ i o )
2005-11-07 11:06:55 +11:00
li r11 ,0
b s l b _ f i n i s h _ l o a d
0 : / * user a d d r e s s : p r o t o - V S I D = c o n t e x t < < 1 5 | E S I D . F i r s t c h e c k
* if t h e a d d r e s s i s w i t h i n t h e b o u n d a r i e s o f t h e u s e r r e g i o n
* /
srdi. r9 ,r10 ,U S E R _ E S I D _ B I T S
2005-04-16 15:20:36 -07:00
bne- 8 f / * i n v a l i d e a b i t s s e t * /
2007-05-08 16:27:27 +10:00
/ * when u s i n g s l i c e s , w e e x t r a c t t h e p s i z e o f f t h e s l i c e b i t m a p s
* and t h e n w e n e e d t o g e t t h e s l l p e n c o d i n g o f f t h e m m u _ p s i z e _ d e f s
* array.
*
* XXX T h i s i s a b i t i n e f f i c i e n t e s p e c i a l l y f o r t h e n o r m a l c a s e ,
* so w e s h o u l d t r y t o i m p l e m e n t a f a s t p a t h f o r t h e s t a n d a r d p a g e
* size u s i n g t h e o l d s l l p v a l u e s o w e a v o i d t h e a r r a y . W e c a n n o t
* really d o d y n a m i c p a t c h i n g u n f o r t u n a t e l y a s p r o c e s s e s m i g h t f l i p
* between 4 k a n d 6 4 k s t a n d a r d p a g e s i z e
* /
# ifdef C O N F I G _ P P C _ M M _ S L I C E S
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 00:57:52 -08:00
cmpldi r10 ,1 6
2007-05-08 16:27:27 +10:00
/* Get the slice index * 4 in r11 and matching slice size mask in r9 */
ld r9 ,P A C A L O W S L I C E S P S I Z E ( r13 )
sldi r11 ,r10 ,2
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 00:57:52 -08:00
blt 5 f
2007-05-08 16:27:27 +10:00
ld r9 ,P A C A H I G H S L I C E P S I Z E ( r13 )
srdi r11 ,r10 ,( S L I C E _ H I G H _ S H I F T - S L I C E _ L O W _ S H I F T - 2 )
andi. r11 ,r11 ,0 x3 c
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 00:57:52 -08:00
2007-05-08 16:27:27 +10:00
5 : /* Extract the psize and multiply to get an array offset */
srd r9 ,r9 ,r11
andi. r9 ,r9 ,0 x f
mulli r9 ,r9 ,M M U P S I Z E D E F S I Z E
2005-08-11 16:55:21 +10:00
2007-05-08 16:27:27 +10:00
/ * Now g e t t o t h e a r r a y a n d o b t a i n t h e s l l p
* /
ld r11 ,P A C A T O C ( r13 )
ld r11 ,m m u _ p s i z e _ d e f s @got(r11)
add r11 ,r11 ,r9
ld r11 ,M M U P S I Z E S L L P ( r11 )
ori r11 ,r11 ,S L B _ V S I D _ U S E R
# else
/* paca context sllp already contains the SLB_VSID_USER bits */
2006-06-15 10:45:18 +10:00
lhz r11 ,P A C A C O N T E X T S L L P ( r13 )
2007-05-08 16:27:27 +10:00
# endif / * C O N F I G _ P P C _ M M _ S L I C E S * /
2005-11-07 11:06:55 +11:00
ld r9 ,P A C A C O N T E X T I D ( r13 )
rldimi r10 ,r9 ,U S E R _ E S I D _ B I T S ,0
b s l b _ f i n i s h _ l o a d
8 : /* invalid EA */
li r10 ,0 / * B A D _ V S I D * /
li r11 ,S L B _ V S I D _ U S E R / * f l a g s d o n ' t m u c h m a t t e r * /
b s l b _ f i n i s h _ l o a d
# ifdef _ _ D I S A B L E D _ _
/ * void s l b _ a l l o c a t e _ u s e r ( u n s i g n e d l o n g e a ) ;
*
* Create a n S L B e n t r y f o r t h e g i v e n E A ( u s e r o r k e r n e l ) .
* r3 = f a u l t i n g a d d r e s s , r13 = P A C A
* r9 , r10 , r11 a r e c l o b b e r e d b y t h i s f u n c t i o n
* No o t h e r r e g i s t e r s a r e e x a m i n e d o r c h a n g e d .
*
* It i s c a l l e d w i t h t r a n s l a t i o n e n a b l e d i n o r d e r t o b e a b l e t o w a l k t h e
* page t a b l e s . T h i s i s n o t c u r r e n t l y u s e d .
* /
_ GLOBAL( s l b _ a l l o c a t e _ u s e r )
/* r3 = faulting address */
srdi r10 ,r3 ,2 8 / * g e t e s i d * /
crset 4 * c r7 + l t / * s e t " u s e r " f l a g f o r l a t e r * /
/* check if we fit in the range covered by the pagetables*/
srdi. r9 ,r3 ,P G T A B L E _ E A D D R _ S I Z E
crnot 4 * c r0 + e q ,4 * c r0 + e q
beqlr
2005-04-16 15:20:36 -07:00
2005-11-07 11:06:55 +11:00
/ * now w e n e e d t o g e t t o t h e p a g e t a b l e s i n o r d e r t o g e t t h e p a g e
* size e n c o d i n g f r o m t h e P M D . I n t h e f u t u r e , w e ' l l b e a b l e t o d e a l
* with 1 T s e g m e n t s t o o b y g e t t i n g t h e e n c o d i n g f r o m t h e P G D i n s t e a d
* /
ld r9 ,P A C A P G D I R ( r13 )
cmpldi c r0 ,r9 ,0
beqlr
rlwinm r11 ,r10 ,8 ,2 5 ,2 8
ldx r9 ,r9 ,r11 / * g e t p g d _ t * /
cmpldi c r0 ,r9 ,0
beqlr
rlwinm r11 ,r10 ,3 ,1 7 ,2 8
ldx r9 ,r9 ,r11 / * g e t p m d _ t * /
cmpldi c r0 ,r9 ,0
beqlr
/* build vsid flags */
andi. r11 ,r9 ,S L B _ V S I D _ L L P
ori r11 ,r11 ,S L B _ V S I D _ U S E R
/* get context to calculate proto-VSID */
2005-08-31 14:34:05 +10:00
ld r9 ,P A C A C O N T E X T I D ( r13 )
2005-11-07 11:06:55 +11:00
rldimi r10 ,r9 ,U S E R _ E S I D _ B I T S ,0
/* fall through slb_finish_load */
# endif / * _ _ D I S A B L E D _ _ * /
2005-04-16 15:20:36 -07:00
2005-11-07 11:06:55 +11:00
/ *
* Finish l o a d i n g o f a n S L B e n t r y a n d r e t u r n
*
2005-12-05 10:24:33 -06:00
* r3 = E A , r10 = p r o t o - V S I D , r11 = f l a g s , c l o b b e r s r9 , c r7 = < > P A G E _ O F F S E T
2005-11-07 11:06:55 +11:00
* /
slb_finish_load :
ASM_ V S I D _ S C R A M B L E ( r10 ,r9 )
rldimi r11 ,r10 ,S L B _ V S I D _ S H I F T ,1 6 / * c o m b i n e V S I D a n d f l a g s * /
/* r3 = EA, r11 = VSID data */
/ *
* Find a s l o t , r o u n d r o b i n . P r e v i o u s l y w e t r i e d t o f i n d a
* free s l o t f i r s t b u t t h a t t o o k t o o l o n g . U n f o r t u n a t e l y w e
* dont h a v e a n y L R U i n f o r m a t i o n t o h e l p u s c h o o s e a s l o t .
* /
# ifdef C O N F I G _ P P C _ I S E R I E S
2006-09-25 18:19:00 +10:00
BEGIN_ F W _ F T R _ S E C T I O N
2005-11-07 11:06:55 +11:00
/ *
* On i S e r i e s , t h e " b o l t e d " s t a c k s e g m e n t c a n b e c a s t o u t o n
* shared p r o c e s s o r s w i t c h s o w e n e e d t o c h e c k f o r a m i s s o n
* it a n d r e s t o r e i t t o t h e r i g h t s l o t .
* /
ld r9 ,P A C A K S A V E ( r13 )
clrrdi r9 ,r9 ,2 8
clrrdi r3 ,r3 ,2 8
li r10 ,S L B _ N U M _ B O L T E D - 1 / * S t a c k g o e s i n l a s t b o l t e d s l o t * /
cmpld r9 ,r3
beq 3 f
2006-09-25 18:19:00 +10:00
END_ F W _ F T R _ S E C T I O N _ I F S E T ( F W _ F E A T U R E _ I S E R I E S )
2005-11-07 11:06:55 +11:00
# endif / * C O N F I G _ P P C _ I S E R I E S * /
ld r10 ,P A C A S T A B R R ( r13 )
addi r10 ,r10 ,1
/* use a cpu feature mask if we ever change our slb size */
cmpldi r10 ,S L B _ N U M _ E N T R I E S
blt+ 4 f
li r10 ,S L B _ N U M _ B O L T E D
4 :
std r10 ,P A C A S T A B R R ( r13 )
3 :
rldimi r3 ,r10 ,0 ,3 6 / * r3 = E A [ 0 : 3 5 ] | e n t r y * /
oris r10 ,r3 ,S L B _ E S I D _ V @h /* r3 |= SLB_ESID_V */
/* r3 = ESID data, r11 = VSID data */
2005-04-16 15:20:36 -07:00
/ *
* No n e e d f o r a n i s y n c b e f o r e o r a f t e r t h i s s l b m t e . T h e e x c e p t i o n
* we e n t e r w i t h a n d t h e r f i d w e e x i t w i t h a r e c o n t e x t s y n c h r o n i z i n g .
* /
slbmte r11 ,r10
2005-11-07 11:06:55 +11:00
/* we're done for kernel addresses */
crclr 4 * c r0 + e q / * s e t r e s u l t t o " s u c c e s s " * /
bgelr c r7
2005-04-16 15:20:36 -07:00
/* Update the slb cache */
lhz r3 ,P A C A S L B C A C H E P T R ( r13 ) / * o f f s e t = p a c a - > s l b _ c a c h e _ p t r * /
cmpldi r3 ,S L B _ C A C H E _ E N T R I E S
bge 1 f
/* still room in the slb cache */
sldi r11 ,r3 ,1 / * r11 = o f f s e t * s i z e o f ( u 1 6 ) * /
rldicl r10 ,r10 ,3 6 ,2 8 / * g e t l o w 1 6 b i t s o f t h e E S I D * /
add r11 ,r11 ,r13 / * r11 = ( u 1 6 * ) p a c a + o f f s e t * /
sth r10 ,P A C A S L B C A C H E ( r11 ) / * p a c a - > s l b _ c a c h e [ o f f s e t ] = e s i d * /
addi r3 ,r3 ,1 / * o f f s e t + + * /
b 2 f
1 : /* offset >= SLB_CACHE_ENTRIES */
li r3 ,S L B _ C A C H E _ E N T R I E S + 1
2 :
sth r3 ,P A C A S L B C A C H E P T R ( r13 ) / * p a c a - > s l b _ c a c h e _ p t r = o f f s e t * /
2005-11-07 11:06:55 +11:00
crclr 4 * c r0 + e q / * s e t r e s u l t t o " s u c c e s s " * /
2005-04-16 15:20:36 -07:00
blr