diff mbox series

[BOOT-WRAPPER,v2,09/10] Add printing functions

Message ID 20240812101555.3558589-10-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series Cleanup initialization | expand

Commit Message

Mark Rutland Aug. 12, 2024, 10:15 a.m. UTC
In subsequent patches we'll want to log messages from specific CPUs. Add
helpers to make this simpler.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Cc: Akos Denke <akos.denke@arm.com>
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Luca Fancellu <luca.fancellu@arm.com>
---
 common/platform.c  | 35 +++++++++++++++++++++++++++++++++++
 include/platform.h |  4 ++++
 2 files changed, 39 insertions(+)

Comments

Andre Przywara Aug. 21, 2024, 4:55 p.m. UTC | #1
On Mon, 12 Aug 2024 11:15:54 +0100
Mark Rutland <mark.rutland@arm.com> wrote:

Hi,

> In subsequent patches we'll want to log messages from specific CPUs. Add
> helpers to make this simpler.
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Acked-by: Marc Zyngier <maz@kernel.org>
> Cc: Akos Denke <akos.denke@arm.com>
> Cc: Andre Przywara <andre.przywara@arm.com>
> Cc: Luca Fancellu <luca.fancellu@arm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>  common/platform.c  | 35 +++++++++++++++++++++++++++++++++++
>  include/platform.h |  4 ++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/common/platform.c b/common/platform.c
> index 1607ee6..4e390e1 100644
> --- a/common/platform.c
> +++ b/common/platform.c
> @@ -65,6 +65,41 @@ void print_ulong_hex(unsigned long val)
>  	}
>  }
>  
> +// 2^32 is 4,294,967,296
> +#define DEC_CHARS_PER_UINT	10
> +
> +void print_uint_dec(unsigned int val)
> +{
> +	char digits[DEC_CHARS_PER_UINT];
> +	int d = 0;
> +
> +	do {
> +		digits[d] = val % 10;
> +		val /= 10;
> +		d++;
> +	} while (val);
> +
> +	while (d--) {
> +		print_char('0' + digits[d]);
> +	}
> +}
> +
> +void print_cpu_warn(unsigned int cpu, const char *str)
> +{
> +	print_string("CPU");
> +	print_uint_dec(cpu);
> +	print_string(" WARNING: ");
> +	print_string(str);
> +}
> +
> +void print_cpu_msg(unsigned int cpu, const char *str)
> +{
> +	print_string("CPU");
> +	print_uint_dec(cpu);
> +	print_string(": ");
> +	print_string(str);
> +}
> +
>  void init_uart(void)
>  {
>  	/*
> diff --git a/include/platform.h b/include/platform.h
> index c88e124..09712b1 100644
> --- a/include/platform.h
> +++ b/include/platform.h
> @@ -12,6 +12,10 @@
>  void print_char(char c);
>  void print_string(const char *str);
>  void print_ulong_hex(unsigned long val);
> +void print_uint_dec(unsigned int val);
> +
> +void print_cpu_warn(unsigned int cpu, const char *str);
> +void print_cpu_msg(unsigned int cpu, const char *str);
>  
>  void init_uart(void);
>
diff mbox series

Patch

diff --git a/common/platform.c b/common/platform.c
index 1607ee6..4e390e1 100644
--- a/common/platform.c
+++ b/common/platform.c
@@ -65,6 +65,41 @@  void print_ulong_hex(unsigned long val)
 	}
 }
 
+// 2^32 is 4,294,967,296
+#define DEC_CHARS_PER_UINT	10
+
+void print_uint_dec(unsigned int val)
+{
+	char digits[DEC_CHARS_PER_UINT];
+	int d = 0;
+
+	do {
+		digits[d] = val % 10;
+		val /= 10;
+		d++;
+	} while (val);
+
+	while (d--) {
+		print_char('0' + digits[d]);
+	}
+}
+
+void print_cpu_warn(unsigned int cpu, const char *str)
+{
+	print_string("CPU");
+	print_uint_dec(cpu);
+	print_string(" WARNING: ");
+	print_string(str);
+}
+
+void print_cpu_msg(unsigned int cpu, const char *str)
+{
+	print_string("CPU");
+	print_uint_dec(cpu);
+	print_string(": ");
+	print_string(str);
+}
+
 void init_uart(void)
 {
 	/*
diff --git a/include/platform.h b/include/platform.h
index c88e124..09712b1 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -12,6 +12,10 @@ 
 void print_char(char c);
 void print_string(const char *str);
 void print_ulong_hex(unsigned long val);
+void print_uint_dec(unsigned int val);
+
+void print_cpu_warn(unsigned int cpu, const char *str);
+void print_cpu_msg(unsigned int cpu, const char *str);
 
 void init_uart(void);