Skip to contentSkip to conversation

Early serial on Power

PATCH Superseded Shawn Anastasio 4 participants 18 messages Jun 21, 2023 – Jun 23, 2023

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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 third patch, which implements the serial console, also includes a set of header additions required to get the build going when including things like xen/lib.h. When applicable, headers from the old Xen 3.2.3 ppc tree were imported or otherwise empty stub headers were added to be filled in later.

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.

Thanks,
Shawn

Shawn Anastasio (4):
automation: Add QEMU to bullseye-ppc64le
automation: Fix KBUILD_DEFCONFIG for *ppc64le jobs xen/ppc: Implement early serial printk on pseries
automation: Add smoke test for ppc64le

 .../build/debian/bullseye-ppc64le.dockerfile  |   2 +
 automation/gitlab-ci/build.yaml               |   8 +-
 automation/gitlab-ci/test.yaml                |  20 ++
 automation/scripts/qemu-smoke-ppc64le.sh      |  27 +++
 xen/arch/ppc/Kconfig.debug                    |   5 +
 xen/arch/ppc/Makefile                         |   3 +
 xen/arch/ppc/boot-of.c                        | 116 ++++++++++
 xen/arch/ppc/configs/ppc64_defconfig          |   1 +
 xen/arch/ppc/early_printk.c                   |  28 +++
 xen/arch/ppc/include/asm/boot.h               |  24 ++
 xen/arch/ppc/include/asm/bug.h                |   6 +
 xen/arch/ppc/include/asm/byteorder.h          |  37 +++
 xen/arch/ppc/include/asm/cache.h              |   6 +
 xen/arch/ppc/include/asm/early_printk.h       |  15 ++
 xen/arch/ppc/include/asm/msr.h                |  67 ++++++
 xen/arch/ppc/include/asm/processor.h          | 207 +++++++++++++++++
 xen/arch/ppc/include/asm/reg_defs.h           | 218 ++++++++++++++++++
 xen/arch/ppc/include/asm/string.h             |   6 +
 xen/arch/ppc/include/asm/types.h              |  35 +++
 xen/arch/ppc/ppc64/Makefile                   |   1 +
 xen/arch/ppc/ppc64/asm-offsets.c              |  55 +++++
 xen/arch/ppc/ppc64/head.S                     |  48 ++--
 xen/arch/ppc/ppc64/of-call.S                  |  85 +++++++
 xen/arch/ppc/setup.c                          |  31 +++
 24 files changed, 1025 insertions(+), 26 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/boot.h
 create mode 100644 xen/arch/ppc/include/asm/bug.h
 create mode 100644 xen/arch/ppc/include/asm/byteorder.h
 create mode 100644 xen/arch/ppc/include/asm/cache.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/reg_defs.h
 create mode 100644 xen/arch/ppc/include/asm/string.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 1/4 automation: Add QEMU to bullseye-ppc64le

Add qemu-system-ppc package to the bullseye-ppc64le container to allow running smoke tests in CI.

---
 automation/build/debian/bullseye-ppc64le.dockerfile | 2 ++
 1 file changed, 2 insertions(+)
automation/build/debian/bullseye-ppc64le.dockerfile +2 -0
index 8a87631b52..8fad26e903 100644
@@ -22,6 +22,8 @@ RUN apt-get update && \
         gcc-powerpc64le-linux-gnu \
         make \
         python3-minimal \
+        # for test phase
+        qemu-system-ppc \
         && \
         apt-get autoremove -y && \
         apt-get clean && \
Signature · 1 line
2.30.2
#3 lore raw

PATCH 2/4 automation: Fix KBUILD_DEFCONFIG for *ppc64le jobs

In reply to Shawn Anastasio

During an iteration of the initial ppc64le support patchset the default defconfig was renamed but build.yaml wasn't updated to reflect this. Fix it up.

---
 automation/gitlab-ci/build.yaml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
automation/gitlab-ci/build.yaml +4 -4
index bd8c7332db..c401f62d61 100644
@@ -548,21 +548,21 @@ debian-bullseye-gcc-ppc64le:
   extends: .gcc-ppc64le-cross-build
   variables:
     CONTAINER: debian:bullseye-ppc64le
-    KBUILD_DEFCONFIG: openpower_defconfig
+    KBUILD_DEFCONFIG: ppc64_defconfig
     HYPERVISOR_ONLY: y
 
 debian-bullseye-gcc-ppc64le-debug:
   extends: .gcc-ppc64le-cross-build-debug
   variables:
     CONTAINER: debian:bullseye-ppc64le
-    KBUILD_DEFCONFIG: openpower_defconfig
+    KBUILD_DEFCONFIG: ppc64_defconfig
     HYPERVISOR_ONLY: y
 
 debian-bullseye-gcc-ppc64le-randconfig:
   extends: .gcc-ppc64le-cross-build
   variables:
     CONTAINER: debian:bullseye-ppc64le
-    KBUILD_DEFCONFIG: openpower_defconfig
+    KBUILD_DEFCONFIG: ppc64_defconfig
     RANDCONFIG: y
     EXTRA_FIXED_RANDCONFIG:
       CONFIG_COVERAGE=n
@@ -571,7 +571,7 @@ debian-bullseye-gcc-ppc64le-debug-randconfig:
   extends: .gcc-ppc64le-cross-build-debug
   variables:
     CONTAINER: debian:bullseye-ppc64le
-    KBUILD_DEFCONFIG: openpower_defconfig
+    KBUILD_DEFCONFIG: ppc64_defconfig
     RANDCONFIG: y
     EXTRA_FIXED_RANDCONFIG:
       CONFIG_COVERAGE=n
Signature · 1 line
2.30.2
Acked-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] automation: Fix KBUILD_DEFCONFIG for *ppc64le jobs

Quoted 5 lines · Shawn Anastasio

During an iteration of the initial ppc64le support patchset the default defconfig was renamed but build.yaml wasn't updated to reflect this. Fix it up.

I'll commit this too.  Clearly it's not fatal to build testing.

#5 lore raw

PATCH 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                   |   3 +
 xen/arch/ppc/boot-of.c                  | 116 +++++++++++++
 xen/arch/ppc/configs/ppc64_defconfig    |   1 +
 xen/arch/ppc/early_printk.c             |  28 +++
 xen/arch/ppc/include/asm/boot.h         |  24 +++
 xen/arch/ppc/include/asm/bug.h          |   6 +
 xen/arch/ppc/include/asm/byteorder.h    |  37 ++++
 xen/arch/ppc/include/asm/cache.h        |   6 +
 xen/arch/ppc/include/asm/early_printk.h |  15 ++
 xen/arch/ppc/include/asm/msr.h          |  67 ++++++++
 xen/arch/ppc/include/asm/processor.h    | 207 ++++++++++++++++++++++
 xen/arch/ppc/include/asm/reg_defs.h     | 218 ++++++++++++++++++++++++
 xen/arch/ppc/include/asm/string.h       |   6 +
 xen/arch/ppc/include/asm/types.h        |  35 ++++
 xen/arch/ppc/ppc64/Makefile             |   1 +
 xen/arch/ppc/ppc64/asm-offsets.c        |  55 ++++++
 xen/arch/ppc/ppc64/head.S               |  48 +++---
 xen/arch/ppc/ppc64/of-call.S            |  85 +++++++++
 xen/arch/ppc/setup.c                    |  31 ++++
 20 files changed, 972 insertions(+), 22 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/bug.h
 create mode 100644 xen/arch/ppc/include/asm/byteorder.h
 create mode 100644 xen/arch/ppc/include/asm/cache.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/reg_defs.h
 create mode 100644 xen/arch/ppc/include/asm/string.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
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 +3 -0
index 98220648af..4c4cdcb60e 100644
@@ -1,4 +1,7 @@
 obj-$(CONFIG_PPC64) += ppc64/
+obj-y += setup.o
+obj-y += boot-of.o
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
 
 $(TARGET): $(TARGET)-syms
 	cp -f $< $@
xen/arch/ppc/boot-of.c new file +116 -0

116 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..309a1a7fd9
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <xen/lib.h>
+#include <asm/boot.h>
+
+static void (*putchar_func)(char);
+
+void early_printk_init(void (*putchar)(char))
+{
+    putchar_func = putchar;
+}
+
+void early_puts(const char *s, size_t nr)
+{
+    if ( !putchar_func )
+        return;
+
+    while ( nr-- > 0 )
+        putchar_func(*s++);
+}
+
+void early_printk(const char *s)
+{
+    if ( !putchar_func )
+        return;
+
+    while ( *s )
+        putchar_func(*s++);
+}
xen/arch/ppc/include/asm/boot.h new file +24 -0
new file mode 100644
index 0000000000..ea4a945bb4
@@ -0,0 +1,24 @@
+/* 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];
+};
+
+extern int enter_of(struct of_service *args, unsigned long entry);
+
+void boot_of_init(unsigned long);
+
+#endif /* _ASM_PPC_BOOT_H */
xen/arch/ppc/include/asm/bug.h new file +6 -0
new file mode 100644
index 0000000000..a23ab1fa74
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_BUG_H
+#define _ASM_PPC_BUG_H
+
+#endif /* _ASM_PPC_BUG_H */
xen/arch/ppc/include/asm/byteorder.h new file +37 -0
new file mode 100644
index 0000000000..cc4d55b355
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _ASM_POWERPC_BYTEORDER_H
+#define _ASM_POWERPC_BYTEORDER_H
+
+#include <asm/types.h>
+#include <xen/compiler.h>
+
+static inline __attribute_const__ __u16 ___arch__swab16(__u16 value)
+{
+    __u16 result;
+
+    asm("rlwimi %0,%1,8,16,23"
+        : "=r" (result)
+        : "r" (value), "0" (value >> 8));
+    return result;
+}
+
+static inline __attribute_const__ __u32 ___arch__swab32(__u32 value)
+{
+    __u32 result;
+
+    asm("rlwimi %0,%1,24,16,23\n\t"
+        "rlwimi %0,%1,8,8,15\n\t"
+        "rlwimi %0,%1,24,0,7"
+        : "=r" (result)
+        : "r" (value), "0" (value >> 24));
+    return result;
+}
+
+#define __arch__swab16(x) ___arch__swab16(x)
+#define __arch__swab32(x) ___arch__swab32(x)
+
+#define __BYTEORDER_HAS_U64__
+
+#include <xen/byteorder/little_endian.h>
+
+#endif /* _ASM_POWERPC_BYTEORDER_H */
xen/arch/ppc/include/asm/cache.h new file +6 -0
new file mode 100644
index 0000000000..8a0a6b7b17
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_CACHE_H
+#define _ASM_PPC_CACHE_H
+
+#endif /* _ASM_PPC_CACHE_H */
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 +67 -0

67 lines not on this page · raw message

xen/arch/ppc/include/asm/processor.h new file +207 -0

207 lines not on this page · raw message

xen/arch/ppc/include/asm/reg_defs.h new file +218 -0

218 lines not on this page · raw message

xen/arch/ppc/include/asm/string.h new file +6 -0
new file mode 100644
index 0000000000..7a420e05e4
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_STRING_H
+#define _ASM_PPC_STRING_H
+
+#endif /* _ASM_PPC_STRING_H */
xen/arch/ppc/include/asm/types.h new file +35 -0
new file mode 100644
index 0000000000..05c42280d4
@@ -0,0 +1,35 @@
+/* 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;
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+typedef __signed__ long __s64;
+typedef unsigned long __u64;
+#endif
+
+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 +55 -0

55 lines not on this page · raw message

xen/arch/ppc/ppc64/head.S +26 -22

56 lines not on this page · raw message

xen/arch/ppc/ppc64/of-call.S new file +85 -0

85 lines not on this page · raw message

xen/arch/ppc/setup.c new file +31 -0
new file mode 100644
index 0000000000..a312c12e6a
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/compile.h>
+#include <xen/init.h>
+#include <asm/boot.h>
+#include <asm/early_printk.h>
+
+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
+        asm volatile("or 31,31,31");
+    }
+
+    unreachable();
+}
Signature · 1 line
2.30.2
#6 lore raw

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

Quoted 27 lines · Shawn Anastasio
 xen/arch/ppc/Kconfig.debug              |   5 +
 xen/arch/ppc/Makefile                   |   3 +
 xen/arch/ppc/boot-of.c                  | 116 +++++++++++++
 xen/arch/ppc/configs/ppc64_defconfig    |   1 +
 xen/arch/ppc/early_printk.c             |  28 +++
 xen/arch/ppc/include/asm/boot.h         |  24 +++
 xen/arch/ppc/include/asm/bug.h          |   6 +
 xen/arch/ppc/include/asm/byteorder.h    |  37 ++++
 xen/arch/ppc/include/asm/cache.h        |   6 +
 xen/arch/ppc/include/asm/early_printk.h |  15 ++
 xen/arch/ppc/include/asm/msr.h          |  67 ++++++++
 xen/arch/ppc/include/asm/processor.h    | 207 ++++++++++++++++++++++
 xen/arch/ppc/include/asm/reg_defs.h     | 218 ++++++++++++++++++++++++
 xen/arch/ppc/include/asm/string.h       |   6 +
 xen/arch/ppc/include/asm/types.h        |  35 ++++
 xen/arch/ppc/ppc64/Makefile             |   1 +
 xen/arch/ppc/ppc64/asm-offsets.c        |  55 ++++++
 xen/arch/ppc/ppc64/head.S               |  48 +++---
 xen/arch/ppc/ppc64/of-call.S            |  85 +++++++++
 xen/arch/ppc/setup.c                    |  31 ++++
 20 files changed, 972 insertions(+), 22 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/bug.h
 create mode 100644 xen/arch/ppc/include/asm/byteorder.h
 create mode 100644 xen/arch/ppc/include/asm/cache.h
Quoted 8 lines
 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/reg_defs.h
 create mode 100644 xen/arch/ppc/include/asm/string.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

This is a surprising amount of infrastructure.  I'm guessing it's a consequence of needing byteorder ?

There's a series still out deleting swathes of junk in byteorder.  I guess I need to kick that thread again, but it mostly boils down to using __builtin_bswap$N() (and on x86, reimplementing them on old enough compilers).  Presumably all versions of GCC (and eventually Clang) we care to support with ppc64 understand this builtin ?

I've noticed a couple of other things.  asm/types.h repeats some antipatterns which we're trying to delete for MISRA reasons in other architectures.  I was already planning to fix that up xen-wide, and I guess now is the better time to do so.

Elsewhere, you've got a number of __inline__'s.  We think those are all vestigial now, so should be switched to using a plain inline.

Also, there are a bunch of UL() or ULL() macros which encoding a difference between asm and C.  In Xen, we use _AC() for that, which you can find in <xen/const.h>.

Similarly, there are some functions which ought to be __init, so it would be good to get them correct from the start.

Maybe as an intermediate step, just get the infinite loop moved from asm up into C?  That gets the stack setup, and various of the asm helpers, without all the rest of the C required to get early_printk() to work.

Something we've been trying very hard to do generally is declutter processor.h, and on x86, we've got asm-defns.h as a more appropriate place to have the stuff which is expected to be common to all asm code, and never encountered in C.

A couple of questions before I dive further in.

Given:

#define r0  0

do the assemblers really not understand register names?  That seems mad.

Also, given the transformations to call into OpenFirmware, presumably this limits Xen to running below the 4G boundary and on identity mappings?

~Andrew

#7 lore raw

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

Quoted 37 lines · Andrew Cooper
Quoted 27 lines · Shawn Anastasio
 xen/arch/ppc/Kconfig.debug              |   5 +
 xen/arch/ppc/Makefile                   |   3 +
 xen/arch/ppc/boot-of.c                  | 116 +++++++++++++
 xen/arch/ppc/configs/ppc64_defconfig    |   1 +
 xen/arch/ppc/early_printk.c             |  28 +++
 xen/arch/ppc/include/asm/boot.h         |  24 +++
 xen/arch/ppc/include/asm/bug.h          |   6 +
 xen/arch/ppc/include/asm/byteorder.h    |  37 ++++
 xen/arch/ppc/include/asm/cache.h        |   6 +
 xen/arch/ppc/include/asm/early_printk.h |  15 ++
 xen/arch/ppc/include/asm/msr.h          |  67 ++++++++
 xen/arch/ppc/include/asm/processor.h    | 207 ++++++++++++++++++++++
 xen/arch/ppc/include/asm/reg_defs.h     | 218 ++++++++++++++++++++++++
 xen/arch/ppc/include/asm/string.h       |   6 +
 xen/arch/ppc/include/asm/types.h        |  35 ++++
 xen/arch/ppc/ppc64/Makefile             |   1 +
 xen/arch/ppc/ppc64/asm-offsets.c        |  55 ++++++
 xen/arch/ppc/ppc64/head.S               |  48 +++---
 xen/arch/ppc/ppc64/of-call.S            |  85 +++++++++
 xen/arch/ppc/setup.c                    |  31 ++++
 20 files changed, 972 insertions(+), 22 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/bug.h
 create mode 100644 xen/arch/ppc/include/asm/byteorder.h
 create mode 100644 xen/arch/ppc/include/asm/cache.h
Quoted 8 lines
 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/reg_defs.h
 create mode 100644 xen/arch/ppc/include/asm/string.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
Quoted 2 lines

This is a surprising amount of infrastructure. I'm guessing it's a consequence of needing byteorder ?

Right, byteorder as well as va_{start,end,arg}. I could try to trim it down further.

Quoted 5 lines

There's a series still out deleting swathes of junk in byteorder. I guess I need to kick that thread again, but it mostly boils down to using __builtin_bswap$N() (and on x86, reimplementing them on old enough compilers). Presumably all versions of GCC (and eventually Clang) we care to support with ppc64 understand this builtin ?

Yes, those builtins should work just fine on any reasonably recent gcc or clang toolchain. What would be the correct approach to integrating these into byteorder.h? Would adding some #define __arch_swab$N __builtin_bswap$N macros be the way to go?

Quoted 7 lines

I've noticed a couple of other things. asm/types.h repeats some antipatterns which we're trying to delete for MISRA reasons in other architectures. I was already planning to fix that up xen-wide, and I guess now is the better time to do so.

Elsewhere, you've got a number of __inline__'s. We think those are all vestigial now, so should be switched to using a plain inline.

Will do.

Quoted 3 lines

Also, there are a bunch of UL() or ULL() macros which encoding a difference between asm and C. In Xen, we use _AC() for that, which you can find in <xen/const.h>.

Thanks for the pointer, I'll update the usage of UL/ULL.

Quoted 2 lines

Similarly, there are some functions which ought to be __init, so it would be good to get them correct from the start.

Good catch. This actually goes along with your subsequent observation about Open Firmware residing in the bottom 4G of memory. See below.

Quoted 3 lines

Maybe as an intermediate step, just get the infinite loop moved from asm up into C? That gets the stack setup, and various of the asm helpers, without all the rest of the C required to get early_printk() to work.

Would you like that plus the serial patch in this same series, or would you like me to just get the C infinite loop going for this series?

Quoted 4 lines

Something we've been trying very hard to do generally is declutter processor.h, and on x86, we've got asm-defns.h as a more appropriate place to have the stuff which is expected to be common to all asm code, and never encountered in C.

Sounds good, I'll move the common asm-only stuff to an asm-defns.h.

Quoted 7 lines

A couple of questions before I dive further in.

Given:

#define r0 0

do the assemblers really not understand register names? That seems mad.

Yeah as surprising as it is, ppc64 assemblers don't handle register names by default. I think at some point a flag was added to GAS (and probably llvm? will have to check) to define them for you, but I'm not sure which version introduced the flag.

I'll do some digging and if the flag is available a reasonable versions of both toolchains (what exactly would constitute this? Are there project-wide expectations of older toolchains working, and if so, how old?) then I can get rid of these.

Quoted 2 lines

Also, given the transformations to call into OpenFirmware, presumably this limits Xen to running below the 4G boundary and on identity mappings?

Interaction with Open Firmware directly shouldn't be necessary past early init, so it shouldn't impose any restrictions on the memory map once paging is up and going. It will just require grabbing all of the required information from OF (essentially dumping the device tree into a local copy) before making the switch.

I'll also mark the relevant functions as __init.

Quoted 1 line

~Andrew

Thanks,
Shawn

#8 lore raw

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

Quoted 37 lines · Shawn Anastasio
Quoted 36 lines · Andrew Cooper
Quoted 35 lines · Shawn Anastasio
 xen/arch/ppc/Kconfig.debug              |   5 +
 xen/arch/ppc/Makefile                   |   3 +
 xen/arch/ppc/boot-of.c                  | 116 +++++++++++++
 xen/arch/ppc/configs/ppc64_defconfig    |   1 +
 xen/arch/ppc/early_printk.c             |  28 +++
 xen/arch/ppc/include/asm/boot.h         |  24 +++
 xen/arch/ppc/include/asm/bug.h          |   6 +
 xen/arch/ppc/include/asm/byteorder.h    |  37 ++++
 xen/arch/ppc/include/asm/cache.h        |   6 +
 xen/arch/ppc/include/asm/early_printk.h |  15 ++
 xen/arch/ppc/include/asm/msr.h          |  67 ++++++++
 xen/arch/ppc/include/asm/processor.h    | 207 ++++++++++++++++++++++
 xen/arch/ppc/include/asm/reg_defs.h     | 218 ++++++++++++++++++++++++
 xen/arch/ppc/include/asm/string.h       |   6 +
 xen/arch/ppc/include/asm/types.h        |  35 ++++
 xen/arch/ppc/ppc64/Makefile             |   1 +
 xen/arch/ppc/ppc64/asm-offsets.c        |  55 ++++++
 xen/arch/ppc/ppc64/head.S               |  48 +++---
 xen/arch/ppc/ppc64/of-call.S            |  85 +++++++++
 xen/arch/ppc/setup.c                    |  31 ++++
 20 files changed, 972 insertions(+), 22 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/bug.h
 create mode 100644 xen/arch/ppc/include/asm/byteorder.h
 create mode 100644 xen/arch/ppc/include/asm/cache.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/reg_defs.h
 create mode 100644 xen/arch/ppc/include/asm/string.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
Quoted 4 lines
Quoted 2 lines

This is a surprising amount of infrastructure. I'm guessing it's a consequence of needing byteorder ?

Right, byteorder as well as va_{start,end,arg}. I could try to trim it down further.

<xen/stdarg.h> should be entirely standalone.

But in general, it's nice to see if we can reduce the inter-dependencies, and bringup of a new arch is the only time we get to see them.

Quoted 10 lines
Quoted 6 lines

There's a series still out deleting swathes of junk in byteorder. I guess I need to kick that thread again, but it mostly boils down to using __builtin_bswap$N() (and on x86, reimplementing them on old enough compilers). Presumably all versions of GCC (and eventually Clang) we care to support with ppc64 understand this builtin ?

Yes, those builtins should work just fine on any reasonably recent gcc or clang toolchain. What would be the correct approach to integrating these into byteorder.h? Would adding some #define __arch_swab$N __builtin_bswap$N macros be the way to go?

In the short term, that's perhaps best.

https://lore.kernel.org/xen-devel/[email protected]/T/#u
is the full series

Quoted 10 lines
Quoted 2 lines

Similarly, there are some functions which ought to be __init, so it would be good to get them correct from the start.

Good catch. This actually goes along with your subsequent observation about Open Firmware residing in the bottom 4G of memory. See below.

Quoted 3 lines

Maybe as an intermediate step, just get the infinite loop moved from asm up into C? That gets the stack setup, and various of the asm helpers, without all the rest of the C required to get early_printk() to work.

Would you like that plus the serial patch in this same series, or would you like me to just get the C infinite loop going for this series?

Whatever is easier, although I expect splitting this patch into two will make things simpler overall.

Quoted 12 lines
Quoted 7 lines

A couple of questions before I dive further in.

Given:

#define r0 0

do the assemblers really not understand register names? That seems mad.

Yeah as surprising as it is, ppc64 assemblers don't handle register names by default. I think at some point a flag was added to GAS (and probably llvm? will have to check) to define them for you, but I'm not sure which version introduced the flag.

Quoted 4 lines

I'll do some digging and if the flag is available a reasonable versions of both toolchains (what exactly would constitute this? Are there project-wide expectations of older toolchains working, and if so, how old?) then I can get rid of these.

You can pick a minimum version as you see fit, which is basically anything goes prior to PPC64 being declared supported in Xen.

It needs to end up in the root README (but a patch for that probably wants to wait until the port is a little more mature), but if I were you I wouldn't care about supporting anything older than comes in current distro released this year.

Quoted 9 lines
Quoted 2 lines

Also, given the transformations to call into OpenFirmware, presumably this limits Xen to running below the 4G boundary and on identity mappings?

Interaction with Open Firmware directly shouldn't be necessary past early init, so it shouldn't impose any restrictions on the memory map once paging is up and going. It will just require grabbing all of the required information from OF (essentially dumping the device tree into a local copy) before making the switch.

I'll also mark the relevant functions as __init.

Ah, in which case there's something magic in the build system which is (AFAIU) unique to Xen.

obj-y += foo.init.o

for a foo.o which are expected to contain no runtime code at all.  This trick also manages to string literals into .init.rodata, rather than living in the general mergable string section.

~Andrew

#9 lore raw

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

In reply to Shawn Anastasio
Quoted 11 lines · Shawn Anastasio
Quoted 5 lines · Andrew Cooper

Given:

#define r0 0

do the assemblers really not understand register names? That seems mad.

Yeah as surprising as it is, ppc64 assemblers don't handle register names by default. I think at some point a flag was added to GAS (and probably llvm? will have to check) to define them for you, but I'm not sure which version introduced the flag.

Isn't it that you simply need to prefix them with %? That looks to be working for me without any special options in PPC code I maintain for an entirely different purpose.

Jan

#10 lore raw

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

Quoted 8 lines · Jan Beulich
Quoted 7 lines · Shawn Anastasio
Quoted 5 lines · Andrew Cooper

Given:

#define r0 0

do the assemblers really not understand register names? That seems mad.

Quoted 8 lines
Quoted 4 lines

Yeah as surprising as it is, ppc64 assemblers don't handle register names by default. I think at some point a flag was added to GAS (and probably llvm? will have to check) to define them for you, but I'm not sure which version introduced the flag.

Isn't it that you simply need to prefix them with %? That looks to be working for me without any special options in PPC code I maintain for an entirely different purpose.

Yes, this is the approach I'll go with. Originally I wanted to preserve the non-prefixed syntax, but I discovered that the required flag (-mregnames) is not supported by llvm.

Quoted 1 line

Jan

Thanks,
Shawn

#11 lore raw

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

In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper

I've noticed a couple of other things. asm/types.h repeats some antipatterns which we're trying to delete for MISRA reasons in other architectures. I was already planning to fix that up xen-wide, and I guess now is the better time to do so.

Could you elaborate on the changes you'd like to see in types.h?

Thanks,
Shawn

#12 lore raw

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

In reply to Shawn Anastasio

Hi Shawn,

Below some remark about the coding style. I will try to spot all of them so please go through your code and check if my comments applies in other places.

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

---
  xen/arch/ppc/Kconfig.debug              |   5 +
  xen/arch/ppc/Makefile                   |   3 +
  xen/arch/ppc/boot-of.c                  | 116 +++++++++++++
  xen/arch/ppc/configs/ppc64_defconfig    |   1 +
  xen/arch/ppc/early_printk.c             |  28 +++
  xen/arch/ppc/include/asm/boot.h         |  24 +++
  xen/arch/ppc/include/asm/bug.h          |   6 +
  xen/arch/ppc/include/asm/byteorder.h    |  37 ++++
  xen/arch/ppc/include/asm/cache.h        |   6 +
  xen/arch/ppc/include/asm/early_printk.h |  15 ++
  xen/arch/ppc/include/asm/msr.h          |  67 ++++++++
  xen/arch/ppc/include/asm/processor.h    | 207 ++++++++++++++++++++++
  xen/arch/ppc/include/asm/reg_defs.h     | 218 ++++++++++++++++++++++++
  xen/arch/ppc/include/asm/string.h       |   6 +
  xen/arch/ppc/include/asm/types.h        |  35 ++++
  xen/arch/ppc/ppc64/Makefile             |   1 +
  xen/arch/ppc/ppc64/asm-offsets.c        |  55 ++++++
  xen/arch/ppc/ppc64/head.S               |  48 +++---
  xen/arch/ppc/ppc64/of-call.S            |  85 +++++++++
  xen/arch/ppc/setup.c                    |  31 ++++
  20 files changed, 972 insertions(+), 22 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/bug.h create mode 100644 xen/arch/ppc/include/asm/byteorder.h create mode 100644 xen/arch/ppc/include/asm/cache.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/reg_defs.h create mode 100644 xen/arch/ppc/include/asm/string.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

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 +0 -0
index 98220648af..4c4cdcb60e 100644

xen/arch/ppc/Makefile line 4

Quoted 4 lines
xen/arch/ppc/Makefile +3 -0
@@ -1,4 +1,7 @@
  obj-$(CONFIG_PPC64) += ppc64/
+obj-y += setup.o
+obj-y += boot-of.o
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o

We commonly order the file alphabetically. So setup.o should be last.

Quoted 14 lines
xen/arch/ppc/Makefile +0 -0
  $(TARGET): $(TARGET)-syms
  	cp -f $< $@
xen/arch/ppc/boot-of.c new file +5 -0
new file mode 100644
index 0000000000..1ceeaf1250
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or

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

Quoted 10 lines
xen/arch/ppc/boot-of.c new file +10 -0
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

As you already have the SPDX license, the full license should be dropped.

Quoted 30 lines
xen/arch/ppc/boot-of.c new file +30 -0
+ *
+ * Copyright IBM Corp. 2005, 2006, 2007
+ * Copyright Raptor Engineering, LLC
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ *          Hollis Blanchard <[email protected]>
+ *          Shawn Anastasio <[email protected]>
+ */
+
+#include <xen/lib.h>
+#include <asm/boot.h>
+#include <asm/byteorder.h>
+#include <asm/early_printk.h>
+
+#define ADDR(x) (uint32_t)(unsigned long)(x)
+
+/* OF entrypoint*/
+static unsigned long of_vec;
+
+/* OF device handles*/
+static int bof_chosen;
+static int of_out;
+
+static int of_call(const char *service, uint32_t nargs, uint32_t nrets,
+                   int32_t rets[], ...)
+{
+    int rc;
+    va_list args;
+    int i;
+    struct of_service s = { 0 };

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

Quoted 10 lines
xen/arch/ppc/boot-of.c new file +10 -0
+
+    s.ofs_service = cpu_to_be32(ADDR(service));
+    s.ofs_nargs = cpu_to_be32(nargs);
+    s.ofs_nrets = cpu_to_be32(nrets);
+
+    /* copy all the params into the args array */
+    va_start(args, rets);
+
+    for ( i = 0; i < nargs; i++ )
+    {

We don't add {} for a single line.

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

Quoted 10 lines
xen/arch/ppc/boot-of.c new file +10 -0
+        s.ofs_args[i] = cpu_to_be32(va_arg(args, uint32_t));
+    }
+
+    va_end(args);
+
+    rc = enter_of(&s, of_vec);
+
+    /* copy all return values to the output rets array */
+    for ( i = 0; i < nrets; i++ )
+    {

Ditto.

Quoted 41 lines
xen/arch/ppc/boot-of.c new file +41 -0
+        rets[i] = be32_to_cpu(s.ofs_args[i + nargs]);
+    }
+
+    return rc;
+}
+
+static int of_finddevice(const char *devspec)
+{
+    int rets[1] = { OF_FAILURE };
+
+    of_call("finddevice", 1, 1, rets, devspec);
+    return rets[0];
+}
+
+static int of_getprop(int ph, const char *name, void *buf, uint32_t buflen)
+{
+    int rets[1] = { OF_FAILURE };
+
+    of_call("getprop", 4, 1, rets, ph, ADDR(name), buf, buflen);
+    return rets[0];
+}
+
+int of_write(int ih, const char *addr, uint32_t len)
+{
+    int rets[1] = { OF_FAILURE };
+
+    of_call("write", 3, 1, rets, ih, addr, len);
+    return rets[0];
+}
+
+static void of_putchar(char c)
+{
+    if ( c == '\n' )
+    {
+        char buf = '\r';
+        of_write(of_out, &buf, 1);
+    }
+    of_write(of_out, &c, 1);
+}
+
+void boot_of_init(unsigned long vec)

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

Quoted 10 lines
xen/arch/ppc/boot-of.c new file +10 -0
+{
+    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);
+
+    early_printk_init(of_putchar);
+}

All files usually have an emacs magic block. E.g.:

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/

Quoted 34 lines
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 +18 -0
new file mode 100644
index 0000000000..309a1a7fd9
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <xen/lib.h>
+#include <asm/boot.h>
+
+static void (*putchar_func)(char);
+
+void early_printk_init(void (*putchar)(char))
+{
+    putchar_func = putchar;
+}
+
+void early_puts(const char *s, size_t nr)
+{
+    if ( !putchar_func )
+        return;
+
+    while ( nr-- > 0 )
+        putchar_func(*s++);

xen/arch/ppc/early_printk.c line 28

Quoted 10 lines
xen/arch/ppc/early_printk.c new file +10 -0
+}
+
+void early_printk(const char *s)
+{
+    if ( !putchar_func )
+        return;
+
+    while ( *s )
+        putchar_func(*s++);
+}

Missing emacs magic.

Quoted 16 lines
xen/arch/ppc/include/asm/boot.h new file +10 -0
new file mode 100644
index 0000000000..ea4a945bb4
@@ -0,0 +1,24 @@
+/* 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,

xen/arch/ppc/include/asm/boot.h line 20

Quoted 10 lines
xen/arch/ppc/include/asm/boot.h new file +10 -0
+};
+
+struct of_service {
+    __be32 ofs_service;
+    __be32 ofs_nargs;
+    __be32 ofs_nrets;
+    __be32 ofs_args[10];
+};
+
+extern int enter_of(struct of_service *args, unsigned long entry);

Here you add 'extern' but ...

xen/arch/ppc/include/asm/boot.h line 22

Quoted 2 lines
xen/arch/ppc/include/asm/boot.h new file +2 -0
+
+void boot_of_init(unsigned long);

not here. In Xen, we tend to not add 'extern' for prototypes. Also, please name the parameter as this makes clear what the value is. This would also make MISRA happy (IIRC this would rule 8.2).

xen/arch/ppc/include/asm/boot.h line 24

Quoted 2 lines
xen/arch/ppc/include/asm/boot.h new file +2 -0
+
+#endif /* _ASM_PPC_BOOT_H */

Missing emacs magic.

xen/arch/ppc/include/asm/bug.h line 6

Quoted 12 lines
xen/arch/ppc/include/asm/bug.h new file +6 -0
new file mode 100644
index 0000000000..a23ab1fa74
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_BUG_H
+#define _ASM_PPC_BUG_H
+
+#endif /* _ASM_PPC_BUG_H */

Can you clarify why you do need this empty header?

Also missing emacs magic.

Quoted 8 lines
xen/arch/ppc/include/asm/byteorder.h new file +2 -0
new file mode 100644
index 0000000000..cc4d55b355
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _ASM_POWERPC_BYTEORDER_H

xen/arch/ppc/include/asm/byteorder.h line 12

Quoted 10 lines
xen/arch/ppc/include/asm/byteorder.h new file +10 -0
+#define _ASM_POWERPC_BYTEORDER_H
+
+#include <asm/types.h>
+#include <xen/compiler.h>
+
+static inline __attribute_const__ __u16 ___arch__swab16(__u16 value)
+{
+    __u16 result;
+
+    asm("rlwimi %0,%1,8,16,23"

In general, we tend to add a space of after the commas.

xen/arch/ppc/include/asm/byteorder.h line 24

Quoted 12 lines
xen/arch/ppc/include/asm/byteorder.h new file +12 -0
+        : "=r" (result)
+        : "r" (value), "0" (value >> 8));
+    return result;
+}
+
+static inline __attribute_const__ __u32 ___arch__swab32(__u32 value)
+{
+    __u32 result;
+
+    asm("rlwimi %0,%1,24,16,23\n\t"
+        "rlwimi %0,%1,8,8,15\n\t"
+        "rlwimi %0,%1,24,0,7"

Same here.

xen/arch/ppc/include/asm/byteorder.h line 37

Quoted 13 lines
xen/arch/ppc/include/asm/byteorder.h new file +13 -0
+        : "=r" (result)
+        : "r" (value), "0" (value >> 24));
+    return result;
+}
+
+#define __arch__swab16(x) ___arch__swab16(x)
+#define __arch__swab32(x) ___arch__swab32(x)
+
+#define __BYTEORDER_HAS_U64__
+
+#include <xen/byteorder/little_endian.h>
+
+#endif /* _ASM_POWERPC_BYTEORDER_H */

Missing emacs magic.

xen/arch/ppc/include/asm/cache.h line 6

Quoted 12 lines
xen/arch/ppc/include/asm/cache.h new file +6 -0
new file mode 100644
index 0000000000..8a0a6b7b17
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_CACHE_H
+#define _ASM_PPC_CACHE_H
+
+#endif /* _ASM_PPC_CACHE_H */

Can you clarify why you do need this empty header?

Also missing emacs magic.

Quoted 11 lines
xen/arch/ppc/include/asm/early_printk.h new file +5 -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>

xen/arch/ppc/include/asm/early_printk.h line 15

Quoted 10 lines
xen/arch/ppc/include/asm/early_printk.h new file +10 -0
+
+#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 */

Missing emacs magic.

Quoted 11 lines
xen/arch/ppc/include/asm/msr.h new file +5 -0
new file mode 100644
index 0000000000..7ef0b5e3ad
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or

xen/arch/ppc/include/asm/msr.h line 15

Quoted 10 lines
xen/arch/ppc/include/asm/msr.h new file +10 -0
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Can you drop the full license?

Quoted 42 lines
xen/arch/ppc/include/asm/msr.h new file +42 -0
+ *
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ */
+
+#ifndef _POWERPC_MSR_H
+#define _POWERPC_MSR_H
+
+#ifdef __ASSEMBLY__
+#define ULL(x) x
+#else
+#define ULL(x) x ## ULL
+#endif
+
+/* Flags in MSR: */
+#define MSR_SF      ULL(0x8000000000000000)
+#define MSR_TA      ULL(0x4000000000000000)
+#define MSR_ISF     ULL(0x2000000000000000)
+#define MSR_HV      ULL(0x1000000000000000)
+#define MSR_VMX     ULL(0x0000000002000000)
+#define MSR_MER     ULL(0x0000000000200000)
+#define MSR_POW     ULL(0x0000000000040000)
+#define MSR_ILE     ULL(0x0000000000010000)
+#define MSR_EE      ULL(0x0000000000008000)
+#define MSR_PR      ULL(0x0000000000004000)
+#define MSR_FP      ULL(0x0000000000002000)
+#define MSR_ME      ULL(0x0000000000001000)
+#define MSR_FE0     ULL(0x0000000000000800)
+#define MSR_SE      ULL(0x0000000000000400)
+#define MSR_BE      ULL(0x0000000000000200)
+#define MSR_FE1     ULL(0x0000000000000100)
+#define MSR_IP      ULL(0x0000000000000040)
+#define MSR_IR      ULL(0x0000000000000020)
+#define MSR_DR      ULL(0x0000000000000010)
+#define MSR_PMM     ULL(0x0000000000000004)
+#define MSR_RI      ULL(0x0000000000000002)
+#define MSR_LE      ULL(0x0000000000000001)
+
+/* MSR bits set on the systemsim simulator */
+#define MSR_SIM       ULL(0x0000000020000000)
+#define MSR_SYSTEMSIM ULL(0x0000000010000000)

xen/arch/ppc/include/asm/msr.h line 67

Quoted 10 lines
xen/arch/ppc/include/asm/msr.h new file +10 -0
+
+/* On a trap, srr1's copy of msr defines some bits as follows: */
+#define MSR_TRAP_FE     ULL(0x0000000000100000) /* Floating Point Exception */
+#define MSR_TRAP_IOP    ULL(0x0000000000080000) /* Illegal Instruction */
+#define MSR_TRAP_PRIV   ULL(0x0000000000040000) /* Privileged Instruction */
+#define MSR_TRAP        ULL(0x0000000000020000) /* Trap Instruction */
+#define MSR_TRAP_NEXT   ULL(0x0000000000010000) /* PC is next instruction */
+#define MSR_TRAP_BITS  (MSR_TRAP_FE|MSR_TRAP_IOP|MSR_TRAP_PRIV|MSR_TRAP)
+
+#endif /* _POWERPC_MSR_H */

Mising emacs magic.

Quoted 11 lines
xen/arch/ppc/include/asm/processor.h new file +5 -0
new file mode 100644
index 0000000000..6deba051a8
@@ -0,0 +1,207 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or

xen/arch/ppc/include/asm/processor.h line 15

Quoted 10 lines
xen/arch/ppc/include/asm/processor.h new file +10 -0
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Can you drop the full license?

