public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/4] efi_loader: indent entry/exit prints to show nesting level
Date: Thu, 27 Jul 2017 08:04:19 -0400	[thread overview]
Message-ID: <20170727120419.32186-4-robdclark@gmail.com> (raw)
In-Reply-To: <20170727120419.32186-1-robdclark@gmail.com>

This should make it easier to see when a callback back to UEFI world
calls back in to the u-boot world, and generally match up EFI_ENTRY()
and EFI_EXIT() calls.

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 include/efi_loader.h          | 12 ++++++++----
 lib/efi_loader/efi_boottime.c | 25 +++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 4262d0ac6b..037cc7c543 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -17,13 +17,16 @@
 
 int __efi_entry_check(void);
 int __efi_exit_check(void);
+const char *__efi_nesting_inc(void);
+const char *__efi_nesting_dec(void);
 
 /*
  * Enter the u-boot world from UEFI:
  */
 #define EFI_ENTRY(format, ...) do { \
 	assert(__efi_entry_check()); \
-	debug("EFI: Entry %s(" format ")\n", __func__, ##__VA_ARGS__); \
+	debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
+		__func__, ##__VA_ARGS__); \
 	} while(0)
 
 /*
@@ -31,7 +34,8 @@ int __efi_exit_check(void);
  */
 #define EFI_EXIT(ret) ({ \
 	efi_status_t _r = ret; \
-	debug("EFI: Exit: %s: %u\n", __func__, (u32)(_r & ~EFI_ERROR_MASK)); \
+	debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
+		__func__, (u32)(_r & ~EFI_ERROR_MASK)); \
 	assert(__efi_exit_check()); \
 	_r; \
 	})
@@ -40,11 +44,11 @@ int __efi_exit_check(void);
  * Callback into UEFI world from u-boot:
  */
 #define EFI_CALL(exp) do { \
-	debug("EFI: Call: %s\n", #exp); \
+	debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
 	assert(__efi_exit_check()); \
 	exp; \
 	assert(__efi_entry_check()); \
-	debug("EFI: Return From: %s\n", #exp); \
+	debug("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
 	} while(0)
 
 extern struct efi_runtime_services efi_runtime_services;
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 66137d4ff9..de338f009c 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -50,6 +50,7 @@ static volatile void *efi_gd, *app_gd;
 #endif
 
 static int entry_count;
+static int nesting_level;
 
 /* Called on every callback entry */
 int __efi_entry_check(void)
@@ -96,6 +97,28 @@ void efi_restore_gd(void)
 #endif
 }
 
+/*
+ * Two spaces per indent level, maxing out at 10.. which ought to be
+ * enough for anyone ;-)
+ */
+static const char *indent_string(int level)
+{
+	static const char *indent = "                    ";
+	const int max = strlen(indent);
+	level = min(max, level * 2);
+	return &indent[max - level];
+}
+
+const char *__efi_nesting_inc(void)
+{
+	return indent_string(nesting_level++);
+}
+
+const char *__efi_nesting_dec(void)
+{
+	return indent_string(--nesting_level);
+}
+
 /* Low 32 bit */
 #define EFI_LOW32(a) (a & 0xFFFFFFFFULL)
 /* High 32 bit */
@@ -748,9 +771,11 @@ static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
 		return EFI_EXIT(info->exit_status);
 	}
 
+	__efi_nesting_dec();
 	__efi_exit_check();
 	entry(image_handle, &systab);
 	__efi_entry_check();
+	__efi_nesting_inc();
 
 	/* Should usually never get here */
 	return EFI_EXIT(EFI_SUCCESS);
-- 
2.13.0

  parent reply	other threads:[~2017-07-27 12:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 12:04 [U-Boot] [PATCH 1/4] efi_loader: only evaluate EFI_EXIT()'s ret once Rob Clark
2017-07-27 12:04 ` [U-Boot] [PATCH 2/4] efi_loader: Add an EFI_CALL() macro Rob Clark
2017-07-28 22:29   ` [U-Boot] [U-Boot,2/4] " Alexander Graf
2017-07-27 12:04 ` [U-Boot] [PATCH 3/4] efi_loader: add checking for incorrect use of EFI_ENTRY/EXIT Rob Clark
2017-07-28 22:27   ` [U-Boot] [U-Boot, " Alexander Graf
2017-07-27 12:04 ` Rob Clark [this message]
2017-07-28  7:24   ` [U-Boot] [PATCH 4/4] efi_loader: indent entry/exit prints to show nesting level Alexander Graf
2017-07-28  9:19     ` Rob Clark
2017-07-28  9:25       ` Alexander Graf
2017-07-28  9:34         ` Rob Clark
2017-07-28  9:36           ` Alexander Graf
2017-07-28 10:11             ` Rob Clark
2017-07-28 10:22               ` Alexander Graf
2017-07-28 11:54                 ` Rob Clark
2017-07-28 22:25   ` [U-Boot] [U-Boot, " Alexander Graf
2017-07-28 22:28 ` [U-Boot] [U-Boot, 1/4] efi_loader: only evaluate EFI_EXIT()'s ret once Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170727120419.32186-4-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox