linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ash Logan <ash@heyquark.com>
To: paulus@samba.org, mpe@ellerman.id.au,
	christophe.leroy@csgroup.eu, robh+dt@kernel.org,
	benh@kernel.crashing.org
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	j.ne@posteo.net, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Subject: [PATCH 03/12] powerpc: wiiu: bootwrapper support
Date: Wed,  2 Mar 2022 15:43:57 +1100	[thread overview]
Message-ID: <20220302044406.63401-4-ash@heyquark.com> (raw)
In-Reply-To: <20220302044406.63401-1-ash@heyquark.com>

Add support for the Nintendo Wii U game console to the powerpc
bootwrapper.

Signed-off-by: Ash Logan <ash@heyquark.com>
Co-developed-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
---
 arch/powerpc/boot/Makefile    |   4 ++
 arch/powerpc/boot/wiiu-head.S | 103 ++++++++++++++++++++++++++++++++++
 arch/powerpc/boot/wiiu.c      |  73 ++++++++++++++++++++++++
 arch/powerpc/boot/wrapper     |   4 ++
 4 files changed, 184 insertions(+)
 create mode 100644 arch/powerpc/boot/wiiu-head.S
 create mode 100644 arch/powerpc/boot/wiiu.c

diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 9993c6256ad2..4e31bb648f4d 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -155,6 +155,7 @@ src-plat-$(CONFIG_EMBEDDED6xx) += cuboot-pq2.c cuboot-mpc7448hpc2.c \
 					gamecube-head.S gamecube.c \
 					wii-head.S wii.c holly.c \
 					fixed-head.S mvme5100.c
+src-plat-$(CONFIG_WIIU) += wiiu-head.S wiiu.c
 src-plat-$(CONFIG_AMIGAONE) += cuboot-amigaone.c
 src-plat-$(CONFIG_PPC_PS3) += ps3-head.S ps3-hvcall.S ps3.c
 src-plat-$(CONFIG_EPAPR_BOOT) += epapr.c epapr-wrapper.c
@@ -353,6 +354,9 @@ image-$(CONFIG_GAMECUBE)		+= dtbImage.gamecube
 image-$(CONFIG_WII)			+= dtbImage.wii
 image-$(CONFIG_MVME5100)		+= dtbImage.mvme5100
 
+# Board port in arch/powerpc/platform/wiiu/Kconfig
+image-$(CONFIG_WIIU)			+= dtbImage.wiiu
+
 # Board port in arch/powerpc/platform/amigaone/Kconfig
 image-$(CONFIG_AMIGAONE)		+= cuImage.amigaone
 