Quoted 104 lines
xen/arch/ppc/include/asm/processor.h new file +104 -0
+ *
+ * Copyright IBM Corp. 2005, 2006, 2007
+ * Copyright Raptor Engineering, LLC
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ *          Christian Ehrhardt <[email protected]>
+ *          Timothy Pearson <[email protected]>
+ *          Shawn Anastasio <[email protected]>
+ */
+
+#ifndef _ASM_PROCESSOR_H_
+#define _ASM_PROCESSOR_H_
+
+#include <xen/config.h>
+#include <asm/msr.h>
+#include <asm/reg_defs.h>
+
+#define IOBMP_BYTES          8192
+#define IOBMP_INVALID_OFFSET 0x8000
+
+/* Processor Version Register (PVR) field extraction */
+
+#define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
+#define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF)  /* Revison field */
+
+#define __is_processor(pv) (PVR_VER(mfspr(SPRN_PVR)) == (pv))
+
+/*
+ * IBM has further subdivided the standard PowerPC 16-bit version and
+ * revision subfields of the PVR for the PowerPC 403s into the following:
+ */
+
+#define PVR_FAM(pvr)  (((pvr) >> 20) & 0xFFF) /* Family field */
+#define PVR_MEM(pvr)  (((pvr) >> 16) & 0xF)   /* Member field */
+#define PVR_CORE(pvr) (((pvr) >> 12) & 0xF)   /* Core field */
+#define PVR_CFG(pvr)  (((pvr) >> 8) & 0xF)    /* Configuration field */
+#define PVR_MAJ(pvr)  (((pvr) >> 4) & 0xF)    /* Major revision field */
+#define PVR_MIN(pvr)  (((pvr) >> 0) & 0xF)    /* Minor revision field */
+
+/* Processor Version Numbers */
+
+#define PVR_403GA    0x00200000
+#define PVR_403GB    0x00200100
+#define PVR_403GC    0x00200200
+#define PVR_403GCX   0x00201400
+#define PVR_405GP    0x40110000
+#define PVR_STB03XXX 0x40310000
+#define PVR_NP405H   0x41410000
+#define PVR_NP405L   0x41610000
+#define PVR_601      0x00010000
+#define PVR_602      0x00050000
+#define PVR_603      0x00030000
+#define PVR_603e     0x00060000
+#define PVR_603ev    0x00070000
+#define PVR_603r     0x00071000
+#define PVR_604      0x00040000
+#define PVR_604e     0x00090000
+#define PVR_604r     0x000A0000
+#define PVR_620      0x00140000
+#define PVR_740      0x00080000
+#define PVR_750      PVR_740
+#define PVR_740P     0x10080000
+#define PVR_750P     PVR_740P
+#define PVR_7400     0x000C0000
+#define PVR_7410     0x800C0000
+#define PVR_7450     0x80000000
+#define PVR_8540     0x80200000
+#define PVR_8560     0x80200000
+/*
+ * For the 8xx processors, all of them report the same PVR family for
+ * the PowerPC core. The various versions of these processors must be
+ * differentiated by the version number in the Communication Processor
+ * Module (CPM).
+ */
+#define PVR_821  0x00500000
+#define PVR_823  PVR_821
+#define PVR_850  PVR_821
+#define PVR_860  PVR_821
+#define PVR_8240 0x00810100
+#define PVR_8245 0x80811014
+#define PVR_8260 PVR_8240
+
+/* 64-bit processors */
+#define PVR_NORTHSTAR	0x0033
+#define PVR_PULSAR      0x0034
+#define PVR_POWER4	0x0035
+#define PVR_ICESTAR	0x0036
+#define PVR_SSTAR	0x0037
+#define PVR_POWER4p	0x0038
+#define PVR_970		0x0039
+#define PVR_POWER5	0x003A
+#define PVR_POWER5p	0x003B
+#define PVR_970FX	0x003C
+#define PVR_POWER6	0x003E
+#define PVR_POWER7	0x003F
+#define PVR_630		0x0040
+#define PVR_630p	0x0041
+#define PVR_970MP	0x0044
+#define PVR_970GX	0x0045
+#define PVR_POWER7p	0x004A
+#define PVR_POWER8E	0x004B
+#define PVR_POWER8NVL	0x004C
+#define PVR_POWER8	0x004D
+#define PVR_POWER9	0x004E

xen/arch/ppc/include/asm/processor.h line 129

Quoted 10 lines
xen/arch/ppc/include/asm/processor.h new file +10 -0
+#define PVR_POWER10	0x0080
+#define PVR_BE		0x0070
+#define PVR_PA6T	0x0090
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>
+
+/* User-accessible registers: nost of these need to be saved/restored
+ * for every nested Xen invocation. */

The multi-line comment coding style is:

/*
* foo
* bar
*/

For single line comment, they should be:

/* foo bar */

[...]

Quoted 21 lines
xen/arch/ppc/ppc64/head.S +2 -9
index 2fcefb40d8..589c72e382 100644
@@ -1,30 +1,34 @@
  /* SPDX-License-Identifier: GPL-2.0-or-later */
 
+#include <asm/processor.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.
-     */
-    tdi 0, 0, 0x48    /* Reverse endian of b . + 8          */
-    b . + 44          /* Skip trampoline if endian is good  */

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

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

This seems to be refactoring. It would be best if this is done in a separate patch as this is easier to review.

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

Quoted 4 lines
xen/arch/ppc/ppc64/head.S +1 -3
-
-    /* Now that the endianness is confirmed, continue */
-1:  b 1b
+    /* NOTE: argument registers (r3-r9) must be preserved until the C entrypoint */

I feel this is a bit too small to be noticeable. I would suggest to write a large comment so it is more obvious to spot the list of registers that should not be used. One way would be:

/*
* r1 ...
* r2 ..
* r3 ...
* ...
*/

Quoted 16 lines
xen/arch/ppc/ppc64/head.S +14 -0
+    FIXUP_ENDIAN
+
+    /* set up the initial stack */
+    LOAD_IMM64(r1, cpu0_boot_stack)
+    li r8, 0
+    std r8, 0(r1)
+
+    /* call the C entrypoint */
+    LOAD_IMM64(r12, start_xen)
+    mtctr r12
+    bctrl
+
+    /* should never return */
+    trap
 
      .size start, . - start

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

Quoted 10 lines
xen/arch/ppc/ppc64/head.S +9 -0
      .type start, %function
+
+    .section .init.data, "aw", @progbits
+
+    /* Early init stack */
+    .p2align 4
+cpu0_boot_stack_bottom:
+    .space STACK_SIZE
+cpu0_boot_stack:
+    .space STACK_FRAME_OVERHEAD

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw

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

Quoted 5 lines · Julien Grall

Hi Shawn,

Below some remark about the coding style. I will try to spot all of them so please go through your code and check if my comments applies in other places.

Thank you for the detailed comments. I had a couple of follow-up questions for you.

Quoted 17 lines · Shawn Anastasio
Quoted 16 lines
xen/arch/ppc/boot-of.c new file +10 -0
new file mode 100644
index 0000000000..1ceeaf1250
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Quoted 8 lines
Quoted 6 lines
xen/arch/ppc/boot-of.c new file +5 -0
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 

02110-1301, USA.

As you already have the SPDX license, the full license should be dropped.

To clarify, you're suggesting that I remove the license text but keep the copyright lines below? I wouldn't feel comfortable removing the latter since this is derived from code that wasn't written by me.

Quoted 11 lines
Quoted 10 lines

+ *
+ * Copyright IBM Corp. 2005, 2006, 2007
+ * Copyright Raptor Engineering, LLC
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ * Hollis Blanchard <[email protected]>
+ * Shawn Anastasio <[email protected]>
+ */

+extern int enter_of(struct of_service *args, unsigned long entry);

Quoted 8 lines

Here you add 'extern' but ...

xen/arch/ppc/boot-of.c

Quoted 2 lines
xen/arch/ppc/boot-of.c new file +2 -0
+
+void boot_of_init(unsigned long);

not here. In Xen, we tend to not add 'extern' for prototypes. Also, please name the parameter as this makes clear what the value is. This would also make MISRA happy (IIRC this would rule 8.2).

I used extern to mark the enter_of since it's an assembly function rather than a C one, but if this isn't a convention used in the Xen codebase I can drop it.

Quoted 7 lines
Quoted 7 lines
xen/arch/ppc/include/asm/bug.h new file +0 -0
new file mode 100644
index 0000000000..a23ab1fa74
@@ -0,0 +1,6 @@
Quoted 8 lines

xen/arch/ppc/include/asm/bug.h line 6

Quoted 6 lines
xen/arch/ppc/include/asm/bug.h new file +6 -0
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_BUG_H
+#define _ASM_PPC_BUG_H
+
+#endif /* _ASM_PPC_BUG_H */

Can you clarify why you do need this empty header?

Some empty headers were necessary to include <xen/lib.h> which in turn includes various asm/ headers. I have since dropped many of these headers following Andrew's earlier comments, though, and they won't be present in v2.

Quoted 28 lines
Quoted 28 lines
xen/arch/ppc/ppc64/head.S +1 -2
index 2fcefb40d8..589c72e382 100644
@@ -1,30 +1,34 @@
  /* SPDX-License-Identifier: GPL-2.0-or-later */
  +#include <asm/processor.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

xen/arch/ppc/ppc64/head.S +0 -2
-     * 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.

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

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

Quoted 5 lines
xen/arch/ppc/ppc64/head.S +0 -5
-    .long 0xa602487d  /* mflr r10                           */
-    .long 0x14004a39  /* addi r10,r10,20                    */
-    .long 0xa6035a7d  /* mtsrr0 r10                         */
-    .long 0xa6037b7d  /* mtsrr1 r11                         */
-    .long 0x2400004c  /* rfid                               */

This seems to be refactoring. It would be best if this is done in a separate patch as this is easier to review.

Following Andrew's suggestion earlier, I've split this patch into two with the first one only doing the bare minimum to get an infinite loop going in C rather than assembly. That first patch still includes the refactoring of this trampoline into a macro, but the overall patch size is much smaller. Do you think that would be fine to review, or would you like a third commit for only this trampoline's refactoring?

Quoted 1 line

Cheers,

Thanks,
Shawn

#14 lore raw

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

Hi,

Quoted 27 lines · Shawn Anastasio
Quoted 17 lines · Julien Grall
Quoted 16 lines · Shawn Anastasio
xen/arch/ppc/boot-of.c new file +10 -0
new file mode 100644
index 0000000000..1ceeaf1250
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Quoted 8 lines
Quoted 6 lines
xen/arch/ppc/boot-of.c new file +5 -0
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA

02110-1301, USA.

As you already have the SPDX license, the full license should be dropped.

Quoted 3 lines

To clarify, you're suggesting that I remove the license text but keep the copyright lines below? I wouldn't feel comfortable removing the latter since this is derived from code that wasn't written by me.

I am only suggesting to remove the license text. The copyright are fine to keep.

Note that in Xen, we don't tend to add them for new file (I guess this is not the case here) and instead rely on signed-off/author in the commit message.

Quoted 21 lines
Quoted 12 lines
Quoted 11 lines

+ *
+ * Copyright IBM Corp. 2005, 2006, 2007
+ * Copyright Raptor Engineering, LLC
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ * Hollis Blanchard <[email protected]>
+ * Shawn Anastasio <[email protected]>
+ */

+extern int enter_of(struct of_service *args, unsigned long entry);

Quoted 8 lines

Here you add 'extern' but ...

xen/arch/ppc/boot-of.c

Quoted 2 lines
xen/arch/ppc/boot-of.c new file +2 -0
+
+void boot_of_init(unsigned long);

not here. In Xen, we tend to not add 'extern' for prototypes. Also, please name the parameter as this makes clear what the value is. This would also make MISRA happy (IIRC this would rule 8.2).

Quoted 3 lines

I used extern to mark the enter_of since it's an assembly function rather than a C one, but if this isn't a convention used in the Xen codebase I can drop it.

I am not aware of such convention in Xen. But if you want to distinguish assembly vs C function, then I think it would be better to add asm_ in the name so it is clearer.

Quoted 59 lines
Quoted 16 lines
Quoted 8 lines
xen/arch/ppc/include/asm/bug.h new file +0 -0
new file mode 100644
index 0000000000..a23ab1fa74

xen/arch/ppc/include/asm/bug.h line 6

Quoted 6 lines
xen/arch/ppc/include/asm/bug.h new file +6 -0
@@ -0,0 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_PPC_BUG_H
+#define _ASM_PPC_BUG_H
+
+#endif /* _ASM_PPC_BUG_H */

Can you clarify why you do need this empty header?

Some empty headers were necessary to include <xen/lib.h> which in turn includes various asm/ headers. I have since dropped many of these headers following Andrew's earlier comments, though, and they won't be present in v2.

Quoted 28 lines
Quoted 28 lines
xen/arch/ppc/ppc64/head.S +1 -2
index 2fcefb40d8..589c72e382 100644
@@ -1,30 +1,34 @@
   /* SPDX-License-Identifier: GPL-2.0-or-later */
   +#include <asm/processor.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

xen/arch/ppc/ppc64/head.S +0 -2
-     * 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.

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

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

Quoted 5 lines
xen/arch/ppc/ppc64/head.S +0 -5
-    .long 0xa602487d  /* mflr r10                           */
-    .long 0x14004a39  /* addi r10,r10,20                    */
-    .long 0xa6035a7d  /* mtsrr0 r10                         */
-    .long 0xa6037b7d  /* mtsrr1 r11                         */
-    .long 0x2400004c  /* rfid                               */

This seems to be refactoring. It would be best if this is done in a separate patch as this is easier to review.

Quoted 6 lines

Following Andrew's suggestion earlier, I've split this patch into two with the first one only doing the bare minimum to get an infinite loop going in C rather than assembly. That first patch still includes the refactoring of this trampoline into a macro, but the overall patch size is much smaller. Do you think that would be fine to review, or would you like a third commit for only this trampoline's refactoring?

In general we tend to split code movement/refactoring from new code. This helps during reviews. Not sure how small will be your patch. If it is only a few dozen of lines, then it should be fine :).

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

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

Quoted 1 line · Julien Grall

Hi,

Thanks for the response. I had one more question with regards to the emacs footer.

Quoted 10 lines

All files usually have an emacs magic block. E.g.:

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/

Is this absolutely necessary to include? The CODING_STYLE document seems to imply that it's optional and a quick peek at other architectures' code suggests that this is the case.

If it is required, should it also be included in assembly files, or only .c/.h ones?

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

This seems to be refactoring. It would be best if this is done in a separate patch as this is easier to review.

Following Andrew's suggestion earlier, I've split this patch into two with the first one only doing the bare minimum to get an infinite loop going in C rather than assembly. That first patch still includes the refactoring of this trampoline into a macro, but the overall patch size is much smaller. Do you think that would be fine to review, or would you like a third commit for only this trampoline's refactoring?

Quoted 3 lines

In general we tend to split code movement/refactoring from new code. This helps during reviews. Not sure how small will be your patch. If it is only a few dozen of lines, then it should be fine :).

Makes sense, thanks.

Quoted 1 line

Cheers,

Thanks,
Shawn

#16 lore raw

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

Hi,

Quoted 17 lines · Shawn Anastasio
Quoted 1 line · Julien Grall

Hi,

Thanks for the response. I had one more question with regards to the emacs footer.

Quoted 10 lines

All files usually have an emacs magic block. E.g.:

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/

Quoted 3 lines

Is this absolutely necessary to include? The CODING_STYLE document seems to imply that it's optional and a quick peek at other architectures' code suggests that this is the case.

Interesting, I thought the coding style would impose it because from past discussion it seemed that we wanted to use it everywhere but it tends to be forgotten.

Quoted 3 lines

If it is required, should it also be included in assembly files, or only .c/.h ones?

I think it shold be everywhere. But given the CODING_STYLE is more laxed than I remembered, then feel this to ignore this comment :).

Cheers,

Signature · 1 line
Julien Grall
#17 lore raw

PATCH 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