* [PATCH 0/2] MIPS: BMIPS: Improved early panic support
@ 2022-07-15 19:47 Florian Fainelli
2022-07-15 19:47 ` [PATCH 1/2] MIPS: CFE: Add cfe_die() Florian Fainelli
2022-07-15 19:47 ` [PATCH 2/2] MIPS: BMIPS: Utilize cfe_die() for invalid DTB Florian Fainelli
0 siblings, 2 replies; 4+ messages in thread
From: Florian Fainelli @ 2022-07-15 19:47 UTC (permalink / raw)
To: linux-mips
Cc: Florian Fainelli, Thomas Bogendoerfer,
Broadcom internal kernel review list, open list
Hi Thomas,
This patch series adds support for cfe_die() which can be used during
early platform initialization when we do not yet have a valid DTB to
infer an earlycon console from. This is useful while bringing up new
platforms/DTBs as well.
Thanks!
Florian Fainelli (2):
MIPS: CFE: Add cfe_die()
MIPS: BMIPS: Utilize cfe_die() for invalid DTB
arch/mips/Kconfig | 1 +
arch/mips/bmips/setup.c | 14 +++++++-
arch/mips/fw/cfe/cfe_api.c | 48 +++++++++++++++++++++++++-
arch/mips/include/asm/fw/cfe/cfe_api.h | 2 ++
4 files changed, 63 insertions(+), 2 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] MIPS: CFE: Add cfe_die()
2022-07-15 19:47 [PATCH 0/2] MIPS: BMIPS: Improved early panic support Florian Fainelli
@ 2022-07-15 19:47 ` Florian Fainelli
2022-07-15 21:18 ` Florian Fainelli
2022-07-15 19:47 ` [PATCH 2/2] MIPS: BMIPS: Utilize cfe_die() for invalid DTB Florian Fainelli
1 sibling, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2022-07-15 19:47 UTC (permalink / raw)
To: linux-mips
Cc: Florian Fainelli, Thomas Bogendoerfer,
Broadcom internal kernel review list, open list
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.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
arch/mips/fw/cfe/cfe_api.c | 48 +++++++++++++++++++++++++-
arch/mips/include/asm/fw/cfe/cfe_api.h | 2 ++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/arch/mips/fw/cfe/cfe_api.c b/arch/mips/fw/cfe/cfe_api.c
index 0c9c97ab291e..6e7883f1d47e 100644
--- a/arch/mips/fw/cfe/cfe_api.c
+++ b/arch/mips/fw/cfe/cfe_api.c
@@ -13,10 +13,15 @@
*
* Authors: Mitch Lichtenberg, Chris Demetriou
*/
-
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
+#include <asm/mipsregs.h>
#include <asm/fw/cfe/cfe_api.h>
#include "cfe_api_int.h"
+unsigned long __initdata cfe_seal;
+
/* Cast from a native pointer to a cfe_xptr_t and back. */
#define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
#define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
@@ -412,3 +417,44 @@ int cfe_writeblk(int handle, s64 offset, const char *buffer, int length)
return xiocb.xiocb_status;
return xiocb.plist.xiocb_buffer.buf_retlen;
}
+
+void __init cfe_die(char *fmt, ...)
+{
+ char msg[128];
+ va_list ap;
+ int handle;
+ unsigned int count;
+
+ va_start(ap, fmt);
+ vsprintf(msg, fmt, ap);
+ strcat(msg, "\r\n");
+
+ if (cfe_seal != CFE_EPTSEAL)
+ goto no_cfe;
+
+ /* disable XKS01 so that CFE can access the registers */
+#if defined(CONFIG_CPU_BMIPS4380)
+ __write_32bit_c0_register($22, 3,
+ __read_32bit_c0_register($22, 3) & ~BIT(12));
+#elif defined(CONFIG_CPU_BMIPS5000)
+ __write_32bit_c0_register($22, 5,
+ __read_32bit_c0_register($22, 5) & ~BIT(8));
+#endif
+ handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
+ if (handle < 0)
+ goto no_cfe;
+
+ cfe_write(handle, msg, strlen(msg));
+
+ for (count = 0; count < 0x7fffffff; count++)
+ mb();
+ cfe_exit(0, 1);
+ while (1)
+ ;
+
+no_cfe:
+ /* probably won't print anywhere useful */
+ panic("%s", msg);
+
+ va_end(ap);
+}
diff --git a/arch/mips/include/asm/fw/cfe/cfe_api.h b/arch/mips/include/asm/fw/cfe/cfe_api.h
index 6457f36897a2..25df2f4deb31 100644
--- a/arch/mips/include/asm/fw/cfe/cfe_api.h
+++ b/arch/mips/include/asm/fw/cfe/cfe_api.h
@@ -105,5 +105,7 @@ int cfe_setenv(char *name, char *val);
int cfe_write(int handle, const char *buffer, int length);
int cfe_writeblk(int handle, int64_t offset, const char *buffer,
int length);
+extern unsigned long cfe_seal;
+__printf(1, 2) void cfe_die(char *fmt, ...);
#endif /* CFE_API_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] MIPS: BMIPS: Utilize cfe_die() for invalid DTB
2022-07-15 19:47 [PATCH 0/2] MIPS: BMIPS: Improved early panic support Florian Fainelli
2022-07-15 19:47 ` [PATCH 1/2] MIPS: CFE: Add cfe_die() Florian Fainelli
@ 2022-07-15 19:47 ` Florian Fainelli
1 sibling, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2022-07-15 19:47 UTC (permalink / raw)
To: linux-mips
Cc: Florian Fainelli, Thomas Bogendoerfer,
Broadcom internal kernel review list, open list
If we were not specified a correct DTB, we will not be able to print
anything useful with panic() which requires a working console of some
sort. Utilize cfe_die() to callback into the CFE default UART and print
some useful diagnostics.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
arch/mips/Kconfig | 1 +
arch/mips/bmips/setup.c | 14 +++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8db38817320b..0c366088b707 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -294,6 +294,7 @@ config BMIPS_GENERIC
select HARDIRQS_SW_RESEND
select HAVE_PCI
select PCI_DRIVERS_GENERIC
+ select FW_CFE
help
Build a generic DT-based kernel image that boots on select
BCM33xx cable modem chips, BCM63xx DSL chips, and BCM7xxx set-top
diff --git a/arch/mips/bmips/setup.c b/arch/mips/bmips/setup.c
index 31bcfa4e08b9..e95b3f78e7cd 100644
--- a/arch/mips/bmips/setup.c
+++ b/arch/mips/bmips/setup.c
@@ -28,6 +28,7 @@
#include <asm/smp-ops.h>
#include <asm/time.h>
#include <asm/traps.h>
+#include <asm/fw/cfe/cfe_api.h>
#define RELO_NORMAL_VEC BIT(18)
@@ -123,8 +124,19 @@ static const struct bmips_quirk bmips_quirk_list[] = {
{ },
};
+static void __init bmips_init_cfe(void)
+{
+ cfe_seal = fw_arg3;
+
+ if (cfe_seal != CFE_EPTSEAL)
+ return;
+
+ cfe_init(fw_arg0, fw_arg2);
+}
+
void __init prom_init(void)
{
+ bmips_init_cfe();
bmips_cpu_setup();
register_bmips_smp_ops();
}
@@ -165,7 +177,7 @@ void __init plat_mem_setup(void)
dtb = get_fdt();
if (!dtb)
- panic("no dtb found");
+ cfe_die("no dtb found");
__dt_setup_arch(dtb);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] MIPS: CFE: Add cfe_die()
2022-07-15 19:47 ` [PATCH 1/2] MIPS: CFE: Add cfe_die() Florian Fainelli
@ 2022-07-15 21:18 ` Florian Fainelli
0 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2022-07-15 21:18 UTC (permalink / raw)
To: linux-mips
Cc: Thomas Bogendoerfer, Broadcom internal kernel review list,
open list
On 7/15/22 12:47, Florian Fainelli wrote:
> 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.
>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
> arch/mips/fw/cfe/cfe_api.c | 48 +++++++++++++++++++++++++-
> arch/mips/include/asm/fw/cfe/cfe_api.h | 2 ++
> 2 files changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/fw/cfe/cfe_api.c b/arch/mips/fw/cfe/cfe_api.c
> index 0c9c97ab291e..6e7883f1d47e 100644
> --- a/arch/mips/fw/cfe/cfe_api.c
> +++ b/arch/mips/fw/cfe/cfe_api.c
> @@ -13,10 +13,15 @@
> *
> * Authors: Mitch Lichtenberg, Chris Demetriou
> */
> -
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/printk.h>
> +#include <asm/mipsregs.h>
> #include <asm/fw/cfe/cfe_api.h>
> #include "cfe_api_int.h"
>
> +unsigned long __initdata cfe_seal;
> +
> /* Cast from a native pointer to a cfe_xptr_t and back. */
> #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
> #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
> @@ -412,3 +417,44 @@ int cfe_writeblk(int handle, s64 offset, const char *buffer, int length)
> return xiocb.xiocb_status;
> return xiocb.plist.xiocb_buffer.buf_retlen;
> }
> +
> +void __init cfe_die(char *fmt, ...)
> +{
> + char msg[128];
> + va_list ap;
> + int handle;
> + unsigned int count;
> +
> + va_start(ap, fmt);
> + vsprintf(msg, fmt, ap);
> + strcat(msg, "\r\n");
> +
> + if (cfe_seal != CFE_EPTSEAL)
> + goto no_cfe;
> +
> + /* disable XKS01 so that CFE can access the registers */
> +#if defined(CONFIG_CPU_BMIPS4380)
> + __write_32bit_c0_register($22, 3,
> + __read_32bit_c0_register($22, 3) & ~BIT(12));
> +#elif defined(CONFIG_CPU_BMIPS5000)
> + __write_32bit_c0_register($22, 5,
> + __read_32bit_c0_register($22, 5) & ~BIT(8));
> +#endif
Need to make this dynamic using read_c0_prid() because we support selecting multiple types of CPU in a single kernel image. V2 coming shortly.
--
Florian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-15 21:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-15 19:47 [PATCH 0/2] MIPS: BMIPS: Improved early panic support Florian Fainelli
2022-07-15 19:47 ` [PATCH 1/2] MIPS: CFE: Add cfe_die() Florian Fainelli
2022-07-15 21:18 ` Florian Fainelli
2022-07-15 19:47 ` [PATCH 2/2] MIPS: BMIPS: Utilize cfe_die() for invalid DTB Florian Fainelli
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).