mboxd: Introduce a new DEBUG log level

Currently there is no output on the console unless -v is specified on
the command line which enables error output. A second -v will provide
info output.

We probably want error output irrespective of whether a -v was given
on the command line because people generally want to know why their
program stopped working.

Make error output unconditional.

A single -v will give minimal informational output which is a good
level to see what the daemon is doing without barfing all over the
console.

A second -v will enable debug output which will print highly verbose
information which will be useful for debugging. Probably don't enable
this under normal circumstances.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Change-Id: I3da25f7e4e9e976c17389fcceb1d85ef98de7e0a
diff --git a/mboxd_windows.c b/mboxd_windows.c
index f02b0d7..451ecd1 100644
--- a/mboxd_windows.c
+++ b/mboxd_windows.c
@@ -82,8 +82,11 @@
 	 * did we will error out here
 	 */
 	for (i = 0; i < context->windows.num; i++) {
+		uint32_t size = context->windows.window[i].size;
+		MSG_DBG("Window %d @ %p for size 0x%.8x\n", i,
+			mem_location, size);
 		context->windows.window[i].mem = mem_location;
-		mem_location += context->windows.window[i].size;
+		mem_location += size;
 		if (mem_location > (context->mem + context->mem_size)) {
 			/* Tried to allocate window past the end of memory */
 			MSG_ERR("Total size of windows exceeds reserved mem\n");
@@ -110,13 +113,13 @@
 		/* Default to 1MB windows */
 		context->windows.default_size = 1 << 20;
 	}
-	MSG_OUT("Window size: 0x%.8x\n", context->windows.default_size);
+	MSG_INFO("Window size: 0x%.8x\n", context->windows.default_size);
 	if (!context->windows.num) {
 		/* Use the entire reserved memory region by default */
 		context->windows.num = context->mem_size /
 				       context->windows.default_size;
 	}
-	MSG_OUT("Number of Windows: %d\n", context->windows.num);
+	MSG_INFO("Number of windows: %d\n", context->windows.num);
 
 	context->windows.window = calloc(context->windows.num,
 					 sizeof(*context->windows.window));
@@ -404,6 +407,8 @@
 void close_current_window(struct mbox_context *context, bool set_bmc_event,
 			  uint8_t flags)
 {
+	MSG_DBG("Close current window, flags: 0x%.2x\n", flags);
+
 	if (set_bmc_event) {
 		set_bmc_events(context, BMC_EVENT_WINDOW_RESET, SET_BMC_EVENT);
 	}
@@ -443,6 +448,7 @@
 {
 	int i;
 
+	MSG_DBG("Resetting all windows\n");
 	/* We might have an open window which needs closing */
 	if (context->current) {
 		close_current_window(context, set_bmc_event, FLAGS_NONE);
@@ -522,6 +528,8 @@
 	struct window_context *cur;
 	int i;
 
+	MSG_DBG("Searching for window which contains 0x%.8x %s\n",
+		offset, exact ? "exactly" : "");
 	for (i = 0; i < context->windows.num; i++) {
 		cur = &context->windows.window[i];
 		if (cur->flash_offset == FLASH_OFFSET_UNINIT) {
@@ -567,12 +575,15 @@
 	struct window_context *cur = NULL;
 	int rc;
 
+	MSG_DBG("Creating window which maps 0x%.8x %s\n", offset,
+		exact ? "exactly" : "");
 
 	/* Search for an uninitialised window, use this before evicting */
 	cur = search_windows(context, FLASH_OFFSET_UNINIT, true);
 
 	/* No uninitialised window found, we need to choose one to "evict" */
 	if (!cur) {
+		MSG_DBG("No uninitialised window, evicting one\n");
 		cur = find_oldest_window(context);
 	}
 
@@ -628,6 +639,8 @@
 	if (context->version == API_VERSION_1) {
 		uint32_t i;
 
+		MSG_DBG("Checking for window overlap\n");
+
 		for (i = offset; i < (offset + cur->size); i += (cur->size - 1)) {
 			struct window_context *tmp = NULL;
 			do {