diff --git a/arch/powerpc/boot/wiiu-head.S b/arch/powerpc/boot/wiiu-head.S
new file mode 100644
index 000000000000..8586e2e992d5
--- /dev/null
+++ b/arch/powerpc/boot/wiiu-head.S
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Entrypoint head asm
+ * This code expects to be called directly after the Espresso BootROM, which implies certain MSR
+ * states.
+ *
+ * Nintendo Wii U bootwrapper support
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+
+#include "ppc_asm.h"
+
+.text
+.global _zimage_start
+_zimage_start:
+	/* Clear out all BATs. MMU is already off. */
+	li r8, 0
+
+	mtspr 0x210, r8 /* IBAT0U */
+	mtspr 0x212, r8 /* IBAT1U */
+	mtspr 0x214, r8 /* IBAT2U */
+	mtspr 0x216, r8 /* IBAT3U */
+	mtspr 0x218, r8 /* DBAT0U */
+	mtspr 0x21a, r8 /* DBAT1U */
+	mtspr 0x21c, r8 /* DBAT2U */
+	mtspr 0x21e, r8 /* DBAT3U */
+
+	mtspr 0x230, r8 /* IBAT4U */
+	mtspr 0x232, r8 /* IBAT5U */
+	mtspr 0x234, r8 /* IBAT6U */
+	mtspr 0x236, r8 /* IBAT7U */
+	mtspr 0x238, r8 /* DBAT4U */
+	mtspr 0x23a, r8 /* DBAT5U */
+	mtspr 0x23c, r8 /* DBAT6U */
+	mtspr 0x23e, r8 /* DBAT7U */
+
+	/* MEM1 */
+	/* 32MB, starting at 0x00000000... */
+	li r8, 0x000003ff@l
+	mtspr 0x21a, r8 /* DBAT1U */
+	mtspr 0x212, r8 /* IBAT1U */
+
+	/* mapped into phys 0x00000000; read-write; normal caching. */
+	li r8, 0x00000002@l
+	mtspr 0x21b, r8 /* DBAT1L */
+	mtspr 0x213, r8 /* IBAT1L */
+
+	/* Latte MMIO area */
+	/* 64MB, starting at 0x0d800000... */
+	lis r8, 0x0d8007ff@h
+	ori r8, r8,0x0d800007ff@l
+	mtspr 0x21c, r8 /* DBAT2U */
+
+	/* mapped into phys 0x0d800000; read-write; writethrough/nocache/guard*/
+	lis r8, 0x0d80006A@h
+	ori r8, r8,0x0d80006A@l
+	mtspr 0x21d, r8 /* DBAT2L */
+
+	/* Bootloader comms area (actually 0x89200000) */
+	/* 128MiB, starting at 0x88000000... */
+	lis r8, 0x88000fff@h
+	ori r8, r8, 0x88000fff@l
+	mtspr 0x21e, r8 /* DBAT3U */
+
+	/* mapped into phys 0x88000000; read-write; normal caching. */
+	lis r8, 0x88000002@h
+	ori r8, r8, 0x88000002@l
+	mtspr 0x21f, r8 /* DBAT3L */
+
+	/* Turn on BAT 4 through 7, configure CPU */
+	mfspr r8, 0x3f3 /* HID4 */
+	oris r8, r8, 0x3200 /* L2FM: 64-byte fetch, BPD: max depth is 4, SBE */
+	mtspr 0x3f3, r8
+
+	/* Turn on and invalidate caches */
+	mfspr r8, 0x3f0 /* HID0 */
+	/* HID0_ICE | HID0_ICFI | HID0_DCE | HID0_DCFI */
+	ori r8, r8, (1 << 15) | (1 << 11) | (1 << 14) | (1 << 10)
+	mtspr 0x3f0, r8
+	isync
+
+	li r3, 0
+	li r4, 0
+	li r5, 0
+
+	bl get_lr
+get_lr:
+	mflr r8
+	/* Get absolute address of done */
+	addi r8, r8, done - get_lr
+
+	/* Set up MSR */
+	/* MSR_DR | MSR_IR | MSR_FP */
+	/* Data/instruction MMUs, FPU because why not */
+	ori r9, r3, (1 << 4) | (1 << 5) | (1 << 13)
+
+	/* Apply our new MSR, starting execution at "done" */
+	mtsrr0 r8
+	mtsrr1 r9
+	sync
+	rfi
+done:
+	b _zimage_start_lib
diff --git a/arch/powerpc/boot/wiiu.c b/arch/powerpc/boot/wiiu.c
new file mode 100644
index 000000000000..fe88eb2c42ae
--- /dev/null
+++ b/arch/powerpc/boot/wiiu.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Platform support and IPC debug console to linux-loader (on Starbuck)
+ *
+ * Nintendo Wii U bootwrapper support
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+
+#include <stddef.h>
+#include "string.h"
+#include "stdio.h"
+#include "types.h"
+#include "io.h"
+#include "ops.h"
+
+BSS_STACK(8192);
+
+// Volatile is used here since the io.h routines require it
+#define LT_IPC_PPCMSG ((volatile u32 *)0x0d800000)
+#define LT_IPC_PPCCTRL ((volatile u32 *)0x0d800004)
+#define LT_IPC_PPCCTRL_X1 0x1
+
+#define WIIU_LOADER_CMD_PRINT 0x01000000
+
+static void wiiu_ipc_sendmsg(int msg)
+{
+	out_be32(LT_IPC_PPCMSG, msg);
+	out_be32(LT_IPC_PPCCTRL, LT_IPC_PPCCTRL_X1);
+	while (in_be32(LT_IPC_PPCCTRL) & LT_IPC_PPCCTRL_X1)
+		barrier();
+}
+
+/*
+ * Send logging string out over IPC to linux-loader for early printing.
+ * Packs 3 chars at a time where possible.
+ */
+static void wiiu_write_ipc(const char *buf, int len)
+{
+	int i = 0;
+
+	for (i = 0; i + 2 < len; i += 3) {
+		int msg = WIIU_LOADER_CMD_PRINT | (buf[i + 0] << 16) |
+			  (buf[i + 1] << 8) | buf[i + 2];
+
+		wiiu_ipc_sendmsg(msg);
+	}
+
+	if (i < len) {
+		for (; i < len; i++) {
+			int msg = WIIU_LOADER_CMD_PRINT | (buf[i] << 16);
+
+			wiiu_ipc_sendmsg(msg);
+		}
+	}
+}
+
+/*
+ * Note 32MiB heap - not ideal but seems fine for the bootwrapper
+ */
+void platform_init(unsigned int r3, unsigned int r4, unsigned int r5)
+{
+	u32 heapsize;
+
+	console_ops.write = wiiu_write_ipc;
+	printf("wiiu: bootwrapper ok\n");
+
+	heapsize = 32 * 1024 * 1024 - (u32)_end;
+	simple_alloc_init(_end, heapsize, 32, 64);
+	printf("wiiu: heap ok\n");
+
+	fdt_init(_dtb_start);
+	printf("wiiu: dtb ok\n");
+}
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index 9184eda780fd..f42abe4ebde2 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -344,6 +344,10 @@ gamecube|wii)
     link_address='0x600000'
     platformo="$object/$platform-head.o $object/$platform.o"
     ;;
