Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: CFE: Add cfe_die()

Add a cfe_die() implementation which is useful when the kernel does an
early panic and no console is registered. This allows us to print
useful diagnostics such as an invalid DTB having been
configured/selected.

Since the BMIPS_GENERIC kernel can be built with support for multiple
processors, we need to do a runtime determination of the type of CPU
that we are executing on to perform the appropriate XKS01 disabling.

Since cfe_init() + cfe_die() could be conceivably called at very early
stages of the kernel boot, before cpu_probe(), we do not rely on the
structure(s) populated by cpu_probe().

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Florian Fainelli and committed by
Thomas Bogendoerfer
c059ee9d 8a2b4566

+69 -1
+67 -1
arch/mips/fw/cfe/cfe_api.c
··· 13 13 * 14 14 * Authors: Mitch Lichtenberg, Chris Demetriou 15 15 */ 16 - 16 + #include <linux/init.h> 17 + #include <linux/kernel.h> 18 + #include <linux/printk.h> 19 + #include <asm/mipsregs.h> 17 20 #include <asm/fw/cfe/cfe_api.h> 18 21 #include "cfe_api_int.h" 22 + 23 + unsigned long __initdata cfe_seal; 19 24 20 25 /* Cast from a native pointer to a cfe_xptr_t and back. */ 21 26 #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n)) ··· 416 411 if (xiocb.xiocb_status < 0) 417 412 return xiocb.xiocb_status; 418 413 return xiocb.plist.xiocb_buffer.buf_retlen; 414 + } 415 + 416 + void __init cfe_die(char *fmt, ...) 417 + { 418 + unsigned int prid, __maybe_unused rev; 419 + char msg[128]; 420 + va_list ap; 421 + int handle; 422 + unsigned int count; 423 + 424 + va_start(ap, fmt); 425 + vsprintf(msg, fmt, ap); 426 + strcat(msg, "\r\n"); 427 + 428 + if (cfe_seal != CFE_EPTSEAL) 429 + goto no_cfe; 430 + 431 + prid = read_c0_prid(); 432 + if ((prid & PRID_COMP_MASK) != PRID_COMP_BROADCOM) 433 + goto no_cfe; 434 + 435 + rev = prid & PRID_REV_MASK; 436 + 437 + /* disable XKS01 so that CFE can access the registers */ 438 + switch (prid & PRID_IMP_MASK) { 439 + #ifdef CONFIG_CPU_BMIPS4380 440 + case PRID_IMP_BMIPS43XX: 441 + if (rev >= PRID_REV_BMIPS4380_LO && 442 + rev <= PRID_REV_BMIPS4380_HI) 443 + __write_32bit_c0_register($22, 3, 444 + __read_32bit_c0_register($22, 3) & ~BIT(12)); 445 + break; 446 + #endif 447 + #ifdef CONFIG_CPU_BMIPS5000 448 + case PRID_IMP_BMIPS5000: 449 + case PRID_IMP_BMIPS5200: 450 + __write_32bit_c0_register($22, 5, 451 + __read_32bit_c0_register($22, 5) & ~BIT(8)); 452 + break; 453 + #endif 454 + default: 455 + break; 456 + } 457 + 458 + handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE); 459 + if (handle < 0) 460 + goto no_cfe; 461 + 462 + cfe_write(handle, msg, strlen(msg)); 463 + 464 + for (count = 0; count < 0x7fffffff; count++) 465 + mb(); 466 + cfe_exit(0, 1); 467 + while (1) 468 + ; 469 + 470 + no_cfe: 471 + /* probably won't print anywhere useful */ 472 + panic("%s", msg); 473 + 474 + va_end(ap); 419 475 }
+2
arch/mips/include/asm/fw/cfe/cfe_api.h
··· 105 105 int cfe_write(int handle, const char *buffer, int length); 106 106 int cfe_writeblk(int handle, int64_t offset, const char *buffer, 107 107 int length); 108 + extern unsigned long cfe_seal; 109 + __printf(1, 2) void cfe_die(char *fmt, ...); 108 110 109 111 #endif /* CFE_API_H */