^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * c 2001 PPC 64 Team, IBM Corp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/udbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void (*udbg_putc)(char c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) void (*udbg_flush)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) int (*udbg_getc)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int (*udbg_getc_poll)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Early debugging facilities. You can enable _one_ of these via .config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * if you do so your kernel _will not boot_ on anything else. Be careful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) void __init udbg_early_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #if defined(CONFIG_PPC_EARLY_DEBUG_LPAR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* For LPAR machines that have an HVC console on vterm 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) udbg_init_debug_lpar();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #elif defined(CONFIG_PPC_EARLY_DEBUG_LPAR_HVSI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* For LPAR machines that have an HVSI console on vterm 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) udbg_init_debug_lpar_hvsi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #elif defined(CONFIG_PPC_EARLY_DEBUG_G5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* For use on Apple G5 machines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) udbg_init_pmac_realmode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_PANEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* RTAS panel debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) udbg_init_rtas_panel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #elif defined(CONFIG_PPC_EARLY_DEBUG_RTAS_CONSOLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* RTAS console debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) udbg_init_rtas_console();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #elif defined(CONFIG_PPC_EARLY_DEBUG_MAPLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Maple real mode debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) udbg_init_maple_realmode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #elif defined(CONFIG_PPC_EARLY_DEBUG_PAS_REALMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) udbg_init_pas_realmode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #elif defined(CONFIG_PPC_EARLY_DEBUG_BOOTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) udbg_init_btext();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #elif defined(CONFIG_PPC_EARLY_DEBUG_44x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* PPC44x debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) udbg_init_44x_as1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #elif defined(CONFIG_PPC_EARLY_DEBUG_40x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* PPC40x debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) udbg_init_40x_realmode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) udbg_init_cpm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) udbg_init_usbgecko();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #elif defined(CONFIG_PPC_EARLY_DEBUG_MEMCONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* In memory console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) udbg_init_memcons();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #elif defined(CONFIG_PPC_EARLY_DEBUG_EHV_BC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) udbg_init_ehv_bc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #elif defined(CONFIG_PPC_EARLY_DEBUG_PS3GELIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) udbg_init_ps3gelic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_RAW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) udbg_init_debug_opal_raw();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) udbg_init_debug_opal_hvsi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #ifdef CONFIG_PPC_EARLY_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) register_early_udbg_console();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* udbg library, used by xmon et al */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void udbg_puts(const char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (udbg_putc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (s && *s != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) while ((c = *s++) != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) udbg_putc(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (udbg_flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) udbg_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) printk("%s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int udbg_write(const char *s, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int remain = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!udbg_putc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (s && *s != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) while (((c = *s++) != '\0') && (remain-- > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) udbg_putc(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (udbg_flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) udbg_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return n - remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define UDBG_BUFSIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void udbg_printf(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (udbg_putc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) char buf[UDBG_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) udbg_puts(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void __init udbg_progress(char *s, unsigned short hex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) udbg_puts(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) udbg_puts("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Early boot console based on udbg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void udbg_console_write(struct console *con, const char *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) udbg_write(s, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static struct console udbg_console = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .name = "udbg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .write = udbg_console_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .index = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * Called by setup_system after ppc_md->probe and ppc_md->early_init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Call it again after setting udbg_putc in ppc_md->setup_arch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void __init register_early_udbg_console(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (early_console)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (!udbg_putc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (strstr(boot_command_line, "udbg-immortal")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) printk(KERN_INFO "early console immortal !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) udbg_console.flags &= ~CON_BOOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) early_console = &udbg_console;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) register_console(&udbg_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #if 0 /* if you want to use this as a regular output console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) console_initcall(register_udbg_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif