Skip to contentSkip to conversation

Early serial on Power

PATCH Superseded Shawn Anastasio 2 participants 12 messages Jul 18, 2023 – Jul 24, 2023

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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.

Based on v3 of Jan's "common: move a few macros out of xen/lib.h"
(https://lists.xen.org/archives/html/xen-devel/2023-07/msg00582.html)

Thanks,
Shawn

--
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         |  59 ++++++++++
 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                 |  32 ++++++
 22 files changed, 753 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

#1 lore raw

PATCH v4 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 | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 28 deletions(-)
xen/include/xen/lib.h +0 -28
index dae2a1f085..359cfdc784 100644
@@ -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 +32 -0
index 7b92d34504..e2832b0e8a 100644
@@ -22,6 +22,38 @@
 #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
Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] common: Move a few more standalone macros from xen/lib.h to xen/macros.h

Quoted 4 lines · Shawn Anastasio

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.
---

I would have wanted to put this directly on top of my patch, but the submission lack S-o-b.

Quoted 8 lines
xen/include/xen/macros.h +2 -0
@@ -22,6 +22,38 @@
 #define __STR(...) #__VA_ARGS__
 #define STR(...) __STR(__VA_ARGS__)
 
+#ifndef __ASSEMBLY__
+

xen/include/xen/macros.h line 36

Quoted 10 lines
xen/include/xen/macros.h +10 -0
+/* 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). */

While moving this, please correct comment style.

Quoted 5 lines
xen/include/xen/macros.h +5 -0
+#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)

xen/include/xen/macros.h line 51

Quoted 10 lines
xen/include/xen/macros.h +10 -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 )

While I won't insist here, it would be nice if we could also get rid of the bogus leading underscores as these are moved. Arguments here don't need any, while the local variables want to use trailing underscores, like we do elsewhere.

With at least the earlier two items taken care of, feel free to also add

Jan

#3 lore raw

PATCH v4 2/4 xen/ppc: Set up a basic C environment

In reply to Shawn Anastasio

Update ppc64/head.S to set up an initial boot stack, zero the .bss section, and jump to C.

Also 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 (see next commit).

---
 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
index 98220648af..530fba2121 100644
@@ -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
new file mode 100644
index 0000000000..6ea35f6edb
@@ -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
index b9a6814f00..01ca5d0803 100644
@@ -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
index 2fcefb40d8..17f4a3e19c 100644
@@ -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
new file mode 100644
index 0000000000..9e90a6179a
@@ -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 noreturn start_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
#4 lore raw

Re: [PATCH v4 2/4] xen/ppc: Set up a basic C environment

Quoted 6 lines · Shawn Anastasio

Update ppc64/head.S to set up an initial boot stack, zero the .bss section, and jump to C.

Also 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 (see next commit).

Please avoid statements making relative connections between patches or commits. You can't know how many commits will end up between both patches; there's no guarantee any series will be committed all in one go. (In rare cases, where needed for one reason or another, committers may be asked to keep things together.)

That said, such statements are much less of a problem if given in the remarks section, which isn't going to be committed.

xen/arch/ppc/include/asm/config.h line 46

Quoted 8 lines
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

From the v3 discussion I thought it would follow that the description gain mention of this change (and the why behind it). Strictly speaking this could be a separate change (at which point stating the "why" would hopefully be an obvious part), but I wouldn't want to go as far as demanding this to be split off.

Quoted 30 lines
xen/arch/ppc/ppc64/head.S +3 -17
@@ -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                               */

xen/arch/ppc/ppc64/head.S line 17

Quoted 10 lines
xen/arch/ppc/ppc64/head.S +7 -3
-
-    /* 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)

Similarly I had hoped that if not a code comment, a sentence in the description would appear regarding the (temporary) non-PIC-ness.

Jan

#5 lore raw

PATCH v4 3/4 xen/ppc: Implement early serial printk on pseries

In reply to 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.

---
 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        |  59 ++++++++++
 xen/arch/ppc/ppc64/head.S               |   9 ++
 xen/arch/ppc/ppc64/of-call.S            |  83 ++++++++++++++
 xen/arch/ppc/setup.c                    |  19 +++-
 18 files changed, 597 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
index e69de29bb2..608c9ff832 100644
@@ -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
index 530fba2121..098a4dd0a9 100644
@@ -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
index 8783eb3488..f7cc075e45 100644
@@ -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
new file mode 100644
index 0000000000..781f82133e
@@ -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
index 6ea35f6edb..9d7328f4a2 100644
@@ -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
new file mode 100644
index 0000000000..9b8a7c43c2
@@ -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
new file mode 100644
index 0000000000..2b5f6b9f63
@@ -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
index 01ca5d0803..cb27d2781e 100644
@@ -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
new file mode 100644
index 0000000000..d1d8b416f4
@@ -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
new file mode 100644
index 0000000000..cee08e111a
@@ -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
index 3340058c08..f4956daaa9 100644
@@ -1 +1,2 @@
 obj-y += head.o
+obj-y += of-call.o
xen/arch/ppc/ppc64/asm-offsets.c +59 -0

59 lines not on this page · raw message

xen/arch/ppc/ppc64/head.S +9 -0
index 17f4a3e19c..301ba5c8a5 100644
@@ -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
index 9e90a6179a..7c623a49f5 100644
@@ -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 noreturn start_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
#6 lore raw

Re: [PATCH v4 3/4] xen/ppc: Implement early serial printk on pseries

xen/arch/ppc/boot-of.c line 110

Quoted 10 lines · Shawn Anastasio
xen/arch/ppc/boot-of.c new file +10 -0
+void __init boot_of_init(unsigned long vec)
+{
+    int bof_chosen;
+
+    of_vec = vec;
+
+    /* Get a handle to the default console */
+    bof_chosen = of_finddevice("/chosen");
+    of_getprop(bof_chosen, "stdout", &of_out, sizeof(of_out));
+    of_out = be32_to_cpu(of_out);

Can any of these fail, and hence lead to ...

Quoted 1 line

+ early_printk_init(of_putchar);

... this better not getting invoked?

Quoted 4 lines
xen/arch/ppc/ppc64/asm-offsets.c +1 -0
@@ -0,0 +1,59 @@
+/*

xen/arch/ppc/ppc64/asm-offsets.c line 11

Quoted 10 lines
xen/arch/ppc/ppc64/asm-offsets.c +10 -0
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed
+ * to extract and format the required data.
+ */
+
+#include <asm/processor.h>
+
+#define DEFINE(_sym, _val)                                                 \
+    asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
+                  : : "i" (_val) )

Nit: There's a blank missing after the opening paren, which will then want the 2nd line to be indented by one more character. (Instead, as a matter of your taste, you may omit the blank between the two colons.)

Quoted 29 lines
xen/arch/ppc/ppc64/asm-offsets.c +29 -0
+#define BLANK()                                                            \
+    asm volatile ( "\n.ascii\"==><==\"" : : )
+#define OFFSET(_sym, _str, _mem)                                           \
+    DEFINE(_sym, offsetof(_str, _mem));
+
+/* base-2 logarithm */
+#define __L2(_x)  (((_x) & 0x00000002) ?   1 : 0)
+#define __L4(_x)  (((_x) & 0x0000000c) ? ( 2 + __L2( (_x)>> 2)) : __L2( _x))
+#define __L8(_x)  (((_x) & 0x000000f0) ? ( 4 + __L4( (_x)>> 4)) : __L4( _x))
+#define __L16(_x) (((_x) & 0x0000ff00) ? ( 8 + __L8( (_x)>> 8)) : __L8( _x))
+#define LOG_2(_x) (((_x) & 0xffff0000) ? (16 + __L16((_x)>>16)) : __L16(_x))
+
+void __dummy__(void)
+{
+    DEFINE(GPR_WIDTH, sizeof(unsigned long));
+    DEFINE(FPR_WIDTH, sizeof(double));
+
+    OFFSET(UREGS_gprs, struct cpu_user_regs, gprs);
+    OFFSET(UREGS_r0, struct cpu_user_regs, gprs[0]);
+    OFFSET(UREGS_r1, struct cpu_user_regs, gprs[1]);
+    OFFSET(UREGS_r13, struct cpu_user_regs, gprs[13]);
+    OFFSET(UREGS_srr0, struct cpu_user_regs, srr0);
+    OFFSET(UREGS_srr1, struct cpu_user_regs, srr1);
+    OFFSET(UREGS_pc, struct cpu_user_regs, pc);
+    OFFSET(UREGS_msr, struct cpu_user_regs, msr);
+    OFFSET(UREGS_lr, struct cpu_user_regs, lr);
+    OFFSET(UREGS_ctr, struct cpu_user_regs, ctr);
+    OFFSET(UREGS_xer, struct cpu_user_regs, xer);
+    OFFSET(UREGS_hid4, struct cpu_user_regs, hid4);

xen/arch/ppc/ppc64/asm-offsets.c line 50

Quoted 10 lines
xen/arch/ppc/ppc64/asm-offsets.c +10 -0
+    OFFSET(UREGS_dar, struct cpu_user_regs, dar);
+    OFFSET(UREGS_dsisr, struct cpu_user_regs, dsisr);
+    OFFSET(UREGS_cr, struct cpu_user_regs, cr);
+    OFFSET(UREGS_fpscr, struct cpu_user_regs, fpscr);
+    DEFINE(UREGS_sizeof, sizeof(struct cpu_user_regs));
+}
+
+/* TODO: Replace with BUILD_BUG_ON + IS_ALIGNED once we can use <xen/lib.h> */
+_Static_assert(sizeof(struct cpu_user_regs) % STACK_ALIGN == 0,
+               "struct cpu_user_regs not stack aligned!");

But patch 1 makes BUILD_BUG_ON() available now.

Quoted 22 lines
xen/arch/ppc/ppc64/of-call.S new file +19 -0
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Adapted from Linux's arch/powerpc/kernel/entry_64.S, with the
+ * following copyright notice:
+ *
+ *  PowerPC version
+ *    Copyright (C) 1995-1996 Gary Thomas ([email protected])
+ *  Rewritten by Cort Dougan ([email protected]) for PReP
+ *    Copyright (C) 1996 Cort Dougan <[email protected]>
+ *  Adapted for Power Macintosh by Paul Mackerras.
+ *  Low-level exception handlers and MMU support
+ *  rewritten by Paul Mackerras.
+ *    Copyright (C) 1996 Paul Mackerras.
+ *  MPC8xx modifications Copyright (C) 1997 Dan Malek ([email protected]).
+ */
+
+#include <asm/asm-offsets.h>
+#include <asm/asm-defns.h>
+#include <asm/msr.h>

xen/arch/ppc/ppc64/of-call.S line 29

Quoted 10 lines
xen/arch/ppc/ppc64/of-call.S new file +10 -0
+
+/* size of minimum stack frame that can hold an entire cpu_user_regs struct */
+#define STACK_SWITCH_FRAME_SIZE UREGS_sizeof
+
+    .section .init.text, "ax", @progbits
+
+ENTRY(enter_of)
+    mflr %r0
+    std %r0, 16(%r1)
+    stdu %r1,-STACK_SWITCH_FRAME_SIZE(%r1) /* Save SP and create stack space */

Nit: A blank after the comma would again be nice.

Quoted 43 lines
xen/arch/ppc/ppc64/of-call.S new file +43 -0
+    /*
+     * Because PROM is running in 32b mode, it clobbers the high order half
+     * of all registers that it saves.  We therefore save those registers
+     * PROM might touch to the stack.  (%r0, %r3-%r13 are caller saved)
+     */
+    SAVE_GPR(2, %r1)
+    SAVE_GPR(13, %r1)
+    SAVE_NVGPRS(%r1)
+    mfcr %r10
+    mfmsr %r11
+    std %r10, UREGS_cr(%r1)
+    std %r11, UREGS_msr(%r1)
+
+    /* Put PROM address in SRR0 */
+    mtsrr0 %r4
+
+    /* Setup our trampoline return addr in LR */
+    bcl 20, 31, .+4
+0:  mflr %r4
+    addi %r4, %r4, 1f - 0b
+    mtlr %r4
+
+    /* Prepare a 32-bit mode big endian MSR */
+    LOAD_IMM64(%r12, MSR_SF | MSR_LE)
+    andc %r11, %r11, %r12
+    mtsrr1 %r11
+    rfid
+
+1:  /* Return from OF */
+    FIXUP_ENDIAN
+
+    /* Just make sure that %r1 top 32 bits didn't get corrupt by OF */
+    rldicl %r1, %r1, 0, 32
+
+    /* Restore the MSR (back to 64 bits) */
+    ld %r0, UREGS_msr(%r1)
+    mtmsrd %r0
+    isync
+
+    /* Restore other registers */
+    REST_GPR(2, %r1)
+    REST_GPR(13, %r1)
+    REST_NVGPRS(%r1)

xen/arch/ppc/ppc64/of-call.S line 83

Quoted 10 lines
xen/arch/ppc/ppc64/of-call.S new file +10 -0
+    ld %r4, UREGS_cr(%r1)
+    mtcr %r4
+
+    addi %r1, %r1, STACK_SWITCH_FRAME_SIZE
+    ld %r0, 16(%r1)
+    mtlr %r0
+    blr
+
+    .size enter_of, . - enter_of
+    .type enter_of, %function

Before you/we grow more assembly code, may I re-raise a request regarding
readability: I think it would be nice if operands started at a fixed column, unless the insn mnemonic is unusually long. Where exactly to draw the line is up to each archtecture; on x86 we use 8 positions from the start of the mnemonic.

Jan

#7 lore raw

Re: [PATCH v4 3/4] xen/ppc: Implement early serial printk on pseries

Quoted 5 lines · Jan Beulich

Before you/we grow more assembly code, may I re-raise a request regarding
readability: I think it would be nice if operands started at a fixed column, unless the insn mnemonic is unusually long. Where exactly to draw the line is up to each archtecture; on x86 we use 8 positions from the start of the mnemonic.

There is quite a large variance in mnemonic length on ppc -- many common mnemonics only use 2 characters (e.g. ld, mr) while other common ones use 6+ (e.g. rldicr, the mtspr family, etc.). Enforcing a column size that's too short would make the longer mnemonics look misaligned and out of place, but using a longer column length (like 8) that can accommodate most common mnemonics adds too much space between short mnemonics and their arguments.

That said if you still feel strongly about this then I am not strongly opposed to adding an 8-space column alignment.

Quoted 1 line

Jan

Thanks,
Shawn

#8 lore raw

Re: [PATCH v4 3/4] xen/ppc: Implement early serial printk on pseries

Quoted 7 lines · Shawn Anastasio
Quoted 5 lines · Jan Beulich

Before you/we grow more assembly code, may I re-raise a request regarding
readability: I think it would be nice if operands started at a fixed column, unless the insn mnemonic is unusually long. Where exactly to draw the line is up to each archtecture; on x86 we use 8 positions from the start of the mnemonic.

Quoted 7 lines

There is quite a large variance in mnemonic length on ppc -- many common mnemonics only use 2 characters (e.g. ld, mr) while other common ones use 6+ (e.g. rldicr, the mtspr family, etc.). Enforcing a column size that's too short would make the longer mnemonics look misaligned and out of place, but using a longer column length (like 8) that can accommodate most common mnemonics adds too much space between short mnemonics and their arguments.

Common length is 3 on x86, and as said we use 8.

Quoted 2 lines

That said if you still feel strongly about this then I am not strongly opposed to adding an 8-space column alignment.

I certainly think it helps readability a lot. 8 also matches the common use (fair parts of gas'es testsuite, Linux) of hard tabs.

Jan

#9 lore raw

Re: [PATCH v4 3/4] xen/ppc: Implement early serial printk on pseries

In reply to Jan Beulich
Quoted 13 lines · Jan Beulich

xen/arch/ppc/boot-of.c line 110

Quoted 10 lines · Shawn Anastasio
xen/arch/ppc/boot-of.c new file +10 -0
+void __init boot_of_init(unsigned long vec)
+{
+    int bof_chosen;
+
+    of_vec = vec;
+
+    /* Get a handle to the default console */
+    bof_chosen = of_finddevice("/chosen");
+    of_getprop(bof_chosen, "stdout", &of_out, sizeof(of_out));
+    of_out = be32_to_cpu(of_out);

Can any of these fail, and hence lead to ...

These calls are allowed to fail, but their return value in those cases is well-defined (an invalid handle), so...

Quoted 4 lines
Quoted 2 lines

+ early_printk_init(of_putchar);

... this better not getting invoked?

this being invoked is fine even in those cases. It will just result in the invalid handle being passed to of_write and the firmware will refuse to service the writes.

Quoted 10 lines
Quoted 10 lines
xen/arch/ppc/ppc64/asm-offsets.c +7 -0
@@ -0,0 +1,59 @@
+/*
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed
+ * to extract and format the required data.
+ */
+
+#include <asm/processor.h>
Quoted 8 lines

xen/arch/ppc/ppc64/asm-offsets.c line 11

Quoted 4 lines
xen/arch/ppc/ppc64/asm-offsets.c +4 -0
+
+#define DEFINE(_sym, _val)                                                 \
+    asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
+                  : : "i" (_val) )

Nit: There's a blank missing after the opening paren, which will then want the 2nd line to be indented by one more character. (Instead, as a matter of your taste, you may omit the blank between the two colons.)

Will fix.

Quoted 33 lines
Quoted 33 lines
xen/arch/ppc/ppc64/asm-offsets.c +33 -0
+#define BLANK()                                                            \
+    asm volatile ( "\n.ascii\"==><==\"" : : )
+#define OFFSET(_sym, _str, _mem)                                           \
+    DEFINE(_sym, offsetof(_str, _mem));
+
+/* base-2 logarithm */
+#define __L2(_x)  (((_x) & 0x00000002) ?   1 : 0)
+#define __L4(_x)  (((_x) & 0x0000000c) ? ( 2 + __L2( (_x)>> 2)) : __L2( _x))
+#define __L8(_x)  (((_x) & 0x000000f0) ? ( 4 + __L4( (_x)>> 4)) : __L4( _x))
+#define __L16(_x) (((_x) & 0x0000ff00) ? ( 8 + __L8( (_x)>> 8)) : __L8( _x))
+#define LOG_2(_x) (((_x) & 0xffff0000) ? (16 + __L16((_x)>>16)) : __L16(_x))
+
+void __dummy__(void)
+{
+    DEFINE(GPR_WIDTH, sizeof(unsigned long));
+    DEFINE(FPR_WIDTH, sizeof(double));
+
+    OFFSET(UREGS_gprs, struct cpu_user_regs, gprs);
+    OFFSET(UREGS_r0, struct cpu_user_regs, gprs[0]);
+    OFFSET(UREGS_r1, struct cpu_user_regs, gprs[1]);
+    OFFSET(UREGS_r13, struct cpu_user_regs, gprs[13]);
+    OFFSET(UREGS_srr0, struct cpu_user_regs, srr0);
+    OFFSET(UREGS_srr1, struct cpu_user_regs, srr1);
+    OFFSET(UREGS_pc, struct cpu_user_regs, pc);
+    OFFSET(UREGS_msr, struct cpu_user_regs, msr);
+    OFFSET(UREGS_lr, struct cpu_user_regs, lr);
+    OFFSET(UREGS_ctr, struct cpu_user_regs, ctr);
+    OFFSET(UREGS_xer, struct cpu_user_regs, xer);
+    OFFSET(UREGS_hid4, struct cpu_user_regs, hid4);
+    OFFSET(UREGS_dar, struct cpu_user_regs, dar);
+    OFFSET(UREGS_dsisr, struct cpu_user_regs, dsisr);
+    OFFSET(UREGS_cr, struct cpu_user_regs, cr);
+    OFFSET(UREGS_fpscr, struct cpu_user_regs, fpscr);
Quoted 8 lines

xen/arch/ppc/ppc64/asm-offsets.c line 50

Quoted 6 lines
xen/arch/ppc/ppc64/asm-offsets.c +6 -0
+    DEFINE(UREGS_sizeof, sizeof(struct cpu_user_regs));
+}
+
+/* TODO: Replace with BUILD_BUG_ON + IS_ALIGNED once we can use <xen/lib.h> */
+_Static_assert(sizeof(struct cpu_user_regs) % STACK_ALIGN == 0,
+               "struct cpu_user_regs not stack aligned!");

But patch 1 makes BUILD_BUG_ON() available now.

Good point, will fix.

Quoted 26 lines
Quoted 26 lines
xen/arch/ppc/ppc64/of-call.S new file +23 -0
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Adapted from Linux's arch/powerpc/kernel/entry_64.S, with the
+ * following copyright notice:
+ *
+ *  PowerPC version
+ *    Copyright (C) 1995-1996 Gary Thomas ([email protected])
+ *  Rewritten by Cort Dougan ([email protected]) for PReP
+ *    Copyright (C) 1996 Cort Dougan <[email protected]>
+ *  Adapted for Power Macintosh by Paul Mackerras.
+ *  Low-level exception handlers and MMU support
+ *  rewritten by Paul Mackerras.
+ *    Copyright (C) 1996 Paul Mackerras.
+ *  MPC8xx modifications Copyright (C) 1997 Dan Malek ([email protected]).
+ */
+
+#include <asm/asm-offsets.h>
+#include <asm/asm-defns.h>
+#include <asm/msr.h>
+
+/* size of minimum stack frame that can hold an entire cpu_user_regs struct */
+#define STACK_SWITCH_FRAME_SIZE UREGS_sizeof
+
Quoted 8 lines

xen/arch/ppc/ppc64/of-call.S line 29

Quoted 6 lines
xen/arch/ppc/ppc64/of-call.S new file +6 -0
+    .section .init.text, "ax", @progbits
+
+ENTRY(enter_of)
+    mflr %r0
+    std %r0, 16(%r1)
+    stdu %r1,-STACK_SWITCH_FRAME_SIZE(%r1) /* Save SP and create stack space */

Nit: A blank after the comma would again be nice.

Will fix.

Quoted 45 lines
Quoted 45 lines
xen/arch/ppc/ppc64/of-call.S new file +45 -0
+    /*
+     * Because PROM is running in 32b mode, it clobbers the high order half
+     * of all registers that it saves.  We therefore save those registers
+     * PROM might touch to the stack.  (%r0, %r3-%r13 are caller saved)
+     */
+    SAVE_GPR(2, %r1)
+    SAVE_GPR(13, %r1)
+    SAVE_NVGPRS(%r1)
+    mfcr %r10
+    mfmsr %r11
+    std %r10, UREGS_cr(%r1)
+    std %r11, UREGS_msr(%r1)
+
+    /* Put PROM address in SRR0 */
+    mtsrr0 %r4
+
+    /* Setup our trampoline return addr in LR */
+    bcl 20, 31, .+4
+0:  mflr %r4
+    addi %r4, %r4, 1f - 0b
+    mtlr %r4
+
+    /* Prepare a 32-bit mode big endian MSR */
+    LOAD_IMM64(%r12, MSR_SF | MSR_LE)
+    andc %r11, %r11, %r12
+    mtsrr1 %r11
+    rfid
+
+1:  /* Return from OF */
+    FIXUP_ENDIAN
+
+    /* Just make sure that %r1 top 32 bits didn't get corrupt by OF */
+    rldicl %r1, %r1, 0, 32
+
+    /* Restore the MSR (back to 64 bits) */
+    ld %r0, UREGS_msr(%r1)
+    mtmsrd %r0
+    isync
+
+    /* Restore other registers */
+    REST_GPR(2, %r1)
+    REST_GPR(13, %r1)
+    REST_NVGPRS(%r1)
+    ld %r4, UREGS_cr(%r1)
+    mtcr %r4
Quoted 8 lines

xen/arch/ppc/ppc64/of-call.S line 83

Quoted 8 lines
xen/arch/ppc/ppc64/of-call.S new file +8 -0
+
+    addi %r1, %r1, STACK_SWITCH_FRAME_SIZE
+    ld %r0, 16(%r1)
+    mtlr %r0
+    blr
+
+    .size enter_of, . - enter_of
+    .type enter_of, %function

Thanks,
Shawn

#10 lore raw

Re: [PATCH v4 3/4] xen/ppc: Implement early serial printk on pseries

Quoted 19 lines · Shawn Anastasio
Quoted 13 lines · Jan Beulich

xen/arch/ppc/boot-of.c line 110

Quoted 10 lines · Shawn Anastasio
xen/arch/ppc/boot-of.c new file +10 -0
+void __init boot_of_init(unsigned long vec)
+{
+    int bof_chosen;
+
+    of_vec = vec;
+
+    /* Get a handle to the default console */
+    bof_chosen = of_finddevice("/chosen");
+    of_getprop(bof_chosen, "stdout", &of_out, sizeof(of_out));
+    of_out = be32_to_cpu(of_out);

Can any of these fail, and hence lead to ...

These calls are allowed to fail, but their return value in those cases is well-defined (an invalid handle), so...

Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+ early_printk_init(of_putchar);

... this better not getting invoked?

this being invoked is fine even in those cases. It will just result in the invalid handle being passed to of_write and the firmware will refuse to service the writes.

I assumed all this to be the case; the question was more towards "Wouldn't it make sense to avoid installing the function pointer in such a case?"

Jan

#11 lore raw

PATCH v4 4/4 automation: Add smoke test for ppc64le

In reply to 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.

---
 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
index d5cb238b0a..45e8ddb7a3 100644
@@ -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
new file mode 100755
index 0000000000..eb55221221
@@ -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