console: Set log level from nvram

Submitted by Michael Neuling on April 20, 2017, 7:15 a.m.

Details

Message ID 20170420071500.1674-1-mikey@neuling.org
State New
Headers show

Commit Message

Michael Neuling April 20, 2017, 7:15 a.m.
This adds two new nvram options to set the console log level for the
driver/uart and in memory.  These are called log-level-memory and
log-level-driver.

These are only set once we have nvram inited.

To set them you do:
  nvram -p ibm,skiboot --update-config log-level-memory=9
  nvram -p ibm,skiboot --update-config log-level-driver=9

You can also use the named versions of emerg, alert, crit, err,
warning, notice, printf, info, debug, trace or insane.  ie.
    nvram -p ibm,skiboot --update-config log-level-driver=insane

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 core/init.c       | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/skiboot.h |  4 +++-
 2 files changed, 63 insertions(+), 1 deletion(-)

Comments

Cyril Bur April 20, 2017, 7:31 a.m.
On Thu, 2017-04-20 at 17:15 +1000, Michael Neuling wrote:
> This adds two new nvram options to set the console log level for the
> driver/uart and in memory.  These are called log-level-memory and
                             ^ Space?


> log-level-driver.
> 
> These are only set once we have nvram inited.
> 
> To set them you do:
>   nvram -p ibm,skiboot --update-config log-level-memory=9
>   nvram -p ibm,skiboot --update-config log-level-driver=9
> 
> You can also use the named versions of emerg, alert, crit, err,
> warning, notice, printf, info, debug, trace or insane.  ie.
>     nvram -p ibm,skiboot --update-config log-level-driver=insane
> 
> Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Michael Neuling <mikey@neuling.org>

Reviewed-by: Cyril Bur <cyril.bur@au1.ibm.com>

> ---
>  core/init.c       | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/skiboot.h |  4 +++-
>  2 files changed, 63 insertions(+), 1 deletion(-)
> 
> diff --git a/core/init.c b/core/init.c
> index 6b8137c8c7..9d4d185dda 100644
> --- a/core/init.c
> +++ b/core/init.c
> @@ -68,6 +68,8 @@ struct debug_descriptor debug_descriptor = {
>  	.state_flags	= 0,
>  	.memcons_phys	= (uint64_t)&memcons,
>  	.trace_mask	= 0, /* All traces disabled by default */
> +	/* console log level:
> +	 *   high 4 bits in memory, low 4 bits driver (e.g. uart). */
>  #ifdef DEBUG
>  	.console_log_levels = (PR_DEBUG << 4) | PR_DEBUG,
>  #else
> @@ -615,6 +617,61 @@ static void dt_init_misc(void)
>  	dt_fixups();
>  }
>  
> +static u8 console_get_level(const char *s)
> +{
> +	if (strcmp(s, "emerg") == 0)
> +		return PR_EMERG;
> +	if (strcmp(s, "alert") == 0)
> +		return PR_ALERT;
> +	if (strcmp(s, "crit") == 0)
> +		return PR_CRIT;
> +	if (strcmp(s, "err") == 0)
> +		return PR_ERR;
> +	if (strcmp(s, "warning") == 0)
> +		return PR_WARNING;
> +	if (strcmp(s, "notice") == 0)
> +		return PR_NOTICE;
> +	if (strcmp(s, "printf") == 0)
> +		return PR_PRINTF;
> +	if (strcmp(s, "info") == 0)
> +		return PR_INFO;
> +	if (strcmp(s, "debug") == 0)
> +		return PR_DEBUG;
> +	if (strcmp(s, "trace") == 0)
> +		return PR_TRACE;
> +	if (strcmp(s, "insane") == 0)
> +		return PR_INSANE;
> +	/* Assume it's a number instead */

So if you'd told me that this patch existed I would have naively put
the actual #define name as a string in the flash but on reflection this
is better.

> +	return atoi(s);

Ability to put number is great++!

> +}
> +
> +static void console_log_level(void)
> +{
> +	const char *s;
> +	u8 level;
> +
> +	/* console log level:
> +	 *   high 4 bits in memory, low 4 bits driver (e.g. uart). */
> +	s = nvram_query("log-level-driver");
> +	if (s) {
> +		level = console_get_level(s);
> +		debug_descriptor.console_log_levels =
> +			(debug_descriptor.console_log_levels & 0xf0 ) |
> +			(level & 0x0f);
> +		prlog(PR_NOTICE, "console: Setting driver log level to %i\n",
> +		      level & 0x0f);
> +	}
> +	s = nvram_query("log-level-memory");
> +	if (s) {
> +		level = console_get_level(s);
> +		debug_descriptor.console_log_levels =
> +			(debug_descriptor.console_log_levels & 0x0f ) |
> +			((level & 0x0f) << 4);
> +		prlog(PR_NOTICE, "console: Setting memory log level to %i\n",
> +		      level & 0x0f);
> +	}
> +}
> +
>  typedef void (*ctorcall_t)(void);
>  
>  static void __nomcount do_ctors(void)
> @@ -921,6 +978,9 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
>  	/* Read in NVRAM and set it up */
>  	nvram_init();
>  
> +	/* Set the console level */
> +	console_log_level();
> +
>  	/* Secure/Trusted Boot init. We look for /ibm,secureboot in DT */
>  	stb_init();
>  
> diff --git a/include/skiboot.h b/include/skiboot.h
> index 2b1f8a577e..5c8b0c854d 100644
> --- a/include/skiboot.h
> +++ b/include/skiboot.h
> @@ -91,7 +91,9 @@ static inline bool opal_booting(void)
>  	return !(debug_descriptor.state_flags & OPAL_BOOT_COMPLETE);
>  }
>  
> -/* Console logging */
> +/* Console logging
> + * Update console_get_level() if you add here
> + */
>  #define PR_EMERG	0
>  #define PR_ALERT	1
>  #define PR_CRIT		2

Patch hide | download patch | download mbox

diff --git a/core/init.c b/core/init.c
index 6b8137c8c7..9d4d185dda 100644
--- a/core/init.c
+++ b/core/init.c
@@ -68,6 +68,8 @@  struct debug_descriptor debug_descriptor = {
 	.state_flags	= 0,
 	.memcons_phys	= (uint64_t)&memcons,
 	.trace_mask	= 0, /* All traces disabled by default */
+	/* console log level:
+	 *   high 4 bits in memory, low 4 bits driver (e.g. uart). */
 #ifdef DEBUG
 	.console_log_levels = (PR_DEBUG << 4) | PR_DEBUG,
 #else
@@ -615,6 +617,61 @@  static void dt_init_misc(void)
 	dt_fixups();
 }
 
+static u8 console_get_level(const char *s)
+{
+	if (strcmp(s, "emerg") == 0)
+		return PR_EMERG;
+	if (strcmp(s, "alert") == 0)
+		return PR_ALERT;
+	if (strcmp(s, "crit") == 0)
+		return PR_CRIT;
+	if (strcmp(s, "err") == 0)
+		return PR_ERR;
+	if (strcmp(s, "warning") == 0)
+		return PR_WARNING;
+	if (strcmp(s, "notice") == 0)
+		return PR_NOTICE;
+	if (strcmp(s, "printf") == 0)
+		return PR_PRINTF;
+	if (strcmp(s, "info") == 0)
+		return PR_INFO;
+	if (strcmp(s, "debug") == 0)
+		return PR_DEBUG;
+	if (strcmp(s, "trace") == 0)
+		return PR_TRACE;
+	if (strcmp(s, "insane") == 0)
+		return PR_INSANE;
+	/* Assume it's a number instead */
+	return atoi(s);
+}
+
+static void console_log_level(void)
+{
+	const char *s;
+	u8 level;
+
+	/* console log level:
+	 *   high 4 bits in memory, low 4 bits driver (e.g. uart). */
+	s = nvram_query("log-level-driver");
+	if (s) {
+		level = console_get_level(s);
+		debug_descriptor.console_log_levels =
+			(debug_descriptor.console_log_levels & 0xf0 ) |
+			(level & 0x0f);
+		prlog(PR_NOTICE, "console: Setting driver log level to %i\n",
+		      level & 0x0f);
+	}
+	s = nvram_query("log-level-memory");
+	if (s) {
+		level = console_get_level(s);
+		debug_descriptor.console_log_levels =
+			(debug_descriptor.console_log_levels & 0x0f ) |
+			((level & 0x0f) << 4);
+		prlog(PR_NOTICE, "console: Setting memory log level to %i\n",
+		      level & 0x0f);
+	}
+}
+
 typedef void (*ctorcall_t)(void);
 
 static void __nomcount do_ctors(void)
@@ -921,6 +978,9 @@  void __noreturn __nomcount main_cpu_entry(const void *fdt)
 	/* Read in NVRAM and set it up */
 	nvram_init();
 
+	/* Set the console level */
+	console_log_level();
+
 	/* Secure/Trusted Boot init. We look for /ibm,secureboot in DT */
 	stb_init();
 
diff --git a/include/skiboot.h b/include/skiboot.h
index 2b1f8a577e..5c8b0c854d 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -91,7 +91,9 @@  static inline bool opal_booting(void)
 	return !(debug_descriptor.state_flags & OPAL_BOOT_COMPLETE);
 }
 
-/* Console logging */
+/* Console logging
+ * Update console_get_level() if you add here
+ */
 #define PR_EMERG	0
 #define PR_ALERT	1
 #define PR_CRIT		2