summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2019-08-08 12:10:22 +0530
committerAnup Patel <[email protected]>2019-08-09 12:38:33 +0530
commitdbff3e9f12f0abbdf475baaef4760c24af0d4227 (patch)
tree861e23030839b2d218a391d3e29f51398be3b39d
parentb1318e578b81690d7dcc57019e3f26c2b563bd74 (diff)
lib: Introduce sbi_dprintf() API
This patch introduces new sbi_dprintf() API for runtime debug prints. The sbi_dprintf() will print to console for a given HART only when SBI_SCRATCH_DEBUG_PRINTS option in enabled in sbi_scratch for this HART. We can now add debug prints using sbi_dprintf() at important places in OpenSBI sources. These debug prints will only show up when previous booting stage or compile time parameter sets the SBI_SCRATCH_DEBUG_PRINTS option in scratch space. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
-rw-r--r--include/sbi/sbi_console.h4
-rw-r--r--include/sbi/sbi_scratch.h2
-rw-r--r--lib/sbi/sbi_console.c13
3 files changed, 19 insertions, 0 deletions
diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h
index 16021d06..45af22f3 100644
--- a/include/sbi/sbi_console.h
+++ b/include/sbi/sbi_console.h
@@ -31,6 +31,10 @@ int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...);
int __printf(1, 2) sbi_printf(const char *format, ...);
struct sbi_scratch;
+
+int __printf(2, 3) sbi_dprintf(struct sbi_scratch *scratch,
+ const char *format, ...);
+
int sbi_console_init(struct sbi_scratch *scratch);
#endif
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h
index 46ea38f1..fd18bb24 100644
--- a/include/sbi/sbi_scratch.h
+++ b/include/sbi/sbi_scratch.h
@@ -74,6 +74,8 @@ struct sbi_scratch {
enum sbi_scratch_options {
/** Disable prints during boot */
SBI_SCRATCH_NO_BOOT_PRINTS = (1 << 0),
+ /** Enable runtime debug prints */
+ SBI_SCRATCH_DEBUG_PRINTS = (1 << 1),
};
/** Get pointer to sbi_scratch for current HART */
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
index 30fb2c8f..03dcdb24 100644
--- a/lib/sbi/sbi_console.c
+++ b/lib/sbi/sbi_console.c
@@ -375,6 +375,19 @@ int sbi_printf(const char *format, ...)
return retval;
}
+int sbi_dprintf(struct sbi_scratch *scratch, const char *format, ...)
+{
+ va_list args;
+ int retval = 0;
+
+ va_start(args, format);
+ if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS)
+ retval = print(NULL, NULL, format, args);
+ va_end(args);
+
+ return retval;
+}
+
int sbi_console_init(struct sbi_scratch *scratch)
{
console_plat = sbi_platform_ptr(scratch);