Early serial on Power
v5 cover Early serial on Power
Hello all,
This series adds support for early serial printing on Power, as well as a simple CI smoke test modeled after the riscv one.
The first patch is responsible for setting up a basic C environment with an initial stack while the second sets up an Open Firmware serial console and primitive early_printk infrastructure.
This will currently only run on QEMU pseries VMs, since the firmware interface on bare metal differs significantly. Support for bare metal will be added in a future series along with support for the position-independent code model.
Thanks,
Shawn
--
Changes in v5:
- (xen/macros.h) Add signoff
- (xen/macros.h) Fix up comment formatting and macro parameter names
- (*.S) Use 8-space column alignment for assembly
- (of-call.S) Add missing space after comma
- (asm-offsets.c) Fix DEFINE() macro formatting
- (asm-offsets.c) Replace _Static_assert with BUILD_BUG_ON
Changes in v4:
- Add macros.h patch for ARRAY_SIZE
- Based on v3 of Jan's "common: move a few macros out of xen/lib.h"
- (head.S) Remove unnecessary '.section .init.data'
- (head.S) Fixup spacing, remove unnecessary parens
- (setup.c, processor.h) Fix style of HMT_very_low macro
- (early_printk.c) Build early_printk.c as .init.o
- (early_printk.c) Mark putchar_func as __initdata
- (boot-of.c) Clarify original license in top comment
- (boot-of.c) Add parens around ADDR macro definition
- (boot-of.c) Add missing ADDR() for pointer arguments
- (boot-of.c) Add comment explaining ADDR macro
- (boot-of.c) Fix style (indentation, comment capitalization)
- (boot-of.c) Fix type inconsistency in boot-of.c
- (boot-of.c) Use ARRAY_SIZE instead of hard-coding nrets
- (boot-of.c) Change bof_chosen variable to function-scope
- (processor.h) Remove duplicate <xen/types.h> include
- (processor.h) Remove unnecessary <xen/config.h> include
- (processor.h) Move HMT_very_low macro to !defined(ASSEMBLY) block
- (processor.h) Fixup struct cpu_user_regs comment style
Changes in v3:
- Set up r2 TOC pointer in start
- Change indirect call to start_xen to a direct one
- Use 32-bit constant loads for stack pointer, etc. in start
- Our load address is < 4GB so this works fine
- In a future series we'll get -fPIC working and change all of these immediate address loads to TOC-relative ones.
- Move .bss initialization to patch 2
- Move cpu0_boot_stack declaration to setup.c
- Bump stack size down to one page (64k), previous was way overkill.
- Remove unnecessary STACK_FRAME_OVERHEAD component from of-call.S stack frame size calculation
- Add assertion that struct cpu_user_regs is stack-aligned
- Move magic or 31,31,31 to appropriately-named macro
- Fix formatting of loop in setup.c
- Add newline in arch/ppc/Makefile to preserve alphabetical ordering per group
- Rebase on staging, including the final version of 'xen/types: Rework stdint vs __{u,s}$N types'
Changes in v2:
- Split main patch into two - one for basic C environment setup and one for serial
- Mark OpenFirmware functions and early_printk functions as __init and change boot-of.o to boot-of.init.o in Makefile
- Change <xen/lib.h> include to <xen/stdarg.h> and drop skeleton headers that are no longer necessary for build as a result
- Add loop to clear .bss before jumping to C environment that was accidentally excluded from the first series
- Move common asm macros from processor.h to asm-defns.h
- Change note in head.S about preserved registers to a multi-line comment so it's more noticeable
- Drop reg-defs.h and use '%'-prefixed register names in assembly
- This is necessary since -mregnames, which allows standard non-prefixed register names without manual macro definitions, is not supported by LLVM's assembler.
- Drop inline asm swab routines in favor of __builtin_bswap family
- Fix up types.h in accordance with (as of now, unmerged) 'xen/types: Rework stdint vs __{u,s}$N types'
- Remove unnecessary braces for single-line statements
- Remove unnecessary license text when SPDX header is present
- Fix alphabetical ordering of object declarations in Makefile
- Drop 'extern' from enter_of prototype, ensure prototypes have argument names
Shawn Anastasio (4):
common: Move a few more standalone macros from xen/lib.h to
xen/macros.h
xen/ppc: Set up a basic C environment
xen/ppc: Implement early serial printk on pseries
automation: Add smoke test for ppc64le
automation/gitlab-ci/test.yaml | 20 ++++ automation/scripts/qemu-smoke-ppc64le.sh | 27 +++++ xen/arch/ppc/Kconfig.debug | 5 + xen/arch/ppc/Makefile | 4 + xen/arch/ppc/boot-of.c | 113 +++++++++++++++++++ xen/arch/ppc/configs/ppc64_defconfig | 1 + xen/arch/ppc/early_printk.c | 28 +++++ xen/arch/ppc/include/asm/asm-defns.h | 57 ++++++++++ xen/arch/ppc/include/asm/boot.h | 23 ++++ xen/arch/ppc/include/asm/byteorder.h | 12 ++ xen/arch/ppc/include/asm/config.h | 5 +- xen/arch/ppc/include/asm/early_printk.h | 15 +++ xen/arch/ppc/include/asm/msr.h | 51 +++++++++ xen/arch/ppc/include/asm/processor.h | 138 +++++++++++++++++++++++ xen/arch/ppc/include/asm/types.h | 21 ++++ xen/arch/ppc/ppc64/Makefile | 1 + xen/arch/ppc/ppc64/asm-offsets.c | 58 ++++++++++ xen/arch/ppc/ppc64/head.S | 47 ++++---- xen/arch/ppc/ppc64/of-call.S | 83 ++++++++++++++ xen/arch/ppc/setup.c | 32 ++++++ xen/include/xen/lib.h | 28 ----- xen/include/xen/macros.h | 34 ++++++ 22 files changed, 754 insertions(+), 49 deletions(-) create mode 100755 automation/scripts/qemu-smoke-ppc64le.sh create mode 100644 xen/arch/ppc/boot-of.c create mode 100644 xen/arch/ppc/early_printk.c create mode 100644 xen/arch/ppc/include/asm/asm-defns.h create mode 100644 xen/arch/ppc/include/asm/boot.h create mode 100644 xen/arch/ppc/include/asm/byteorder.h create mode 100644 xen/arch/ppc/include/asm/early_printk.h create mode 100644 xen/arch/ppc/include/asm/msr.h create mode 100644 xen/arch/ppc/include/asm/processor.h create mode 100644 xen/arch/ppc/include/asm/types.h create mode 100644 xen/arch/ppc/ppc64/of-call.S create mode 100644 xen/arch/ppc/setup.c
--
2.30.2
PATCH v5 1/4 common: Move a few more standalone macros from xen/lib.h to xen/macros.h
Move a few more macros which have no dependencies on other headers from xen/lib.h to xen/macros.h. Notably, this includes BUILD_BUG_ON* and ARRAY_SIZE.
--- xen/include/xen/lib.h | 28 ---------------------------- xen/include/xen/macros.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-)
xen/include/xen/lib.h +0 -28
@@ -21,24 +21,6 @@unlikely (ret_warn_on_); \ }) -/* All clang versions supported by Xen have _Static_assert. */ -#if defined(__clang__) || \ - (__GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 )) -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON (cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) - -/* Force a compilation error if condition is true, but also produce a -result (of value 0 and type size_t), so the expression can be used -e.g. in a structure initializer (or where-ever else comma expressions -aren't permitted). */ -#define BUILD_BUG_ON_ZERO (cond) \ - (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0) -#else -#define BUILD_BUG_ON_ZERO (cond) \ - (sizeof(struct { unsigned u : !(cond); }) & 0) -#define BUILD_BUG_ON (cond) ((void)BUILD_BUG_ON_ZERO(cond)) -#endif -#ifndef NDEBUG #define ASSERT (p) \ do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
@@ -48,16 +30,6 @@#define ASSERT_UNREACHABLE () do { } while (0)#endif -#define ABS (_x) ({ \ - typeof(_x) __x = (_x); \ - (__x < 0) ? -__x : __x; \ -}) - -#define SWAP (_a, _b) \ - do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 ) - -#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x)) -#define __ACCESS_ONCE (x) ({ \ (void)(typeof(x))0;/* Scalar typecheck. */ \ (volatile typeof(x) *)&(x); })
xen/include/xen/macros.h +34 -0
@@ -22,6 +22,40 @@#define __STR (...) #__VA_ARGS__#define STR (...) __STR(__VA_ARGS__) +#ifndef __ASSEMBLY__ + +/* All clang versions supported by Xen have _Static_assert. */ +#if defined(__clang__) || \ + (__GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 )) +/* Force a compilation error if condition is true */ +#define BUILD_BUG_ON (cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) + +/* +* Force a compilation error if condition is true, but also produce a +* result (of value 0 and type size_t), so the expression can be used +* e.g. in a structure initializer (or where-ever else comma expressions +* aren't permitted). +*/ +#define BUILD_BUG_ON_ZERO (cond) \ + (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0) +#else +#define BUILD_BUG_ON_ZERO (cond) \ + (sizeof(struct { unsigned u : !(cond); }) & 0) +#define BUILD_BUG_ON (cond) ((void)BUILD_BUG_ON_ZERO(cond)) +#endif + +#define ABS (x) ({ \ + typeof(x) x_ = (x); \ + (x_ < 0) ? -x_ : x_; \ +}) + +#define SWAP (a, b) \ + do { typeof(a) t_ = (a); (a) = (b); (b) = t_; } while ( 0 ) + +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x)) + +#endif /* __ASSEMBLY__ */ +#endif /* __MACROS_H__ */ /*
Signature · 1 line
2.30.2
PATCH v5 2/4 xen/ppc: Set up a basic C environment
In reply to Shawn AnastasioUpdate ppc64/head.S to set up an initial boot stack, zero the .bss section, and jump to C. The required setup is done using 32-bit immediate address loads for now, but they will be changed to TOC-relative loads once the position-independent code model is enabled.
Additionally, move the cpu0_boot_stack declaration to setup.c and change STACK_ORDER from 2 to 0. For now, ppc64 is using 64k pages and thus the larger STACK_ORDER is unnecessary.
Finally, refactor the endian fixup trampoline into its own macro, since it will need to be used in multiple places, including every time we make a call into firmware.
--- xen/arch/ppc/Makefile | 2 ++ xen/arch/ppc/include/asm/asm-defns.h | 40 ++++++++++++++++++++++++++++ xen/arch/ppc/include/asm/config.h | 2 +- xen/arch/ppc/ppc64/head.S | 38 +++++++++++++------------- xen/arch/ppc/setup.c | 19 +++++++++++++ 5 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 xen/arch/ppc/include/asm/asm-defns.h create mode 100644 xen/arch/ppc/setup.c
xen/arch/ppc/Makefile +2 -0
@@ -1,5 +1,7 @@ obj-$(CONFIG_PPC64) += ppc64/ +obj-y += setup.o + $(TARGET): $(TARGET)-syms cp -f $< $@
xen/arch/ppc/include/asm/asm-defns.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_PPC_ASM_DEFNS_H +#define _ASM_PPC_ASM_DEFNS_H + +/* +* Load a 64-bit immediate value into the specified GPR. +*/ +#define LOAD_IMM64 (reg, val) \ + lis reg, (val) @highest; \ + ori reg, reg, (val) @higher; \ + rldicr reg, reg, 32, 31; \ + oris reg, reg, (val) @h; \ + ori reg, reg, (val) @l; + +#define LOAD_IMM32 (reg, val) \ + lis reg, (val) @h; \ + ori reg, reg, (val) @l; \ + +/* +* Depending on how we were booted, the CPU could be running in either +* Little Endian or Big Endian mode. The following trampoline from Linux +* cleverly uses an instruction that encodes to a NOP if the CPU's +* endianness matches the assumption of the assembler (LE, in our case) +* or a branch to code that performs the endian switch in the other case. +*/ +#define FIXUP_ENDIAN \ + tdi 0, 0, 0x48; /* Reverse endian of b . + 8 */ \ + b . + 44; /* Skip trampoline if endian is good */ \ + .long 0xa600607d; /* mfmsr r11 */ \ + .long 0x01006b69; /* xori r11,r11,1 */ \ + .long 0x00004039; /* li r10,0 */ \ + .long 0x6401417d; /* mtmsrd r10,1 */ \ + .long 0x05009f42; /* bcl 20,31,$+4 */ \ + .long 0xa602487d; /* mflr r10 */ \ + .long 0x14004a39; /* addi r10,r10,20 */ \ + .long 0xa6035a7d; /* mtsrr0 r10 */ \ + .long 0xa6037b7d; /* mtsrr1 r11 */ \ + .long 0x2400004c /* rfid */ + +#endif /* _ASM_PPC_ASM_DEFNS_H */
xen/arch/ppc/include/asm/config.h +1 -1
@@ -43,7 +43,7 @@#define SMP_CACHE_BYTES (1 << 6) -#define STACK_ORDER 2 +#define STACK_ORDER 0#define STACK_SIZE (PAGE_SIZE << STACK_ORDER)/* 288 bytes below the stack pointer must be preserved by interrupt handlers */
xen/arch/ppc/ppc64/head.S +18 -20
@@ -1,30 +1,28 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <asm/asm-defns.h> + .section .text.header, "ax", %progbits ENTRY(start) /* - * Depending on how we were booted, the CPU could be running in either - * Little Endian or Big Endian mode. The following trampoline from Linux - * cleverly uses an instruction that encodes to a NOP if the CPU's - * endianness matches the assumption of the assembler (LE, in our case) - * or a branch to code that performs the endian switch in the other case. + * NOTE: argument registers (r3-r9) must be preserved until the C entrypoint */ - tdi 0, 0, 0x48 /* Reverse endian of b . + 8 */ - b . + 44 /* Skip trampoline if endian is good */ - .long 0xa600607d /* mfmsr r11 */ - .long 0x01006b69 /* xori r11,r11,1 */ - .long 0x00004039 /* li r10,0 */ - .long 0x6401417d /* mtmsrd r10,1 */ - .long 0x05009f42 /* bcl 20,31,$+4 */ - .long 0xa602487d /* mflr r10 */ - .long 0x14004a39 /* addi r10,r10,20 */ - .long 0xa6035a7d /* mtsrr0 r10 */ - .long 0xa6037b7d /* mtsrr1 r11 */ - .long 0x2400004c /* rfid */ - - /* Now that the endianness is confirmed, continue */ -1: b 1b + FIXUP_ENDIAN + + /* set up the TOC pointer */ + LOAD_IMM32(%r2, .TOC.) + + /* set up the initial stack */ + LOAD_IMM32(%r1, cpu0_boot_stack) + li %r11, 0 + stdu %r11, -STACK_FRAME_OVERHEAD(%r1) + + /* call the C entrypoint */ + bl start_xen + + /* should never return */ + trap .size start, . - start .type start, %function
xen/arch/ppc/setup.c new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <xen/init.h> + +/* Xen stack for bringing up the first CPU. */ +unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]__aligned(STACK_SIZE) ; + +/* Macro to adjust thread priority for hardware multithreading */ +#define HMT_very_low () asm volatile ( "or %r31, %r31, %r31" ) + +void __init noreturnstart_xen (unsigned long r3,unsigned long r4, +unsigned long r5,unsigned long r6, +unsigned long r7) +{ +for ( ; ; ) +/* Set current hardware thread to very low priority */ +HMT_very_low (); + +unreachable (); +}
Signature · 1 line
2.30.2
Re: [PATCH v5 2/4] xen/ppc: Set up a basic C environment
Quoted 9 lines · Shawn Anastasio
Update
ppc64/head.Sto set up an initial boot stack, zero the .bss section, and jump to C. The required setup is done using 32-bit immediate address loads for now, but they will be changed to TOC-relative loads once the position-independent code model is enabled.Additionally, move the
cpu0_boot_stackdeclaration tosetup.cand changeSTACK_ORDERfrom 2 to 0. For now, ppc64 is using 64k pages and thus the largerSTACK_ORDERis unnecessary.
Quoted 5 lines
Finally, refactor the endian fixup trampoline into its own macro, since it will need to be used in multiple places, including every time we make a call into firmware.
Signed-off-by Shawn Anastasio <[email protected]>
I don't think I'm qualified to really give an R-b, so
will need to do.
Jan
PATCH v5 3/4 xen/ppc: Implement early serial printk on pseries
In reply to Shawn AnastasioOn typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into ppc64/of-call.S.
Support for bare metal (PowerNV) will be implemented in a future patch.
--- xen/arch/ppc/Kconfig.debug | 5 + xen/arch/ppc/Makefile | 2 + xen/arch/ppc/boot-of.c | 113 +++++++++++++++++++ xen/arch/ppc/configs/ppc64_defconfig | 1 + xen/arch/ppc/early_printk.c | 28 +++++ xen/arch/ppc/include/asm/asm-defns.h | 17 +++ xen/arch/ppc/include/asm/boot.h | 23 ++++ xen/arch/ppc/include/asm/byteorder.h | 12 +++ xen/arch/ppc/include/asm/config.h | 3 + xen/arch/ppc/include/asm/early_printk.h | 15 +++ xen/arch/ppc/include/asm/msr.h | 51 +++++++++ xen/arch/ppc/include/asm/processor.h | 138 ++++++++++++++++++++++++ xen/arch/ppc/include/asm/types.h | 21 ++++ xen/arch/ppc/ppc64/Makefile | 1 + xen/arch/ppc/ppc64/asm-offsets.c | 58 ++++++++++ xen/arch/ppc/ppc64/head.S | 9 ++ xen/arch/ppc/ppc64/of-call.S | 83 ++++++++++++++ xen/arch/ppc/setup.c | 19 +++- 18 files changed, 596 insertions(+), 3 deletions(-) create mode 100644 xen/arch/ppc/boot-of.c create mode 100644 xen/arch/ppc/early_printk.c create mode 100644 xen/arch/ppc/include/asm/boot.h create mode 100644 xen/arch/ppc/include/asm/byteorder.h create mode 100644 xen/arch/ppc/include/asm/early_printk.h create mode 100644 xen/arch/ppc/include/asm/msr.h create mode 100644 xen/arch/ppc/include/asm/processor.h create mode 100644 xen/arch/ppc/include/asm/types.h create mode 100644 xen/arch/ppc/ppc64/of-call.S
xen/arch/ppc/Kconfig.debug +5 -0
@@ -0,0 +1,5 @@ +config EARLY_PRINTK + bool "Enable early printk" + default DEBUG + help + Enables early printk debug messages
xen/arch/ppc/Makefile +2 -0
@@ -1,5 +1,7 @@ obj-$(CONFIG_PPC64) += ppc64/ +obj-y += boot-of.init.o +obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o obj-y += setup.o $(TARGET): $(TARGET)-syms
xen/arch/ppc/boot-of.c new file +113 -0
113 lines not on this page · raw message
xen/arch/ppc/configs/ppc64_defconfig +1 -0
@@ -10,4 +10,5 @@ CONFIG_PPC64=y CONFIG_DEBUG=y CONFIG_DEBUG_INFO=y +CONFIG_EARLY_PRINTK=y CONFIG_EXPERT=y
xen/arch/ppc/early_printk.c new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/init.h> +#include <asm/boot.h> + +static void __initdata (*putchar_func)(char ); + +void __init early_printk_init (void (*putchar)(char )) +{ + putchar_func = putchar; +} + +void __init early_puts (const char *s,size_t nr) +{ +if ( !putchar_func ) +return ; + +while ( nr-- >0 ) +putchar_func (*s++); +} + +void __init early_printk (const char *s) +{ +if ( !putchar_func ) +return ; + +while ( *s ) +putchar_func (*s++); +}
xen/arch/ppc/include/asm/asm-defns.h +17 -0
@@ -37,4 +37,21 @@ .long 0xa6037b7d; /* mtsrr1 r11 */ \ .long 0x2400004c /* rfid */ + +/* Taken from Linux kernel source (arch/powerpc/boot/crt0.S) */ +.macro OP_REGS op, width, start, end, base, offset + .Lreg=\start + .rept (\end - \start + 1) + \op .Lreg,\offset+\width*.Lreg(\base) + .Lreg=.Lreg+1 + .endr +.endm + +#define SAVE_GPRS(start, end, base) OP_REGS std, 8, start, end, base, 0 +#define REST_GPRS (start, end, base) OP_REGS ld, 8, start, end, base, 0 +#define SAVE_GPR (n, base) SAVE_GPRS(n, n, base) +#define REST_GPR (n, base) REST_GPRS(n, n, base) +#define SAVE_NVGPRS (base) SAVE_GPRS(14, 31, base) +#define REST_NVGPRS (base) REST_GPRS(14, 31, base) +#endif /* _ASM_PPC_ASM_DEFNS_H */
xen/arch/ppc/include/asm/boot.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_PPC_BOOT_H +#define _ASM_PPC_BOOT_H + +#include <xen/types.h> + +/* a collection of interfaces used during boot. */ +enum { +OF_FAILURE =-1 , +OF_SUCCESS =0 , +}; + +struct of_service { +__be32 ofs_service; +__be32 ofs_nargs; +__be32 ofs_nrets; +__be32 ofs_args[10 ]; +}; + +int enter_of (struct of_service *args,unsigned long entry); +void boot_of_init (unsigned long vec); + +#endif /* _ASM_PPC_BOOT_H */
xen/arch/ppc/include/asm/byteorder.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _ASM_PPC_BYTEORDER_H +#define _ASM_PPC_BYTEORDER_H + +#define __arch__swab16 __builtin_bswap16 +#define __arch__swab32 __builtin_bswap32 +#define __arch__swab64 __builtin_bswap64 + +#define __BYTEORDER_HAS_U64__ + +#include <xen/byteorder/little_endian.h> + +#endif /* _ASM_PPC_BYTEORDER_H */
xen/arch/ppc/include/asm/config.h +3 -0
@@ -52,6 +52,9 @@/* size of minimum stack frame; C code can write into the caller's stack */ #define STACK_FRAME_OVERHEAD 32 +/* ELFv2 ABI mandates 16 byte alignment */ +#define STACK_ALIGN 16 +#endif /* __PPC_CONFIG_H__ */ /* * Local variables:
xen/arch/ppc/include/asm/early_printk.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_PPC_EARLY_PRINTK_H +#define _ASM_PPC_EARLY_PRINTK_H + +#include <xen/early_printk.h> + +#ifdef CONFIG_EARLY_PRINTK +void early_printk_init (void (*putchar)(char )); +void early_printk (const char *s); +#else +static inline void early_printk_init (void (*putchar)(char )) {} +static inline void early_printk (const char *s) {} +#endif + +#endif /* _ASM_PPC_EARLY_PRINTK_H */
xen/arch/ppc/include/asm/msr.h new file +51 -0
51 lines not on this page · raw message
xen/arch/ppc/include/asm/processor.h new file +138 -0
138 lines not on this page · raw message
xen/arch/ppc/include/asm/types.h new file +21 -0
@@ -0,0 +1,21 @@ +/* from xen/arch/x86/include/asm/types.h */ + +#ifndef _ASM_PPC_TYPES_H +#define _ASM_PPC_TYPES_H + +typedef signed char s8 ; +typedef unsigned char u8 ; + +typedef signed short s16 ; +typedef unsigned short u16 ; + +typedef signed int s32 ; +typedef unsigned int u32 ; + +typedef signed long s64 ; +typedef unsigned long u64 ; +typedef unsigned long paddr_t ; +#define INVALID_PADDR (~0UL) +#define PRIpaddr "016lx" + +#endif /* _ASM_PPC_TYPES_H */
xen/arch/ppc/ppc64/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += head.o +obj-y += of-call.o
xen/arch/ppc/ppc64/asm-offsets.c +58 -0
58 lines not on this page · raw message
xen/arch/ppc/ppc64/head.S +9 -0
@@ -18,6 +18,15 @@ ENTRY(start) li %r11, 0 stdu %r11, -STACK_FRAME_OVERHEAD(%r1) + /* clear .bss */ + LOAD_IMM32(%r14, __bss_start) + LOAD_IMM32(%r15, __bss_end) +1: + std %r11, 0(%r14) + addi %r14, %r14, 8 + cmpld %r14, %r15 + blt 1b + /* call the C entrypoint */ bl start_xen
xen/arch/ppc/ppc64/of-call.S new file +83 -0
83 lines not on this page · raw message
xen/arch/ppc/setup.c +16 -3
@@ -1,16 +1,29 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <xen/init.h> +#include <asm/boot.h> +#include <asm/early_printk.h> +#include <asm/processor.h> /* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]__aligned(STACK_SIZE) ; -/* Macro to adjust thread priority for hardware multithreading */ -#define HMT_very_low () asm volatile ( "or %r31, %r31, %r31" ) -void __init noreturnstart_xen (unsigned long r3,unsigned long r4,unsigned long r5,unsigned long r6,unsigned long r7) { +if ( r5 ) + { +/* OpenFirmware boot protocol */ +boot_of_init (r5); + } +else + { +/* kexec boot: Unimplemented */ +__builtin_trap (); + } + +early_printk ("Hello, ppc64le!\n" ); +for ( ; ; )/* Set current hardware thread to very low priority */ HMT_very_low ();
Signature · 1 line
2.30.2
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.
Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>
with the same remark as for patch 2, plus ...
xen/arch/ppc/include/asm/asm-defns.h line 41
Quoted 8 lines
xen/arch/ppc/include/asm/asm-defns.h +2
-0@@ -37,4 +37,21 @@ .long 0xa6037b7d; /* mtsrr1 r11 */ \ .long 0x2400004c /* rfid */ + +/* Taken from Linux kernel source (arch/powerpc/boot/crt0.S) */
... the introduction of a double blank line here dropped (which I'll take care of while committing).
Jan
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
In reply to Shawn AnastasioQuoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.
Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>
While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to memset() out of boot-of.c (supposedly from of_call()).
Jan
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.
Quoted 8 lines
Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to
memset()out ofboot-of.c(supposedly fromof_call()).
Does removing the { 0 } initializer to struct of_service s on line 43 resolve this?
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 16 lines · Shawn Anastasio
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.Support for bare metal (PowerNV) will be implemented in a future patch.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Shawn Anastasio <[email protected]>While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to
memset()out ofboot-of.c(supposedly fromof_call()).Does removing the
{ 0 }initializer tostruct of_service son line 43 resolve this?
Yes, that's what's causing the call (and removing, whether or not correct, helps).
Jan
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Shawn Anastasio
Quoted 20 lines · Jan Beulich
Quoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to
memset()out ofboot-of.c(supposedly fromof_call()).
Quoted 5 lines
Quoted 2 lines
Does removing the
{ 0 }initializer tostruct of_service son line 43 resolve this?Yes, that's what's causing the call (and removing, whether or not correct, helps).
Thanks for confirming. Removing it should be fine since the code manually initializes all of the other fields of the struct. The only behavioral difference is that the members of ofs_args at indices >= nargs would be left uninitialized. This shouldn't be an issue though since we're guarding reads of the array on nargs and nrets and thus only read explicitly initialized values (and of course, firmware would do the same).
Naturally we can't avoid memset calls forever. I have lib/ building locally, but if we could get this series in without having to make those changes here that'd be great.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 38 lines · Shawn Anastasio
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Shawn Anastasio
Quoted 20 lines · Jan Beulich
Quoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to
memset()out ofboot-of.c(supposedly fromof_call()).Quoted 5 lines
Quoted 2 lines
Does removing the
{ 0 }initializer tostruct of_service son line 43 resolve this?Yes, that's what's causing the call (and removing, whether or not correct, helps).
Thanks for confirming. Removing it should be fine since the code manually initializes all of the other fields of the struct. The only behavioral difference is that the members of
ofs_argsat indices >= nargs would be left uninitialized. This shouldn't be an issue though since we're guarding reads of the array onnargsandnretsand thus only read explicitly initialized values (and of course, firmware would do the same).
Quoted 3 lines
Naturally we can't avoid memset calls forever. I have
lib/building locally, but if we could get this series in without having to make those changes here that'd be great.
Are you suggesting I should put in this patch almost as is, with just that initializer dropped?
Jan
Re: [PATCH v5 3/4] xen/ppc: Implement early serial printk on pseries
Quoted 39 lines · Jan Beulich
Quoted 38 lines · Shawn Anastasio
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Shawn Anastasio
Quoted 20 lines · Jan Beulich
Quoted 11 lines · Shawn Anastasio
On typical Power VMs (e.g. QEMU's -M pseries), a variety of services including an early serial console are provided by Open Firmware. Implement the required interfaces to call into Open Firmware and write to the serial console.
Since Open Firmware runs in 32-bit Big Endian mode and Xen runs in 64-bit Little Endian mode, a thunk is required to save/restore any potentially-clobbered registers as well as to perform the required endianness switch. Thankfully, linux already has such a routine, which was imported into
ppc64/of-call.S.Quoted 4 lines
Support for bare metal (PowerNV) will be implemented in a future patch.
Signed-off-by Shawn Anastasio <[email protected]>While I've committed the earlier two patches, I had to back out this one. In my environment (gcc13) the build fails due an unresolved reference to
memset()out ofboot-of.c(supposedly fromof_call()).Quoted 5 lines
Quoted 2 lines
Does removing the
{ 0 }initializer tostruct of_service son line 43 resolve this?Yes, that's what's causing the call (and removing, whether or not correct, helps).
Thanks for confirming. Removing it should be fine since the code manually initializes all of the other fields of the struct. The only behavioral difference is that the members of
ofs_argsat indices >= nargs would be left uninitialized. This shouldn't be an issue though since we're guarding reads of the array onnargsandnretsand thus only read explicitly initialized values (and of course, firmware would do the same).
Quoted 6 lines
Quoted 3 lines
Naturally we can't avoid memset calls forever. I have
lib/building locally, but if we could get this series in without having to make those changes here that'd be great.Are you suggesting I should put in this patch almost as is, with just that initializer dropped?
Yes. I've tested the change locally and it still behaves correctly, so if dropping it removes the memset invocation on your toolchain then I'd say the patch is fine to go with that initializer dropped.
I could also submit a v6 with the initializer dropped, if you'd be more comfortable with that.
Quoted 1 line
Jan
Thanks,
Shawn
PATCH v5 4/4 automation: Add smoke test for ppc64le
In reply to Shawn AnastasioAdd an initial smoke test that boots xen on a ppc64/pseries machine and checks for a magic string. Based on the riscv smoke test.
Eventually the powernv9 (POWER9 bare metal) machine type will want to be tested as well, but for now we only boot on pseries.
--- automation/gitlab-ci/test.yaml | 20 ++++++++++++++++++ automation/scripts/qemu-smoke-ppc64le.sh | 27 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 automation/scripts/qemu-smoke-ppc64le.sh
automation/gitlab-ci/test.yaml +20 -0
@@ -71,6 +71,19 @@ tags: - x86_64 +.qemu-ppc64le: + extends: .test-jobs-common + variables: + CONTAINER: debian:bullseye-ppc64le + LOGFILE: qemu-smoke-ppc64le.log + artifacts: + paths: + - smoke.serial + - '*.log' + when: always + tags: + - x86_64 + .xilinx-arm64: extends: .test-jobs-common variables:
@@ -444,3 +457,10 @@ qemu-smoke-riscv64-gcc: - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE} needs: - archlinux-current-gcc-riscv64-debug + +qemu-smoke-ppc64le-pseries-gcc: + extends: .qemu-ppc64le + script: + - ./automation/scripts/qemu-smoke-ppc64le.sh pseries-5.2 2>&1 | tee ${LOGFILE} + needs: + - debian-bullseye-gcc-ppc64le-debug
automation/scripts/qemu-smoke-ppc64le.sh new file +27 -0
@@ -0,0 +1,27 @@ +#!/bin/bash + +set -ex + +# machine type from first arg passed directly to qemu -M +machine=$1 + +# Run the test +rm -f smoke.serial +set +e + +touch smoke.serial + +timeout -k 1 20 \ +qemu-system-ppc64 \ + -M $machine \ + -m 2g \ + -smp 1 \ + -vga none \ + -monitor none \ + -nographic \ + -serial file:smoke.serial \ + -kernel binaries/xen + +set -e +(grep -q "Hello, ppc64le!" smoke.serial) || exit 1 +exit 0
Signature · 1 line
2.30.2
Re: [PATCH v5 4/4] automation: Add smoke test for ppc64le
Quoted 8 lines · Shawn Anastasio
Add an initial smoke test that boots xen on a ppc64/pseries machine and checks for a magic string. Based on the riscv smoke test.
Eventually the powernv9 (POWER9 bare metal) machine type will want to be tested as well, but for now we only boot on pseries.
Signed-off-by Shawn Anastasio <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>
Re: [PATCH v5 4/4] automation: Add smoke test for ppc64le
In reply to Shawn AnastasioOn 2023/7/22 01:02, Shawn Anastasio wrote:
Add an initial smoke test that boots xen on a ppc64/pseries machine and
checks for a magic string. Based on the riscv smoke test.
Eventually the powernv9 (POWER9 bare metal) machine type will want to be
tested as well, but for now we only boot on pseries.
Quoted 7 lines · Shawn Anastasio
Changes in v5:
- (xen/macros.h) Add signoff
- (xen/macros.h) Fix up comment formatting and macro parameter names
- (*.S) Use 8-space column alignment for assembly
- (of-call.S) Add missing space after comma
- (asm-offsets.c) FixDEFINE()macro formatting
- (asm-offsets.c) Replace_Static_assertwithBUILD_BUG_ON
One more general remark / request: Having change logs in cover letters is certainly okay and better than none at all, but for review purposes it is far more useful when provided in the individual patches. Not the least because, as you will likely understand, the larger the series, the harder it is to associate each of the remarks here with individual patches.
Jan