* [PATCH] MIPS: reloc: make flush_cache_all() usable
@ 2019-06-21 5:15 Antony Pavlov
2019-06-26 6:53 ` Sascha Hauer
0 siblings, 1 reply; 4+ messages in thread
From: Antony Pavlov @ 2019-06-21 5:15 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
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().
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
arch/mips/lib/reloc.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
index 14ba6167dd..6f1cd6d82f 100644
--- a/arch/mips/lib/reloc.c
+++ b/arch/mips/lib/reloc.c
@@ -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();
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: reloc: make flush_cache_all() usable
2019-06-21 5:15 [PATCH] MIPS: reloc: make flush_cache_all() usable Antony Pavlov
@ 2019-06-26 6:53 ` Sascha Hauer
2019-06-28 8:35 ` Antony Pavlov
0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2019-06-26 6:53 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox, Oleksij Rempel
Hi Antony,
On Fri, Jun 21, 2019 at 08:15:07AM +0300, Antony Pavlov wrote:
> 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().
>
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
> arch/mips/lib/reloc.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> index 14ba6167dd..6f1cd6d82f 100644
> --- a/arch/mips/lib/reloc.c
> +++ b/arch/mips/lib/reloc.c
> @@ -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();
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
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: reloc: make flush_cache_all() usable
2019-06-26 6:53 ` Sascha Hauer
@ 2019-06-28 8:35 ` Antony Pavlov
2019-07-01 7:41 ` Sascha Hauer
0 siblings, 1 reply; 4+ messages in thread
From: Antony Pavlov @ 2019-06-28 8:35 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox, Oleksij Rempel
On Wed, 26 Jun 2019 08:53:54 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:
> Hi Antony,
>
> On Fri, Jun 21, 2019 at 08:15:07AM +0300, Antony Pavlov wrote:
> > 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().
> >
> > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> > ---
> > arch/mips/lib/reloc.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> > diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> > index 14ba6167dd..6f1cd6d82f 100644
> > --- a/arch/mips/lib/reloc.c
> > +++ b/arch/mips/lib/reloc.c
> > @@ -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();
>
> Can we initialize one field in current_cpu_data to something nonzero so
> that it goes out of the bss?
Or clear only current_cpu_data and keep it in 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.
It's two diffrent bss segments: one before relocation and one after relocation.
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: reloc: make flush_cache_all() usable
2019-06-28 8:35 ` Antony Pavlov
@ 2019-07-01 7:41 ` Sascha Hauer
0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-07-01 7:41 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox, Oleksij Rempel
On Fri, Jun 28, 2019 at 11:35:45AM +0300, Antony Pavlov wrote:
> On Wed, 26 Jun 2019 08:53:54 +0200
> Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> > Hi Antony,
> >
> > On Fri, Jun 21, 2019 at 08:15:07AM +0300, Antony Pavlov wrote:
> > > 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().
> > >
> > > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> > > ---
> > > arch/mips/lib/reloc.c | 12 ++++++++++++
> > > 1 file changed, 12 insertions(+)
> > >
> > > diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> > > index 14ba6167dd..6f1cd6d82f 100644
> > > --- a/arch/mips/lib/reloc.c
> > > +++ b/arch/mips/lib/reloc.c
> > > @@ -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();
> >
> > Can we initialize one field in current_cpu_data to something nonzero so
> > that it goes out of the bss?
>
> Or clear only current_cpu_data and 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.
>
> > 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.
>
> 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
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-01 7:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21 5:15 [PATCH] MIPS: reloc: make flush_cache_all() usable Antony Pavlov
2019-06-26 6:53 ` Sascha Hauer
2019-06-28 8:35 ` Antony Pavlov
2019-07-01 7:41 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox