All of lore.kernel.org
 help / color / mirror / Atom feed
From: Suzuki Poulose <suzuki@in.ibm.com>
To: Michal Simek <monstr@monstr.eu>
Cc: tmarri@apm.com, linuxppc-dev@ozlabs.org,
	john.williams@petalogix.com, arnd@arndb.de
Subject: Re: [RFC PATCH 7/7] powerpc: Support RELOCATABLE kernel for PPC44x
Date: Tue, 12 Jul 2011 16:39:52 +0530	[thread overview]
Message-ID: <4E1C2B80.1090908@in.ibm.com> (raw)
In-Reply-To: <1308233668-24166-8-git-send-email-monstr@monstr.eu>

On 06/16/11 19:44, Michal Simek wrote:
> Changes:
> - Find out address where kernel runs
> - Create the first 256MB TLB from online detected address
>
> Limitations:
> - Kernel must be aligned to 256MB
>
> Backport:
> - Changes in page.h are backported from newer kernel version
>
> mmu_mapin_ram function has to reflect offset in memory start.
> memstart_addr and kernstart_addr are setup directly from asm
> code to ensure that only ppc44x is affected.
>
> Signed-off-by: Michal Simek<monstr@monstr.eu>
> ---
>   arch/powerpc/Kconfig            |    3 ++-
>   arch/powerpc/include/asm/page.h |    7 ++++++-
>   arch/powerpc/kernel/head_44x.S  |   28 ++++++++++++++++++++++++++++
>   arch/powerpc/mm/44x_mmu.c       |    6 +++++-
>   4 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 45c9683..34c521e 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -796,7 +796,8 @@ config LOWMEM_CAM_NUM
>
>   config RELOCATABLE
>   	bool "Build a relocatable kernel (EXPERIMENTAL)"
> -	depends on EXPERIMENTAL&&  ADVANCED_OPTIONS&&  FLATMEM&&  FSL_BOOKE
> +	depends on EXPERIMENTAL&&  ADVANCED_OPTIONS&&  FLATMEM
> +	depends on FSL_BOOKE || (44x&&  !SMP)
>   	help
>   	  This builds a kernel image that is capable of running at the
>   	  location the kernel is loaded at (some alignment restrictions may
> diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
> index 4940662..e813cc2 100644
> --- a/arch/powerpc/include/asm/page.h
> +++ b/arch/powerpc/include/asm/page.h
> @@ -108,8 +108,13 @@ extern phys_addr_t kernstart_addr;
>   #define pfn_to_kaddr(pfn)	__va((pfn)<<  PAGE_SHIFT)
>   #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr)>>  PAGE_SHIFT)
>
> -#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - MEMORY_START))
> +#ifdef CONFIG_BOOKE
> +#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) - PHYSICAL_START + KERNELBASE))
> +#define __pa(x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE)
> +#else
> +#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))
>   #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)
> +#endif
>
>   /*
>    * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
> diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
> index d80ce05..6a63d32 100644
> --- a/arch/powerpc/kernel/head_44x.S
> +++ b/arch/powerpc/kernel/head_44x.S
> @@ -59,6 +59,17 @@ _ENTRY(_start);
>   	 * of abatron_pteptrs
>   	 */
>   	nop
> +
> +#ifdef CONFIG_RELOCATABLE
> +	bl	jump                            /* Find our address */
> +	nop
> +jump:	mflr	r25                              /* Make it accessible */
> +	/* just for and */
> +	lis     r26, 0xfffffff0@h
> +	ori     r26, r26, 0xfffffff0@l
> +	and.	r21, r25, r26
> +#endif

Hmm. So we are assuming we are running from a 1:1 mapping at the entry.
It is much more safe to read our tlb entry and use the RPN instead.


> +#ifdef CONFIG_RELOCATABLE
> +	/* load physical address where kernel runs */
> +	mr	r4,r21
> +#else
>   	/* Kernel is at PHYSICAL_START */
>   	lis	r4,PHYSICAL_START@h
>   	ori	r4,r4,PHYSICAL_START@l
> +#endif
>
>   	/* Load the kernel PID = 0 */
>   	li	r0,0
> @@ -258,6 +274,18 @@ skpinv:	addi	r4,r4,1				/* Increment */
>   	mr	r5,r29
>   	mr	r6,r28
>   	mr	r7,r27
> +
> +#ifdef CONFIG_RELOCATABLE
> +	/* save kernel and memory start */
> +	lis	r25,kernstart_addr@h
> +	ori	r25,r25,kernstart_addr@l
> +	stw	r21,4(r25)

1) You have to use ERPN value in the higher word of kernel_start_addr.
2) You have to account for the (KERNEL_BASE - PAGE_OFFSET) shift for kernel_start_addr.

> +
> +	lis	r25,memstart_addr@h
> +	ori	r25,r25,memstart_addr@l
> +	stw	r21,4(r25)

> +#endif
> +

Suzuki

      reply	other threads:[~2011-07-12 11:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16 14:14 [RFC] Relocatable kernel for ppc44x Michal Simek
2011-06-16 14:14 ` [RFC PATCH 1/7] powerpc: ppc440 remove zero physical memory base assumption Michal Simek
2011-06-16 14:14   ` [RFC PATCH 2/7] powerpc: Permit non-zero physical start address for PPC44x Michal Simek
2011-06-16 14:14     ` [RFC PATCH 3/7] powerpc: simpleboot get load address from ELF instead of assuming zero Michal Simek
2011-06-16 14:14       ` [RFC PATCH 4/7] powerpc: Let simpleboot function with non zero-based memory maps Michal Simek
2011-06-16 14:14         ` [RFC PATCH 5/7] powerpc: Consider a non-zero boot address when computing the bootwrapper start Michal Simek
2011-06-16 14:14           ` [RFC PATCH 6/7] powerpc: Update the default FIT image to use the correct load/boot addresses Michal Simek
2011-06-16 14:14             ` [RFC PATCH 7/7] powerpc: Support RELOCATABLE kernel for PPC44x Michal Simek
2011-07-12 11:09               ` Suzuki Poulose [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E1C2B80.1090908@in.ibm.com \
    --to=suzuki@in.ibm.com \
    --cc=arnd@arndb.de \
    --cc=john.williams@petalogix.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=monstr@monstr.eu \
    --cc=tmarri@apm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.