Extend cache-l2x0 to support the 16-way PL310
PATCH 1/1 Extend cache-l2x0 to support the 16-way PL310
Support the PL310 16-way cache controller.
Also adds support for smaller than 8 way PL210 controllers.
This is the 2nd iteration. (forgot to mask out only the cache part ID bits).
Jason S. McMullan (1):
[arm l2x0] Extend cache-l2x0 to support the 16-way PL310
arch/arm/include/asm/hardware/cache-l2x0.h | 3 ++ arch/arm/mm/cache-l2x0.c | 30 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
PATCH 1/1 Extend cache-l2x0 to support the 16-way PL310
The L310 cache controller's interface is almost identical to the L210. One major difference is that the PL310 can have up to 16 ways.
This change uses the cache's part ID and the Assciativity bits in the AUX_CTRL register to determine the number of ways.
--- arch/arm/include/asm/hardware/cache-l2x0.h | 3 ++ arch/arm/mm/cache-l2x0.c | 30 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
arch/arm/include/asm/hardware/cache-l2x0.h +3 -0
@@ -21,6 +21,9 @@#define __ASM_ARM_HARDWARE_L2X0_H#define L2X0_CACHE_ID 0x000 +#define L2X0_CACHE_ID_PART_MASK (0xf << 6) +#define L2X0_CACHE_ID_PART_L210 (1 << 6) +#define L2X0_CACHE_ID_PART_L310 (3 << 6)#define L2X0_CACHE_TYPE 0x004#define L2X0_CTRL 0x100#define L2X0_AUX_CTRL 0x104
arch/arm/mm/cache-l2x0.c +26 -4
@@ -27,6 +27,7 @@static void __iomem *l2x0_base;static DEFINE_SPINLOCK (l2x0_lock); +static uint32_t l2x0_way_mask;/* Bitmask of active ways */ static inline void cache_wait (void __iomem *reg,unsigned long mask) {
@@ -106,10 +107,9 @@ static inline void l2x0_inv_all(void) {unsigned long flags; -/* invalidate all ways */ spin_lock_irqsave (&l2x0_lock, flags); -writel (0xff , l2x0_base +L2X0_INV_WAY ); -cache_wait (l2x0_base +L2X0_INV_WAY ,0xff ); +writel (l2x0_way_mask, l2x0_base +L2X0_INV_WAY ); +cache_wait (l2x0_base +L2X0_INV_WAY , l2x0_way_mask);cache_sync ();spin_unlock_irqrestore (&l2x0_lock, flags); }
@@ -217,10 +217,32 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)* accessing the below registers will fault. */ if (!(readl (l2x0_base +L2X0_CTRL ) &1 )) { +int ways; +uint32_t cache_id;/* l2x0 controller is disabled */ - + cache_id =readl (l2x0_base +L2X0_CACHE_ID ); aux =readl (l2x0_base +L2X0_AUX_CTRL ); + +/* Determine the number of ways */ +switch (cache_id &L2X0_CACHE_ID_PART_MASK ) { +case L2X0_CACHE_ID_PART_L310 : +if (aux & (1 <<16 )) + ways =16 ; +else + ways =8 ; +break ; +case L2X0_CACHE_ID_PART_L210 : + ways = (aux >>13 ) &0xf ; +break ; +default : +/* Assume unknown chips have 8 ways */ + ways =8 ; +break ; + } + + l2x0_way_mask = (1 << ways) -1 ; + aux &= aux_mask; aux |= aux_val;writel (aux, l2x0_base +L2X0_AUX_CTRL );
Signature · 1 line
1.7.0.4
PATCH 1/1 Extend cache-l2x0 to support the 16-way PL310
Hi Jason,
This is looking good. Some pedantry:
Quoted 15 lines
arch/arm/mm/cache-l2x0.c +1
-0@@ -27,6 +27,7 @@static void __iomem *l2x0_base;static DEFINE_SPINLOCK (l2x0_lock); +static uint32_t l2x0_way_mask;/* Bitmask of active ways */ static inline void cache_wait (void __iomem *reg,unsigned long mask) {@@ -106,10 +107,9 @@ static inline void l2x0_inv_all(void) {unsigned long flags;
arch/arm/mm/cache-l2x0.c static inline void l2x0_inv_all(void) · line 115
Quoted 10 lines
arch/arm/mm/cache-l2x0.c +2
-3-/* invalidate all ways */ spin_lock_irqsave (&l2x0_lock, flags); -writel (0xff , l2x0_base +L2X0_INV_WAY ); -cache_wait (l2x0_base +L2X0_INV_WAY ,0xff ); +writel (l2x0_way_mask, l2x0_base +L2X0_INV_WAY ); +cache_wait (l2x0_base +L2X0_INV_WAY , l2x0_way_mask);cache_sync ();spin_unlock_irqrestore (&l2x0_lock, flags); }
I think the comment can stay in the code as it's actually true now!
arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask) · line 221
Quoted 6 lines
arch/arm/mm/cache-l2x0.c +2
-0@@ -217,10 +217,32 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)* accessing the below registers will fault. */ if (!(readl (l2x0_base +L2X0_CTRL ) &1 )) { +int ways; +uint32_t cache_id;
These declarations should probably be at the top of the function. Actually, you could just assign to l2x0_way_mask directly. Also, l2x0.c appears to use the __u32 datatype instead of uint32_t or u32, so it's probably best just to follow suit.
Quoted 17 lines
arch/arm/mm/cache-l2x0.c +14
-1/* l2x0 controller is disabled */ - + cache_id =readl (l2x0_base +L2X0_CACHE_ID ); aux =readl (l2x0_base +L2X0_AUX_CTRL ); + +/* Determine the number of ways */ +switch (cache_id &L2X0_CACHE_ID_PART_MASK ) { +case L2X0_CACHE_ID_PART_L310 : +if (aux & (1 <<16 )) + ways =16 ; +else + ways =8 ; +break ; +case L2X0_CACHE_ID_PART_L210 : + ways = (aux >>13 ) &0xf ; +break ; +default :
arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask) · line 248
Quoted 10 lines
arch/arm/mm/cache-l2x0.c +7
-0+/* Assume unknown chips have 8 ways */ + ways =8 ; +break ; + } + + l2x0_way_mask = (1 << ways) -1 ; + aux &= aux_mask; aux |= aux_val;writel (aux, l2x0_base +L2X0_AUX_CTRL );
As Russell pointed out, it would be helpful to print out a message here [instead of "L2X0 cache controller enabled"], particularly if the chip is unknown and we assume an 8-way configuration. Printing out the part, number of ways and perhaps the auxiliary ctrl register would be useful.
Cheers,
Will
PATCH 1/1 Extend cache-l2x0 to support the 16-way PL310
In reply to Jason S. McMullanThe L310 cache controller's interface is almost identical to the L210. One major difference is that the PL310 can have up to 16 ways.
This change uses the cache's part ID and the Assciativity bits in the AUX_CTRL register to determine the number of ways.
--- arch/arm/include/asm/hardware/cache-l2x0.h | 3 ++ arch/arm/mm/cache-l2x0.c | 30 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
arch/arm/include/asm/hardware/cache-l2x0.h +3 -0
@@ -21,6 +21,9 @@#define __ASM_ARM_HARDWARE_L2X0_H#define L2X0_CACHE_ID 0x000 +#define L2X0_CACHE_ID_PART_MASK (0xf << 6) +#define L2X0_CACHE_ID_PART_L210 (1 << 6) +#define L2X0_CACHE_ID_PART_L310 (3 << 6)#define L2X0_CACHE_TYPE 0x004#define L2X0_CTRL 0x100#define L2X0_AUX_CTRL 0x104
arch/arm/mm/cache-l2x0.c +26 -4
@@ -27,6 +27,7 @@static void __iomem *l2x0_base;static DEFINE_SPINLOCK (l2x0_lock); +static uint32_t l2x0_way_mask;/* Bitmask of active ways */ static inline void cache_wait (void __iomem *reg,unsigned long mask) {
@@ -106,10 +107,9 @@ static inline void l2x0_inv_all(void) {unsigned long flags; -/* invalidate all ways */ spin_lock_irqsave (&l2x0_lock, flags); -writel (0xff , l2x0_base +L2X0_INV_WAY ); -cache_wait (l2x0_base +L2X0_INV_WAY ,0xff ); +writel (l2x0_way_mask, l2x0_base +L2X0_INV_WAY ); +cache_wait (l2x0_base +L2X0_INV_WAY , l2x0_way_mask);cache_sync ();spin_unlock_irqrestore (&l2x0_lock, flags); }
@@ -217,10 +217,32 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)* accessing the below registers will fault. */ if (!(readl (l2x0_base +L2X0_CTRL ) &1 )) { +int ways; +uint32_t cache_id;/* l2x0 controller is disabled */ - + cache_id =readl (l2x0_base +L2X0_CACHE_ID ); aux =readl (l2x0_base +L2X0_AUX_CTRL ); + +/* Determine the number of ways */ +switch (cache_id &L2X0_CACHE_ID_PART_MASK ) { +case L2X0_CACHE_ID_PART_L310 : +if (aux & (1 <<16 )) + ways =16 ; +else + ways =8 ; +break ; +case L2X0_CACHE_ID_PART_L210 : + ways = (aux >>13 ) &0xf ; +break ; +default : +/* Assume unknown chips have 8 ways */ + ways =8 ; +break ; + } + + l2x0_way_mask = (1 << ways) -1 ; + aux &= aux_mask; aux |= aux_val;writel (aux, l2x0_base +L2X0_AUX_CTRL );
Signature · 1 line
1.7.0.4