Skip to content
  • Russell King's avatar
    ARM: P2V: introduce phys_to_virt/virt_to_phys runtime patching · dc21af99
    Russell King authored
    
    
    This idea came from Nicolas, Eric Miao produced an initial version,
    which was then rewritten into this.
    
    Patch the physical to virtual translations at runtime.  As we modify
    the code, this makes it incompatible with XIP kernels, but allows us
    to achieve this with minimal loss of performance.
    
    As many translations are of the form:
    
    	physical = virtual + (PHYS_OFFSET - PAGE_OFFSET)
    	virtual = physical - (PHYS_OFFSET - PAGE_OFFSET)
    
    we generate an 'add' instruction for __virt_to_phys(), and a 'sub'
    instruction for __phys_to_virt().  We calculate at run time (PHYS_OFFSET
    - PAGE_OFFSET) by comparing the address prior to MMU initialization with
    where it should be once the MMU has been initialized, and place this
    constant into the above add/sub instructions.
    
    Once we have (PHYS_OFFSET - PAGE_OFFSET), we can calculate the real
    PHYS_OFFSET as PAGE_OFFSET is a build-time constant, and save this for
    the C-mode PHYS_OFFSET variable definition to use.
    
    At present, we are unable to support Realview with Sparsemem enabled
    as this uses a complex mapping function, and MSM as this requires a
    constant which will not fit in our math instruction.
    
    Add a module version magic string for this feature to prevent
    incompatible modules being loaded.
    
    Tested-by: default avatarTony Lindgren <tony@atomide.com>
    Reviewed-by: default avatarNicolas Pitre <nicolas.pitre@linaro.org>
    Tested-by: default avatarNicolas Pitre <nicolas.pitre@linaro.org>
    Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
    dc21af99