xen/ppc: Add early Radix MMU support
v2 cover xen/ppc: Add early Radix MMU support
Hello all,
This series adds support for bringing up the Radix MMU with basic identity-mapped page tables.
In order to simplify the memory layout, the series changes XEN_VIRT _START to 0xC000_0000_0000_0000, which has a couple of convenient properties. When the MMU is off, the top 4 address bits are ignored by the hardware, so this is equivalent to physical address 0. When the MMU is enabled, the top 4 address bits are used to select the memory quadrant, and 0xC corresponds to quadrant 3 which is used for kernel memory. Thus, by linking the kernel here and ensuring its physical load address is 0x0, we are able to run at the correct address both before and after the MMU is enabled.
Additionally, as the Radix MMU was only added in ISA 3.0 (POWER9), this series also drops support for POWER8 for now, to avoid having a non-working build configuration in-tree.
Thanks,
Shawn
Shawn Anastasio (3):
xen/ppc: Bump minimum target ISA to 3.0 (POWER9) xen/ppc: Relocate kernel to physical address 0 on boot xen/ppc: Implement initial Radix MMU support
xen/arch/ppc/Kconfig | 7 +- xen/arch/ppc/Makefile | 2 + xen/arch/ppc/arch.mk | 1 - xen/arch/ppc/include/asm/bitops.h | 9 + xen/arch/ppc/include/asm/config.h | 2 +- xen/arch/ppc/include/asm/mm.h | 18 ++ xen/arch/ppc/include/asm/page-bits.h | 3 +- xen/arch/ppc/include/asm/page.h | 178 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 138 ++++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 268 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 42 +++++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 15 files changed, 793 insertions(+), 9 deletions(-) create mode 100644 xen/arch/ppc/include/asm/bitops.h create mode 100644 xen/arch/ppc/include/asm/mm.h create mode 100644 xen/arch/ppc/include/asm/page.h create mode 100644 xen/arch/ppc/include/asm/regs.h create mode 100644 xen/arch/ppc/mm-radix.c create mode 100644 xen/arch/ppc/tlb-radix.c
--
2.30.2
PATCH v2 1/3 xen/ppc: Bump minimum target ISA to 3.0 (POWER9)
In preparation for implementing ISA3+ Radix MMU support, drop ISA 2.07B from the supported ISA list to avoid having a non-working configuration in tree. It can be re-added at a later point when Hash MMU support is added.
---
v2: no changes.
xen/arch/ppc/Kconfig | 7 +------ xen/arch/ppc/arch.mk | 1 - 2 files changed, 1 insertion(+), 7 deletions(-)
xen/arch/ppc/Kconfig +1 -6
@@ -20,15 +20,10 @@ menu "ISA Selection" choice prompt "Base ISA" - default POWER_ISA_2_07B + default POWER_ISA_3_00 help This selects the base ISA version that Xen will target. -config POWER_ISA_2_07B - bool "Power ISA 2.07B (POWER8)" - help - Target version 2.07B of the Power ISA (POWER8) or later - config POWER_ISA_3_00 bool "Power ISA 3.00 (POWER9)" help
xen/arch/ppc/arch.mk +0 -1
@@ -1,7 +1,6 @@ ######################################## # Power-specific definitions -ppc-march-$(CONFIG_POWER_ISA_2_07B) := power8 ppc-march-$(CONFIG_POWER_ISA_3_00) := power9 CFLAGS += -m64 -mlittle-endian -mcpu=$(ppc-march-y)
--
2.30.2
PATCH v2 2/3 xen/ppc: Relocate kernel to physical address 0 on boot
In reply to Shawn AnastasioIntroduce a small assembly loop in start to copy the kernel to physical address 0 before continuing. This ensures that the physical address lines up with XEN_VIRT_START (0xc000000000000000) and allows us to identity map the kernel when the MMU is set up in the next patch.
We are also able to start execution at XEN_VIRT_START after the copy since hardware will ignore the top 4 address bits when operating in Real Mode (MMU off).
---
v2:
- Fix definition of XEN_VIRT_START macro which incorrectly used _AT instead of _AC.
- Use _start instead of start as symbol referring to beginning of Xen binary
xen/arch/ppc/include/asm/config.h | 2 +- xen/arch/ppc/ppc64/head.S | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)
xen/arch/ppc/include/asm/config.h +1 -1
@@ -39,7 +39,7 @@ name:#endif -#define XEN_VIRT_START _AT(UL, 0xc000000000000000) +#define XEN_VIRT_START _AC(0xc000000000000000, UL)#define SMP_CACHE_BYTES (1 << 6)
xen/arch/ppc/ppc64/head.S +27 -0
@@ -17,6 +17,33 @@ ENTRY(start) addis %r2, %r12, .TOC.-1b@ha addi %r2, %r2, .TOC.-1b@l + /* + * Copy Xen to physical address zero and jump to XEN_VIRT_START + * (0xc000000000000000). This works because the hardware will ignore the top + * four address bits when the MMU is off. + */ + LOAD_REG_ADDR(%r1, _start) + LOAD_IMM64(%r12, XEN_VIRT_START) + + /* If we're at the correct address, skip copy */ + cmpld %r1, %r12 + beq .L_correct_address + + /* Copy bytes until _end */ + LOAD_REG_ADDR(%r11, _end) + addi %r1, %r1, -8 + li %r13, -8 +.L_copy_xen: + ldu %r10, 8(%r1) + stdu %r10, 8(%r13) + cmpld %r1, %r11 + blt .L_copy_xen + + /* Jump to XEN_VIRT_START */ + mtctr %r12 + bctr +.L_correct_address: + /* set up the initial stack */ LOAD_REG_ADDR(%r1, cpu0_boot_stack) li %r11, 0
--
2.30.2
PATCH v2 3/3 xen/ppc: Implement initial Radix MMU support
In reply to Shawn AnastasioAdd code to construct early identity-mapped page tables as well as the required process and partition tables to enable the MMU.
---
v2:
- Add missing ')' to mm.h/maddr_to_virt definition
- Add missing parens around va argument in XEN_PT_INDEX_LVL
- Drop '&' asm constraint modifier in processor.h/mfmsr()
- Fix asm constraint formatting in processor.h
- Change mtspr,mfspr to functions in processor.h
- Drop unnecessary _Static_assert in mm-radix.c
- Drop unnecessary cast in setup_initial_mapping
- Use __va() to obtain pde/pte addresses in setup_initial_mapping
- Wrap >80col lines in mm-radix.c
- Drop unnecessary parameters in setup_{process,partition}_table
- Add __init to setup_{process,partition}_table
- Drop unnecessary opal.c changes
- Drop manual prototype of setup_initial_pagetables in setup.c in favor of using the one already in asm/mm.h
- Fix formatting of tlbiel asm block in tlb-radix.c
xen/arch/ppc/Makefile | 2 + xen/arch/ppc/include/asm/bitops.h | 9 + xen/arch/ppc/include/asm/mm.h | 18 ++ xen/arch/ppc/include/asm/page-bits.h | 3 +- xen/arch/ppc/include/asm/page.h | 178 ++++++++++++++++++ xen/arch/ppc/include/asm/processor.h | 34 ++++ xen/arch/ppc/include/asm/regs.h | 138 ++++++++++++++ xen/arch/ppc/include/asm/types.h | 1 + xen/arch/ppc/mm-radix.c | 268 +++++++++++++++++++++++++++ xen/arch/ppc/ppc64/head.S | 15 ++ xen/arch/ppc/setup.c | 3 + xen/arch/ppc/tlb-radix.c | 96 ++++++++++ 12 files changed, 764 insertions(+), 1 deletion(-) create mode 100644 xen/arch/ppc/include/asm/bitops.h create mode 100644 xen/arch/ppc/include/asm/mm.h create mode 100644 xen/arch/ppc/include/asm/page.h create mode 100644 xen/arch/ppc/include/asm/regs.h create mode 100644 xen/arch/ppc/mm-radix.c create mode 100644 xen/arch/ppc/tlb-radix.c
xen/arch/ppc/Makefile +2 -0
@@ -2,8 +2,10 @@ obj-$(CONFIG_PPC64) += ppc64/ obj-y += boot-of.init.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o +obj-y += mm-radix.o obj-y += opal.o obj-y += setup.o +obj-y += tlb-radix.o $(TARGET): $(TARGET)-syms cp -f $< $@
xen/arch/ppc/include/asm/bitops.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _ASM_PPC_BITOPS_H +#define _ASM_PPC_BITOPS_H + +/* PPC bit number conversion */ +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) +#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +#endif /* _ASM_PPC_BITOPS_H */
xen/arch/ppc/include/asm/mm.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _ASM_PPC_MM_H +#define _ASM_PPC_MM_H + +#include <asm/page-bits.h> + +#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT) +#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) + +#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START)) + +/* Convert between Xen-heap virtual addresses and machine addresses. */ +#define __pa (x) (virt_to_maddr(x)) +#define __va (x) (maddr_to_virt(x)) + +void setup_initial_pagetables (void ); + +#endif /* _ASM_PPC_MM_H */
xen/arch/ppc/include/asm/page-bits.h +2 -1
@@ -2,6 +2,7 @@#define __PPC_PAGE_BITS_H__#define PAGE_SHIFT 16/* 64 KiB Pages */ -#define PADDR_BITS 48 +#define PADDR_BITS 53 +#define VADDR_BITS 52#endif /* __PPC_PAGE_BITS_H__ */
xen/arch/ppc/include/asm/page.h new file +178 -0
178 lines not on this page · raw message
xen/arch/ppc/include/asm/processor.h +34 -0
@@ -133,6 +133,40 @@ struct cpu_user_regsuint32_t entry_vector; }; +static __inline__void sync (void ) +{ + asmvolatile ("sync" ); +} + +static __inline__void isync (void ) +{ + asmvolatile ("isync" ); +} + +static inline unsigned long mfmsr (void ) +{ +unsigned long msr; + asmvolatile ("mfmsr %0" :"=r" (msr) ); +return msr; +} + +static inline void mtmsrd (unsigned long msr) +{ + asmvolatile ("mtmsrd %0" : :"r" (msr) ); +} + +static inline void mtspr (uint16_t spr,unsigned long val) +{ + asmvolatile ("mtspr %0, %1" : :"K" (spr),"r" (val) ); +} + +static inline unsigned long mfspr (uint16_t spr) +{ +unsigned long val; + asmvolatile ("mfspr %0, %1" :"=r" (val) :"K" (spr) ); +return val; +} +/* * panic() isn't available at the moment so an infinite loop will be * used temporarily.
xen/arch/ppc/include/asm/regs.h new file +138 -0
138 lines not on this page · raw message
xen/arch/ppc/include/asm/types.h +1 -0
@@ -4,6 +4,7 @@#define _ASM_PPC_TYPES_Htypedef unsigned long paddr_t ; +typedef unsigned long vaddr_t ;#define INVALID_PADDR (~0UL)#define PRIpaddr "016lx"
xen/arch/ppc/mm-radix.c new file +268 -0
268 lines not on this page · raw message
xen/arch/ppc/ppc64/head.S +15 -0
@@ -2,6 +2,7 @@ #include <asm/asm-defns.h> #include <asm/asm-offsets.h> +#include <asm/msr.h> .section .text.header, "ax", %progbits
@@ -66,3 +67,17 @@ ENTRY(start) .size start, . - start .type start, %function + +ENTRY(enable_mmu) + mflr %r3 + mfmsr %r4 + + /* enable instruction and data relocation (MMU) */ + ori %r4, %r4, (MSR_IR | MSR_DR) + + mtsrr0 %r3 /* return to caller after MMU enable */ + mtsrr1 %r4 + rfid + + .size enable_mmu, . - enable_mmu + .type enable_mmu, %function
xen/arch/ppc/setup.c +3 -0
@@ -2,6 +2,7 @@#include <xen/init.h> #include <asm/boot.h> #include <asm/early_printk.h> +#include <asm/mm.h> #include <asm/processor.h> /* Xen stack for bringing up the first CPU. */
@@ -27,6 +28,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,boot_opal_init ((void *)r3); } +setup_initial_pagetables (); +early_printk ("Hello, ppc64le!\n" );for ( ; ; )
xen/arch/ppc/tlb-radix.c new file +96 -0
96 lines not on this page · raw message
--
2.30.2