diff mbox

[3/3] powerpc/kexec: Add support for FSL-BookE

Message ID 1270412343-19334-4-git-send-email-sebastian@breakpoint.cc
State Accepted, archived
Delegated to: Kumar Gala
Headers show

Commit Message

Sebastian Andrzej Siewior April 4, 2010, 8:19 p.m. UTC
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

This adds support kexec on FSL-BookE where the MMU can not be simply
switched off. The code borrows the initial MMU-setup code to create the
identical mapping mapping. The only difference to the original boot code
is the size of the mapping(s) and the executeable address.
The kexec code maps the first 2 GiB of memory in 256 MiB steps. This
should work also on e500v1 boxes.
SMP support is still not available.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/powerpc/Kconfig                          |    2 +-
 arch/powerpc/include/asm/kexec.h              |   13 +++++++++
 arch/powerpc/kernel/fsl_booke_entry_mapping.S |   37 +++++++++++++++++++++++++
 arch/powerpc/kernel/head_fsl_booke.S          |    2 +
 arch/powerpc/kernel/misc_32.S                 |   17 +++++++++++
 5 files changed, 70 insertions(+), 1 deletions(-)

Comments

Kumar Gala May 7, 2010, 6:50 a.m. UTC | #1
On Apr 4, 2010, at 3:19 PM, Sebastian Andrzej Siewior wrote:

> From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> 
> This adds support kexec on FSL-BookE where the MMU can not be simply
> switched off. The code borrows the initial MMU-setup code to create the
> identical mapping mapping. The only difference to the original boot code
> is the size of the mapping(s) and the executeable address.
> The kexec code maps the first 2 GiB of memory in 256 MiB steps. This
> should work also on e500v1 boxes.
> SMP support is still not available.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> arch/powerpc/Kconfig                          |    2 +-
> arch/powerpc/include/asm/kexec.h              |   13 +++++++++
> arch/powerpc/kernel/fsl_booke_entry_mapping.S |   37 +++++++++++++++++++++++++
> arch/powerpc/kernel/head_fsl_booke.S          |    2 +
> arch/powerpc/kernel/misc_32.S                 |   17 +++++++++++
> 5 files changed, 70 insertions(+), 1 deletions(-)

Can you explain this a bit more.  Mostly would like to have a brief description of the sequence of events as part of the commit message.

Something like:

* Running kernel calls machine_kexec()
* machine_kexec_32()
* jump to relocate code
* relocate clears out TLBs and sets up 2g mapping
...

what I have above might not be quite right.

- k
Sebastian Andrzej Siewior May 7, 2010, 7:24 a.m. UTC | #2
* Kumar Gala | 2010-05-07 01:50:29 [-0500]:

>Can you explain this a bit more.  Mostly would like to have a brief description of the sequence of events as part of the commit message.
>
>Something like:
>
>* Running kernel calls machine_kexec()
>* machine_kexec_32()
>* jump to relocate code
>* relocate clears out TLBs and sets up 2g mapping
>...
>
>what I have above might not be quite right.
That is correct:
- kexec -l loads the kernel, dtb, ... in userland. It sets up the kimage
  struct including buffers with the new kernel and a copy list which
  looks like src, dst, bytes.
  KEXEC_*_MEMORY_LIMIT is limiting the memory which it might allocate.
- kexec -e start the kexec, that is
  * syscall reboot - kernel/sys.c
  * kernel_kexec() kernel/kexec.c
  * machine_kexec()  arch/powerpc/kernel/machine_kexec.c
  * default_machine_kexec() arch/powerpc/kernel/machine_kexec_32.c
- copy relocate_new_kernel() into a buffer which was allocated during
  kexec -l. That buffer is somewhere between 0..2GiB and will not be
  overwritten.
- jump there.
  Here we clear the tlbs and setup a 1:1 mapping. Then we copy the
  data from somewhere in 0..2GiB to its final position according to the
  list. Data means new kernel, device tree and purgatory code.
- After that, the code ends in
    mtlr    r5
    blrl
  r5 has the address of purgatory_start(), purgatory/arch/ppc/v2wrap.S
  in kexec userland [0].
- here we setup stack, jump to purgatory(). We have no console and still
  the 2GiB 1:1 mapping
- the code performs a sha256 check to make sure the kernel is correct.
- then we get back from purgatory(), load r3 - r9 and the blr at the
  bottom shoots us finally to new kernel.
- now we boot the kernel.

>- k

[0] git://git.kernel.org/pub/scm/linux/kernel/git/horms/kexec-tools.git

Sebastian
wilbur.chan May 7, 2010, 11:35 a.m. UTC | #3
Most booke powerpc are based on SMP, I am looking forward someone to
implement this. hiahia
Josh Boyer May 7, 2010, 12:16 p.m. UTC | #4
On Fri, May 07, 2010 at 07:35:34PM +0800, wilbur.chan wrote:
>Most booke powerpc are based on SMP, I am looking forward someone to
>implement this. hiahia

Erm, actually most Book-E powerpc CPUs are not SMP.  SMP Book-E cores are only
a fairly recent development, and if I recall correctly you need an e500mc core
to really have it work properly.

josh
Kumar Gala May 7, 2010, 12:50 p.m. UTC | #5
On May 7, 2010, at 7:16 AM, Josh Boyer wrote:

> On Fri, May 07, 2010 at 07:35:34PM +0800, wilbur.chan wrote:
>> Most booke powerpc are based on SMP, I am looking forward someone to
>> implement this. hiahia
> 
> Erm, actually most Book-E powerpc CPUs are not SMP.  SMP Book-E cores are only
> a fairly recent development, and if I recall correctly you need an e500mc core
> to really have it work properly.

e500v2 also does SMP.  MPC8572, P2020, P102x are all e500v2 SMP :)

- k
Kumar Gala May 24, 2010, 7:01 p.m. UTC | #6
On Apr 4, 2010, at 3:19 PM, Sebastian Andrzej Siewior wrote:

> From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> 
> This adds support kexec on FSL-BookE where the MMU can not be simply
> switched off. The code borrows the initial MMU-setup code to create the
> identical mapping mapping. The only difference to the original boot code
> is the size of the mapping(s) and the executeable address.
> The kexec code maps the first 2 GiB of memory in 256 MiB steps. This
> should work also on e500v1 boxes.
> SMP support is still not available.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> arch/powerpc/Kconfig                          |    2 +-
> arch/powerpc/include/asm/kexec.h              |   13 +++++++++
> arch/powerpc/kernel/fsl_booke_entry_mapping.S |   37 +++++++++++++++++++++++++
> arch/powerpc/kernel/head_fsl_booke.S          |    2 +
> arch/powerpc/kernel/misc_32.S                 |   17 +++++++++++
> 5 files changed, 70 insertions(+), 1 deletions(-)

applied to next

- k
diff mbox

Patch

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2e19500..f8ce19d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -350,7 +350,7 @@  config ARCH_ENABLE_MEMORY_HOTREMOVE
 
 config KEXEC
 	bool "kexec system call (EXPERIMENTAL)"
-	depends on PPC_BOOK3S && EXPERIMENTAL
+	depends on (PPC_BOOK3S || (FSL_BOOKE && !SMP)) && EXPERIMENTAL
 	help
 	  kexec is a system call that implements the ability to shutdown your
 	  current kernel, and to start another kernel.  It is like a reboot
diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
index 7e06b43..83f6481 100644
--- a/arch/powerpc/include/asm/kexec.h
+++ b/arch/powerpc/include/asm/kexec.h
@@ -2,6 +2,18 @@ 
 #define _ASM_POWERPC_KEXEC_H
 #ifdef __KERNEL__
 
+#ifdef CONFIG_FSL_BOOKE
+
+/*
+ * On FSL-BookE we setup a 1:1 mapping which covers the first 2GiB of memory
+ * and therefore we can only deal with memory within this range
+ */
+#define KEXEC_SOURCE_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL)
+#define KEXEC_DESTINATION_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL)
+#define KEXEC_CONTROL_MEMORY_LIMIT	(2 * 1024 * 1024 * 1024UL)
+
+#else
+
 /*
  * Maximum page that is mapped directly into kernel memory.
  * XXX: Since we copy virt we can use any page we allocate
@@ -21,6 +33,7 @@ 
 /* TASK_SIZE, probably left over from use_mm ?? */
 #define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
 #endif
+#endif
 
 #define KEXEC_CONTROL_PAGE_SIZE 4096
 
diff --git a/arch/powerpc/kernel/fsl_booke_entry_mapping.S b/arch/powerpc/kernel/fsl_booke_entry_mapping.S
index cdb1296..beb4d78 100644
--- a/arch/powerpc/kernel/fsl_booke_entry_mapping.S
+++ b/arch/powerpc/kernel/fsl_booke_entry_mapping.S
@@ -159,6 +159,8 @@  skpinv:	addi	r6,r6,1				/* Increment */
 #define M_IF_SMP	0
 #endif
 
+#if defined(ENTRY_MAPPING_BOOT_SETUP)
+
 /* 6. Setup KERNELBASE mapping in TLB1[0] */
 	lis	r6,0x1000		/* Set MAS0(TLBSEL) = TLB1(1), ESEL = 0 */
 	mtspr	SPRN_MAS0,r6
@@ -174,6 +176,41 @@  skpinv:	addi	r6,r6,1				/* Increment */
 /* 7. Jump to KERNELBASE mapping */
 	lis	r6,(KERNELBASE & ~0xfff)@h
 	ori	r6,r6,(KERNELBASE & ~0xfff)@l
+
+#elif defined(ENTRY_MAPPING_KEXEC_SETUP)
+/*
+ * 6. Setup a 1:1 mapping in TLB1. Esel 0 is unsued, 1 or 2 contains the tmp
+ * mapping so we start at 3. We setup 8 mappings, each 256MiB in size. This
+ * will cover the first 2GiB of memory.
+ */
+
+	lis r10, (MAS1_VALID|MAS1_IPROT)@h
+	ori r10,r10, (MAS1_TSIZE(BOOK3E_PAGESZ_256M))@l
+	li  r11, 0
+	li  r0, 8
+	mtctr   r0
+
+next_tlb_setup:
+	addi	r0, r11, 3
+	rlwinm  r0, r0, 16, 4, 15  // Compute esel
+	rlwinm  r9, r11, 28, 0, 3   // Compute [ER]PN
+	oris    r0, r0, (MAS0_TLBSEL(1))@h
+	mtspr   SPRN_MAS0,r0
+	mtspr   SPRN_MAS1,r10
+	mtspr   SPRN_MAS2,r9
+	ori r9, r9, (MAS3_SX|MAS3_SW|MAS3_SR)
+	mtspr   SPRN_MAS3,r9
+	tlbwe
+	addi    r11, r11, 1
+	bdnz+   next_tlb_setup
+
+/* 7. Jump to our 1:1 mapping */
+	li	r6, 0
+
+#else
+	#error You need to specify the mapping or not use this at all.
+#endif
+
 	lis	r7,MSR_KERNEL@h
 	ori	r7,r7,MSR_KERNEL@l
 	bl	1f			/* Find our address */
diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S
index 3dc7ef7..3620cf5 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -95,7 +95,9 @@  _ENTRY(_start);
 
 _ENTRY(__early_start)
 
+#define ENTRY_MAPPING_BOOT_SETUP
 #include "fsl_booke_entry_mapping.S"
+#undef ENTRY_MAPPING_BOOT_SETUP
 
 	/* Establish the interrupt vector offsets */
 	SET_IVOR(0,  CriticalInput);
diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S
index 8649f53..99bc652 100644
--- a/arch/powerpc/kernel/misc_32.S
+++ b/arch/powerpc/kernel/misc_32.S
@@ -706,6 +706,22 @@  relocate_new_kernel:
 	/* r4 = reboot_code_buffer */
 	/* r5 = start_address      */
 
+#ifdef CONFIG_FSL_BOOKE
+
+	mr	r29, r3
+	mr	r30, r4
+	mr	r31, r5
+
+#define ENTRY_MAPPING_KEXEC_SETUP
+#include "fsl_booke_entry_mapping.S"
+#undef ENTRY_MAPPING_KEXEC_SETUP
+
+	mr      r3, r29
+	mr      r4, r30
+	mr      r5, r31
+
+	li	r0, 0
+#else
 	li	r0, 0
 
 	/*
@@ -722,6 +738,7 @@  relocate_new_kernel:
 	rfi
 
 1:
+#endif
 	/* from this point address translation is turned off */
 	/* and interrupts are disabled */