+wiiu)
+    link_address='0x600000'
+    platformo="$object/wiiu-head.o $object/$platform.o"
+    ;;
 microwatt)
     link_address='0x500000'
     platformo="$object/fixed-head.o $object/$platform.o"
-- 
2.35.1


  parent reply	other threads:[~2022-03-02  4:44 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02  4:43 [PATCH 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-03-02  4:43 ` [PATCH 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-03-02 13:28   ` Rob Herring
2022-03-02  4:43 ` [PATCH 02/12] powerpc: wiiu: device tree Ash Logan
2022-03-02 13:36   ` Rob Herring
2022-03-03  2:41     ` Ash Logan
2022-03-02  4:43 ` Ash Logan [this message]
2022-03-02  4:43 ` [PATCH 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-03-02  4:43 ` [PATCH 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-03-02  4:44 ` [PATCH 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-03-02  4:44 ` [PATCH 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-03-02  4:44 ` [PATCH 08/12] powerpc: wiiu: latte " Ash Logan
2022-03-02  4:44 ` [PATCH 09/12] powerpc: espresso processor support Ash Logan
2022-03-02  4:44 ` [PATCH 10/12] powerpc: wiiu: platform support Ash Logan
2022-03-02  4:44 ` [PATCH 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-05-13 22:43   ` Pali Rohár
2022-05-20  3:41     ` Ash Logan
2022-05-20  8:04       ` Pali Rohár
2022-05-20 10:44         ` Ash Logan
2022-05-20 12:30           ` Pali Rohár
2022-06-09 22:24             ` Pali Rohár
2022-08-08 18:40               ` Pali Rohár
2022-09-08 15:25                 ` Christophe Leroy
2022-09-08 15:35                   ` Pali Rohár
2022-09-08 20:17                     ` Fragmented physical memory on powerpc/32 Pali Rohár
2022-09-10  9:39                       ` Christophe Leroy
2022-09-12 14:48                         ` Mike Rapoport
2022-09-12 21:16                           ` Pali Rohár
2022-09-13  6:11                             ` Christophe Leroy
2022-09-13 12:36                               ` Christophe Leroy
2022-09-14  9:32                                 ` Mike Rapoport
2022-09-14  9:43                                   ` Christophe Leroy
2022-09-14 15:55                                     ` Mike Rapoport
2022-09-14 19:56                                       ` Pali Rohár
2022-03-02  4:44 ` [PATCH 12/12] powerpc: wiiu: Add minimal default config Ash Logan
2022-06-22 13:10 ` [PATCH v2 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-06-22 13:10   ` [PATCH v2 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-06-22 13:10   ` [PATCH v2 02/12] powerpc: wiiu: device tree Ash Logan
2022-06-22 13:10   ` [PATCH v2 03/12] powerpc: wiiu: bootwrapper support Ash Logan
2022-06-22 13:10   ` [PATCH v2 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-06-22 13:10   ` [PATCH v2 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-06-22 13:10   ` [PATCH v2 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-06-27  0:15     ` kernel test robot
2022-06-22 13:10   ` [PATCH v2 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-06-22 13:10   ` [PATCH v2 08/12] powerpc: wiiu: latte " Ash Logan
2022-06-27  2:51     ` kernel test robot
2022-06-22 13:10   ` [PATCH v2 09/12] powerpc: espresso processor support Ash Logan
2022-06-22 13:10   ` [PATCH v2 10/12] powerpc: wiiu: platform support Ash Logan
2022-06-22 13:10   ` [PATCH v2 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-06-22 13:10   ` [PATCH v2 12/12] powerpc: wiiu: Add minimal default config Ash Logan
2022-06-28 13:31   ` [PATCH v3 00/12] powerpc: Nintendo Wii U support Ash Logan
2022-06-28 13:31     ` [PATCH v3 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-06-29  9:52       ` Krzysztof Kozlowski
2022-06-28 13:31     ` [PATCH v3 02/12] powerpc: wiiu: device tree Ash Logan
2022-06-29  9:58       ` Krzysztof Kozlowski
2022-06-29 16:13         ` Segher Boessenkool
2022-06-29 18:13           ` Krzysztof Kozlowski
2022-06-29 20:28             ` Segher Boessenkool
2022-06-28 13:31     ` [PATCH v3 03/12] powerpc: wiiu: bootwrapper support Ash Logan
2022-06-28 13:31     ` [PATCH v3 04/12] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-06-28 13:31     ` [PATCH v3 05/12] powerpc: wiiu: declare as non-coherent Ash Logan
2022-06-28 13:31     ` [PATCH v3 06/12] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-06-28 13:31     ` [PATCH v3 07/12] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-06-28 13:31     ` [PATCH v3 08/12] powerpc: wiiu: latte " Ash Logan
2022-06-28 13:31     ` [PATCH v3 09/12] powerpc: espresso processor support Ash Logan
2022-06-28 13:31     ` [PATCH v3 10/12] powerpc: wiiu: platform support Ash Logan
2022-06-28 13:31     ` [PATCH v3 11/12] powerpc: wiiu: don't enforce flat memory Ash Logan
2022-06-28 13:31     ` [PATCH v3 12/12] powerpc: wiiu: add minimal default config Ash Logan
2022-11-15 14:47     ` [PATCH v3 00/12] powerpc: Nintendo Wii U support Christophe Leroy
2022-11-19 11:30     ` [PATCH v4 00/11] " Ash Logan
2022-11-19 11:30       ` [PATCH v4 01/11] dt-bindings: wiiu: Document the Nintendo Wii U devicetree Ash Logan
2022-11-19 21:36         ` Rob Herring
2022-11-20 15:30         ` Rob Herring
2024-02-20 16:20         ` Christophe Leroy
2024-02-20 16:24           ` Krzysztof Kozlowski
2022-11-19 11:30       ` [PATCH v4 02/11] powerpc: wiiu: device tree Ash Logan
2022-11-19 11:30       ` [PATCH v4 03/11] powerpc: wiiu: bootwrapper support Ash Logan
2022-11-19 11:30       ` [PATCH v4 04/11] powerpc: wiiu: introduce wiiu platform Ash Logan
2022-11-19 11:30       ` [PATCH v4 05/11] powerpc: wiiu: declare as non-coherent Ash Logan
2022-11-19 11:30       ` [PATCH v4 06/11] powerpc: wiiu: udbg support for latteipc Ash Logan
2022-11-19 11:30       ` [PATCH v4 07/11] powerpc: wiiu: espresso interrupt controller support Ash Logan
2022-11-19 11:30       ` [PATCH v4 08/11] powerpc: wiiu: latte " Ash Logan
2022-11-19 11:30       ` [PATCH v4 09/11] powerpc: espresso processor support Ash Logan
2022-11-19 11:30       ` [PATCH v4 10/11] powerpc: wiiu: platform support Ash Logan
2022-11-19 11:30       ` [PATCH v4 11/11] powerpc: wiiu: add minimal default config Ash Logan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220302044406.63401-4-ash@heyquark.com \
    --to=ash@heyquark.com \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=j.ne@posteo.net \
    --cc=linkmauve@linkmauve.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).