arm: Tidy up the cache aligning warning code
cover arm: Tidy up the cache aligning warning code
This series consolidates the code that warns about cache line alignment problems (with flush and invalidate). It adjusts it so that a warning is always displayed, except when building for SPL (since that bloats the code).
It is assumed that the cache is off in SPL.
Simon Glass (5):
arm: Move check_cache_range() into a common place
arm: Don't invalidate unaligned cache regions Add comments for debug() and pr_fmt
Add warn_non_spl() to show a message in U-Boot proper
arm: Show cache warnings in U-Boot proper only
arch/arm/cpu/arm11/cpu.c | 17 ----------------- arch/arm/cpu/arm926ejs/cache.c | 17 ----------------- arch/arm/cpu/armv7/cache_v7.c | 40 ++-------------------------------------- arch/arm/include/asm/cache.h | 2 ++ arch/arm/lib/cache.c | 22 ++++++++++++++++++++++ include/common.h | 12 ++++++++++++ 6 files changed, 38 insertions(+), 72 deletions(-)
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 1/5 arm: Move check_cache_range() into a common place
This code is common, so move it into a common file.
---
arch/arm/cpu/arm11/cpu.c | 17 ----------------- arch/arm/cpu/arm926ejs/cache.c | 17 ----------------- arch/arm/cpu/armv7/cache_v7.c | 17 ----------------- arch/arm/include/asm/cache.h | 2 ++ arch/arm/lib/cache.c | 22 ++++++++++++++++++++++ 5 files changed, 24 insertions(+), 51 deletions(-)
arch/arm/cpu/arm11/cpu.c +0 -17
@@ -69,23 +69,6 @@ void flush_dcache_all(void) asmvolatile ("mcr p15, 0, %0, c7, c10, 4" : :"r" (0 )); } -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -void invalidate_dcache_range (unsigned long start,unsigned long stop) {if (!check_cache_range (start, stop))
arch/arm/cpu/arm926ejs/cache.c +0 -17
@@ -29,23 +29,6 @@ void flush_dcache_all(void) ); } -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -void invalidate_dcache_range (unsigned long start,unsigned long stop) {if (!check_cache_range (start, stop))
arch/arm/cpu/armv7/cache_v7.c +0 -17
@@ -19,23 +19,6 @@void v7_flush_dcache_all (void );void v7_invalidate_dcache_all (void ); -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -static u32 get_ccsidr (void ) {u32 ccsidr;
arch/arm/include/asm/cache.h +2 -0
@@ -29,6 +29,8 @@ static inline void invalidate_l2_cache(void) }#endif +int check_cache_range (unsigned long start,unsigned long stop); +void l2_cache_enable (void );void l2_cache_disable (void );void set_section_dcache (int section,enum dcache_option option);
arch/arm/lib/cache.c +22 -0
@@ -10,6 +10,10 @@#include <common.h> #include <malloc.h> +#ifndef CONFIG_SYS_CACHELINE_SIZE +#define CONFIG_SYS_CACHELINE_SIZE 32 +#endif +/* * Flush range from all levels of d-cache/unified-cache. * Affects the range [start, start + size - 1].
@@ -46,6 +50,24 @@ __weak void flush_dcache_range(unsigned long start, unsigned long stop)/* An empty stub, real implementation should be in platform code */ } +int check_cache_range (unsigned long start,unsigned long stop) +{ +int ok =1 ; + +if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) + ok =0 ; + +if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) + ok =0 ; + +if (!ok) { +debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , + start, stop); + } + +return ok; +} +#ifdef CONFIG_SYS_NONCACHED_MEMORY /* * Reserve one MMU section worth of address space below the malloc() area that
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 1/5 arm: Move check_cache_range() into a common place
Quoted 3 lines · Simon Glass
This code is common, so move it into a common file.
Signed-off-by Simon Glass <[email protected]>
Quoted 147 lines
---
arch/arm/cpu/arm11/cpu.c | 17 ----------------- arch/arm/cpu/arm926ejs/cache.c | 17 ----------------- arch/arm/cpu/armv7/cache_v7.c | 17 ----------------- arch/arm/include/asm/cache.h | 2 ++ arch/arm/lib/cache.c | 22 ++++++++++++++++++++++ 5 files changed, 24 insertions(+), 51 deletions(-)arch/arm/cpu/arm11/cpu.c +0
-17@@ -69,23 +69,6 @@ void flush_dcache_all(void) asmvolatile ("mcr p15, 0, %0, c7, c10, 4" : :"r" (0 )); } -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -void invalidate_dcache_range (unsigned long start,unsigned long stop) {if (!check_cache_range (start, stop))arch/arm/cpu/arm926ejs/cache.c +0
-17@@ -29,23 +29,6 @@ void flush_dcache_all(void) ); } -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -void invalidate_dcache_range (unsigned long start,unsigned long stop) {if (!check_cache_range (start, stop))arch/arm/cpu/armv7/cache_v7.c +0
-17@@ -19,23 +19,6 @@void v7_flush_dcache_all (void );void v7_invalidate_dcache_all (void ); -static int check_cache_range (unsigned long start,unsigned long stop) -{ -int ok =1 ; - -if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) - ok =0 ; - -if (!ok) -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); - -return ok; -} -static u32 get_ccsidr (void ) {u32 ccsidr;arch/arm/include/asm/cache.h +2
-0@@ -29,6 +29,8 @@ static inline void invalidate_l2_cache(void) }#endif +int check_cache_range (unsigned long start,unsigned long stop); +void l2_cache_enable (void );void l2_cache_disable (void );void set_section_dcache (int section,enum dcache_option option);arch/arm/lib/cache.c +22
-0@@ -10,6 +10,10 @@#include <common.h> #include <malloc.h> +#ifndef CONFIG_SYS_CACHELINE_SIZE +#define CONFIG_SYS_CACHELINE_SIZE 32 +#endif +/* * Flush range from all levels of d-cache/unified-cache. * Affects the range [start, start + size - 1]. @@ -46,6 +50,24 @@ __weak void flush_dcache_range(unsigned long start, unsigned long stop)/* An empty stub, real implementation should be in platform code */ } +int check_cache_range (unsigned long start,unsigned long stop) +{ +int ok =1 ; + +if (start & (CONFIG_SYS_CACHELINE_SIZE -1 )) + ok =0 ; + +if (stop & (CONFIG_SYS_CACHELINE_SIZE -1 )) + ok =0 ; + +if (!ok) { +debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , + start, stop); + } + +return ok; +} +#ifdef CONFIG_SYS_NONCACHED_MEMORY /* * Reserve one MMU section worth of address space below the malloc() area that
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/5 arm: Move check_cache_range() into a common place
In reply to Simon GlassQuoted 4 lines · Simon Glass
This code is common, so move it into a common file.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Marek Vasut <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160716/b8444785/attachment.sig>
PATCH 2/5 arm: Don't invalidate unaligned cache regions
In reply to Simon GlassAt present armv7 will unhappily invalidate a cache region and print an error message. Make it skip the operation instead, as it does with other cache operations.
---
arch/arm/cpu/armv7/cache_v7.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
arch/arm/cpu/armv7/cache_v7.c +2 -21
@@ -44,27 +44,8 @@ static void v7_dcache_inval_range(u32 start, u32 stop, u32 line_len) {u32 mva; -/* -* If start address is not aligned to cache-line do not -* invalidate the first cache-line -*/ -if (start & (line_len -1 )) { -printf ("ERROR: %s - start address is not aligned - 0x%08x\n" , - __func__, start); -/* move to next cache line */ - start = (start + line_len -1 ) & ~(line_len -1 ); - } - -/* -* If stop address is not aligned to cache-line do not -* invalidate the last cache-line -*/ -if (stop & (line_len -1 )) { -printf ("ERROR: %s - stop address is not aligned - 0x%08x\n" , - __func__, stop); -/* align to the beginning of this cache line */ - stop &= ~(line_len -1 ); - } +if (!check_cache_range (start, stop)) +return ;for (mva = start; mva < stop; mva = mva + line_len) {/* DCIMVAC - Invalidate data cache by MVA to PoC */
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 2/5 arm: Don't invalidate unaligned cache regions
Quoted 5 lines · Simon Glass
At present armv7 will unhappily invalidate a cache region and print an error message. Make it skip the operation instead, as it does with other cache operations.
Signed-off-by Simon Glass <[email protected]>
Quoted 40 lines
---
arch/arm/cpu/armv7/cache_v7.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)arch/arm/cpu/armv7/cache_v7.c +2
-21@@ -44,27 +44,8 @@ static void v7_dcache_inval_range(u32 start, u32 stop, u32 line_len) {u32 mva; -/* -* If start address is not aligned to cache-line do not -* invalidate the first cache-line -*/ -if (start & (line_len -1 )) { -printf ("ERROR: %s - start address is not aligned - 0x%08x\n" , - __func__, start); -/* move to next cache line */ - start = (start + line_len -1 ) & ~(line_len -1 ); - } - -/* -* If stop address is not aligned to cache-line do not -* invalidate the last cache-line -*/ -if (stop & (line_len -1 )) { -printf ("ERROR: %s - stop address is not aligned - 0x%08x\n" , - __func__, stop); -/* align to the beginning of this cache line */ - stop &= ~(line_len -1 ); - } +if (!check_cache_range (start, stop)) +return ;for (mva = start; mva < stop; mva = mva + line_len) {/* DCIMVAC - Invalidate data cache by MVA to PoC */
Signature · 2 lines
Best regards, Marek Vasut
PATCH 2/5 arm: Don't invalidate unaligned cache regions
In reply to Simon GlassQuoted 6 lines · Simon Glass
At present armv7 will unhappily invalidate a cache region and print an error message. Make it skip the operation instead, as it does with other cache operations.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Marek Vasut <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160716/6d28152d/attachment.sig>
PATCH 3/5 Add comments for debug() and pr_fmt
In reply to Simon GlassAdd a note to each of these so it is more obvious how they work.
---
include/common.h | 2 ++ 1 file changed, 2 insertions(+)
include/common.h +2 -0
@@ -100,6 +100,7 @@ typedef volatile unsigned char vu_char;#define _DEBUG 0#endif +/* Define this at the top of a file to add a prefix to debug messages */ #ifndef pr_fmt#define pr_fmt (fmt) fmt#endif
@@ -115,6 +116,7 @@ typedef volatile unsigned char vu_char; printf(pr_fmt(fmt), ##args); \ } while (0) +/* Show a message if DEBUG is defined in a file */ #define debug(fmt, args...) \ debug_cond(_DEBUG, fmt, ##args)
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 3/5 Add comments for debug() and pr_fmt
Quoted 3 lines · Simon Glass
Add a note to each of these so it is more obvious how they work.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160716/a44da505/attachment.sig>
PATCH 4/5 Add warn_non_spl() to show a message in U-Boot proper
In reply to Simon GlassSPL tends to be more space-constrained that U-Boot proper. Some error messages are best suppressed in SPL. Add a macros to make this easy.
warn_non_spl() does nothing when built in SPL code.
---
include/common.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/common.h +10 -0
@@ -100,6 +100,12 @@ typedef volatile unsigned char vu_char;#define _DEBUG 0#endif +#ifdef CONFIG_SPL_BUILD +#define _SPL_BUILD 1 +#else +#define _SPL_BUILD 0 +#endif +/* Define this at the top of a file to add a prefix to debug messages */ #ifndef pr_fmt#define pr_fmt (fmt) fmt
@@ -120,6 +126,10 @@ typedef volatile unsigned char vu_char; #define debug(fmt, args...) \ debug_cond(_DEBUG, fmt, ##args) +/* Show a message if not in SPL */ +#define warn_non_spl(fmt, args...) \ + debug_cond(!_SPL_BUILD, fmt, ##args) +/* * An assertion is run-time check done in debug mode only. If DEBUG is not * defined then it is skipped. If DEBUG is defined and the assertion fails,
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 4/5 Add warn_non_spl() to show a message in U-Boot proper
Quoted 6 lines · Simon Glass
SPL tends to be more space-constrained that U-Boot proper. Some error messages are best suppressed in SPL. Add a macros to make this easy.
warn_non_spl()does nothing when built in SPL code.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160716/ff1eccc9/attachment.sig>
PATCH 5/5 arm: Show cache warnings in U-Boot proper only
In reply to Simon GlassAvoid bloating the SPL image size.
---
arch/arm/lib/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/lib/cache.c +2 -2
@@ -61,8 +61,8 @@ int check_cache_range(unsigned long start, unsigned long stop) ok =0 ;if (!ok) { -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); +warn_non_spl ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , + start, stop); }return ok;
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 5/5 arm: Show cache warnings in U-Boot proper only
Quoted 3 lines · Simon Glass
Avoid bloating the SPL image size.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160716/581a435b/attachment.sig>
PATCH 5/5 arm: Show cache warnings in U-Boot proper only
In reply to Simon GlassQuoted 13 lines · Simon Glass
Avoid bloating the SPL image size.
Signed-off-by Simon Glass <[email protected]>---
arch/arm/lib/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/lib/cache.c +0
-0
arch/arm/lib/cache.c int check_cache_range(unsigned long start, unsigned long stop) · line 68
Quoted 10 lines
arch/arm/lib/cache.c +2
-2@@ -61,8 +61,8 @@ int check_cache_range(unsigned long start, unsigned long stop) ok =0 ;if (!ok) { -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); +warn_non_spl ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , + start, stop); }return ok;
Since this i've, and probably many others, have a bunch of warnings on doing something in u-boot.
Just compiled and installed today new u-boot on my zynq-board.
"
U-Boot 2016.09-rc1-00353-g2ac625b-dirty (Aug 02 2016 - 08:06:57 +0200)
I2C: ready DRAM: ECC disabled 256 MiB MMC: sdhci at e0100000: 0 SF: Detected S25FL128S_64K with page size 256 Bytes, erase size 64 KiB, total 16 MiB FPGA: id 0x2 (7z010) Net: ZYNQ GEM: e000b000, phyaddr 0, interface rgmii-id
*CACHE: Misaligned operation at range [0fff03b0, 0fff03b4]*
Warning: ethernet at e000b000 (eth0) using random MAC address - aa:99:75:dd:1d:71
eth0: ethernet at e000b000
SF: Detected S25FL128S_64K with page size 256 Bytes, erase size 64 KiB, total 16 MiB
device 0 offset 0xc0000, size 0x10000
SF: 65536 bytes @ 0xc0000 Read: OK
## Executing script at 000c0000
=> dhcp
*CACHE: Misaligned operation at range [0eb583b0, 0eb583b4]** **CACHE: Misaligned operation at range [0eb583b4, 0eb583b8]* BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.21.193 (1008 ms)
=>
"
Do we have real trouble inside or can we quiet this warning?
cheers,
Hannes
PATCH 5/5 arm: Show cache warnings in U-Boot proper only
Hi,
Quoted 59 lines · Hannes Schmelzer
Quoted 13 lines · Simon Glass
Avoid bloating the SPL image size.
Signed-off-by Simon Glass <[email protected]>---
arch/arm/lib/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/lib/cache.c +0
-0arch/arm/lib/cache.c int check_cache_range(unsigned long start, unsigned · line 68
Quoted 10 lines
arch/arm/lib/cache.c +2
-2@@ -61,8 +61,8 @@ int check_cache_range(unsigned long start, unsigned long stop) ok =0 ;if (!ok) { -debug ("CACHE: Misaligned operation at range [%08lx, %08lx]\n" , - start, stop); + warn_non_spl("CACHE: Misaligned operation at range [%08lx, %08lx]\n", + start, stop); }return ok;Since this i've, and probably many others, have a bunch of warnings on doing something in u-boot.
Just compiled and installed today new u-boot on my zynq-board.
"
U-Boot 2016.09-rc1-00353-g2ac625b-dirty (Aug 02 2016 - 08:06:57 +0200)I2C: ready DRAM: ECC disabled 256 MiB MMC: sdhci at e0100000: 0 SF: Detected S25FL128S_64K with page size 256 Bytes, erase size 64 KiB, total 16 MiB FPGA: id 0x2 (7z010) Net: ZYNQ GEM: e000b000, phyaddr 0, interface rgmii-id*CACHE: Misaligned operation at range [
0fff03b0, 0fff03b4]*Warning: ethernet at
e000b000(eth0) using random MAC address - aa:99:75:dd:1d:71
eth0: ethernet ate000b000
SF: DetectedS25FL128S_64Kwith page size 256 Bytes, erase size 64 KiB, total 16 MiB
device 0 offset0xc0000, size0x10000
SF: 65536 bytes @0xc0000Read: OK
## Executing script at000c0000
=> dhcp
*CACHE: Misaligned operation at range [0eb583b0, 0eb583b4]** **CACHE: Misaligned operation at range [0eb583b4, 0eb583b8]* BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.21.193 (1008 ms)
=>
"
Quoted 1 line
Do we have real trouble inside or can we quiet this warning?
I have seen it too. Look at gem driver which is flushing cache which is not aligned. There must be some changes in the code to remove these warnings. Also worth to add this to test/py to capture it in future.
Thanks,
Michal
Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP SoCs -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160802/fc6e152d/attachment.sig>