sparc32: make srmmu helpers leon compatible
RFC PATCH 1/1 sparc32: make srmmu helpers leon compatible
I am trying to make the saprc32 kernel compatible with leon and sun4m, sun4d boxes at the same time.
The stuff in arch/sparc/mm/ looked like the simplest to fix so I looked at that first.
Some of the helper functions used ASI_M_MMUREGS which is redefiend to 0x19 in the LEON case - so these functions needs some special care.
I was originally planning to use the cpuid_patch support to deal with the differences - but this is only in place _after_ we have initialised the mmu.
But sparc_cpu_model is set before we initialize the mmu, so we could use that.
I came up with the following that I am not too happy with... Some of the functions are really not used by leon, but I converted all to be complete.
Any better ideas?
Could we call per_cpu_patch() before paging_init() maybe?
The patch below depends on other changes I only have in my tree - to be submitted if/when ready.
Sam
arch/sparc/include/asm/cpu_type.h +2 -0
@@ -1,6 +1,7 @@#ifndef __ASM_CPU_TYPE_H#define __ASM_CPU_TYPE_H +#ifndef __ASSEMBLY__/* * Sparc (general) CPU types */
@@ -25,4 +26,5 @@ extern enum sparc_cpu sparc_cpu_model;#endif +#endif /* __ASSEMBLY__ */ #endif /* __ASM_CPU_TYPE_H */
arch/sparc/include/asm/pgtsrmmu.h +74 -22
140 lines not on this page · raw message
David Miller
maintainerFrom: Sam Ravnborg <[email protected]>
Date: Sat, 19 May 2012 22:03:21 +0200
Quoted 1 line
Could we call
per_cpu_patch()beforepaging_init()maybe?
You definitely want to patch this since it's just the ASI value in the loads and stores.
But the reason we have to invoke per_cpu_patch() after paging_init() is that we need the cache flushing operations hooked up.
Otherwise we can't flush the instruction cache properly.
Actually...
The way we do that now is overkill. We only needed to use the MMU cache ops when we had sun4c around because sun4c lacked support for the "flush" instruction.
But all sun4m and later chips have it so we can use it unconditionally.
So in the per_cpu_patch() code, get rid of the cache ops invocation, and instead execute a "flush %reg" after each of the instruction patch assignments, where %reg is set to the address of the instruction that was stored into.
Perhaps take the flushi() definition from asm/cacheflush_64.h and place it into asm/cacheflush.h, then you can simply use that.
We can then use it to do things like make kprobes and jump_label work on sparc32.
Quoted 7 lines · David Miller
From: Sam Ravnborg <[email protected]>
Date: Sat, 19 May 2012 22:03:21 +0200Quoted 1 line
Could we call
per_cpu_patch()beforepaging_init()maybe?You definitely want to patch this since it's just the ASI value in the loads and stores.
This is what I came up with - on top of the other patches I sent which introduced flushi().
Only RFC for now - I plan to submit a longer set
of patches that does most of the work to allow leon
to be used in parallel with the sun platfroms.
The sparc64 code I copied the run-time patching from used the following sequence for flushing the ICache:
wmb();
__asm__ __volatile__("flush %0" : : "r" (addr + 0));Compare this to the flushi() variant:
#define flushi(addr) __asm__ __volatile__ ("flush %0" : : "r" (addr) : "memory")
As far as I understand the macros "wmb()" is just another way to tell gcc what it may do. And the "memory" clobber in flushi() serve the same purpose as wmb().
On sparc64 wmb() is: __asm__ __volatile__("":::"memory")
One could introduce flushi() in the relevant functions in setup_64.c..
Sam
From bb1d384e188e67eea65f3499ceb3acb847b90541 Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 22:31:44 +0200
Subject: [PATCH] sparc32: introduce run-time patching of srmmu access functions
LEON uses a different ASI than SUN for MMUREGS To handle this introduce a dedicated run-time patching for the functions which uses MMUREGS ASI.
--- arch/sparc/include/asm/pgtsrmmu.h | 68 ++-------------------- arch/sparc/include/asm/sections.h | 3 + arch/sparc/kernel/setup_32.c | 25 ++++++++ arch/sparc/kernel/vmlinux.lds.S | 5 ++ arch/sparc/mm/Makefile | 1 + arch/sparc/mm/srmmu_access.S | 112 +++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 61 deletions(-) create mode 100644 arch/sparc/mm/srmmu_access.S
arch/sparc/include/asm/pgtsrmmu.h +7 -61
@@ -148,67 +148,13 @@ extern void *srmmu_nocache_pool;#define __nocache_fix (VADDR ) __va(__nocache_pa(VADDR))/* Accessing the MMU control register. */ -static inline unsigned int srmmu_get_mmureg (void ) -{ -unsigned int retval; - __asm__ __volatile__("lda [%%g0] %1, %0\n\t" : -"=r" (retval) : -"i" (ASI_M_MMUREGS )); -return retval; -} - -static inline void srmmu_set_mmureg (unsigned long regval) -{ - __asm__ __volatile__("sta %0, [%%g0] %1\n\t" : : -"r" (regval),"i" (ASI_M_MMUREGS ) :"memory" ); - -} - -static inline void srmmu_set_ctable_ptr (unsigned long paddr) -{ - paddr = ((paddr >>4 ) &SRMMU_CTX_PMASK ); - __asm__ __volatile__("sta %0, [%1] %2\n\t" : : -"r" (paddr),"r" (SRMMU_CTXTBL_PTR ), -"i" (ASI_M_MMUREGS ) : -"memory" ); -} - -static inline void srmmu_set_context (int context) -{ - __asm__ __volatile__("sta %0, [%1] %2\n\t" : : -"r" (context),"r" (SRMMU_CTX_REG ), -"i" (ASI_M_MMUREGS ) :"memory" ); -} - -static inline int srmmu_get_context (void ) -{ - registerint retval; - __asm__ __volatile__("lda [%1] %2, %0\n\t" : -"=r" (retval) : -"r" (SRMMU_CTX_REG ), -"i" (ASI_M_MMUREGS )); -return retval; -} - -static inline unsigned int srmmu_get_fstatus (void ) -{ -unsigned int retval; - - __asm__ __volatile__("lda [%1] %2, %0\n\t" : -"=r" (retval) : -"r" (SRMMU_FAULT_STATUS ),"i" (ASI_M_MMUREGS )); -return retval; -} - -static inline unsigned int srmmu_get_faddr (void ) -{ -unsigned int retval; - - __asm__ __volatile__("lda [%1] %2, %0\n\t" : -"=r" (retval) : -"r" (SRMMU_FAULT_ADDR ),"i" (ASI_M_MMUREGS )); -return retval; -} +unsigned int srmmu_get_mmureg (void ); +void srmmu_set_mmureg (unsigned long regval); +void srmmu_set_ctable_ptr (unsigned long paddr); +void srmmu_set_context (int context); +int srmmu_get_context (void ); +unsigned int srmmu_get_fstatus (void ); +unsigned int srmmu_get_faddr (void );/* This is guaranteed on all SRMMU's. */ static inline void srmmu_flush_whole_tlb (void )
arch/sparc/include/asm/sections.h +3 -0
@@ -7,4 +7,7 @@/* sparc entry point */ extern char _start[]; +extern char __leon_1insn_patch[]; +extern char __leon_1insn_patch_end[]; +#endif
arch/sparc/kernel/setup_32.c +25 -0
@@ -45,6 +45,7 @@#include <asm/cpudata.h> #include <asm/setup.h> #include <asm/cacheflush.h> +#include <asm/sections.h> #include "kernel.h"
@@ -237,6 +238,29 @@ static void __init per_cpu_patch(void) } } +struct leon_1insn_patch_entry { +unsigned int addr; +unsigned int insn; +}; + +static void leon_patch (void ) +{ +struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch; +struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end; + +if (sparc_cpu_model != sparc_leon) +return ; + +while (start < end) { +unsigned long addr = start->addr; + + *(unsigned int *) (addr +0 ) = start->insn; +flushi (addr); + + start++; + } +} +enum sparc_cpu sparc_cpu_model;EXPORT_SYMBOL (sparc_cpu_model);
@@ -340,6 +364,7 @@ void __init setup_arch(char **cmdline_p)/* Run-time patch instructions to match the cpu model */ per_cpu_patch (); +leon_patch ();paging_init ();
arch/sparc/kernel/vmlinux.lds.S +5 -0
@@ -107,6 +107,11 @@ SECTIONS *(.sun4v_2insn_patch) __sun4v_2insn_patch_end = .; } + .leon_1insn_patch : { + __leon_1insn_patch = .; + *(.leon_1insn_patch) + __leon_1insn_patch_end = .; + } .swapper_tsb_phys_patch : { __swapper_tsb_phys_patch = .; *(.swapper_tsb_phys_patch)
arch/sparc/mm/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o obj-y += fault_$(BITS).o obj-y += init_$(BITS).o obj-$(CONFIG_SPARC32) += extable.o srmmu.o iommu.o io-unit.o +obj-$(CONFIG_SPARC32) += srmmu_access.o obj-$(CONFIG_SPARC32) += hypersparc.o viking.o tsunami.o swift.o obj-$(CONFIG_SPARC_LEON)+= leon_mm.o
arch/sparc/mm/srmmu_access.S new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.6.0.6
David Miller
maintainerFrom: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 22:44:47 +0200
Quoted 5 lines
This is what I came up with - on top of the other patches I sent which introduced
flushi().
Only RFC for now - I plan to submit a longer set
of patches that does most of the work to allow leon
to be used in parallel with the sun platfroms.
Looks great. If you want to get fancy you can write a macro for the whole section dance and LEON insn entry stuff.
Quoted 9 lines
The sparc64 code I copied the run-time patching from used the following sequence for flushing the ICache:
wmb(); __asm__ __volatile__("flush %0" : : "r" (addr + 0));Compare this to the
flushi()variant:
#define flushi(addr)__asm____volatile__("flush %0" : : "r" (addr) : "memory")
Quoted 7 lines
As far as I understand the macros "
wmb()" is just another way to tell gcc what it may do. And the "memory" clobber influshi()serve the same purpose aswmb().On sparc64
wmb()is:__asm____volatile__("":::"memory")One could introduce
flushi()in the relevant functions insetup_64.c..
On sparc64wmb() used to actually do something, with a membar (MEMory BARrier) instruction, which sparc32 doesn't have and doesn't need.
Quoted 3 lines
Looks great. If you want to get fancy you can write a macro for the whole section dance and LEON insn entry stuff.
Thanks for the quick feedback!
As we need this in several places being fancy would be good. So I updated the patch.
I like how the two implementations are now much simpler to compare:
SUN_INS(lda [%g0] ASI_M_MMUREGS, %o0)LEON_IN(lda [%g0] ASI_LEON_MMUREGS, %o0)
If I fool around with %g0 versus %o0 it will scream at me. And getting rid of the line-nose is good too!
I deliberatly used 8 letter names to avoid breaking the indentation in the code.
Updated RFC patch below.
Sam
From d7773fd2e4f81e63dcccc1db3753a1433ce1e19d Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 22:31:44 +0200
Subject: [PATCH] sparc32: introduce run-time patching of srmmu access functions
LEON uses a different ASI than SUN for MMUREGS To handle this introduce a dedicated run-time patching for the functions which uses MMUREGS ASI.
--- arch/sparc/include/asm/asmmacro.h | 9 ++++ arch/sparc/include/asm/pgtsrmmu.h | 68 +++--------------------------- arch/sparc/include/asm/sections.h | 3 + arch/sparc/kernel/setup_32.c | 25 +++++++++++ arch/sparc/kernel/vmlinux.lds.S | 5 ++ arch/sparc/mm/Makefile | 1 + arch/sparc/mm/srmmu_access.S | 82 +++++++++++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 61 deletions(-) create mode 100644 arch/sparc/mm/srmmu_access.S
arch/sparc/include/asm/asmmacro.h +9 -0
@@ -20,4 +20,13 @@/* All traps low-level code here must end with this macro. */ #define RESTORE_ALL b ret_trap_entry; clr %l6; +#define SUN_INS (...) \ +662: __VA_ARGS__ + +#define LEON_IN (...) \ + .section leon_1insn_patch, "ax"; \ + .word 662b; \ + __VA_ARGS__; \ + .previous +#endif /* !(_SPARC_ASMMACRO_H) */
arch/sparc/include/asm/pgtsrmmu.h +7 -61
74 lines not on this page · raw message
arch/sparc/include/asm/sections.h +3 -0
@@ -7,4 +7,7 @@/* sparc entry point */ extern char _start[]; +extern char __leon_1insn_patch[]; +extern char __leon_1insn_patch_end[]; +#endif
arch/sparc/kernel/setup_32.c +25 -0
@@ -45,6 +45,7 @@#include <asm/cpudata.h> #include <asm/setup.h> #include <asm/cacheflush.h> +#include <asm/sections.h> #include "kernel.h"
@@ -237,6 +238,29 @@ static void __init per_cpu_patch(void) } } +struct leon_1insn_patch_entry { +unsigned int addr; +unsigned int insn; +}; + +static void leon_patch (void ) +{ +struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch; +struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end; + +if (sparc_cpu_model != sparc_leon) +return ; + +while (start < end) { +unsigned long addr = start->addr; + + *(unsigned int *) (addr +0 ) = start->insn; +flushi (addr); + + start++; + } +} +enum sparc_cpu sparc_cpu_model;EXPORT_SYMBOL (sparc_cpu_model);
@@ -340,6 +364,7 @@ void __init setup_arch(char **cmdline_p)/* Run-time patch instructions to match the cpu model */ per_cpu_patch (); +leon_patch ();paging_init ();
arch/sparc/kernel/vmlinux.lds.S +5 -0
@@ -107,6 +107,11 @@ SECTIONS *(.sun4v_2insn_patch) __sun4v_2insn_patch_end = .; } + .leon_1insn_patch : { + __leon_1insn_patch = .; + *(.leon_1insn_patch) + __leon_1insn_patch_end = .; + } .swapper_tsb_phys_patch : { __swapper_tsb_phys_patch = .; *(.swapper_tsb_phys_patch)
arch/sparc/mm/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o obj-y += fault_$(BITS).o obj-y += init_$(BITS).o obj-$(CONFIG_SPARC32) += extable.o srmmu.o iommu.o io-unit.o +obj-$(CONFIG_SPARC32) += srmmu_access.o obj-$(CONFIG_SPARC32) += hypersparc.o viking.o tsunami.o swift.o obj-$(CONFIG_SPARC_LEON)+= leon_mm.o
arch/sparc/mm/srmmu_access.S new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
1.6.0.6
David Miller
maintainerFrom: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 23:18:39 +0200
Quoted 1 line
Updated RFC patch below.
Looks good.
Two small things.
First, you might want to make the LEON case the default, because then it'll get tested more extensively.
Second, have you audited to make sure that none of this code runs before the patchup code does?
Quoted 11 lines · David Miller
From: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 23:18:39 +0200Quoted 1 line
Updated RFC patch below.
Looks good.
Two small things.
First, you might want to make the LEON case the default, because then it'll get tested more extensively.
Good point - will do.
Quoted 2 lines
Second, have you audited to make sure that none of this code runs before the patchup code does?
Yes - but a lot of other places that require patching will run long time before (wof.S, wuf.S etc). At least I assume so.
My plan is to introduce a sparc_start_kernel() function in setup_32.c which is called from head_32.S.
There I will do the initial stuff like patching and prom_init. And then call the real start_kernel().
The final patchset will establish this before introducing any users so I do not change when I patch in the middle of the patch-set.
The current patch was to make sure I was on the right track, hence the RFC.
Sam
David Miller
maintainerFrom: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 23:34:52 +0200
Quoted 5 lines · David Miller
Quoted 2 lines
Second, have you audited to make sure that none of this code runs before the patchup code does?
Yes - but a lot of other places that require patching will run long time before (
wof.S,wuf.Setc). At least I assume so.
The wof.S and wuf.S cases would only execute after we've started userland, as that code is used to validate the user stack in the register window store area.
Therefore it won't run unless PSR_PS is clear in %psr or there are user register windows in the cpu.
Neither of which will be true during early boot.
You should therefore be fine except for the bits in head_32.S which you'll need to use tests and branches for anyways.
Quoted 9 lines · David Miller
From: Sam Ravnborg <[email protected]>
Date: Sun, 20 May 2012 23:34:52 +0200Quoted 5 lines · David Miller
Quoted 2 lines
Second, have you audited to make sure that none of this code runs before the patchup code does?
Yes - but a lot of other places that require patching will run long time before (
wof.S,wuf.Setc). At least I assume so.
Quoted 8 lines
The
wof.Sandwuf.Scases would only execute after we've started userland, as that code is used to validate the user stack in the register window store area.Therefore it won't run unless
PSR_PSis clear in %psr or there are user register windows in the cpu.Neither of which will be true during early boot.
Thanks for the explanation, but wof.S and wuf.S was bad examples..
Quoted 3 lines
You should therefore be fine except for the bits in
head_32.Swhich you'll need to use tests and branches for anyways.
We have ~27 places where we reference MMUREGS in kernel/* on top of head_32.S.
Rather than trying to convince myself that they are not called in between start_kernel() and setup_arch() I prefer to patch is all up before calling start_kernel().
This also matches what we do on sparc64 for sun4v.
Anyway - as the merge window is now opened I will put this on hold until -rc2 or so unless you say otherwise.
Sam
David Miller
maintainerFrom: Sam Ravnborg <[email protected]>
Date: Mon, 21 May 2012 07:51:55 +0200
Quoted 2 lines
Anyway - as the merge window is now opened I will put this on hold until -rc2 or so unless you say otherwise.
I encourage you to keep working on it, getting rid of the LEON config option would be a major improvement in maintainability.