From: Ash Logan <ash@heyquark.com>
To: krzysztof.kozlowski+dt@linaro.org, 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, linkmauve@linkmauve.fr,
rw-r-r-0644@protonmail.com, devicetree@vger.kernel.org,
joel@jms.id.au
Subject: [PATCH v3 06/12] powerpc: wiiu: udbg support for latteipc
Date: Tue, 28 Jun 2022 23:31:38 +1000 [thread overview]
Message-ID: <20220628133144.142185-7-ash@heyquark.com> (raw)
In-Reply-To: <20220628133144.142185-1-ash@heyquark.com>
Add support for using the Latte chipset IPC for udbg on the Nintendo Wii
U console.
These messages can then be received by a special firmware running on the
"Starbuck" coprocessor.
Signed-off-by: Ash Logan <ash@heyquark.com>
---
v2->v3: Fix a missing declaration issue by including latteipc_udbg.h.
arch/powerpc/Kconfig.debug | 9 ++
arch/powerpc/include/asm/udbg.h | 1 +
arch/powerpc/kernel/head_book3s_32.S | 20 ++++
arch/powerpc/kernel/udbg.c | 3 +
arch/powerpc/platforms/wiiu/Kconfig | 13 ++
arch/powerpc/platforms/wiiu/Makefile | 2 +
arch/powerpc/platforms/wiiu/udbg_latteipc.c | 124 ++++++++++++++++++++
arch/powerpc/platforms/wiiu/udbg_latteipc.h | 27 +++++
8 files changed, 199 insertions(+)
create mode 100644 arch/powerpc/platforms/wiiu/udbg_latteipc.c
create mode 100644 arch/powerpc/platforms/wiiu/udbg_latteipc.h
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 9f363c143d86..cee97d21f5fb 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -254,6 +254,15 @@ config PPC_EARLY_DEBUG_USBGECKO
Select this to enable early debugging for Nintendo GameCube/Wii
consoles via an external USB Gecko adapter.
+config PPC_EARLY_DEBUG_LATTEIPC
+ bool "Early debugging through Latte chipset IPC"
+ depends on WIIU
+ select LATTEIPC_UDBG
+ help
+ Select this to enable early debugging for Nintendo Wii U consoles via
+ chipset IPC to the security coprocessor. This assumes a firmware is
+ running on the coprocessor to receive messages.
+
config PPC_EARLY_DEBUG_PS3GELIC
bool "Early debugging through the PS3 Ethernet port"
depends on PPC_PS3
diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h
index b4aa0d88ce2c..266b0e744ddc 100644
--- a/arch/powerpc/include/asm/udbg.h
+++ b/arch/powerpc/include/asm/udbg.h
@@ -53,6 +53,7 @@ extern void __init udbg_init_ehv_bc(void);
extern void __init udbg_init_ps3gelic(void);
extern void __init udbg_init_debug_opal_raw(void);
extern void __init udbg_init_debug_opal_hvsi(void);
+extern void __init udbg_init_latteipc(void);
#endif /* __KERNEL__ */
#endif /* _ASM_POWERPC_UDBG_H */
diff --git a/arch/powerpc/kernel/head_book3s_32.S b/arch/powerpc/kernel/head_book3s_32.S
index 6c739beb938c..48d487efb25c 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -164,6 +164,9 @@ __after_mmu_off:
#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
bl setup_usbgecko_bat
#endif
+#ifdef CONFIG_PPC_EARLY_DEBUG_LATTEIPC
+ bl setup_latteipc_bat
+#endif
/*
* Call setup_cpu for CPU 0 and initialize 6xx Idle
@@ -1201,4 +1204,21 @@ setup_usbgecko_bat:
blr
#endif
+#ifdef CONFIG_PPC_EARLY_DEBUG_LATTEIPC
+setup_latteipc_bat:
+ /* prepare a BAT for early io */
+ lis r8, 0x0d80
+
+ /*
+ * The virtual address used must match the virtual address
+ * associated to the fixmap entry FIX_EARLY_DEBUG_BASE.
+ */
+ lis r11, 0xfffe /* top 128K */
+ ori r8, r8, 0x002a /* uncached, guarded ,rw */
+ ori r11, r11, 0x2 /* 128K, Vs=1, Vp=0 */
+ mtspr SPRN_DBAT1L, r8
+ mtspr SPRN_DBAT1U, r11
+ blr
+#endif
+
.data
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index b1544b2f6321..84eae25c195e 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -67,6 +67,9 @@ void __init udbg_early_init(void)
udbg_init_debug_opal_raw();
#elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
udbg_init_debug_opal_hvsi();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_LATTEIPC)
+ /* For use on Nintendo Wii U */
+ udbg_init_latteipc();
#endif
#ifdef CONFIG_PPC_EARLY_DEBUG
diff --git a/arch/powerpc/platforms/wiiu/Kconfig b/arch/powerpc/platforms/wiiu/Kconfig
index 3834834c6bd7..8dfd6ac8774d 100644
--- a/arch/powerpc/platforms/wiiu/Kconfig
+++ b/arch/powerpc/platforms/wiiu/Kconfig
@@ -6,3 +6,16 @@ config WIIU
help
Select WIIU if configuring for the Nintendo Wii U.
More information at: <https://linux-wiiu.org/>
+
+config LATTEIPC_UDBG
+ bool "Chipset IPC udbg console for the Nintendo Wii U"
+ depends on WIIU
+ help
+ If you say yes to this option, support will be included for the
+ Wii U's chipset IPC as a udbg console.
+ These IPC messages can be received by a firmware running on the
+ console's "Starbuck" security coprocessor.
+
+ This driver bypasses the IPC layer completely.
+
+ If in doubt, say N here.
diff --git a/arch/powerpc/platforms/wiiu/Makefile b/arch/powerpc/platforms/wiiu/Makefile
index f66554cd5c45..b1e0e1307f6e 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_LATTEIPC_UDBG) += udbg_latteipc.o
diff --git a/arch/powerpc/platforms/wiiu/udbg_latteipc.c b/arch/powerpc/platforms/wiiu/udbg_latteipc.c
new file mode 100644
index 000000000000..4e44e0cb6494
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/udbg_latteipc.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Nintendo Wii U udbg support (to Starbuck coprocessor, via chipset IPC)
+ *
+ * Copyright (C) 2022 The linux-wiiu Team
+ *
+ * Based on arch/powerpc/platforms/embedded6xx/udbgecko_udbg.c
+ * Copyright (C) 2008-2009 The GameCube Linux Team
+ * Copyright (C) 2008-2009 Albert Herranz
+ */
+
+#include <mm/mmu_decl.h>
+
+#include <linux/io.h>
+#include <asm/prom.h>
+#include <asm/udbg.h>
+#include <asm/fixmap.h>
+
+#include "udbg_latteipc.h"
+
+#define LT_MMIO_BASE ((phys_addr_t)0x0d800000)
+#define LT_IPC_PPCMSG 0x00
+#define LT_IPC_PPCCTRL 0x04
+#define LT_IPC_PPCCTRL_X1 0x01
+
+#define WIIU_LOADER_CMD_PRINT 0x01000000
+
+void __iomem *latteipc_io_base;
+
+/*
+ * Transmits a character.
+ * Sends over IPC to linux-loader for printing.
+ */
+static void latteipc_udbg_putc(char c)
+{
+ void __iomem *ppcmsg_reg = latteipc_io_base + LT_IPC_PPCMSG;
+ void __iomem *ppcctrl_reg = latteipc_io_base + LT_IPC_PPCCTRL;
+
+ out_be32(ppcmsg_reg, WIIU_LOADER_CMD_PRINT | (c << 16));
+ out_be32(ppcctrl_reg, LT_IPC_PPCCTRL_X1);
+
+ while (in_be32(ppcctrl_reg) & LT_IPC_PPCCTRL_X1)
+ barrier();
+}
+
+/*
+ * Retrieves and prepares the virtual address needed to access the hardware.
+ */
+static void __iomem *latteipc_udbg_setup_ipc_io_base(struct device_node *np)
+{
+ void __iomem *ipc_io_base = NULL;
+ phys_addr_t paddr;
+ const unsigned int *reg;
+
+ reg = of_get_property(np, "reg", NULL);
+ if (reg) {
+ paddr = of_translate_address(np, reg);
+ if (paddr)
+ ipc_io_base = ioremap(paddr, reg[1]);
+ }
+ return ipc_io_base;
+}
+
+/*
+ * Latte IPC udbg support initialization.
+ */
+void __init latteipc_udbg_init(void)
+{
+ struct device_node *np;
+ void __iomem *ipc_io_base;
+
+ if (latteipc_io_base)
+ udbg_printf("%s: early -> final\n", __func__);
+
+ np = of_find_compatible_node(NULL, NULL, "nintendo,latte-ipc");
+ if (!np) {
+ udbg_printf("%s: IPC node not found\n", __func__);
+ goto out;
+ }
+
+ ipc_io_base = latteipc_udbg_setup_ipc_io_base(np);
+ if (!ipc_io_base) {
+ udbg_printf("%s: failed to setup IPC io base\n", __func__);
+ goto done;
+ }
+
+ udbg_putc = latteipc_udbg_putc;
+ udbg_printf("latteipc_udbg: ready\n");
+
+done:
+ of_node_put(np);
+out:
+ return;
+}
+
+#ifdef CONFIG_PPC_EARLY_DEBUG_LATTEIPC
+
+void __init udbg_init_latteipc(void)
+{
+ /*
+ * At this point we have a BAT already setup that enables I/O
+ * to the IPC hardware.
+ *
+ * The BAT uses a virtual address range reserved at the fixmap.
+ * This must match the virtual address configured in
+ * head_32.S:setup_latteipc_bat().
+ */
+ latteipc_io_base = (void __iomem *)__fix_to_virt(FIX_EARLY_DEBUG_BASE);
+
+ /* Assume a firmware is present, add hooks */
+ udbg_putc = latteipc_udbg_putc;
+
+ /*
+ * Prepare again the same BAT for MMU_init.
+ * This allows udbg I/O to continue working after the MMU is
+ * turned on for real.
+ * It is safe to continue using the same virtual address as it is
+ * a reserved fixmap area.
+ */
+ setbat(1, (unsigned long)latteipc_io_base, LT_MMIO_BASE, 128 * 1024,
+ PAGE_KERNEL_NCG);
+}
+
+#endif /* CONFIG_PPC_EARLY_DEBUG_LATTEIPC */
diff --git a/arch/powerpc/platforms/wiiu/udbg_latteipc.h b/arch/powerpc/platforms/wiiu/udbg_latteipc.h
new file mode 100644
index 000000000000..ca6d34e49158
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/udbg_latteipc.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Nintendo Wii U udbg support (to Starbuck coprocessor, via chipset IPC)
+ *
+ * Copyright (C) 2022 The linux-wiiu Team
+ *
+ * Based on arch/powerpc/platforms/embedded6xx/udbgecko_udbg.h
+ * Copyright (C) 2008-2009 The GameCube Linux Team
+ * Copyright (C) 2008-2009 Albert Herranz
+ */
+
+#ifndef __LATTEIPC_UDBG_H
+#define __LATTEIPC_UDBG_H
+
+#ifdef CONFIG_LATTEIPC_UDBG
+
+void __init latteipc_udbg_init(void);
+
+#else
+
+static inline void __init latteipc_udbg_init(void)
+{
+}
+
+#endif /* CONFIG_LATTEIPC_UDBG */
+
+#endif /* __LATTEIPC_UDBG_H */
--
2.36.1
next prev parent reply other threads:[~2022-06-28 13:33 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 ` [PATCH 03/12] powerpc: wiiu: bootwrapper support Ash Logan
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 ` Ash Logan [this message]
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=20220628133144.142185-7-ash@heyquark.com \
--to=ash@heyquark.com \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@csgroup.eu \
--cc=devicetree@vger.kernel.org \
--cc=j.ne@posteo.net \
--cc=joel@jms.id.au \
--cc=krzysztof.kozlowski+dt@linaro.org \
--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 \
--cc=rw-r-r-0644@protonmail.com \
/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).