MIPS: reloc: make flush_cache_all() usable
PATCH 1/1 MIPS: reloc: make flush_cache_all() usable
flush_cache_all() uses 'struct cpuinfo_mips current_cpu_data' data fields. These data fields are initialized in r4k_cache_init().
However in the current implementation the r4k_cache_init() function is called __AFTER__ relocate_code().
--- arch/mips/lib/reloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/mips/lib/reloc.c +12 -0
@@ -37,6 +37,7 @@#include <asm/mipsregs.h> #include <asm/relocs.h> #include <asm/sections.h> +#include <asm/cpu-features.h> #include <linux/sizes.h> #include <asm-generic/memory_layout.h>
@@ -157,6 +158,17 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)apply_reloc (type, (void *)addr, off); } +/* clear the BSS first */ +memset (__bss_start,0x00 , bss_len); + +cpu_probe (); + +if (cpu_has_4k_cache) { +extern void r4k_cache_init (void ); + +r4k_cache_init (); + } +/* Ensure the icache is coherent */ flush_cache_all ();
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Antony,
Quoted 30 lines · Antony Pavlov
flush_cache_all()uses 'structcpuinfo_mipscurrent_cpu_data' data fields. These data fields are initialized inr4k_cache_init().However in the current implementation the
r4k_cache_init()function is called__AFTER__relocate_code().Signed-off-by Antony Pavlov <[email protected]>--- arch/mips/lib/reloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/mips/lib/reloc.c +4
-0@@ -37,6 +37,7 @@#include <asm/mipsregs.h> #include <asm/relocs.h> #include <asm/sections.h> +#include <asm/cpu-features.h> #include <linux/sizes.h> #include <asm-generic/memory_layout.h> @@ -157,6 +158,17 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)apply_reloc (type, (void *)addr, off); } +/* clear the BSS first */ +memset (__bss_start,0x00 , bss_len); +
arch/mips/lib/reloc.c void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) · line 173
Quoted 10 lines
arch/mips/lib/reloc.c +8
-0+cpu_probe (); + +if (cpu_has_4k_cache) { +extern void r4k_cache_init (void ); + +r4k_cache_init (); + } +/* Ensure the icache is coherent */ flush_cache_all ();
Can we initialize one field in current_cpu_data to something nonzero so that it goes out of the bss?
Another way would be to pass cpu_probe() a pointer to a struct cpuinfo_mips allocated on the stack and then pass it to flush_cache_all().
Clearing the bss twice doesn't look very nice.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 30 lines · On Wed, 26 Jun 2019 08:53:54 +0200 Sascha Hauer <[email protected]> wrote:
Hi Antony,
Quoted 27 lines · Antony Pavlov
flush_cache_all()uses 'structcpuinfo_mipscurrent_cpu_data' data fields. These data fields are initialized inr4k_cache_init().However in the current implementation the
r4k_cache_init()function is called__AFTER__relocate_code().Signed-off-by Antony Pavlov <[email protected]>--- arch/mips/lib/reloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/mips/lib/reloc.c +1
-0@@ -37,6 +37,7 @@#include <asm/mipsregs.h> #include <asm/relocs.h> #include <asm/sections.h> +#include <asm/cpu-features.h> #include <linux/sizes.h> #include <asm-generic/memory_layout.h> @@ -157,6 +158,17 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)apply_reloc (type, (void *)addr, off); }
Quoted 16 lines
arch/mips/lib/reloc.c void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) · line 173
Quoted 13 lines
arch/mips/lib/reloc.c +11
-0+/* clear the BSS first */ +memset (__bss_start,0x00 , bss_len); + +cpu_probe (); + +if (cpu_has_4k_cache) { +extern void r4k_cache_init (void ); + +r4k_cache_init (); + } +/* Ensure the icache is coherent */ flush_cache_all ();Can we initialize one field in
current_cpu_datato something nonzero so that it goes out of the bss?
Or clear only current_cpu_data and keep it in bss?
Quoted 5 lines
Another way would be to pass
cpu_probe()a pointer to a structcpuinfo_mipsallocated on the stack and then pass it toflush_cache_all().Clearing the bss twice doesn't look very nice.
It's two diffrent bss segments: one before relocation and one after relocation.
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 50 lines · Antony Pavlov
Quoted 30 lines · On Wed, 26 Jun 2019 08:53:54 +0200 Sascha Hauer <[email protected]> wrote:
Hi Antony,
Quoted 27 lines · Antony Pavlov
flush_cache_all()uses 'structcpuinfo_mipscurrent_cpu_data' data fields. These data fields are initialized inr4k_cache_init().However in the current implementation the
r4k_cache_init()function is called__AFTER__relocate_code().Signed-off-by Antony Pavlov <[email protected]>--- arch/mips/lib/reloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/mips/lib/reloc.c +1
-0@@ -37,6 +37,7 @@#include <asm/mipsregs.h> #include <asm/relocs.h> #include <asm/sections.h> +#include <asm/cpu-features.h> #include <linux/sizes.h> #include <asm-generic/memory_layout.h> @@ -157,6 +158,17 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)apply_reloc (type, (void *)addr, off); }Quoted 16 lines
arch/mips/lib/reloc.c void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) · line 173
Quoted 13 lines
arch/mips/lib/reloc.c +11
-0+/* clear the BSS first */ +memset (__bss_start,0x00 , bss_len); + +cpu_probe (); + +if (cpu_has_4k_cache) { +extern void r4k_cache_init (void ); + +r4k_cache_init (); + } +/* Ensure the icache is coherent */ flush_cache_all ();Can we initialize one field in
current_cpu_datato something nonzero so that it goes out of the bss?
Quoted 1 line
Or clear only
current_cpu_dataand keep it in bss?
That would at least make it clear why this is done.
That's important because otherwise some day somebody sends a patch "mips: remove duplicate clearing of bss" and I might apply it because it looks correct ;)
There might be one problem with putting current_cpu_data into bss. I don't know much about MIPS booting, but in case the initial image is located in some potentially small SRAM then putting current_cpu_data into bss means that the SRAM has to be big enough for initial image and bss.
Quoted 8 lines
Quoted 6 lines
Another way would be to pass
cpu_probe()a pointer to a structcpuinfo_mipsallocated on the stack and then pass it toflush_cache_all().Clearing the bss twice doesn't look very nice.
It's two diffrent bss segments: one before relocation and one after relocation.
Yes, I know, otherwise you could just drop the second bss clearing.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox