summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mboxd_msg.c15
-rw-r--r--mboxd_msg.h9
-rw-r--r--mboxd_windows.c24
-rw-r--r--mboxd_windows.h1
4 files changed, 47 insertions, 2 deletions
diff --git a/mboxd_msg.c b/mboxd_msg.c
index d02e0bf..0cc1cd2 100644
--- a/mboxd_msg.c
+++ b/mboxd_msg.c
@@ -147,6 +147,20 @@ static int mbox_handle_reset(struct mbox_context *context,
}
/*
+ * get_suggested_timeout() - get the suggested timeout value in seconds
+ * @context: The mbox context pointer
+ *
+ * Return: Suggested timeout in seconds
+ */
+static uint16_t get_suggested_timeout(struct mbox_context *context)
+{
+ struct window_context *window = find_largest_window(context);
+ uint32_t max_size_mb = window ? (window->size >> 20) : 0;
+
+ return align_up(max_size_mb * FLASH_ACCESS_MS_PER_MB, 1000) / 1000;
+}
+
+/*
* Command: GET_MBOX_INFO
* Get the API version, default window size and block size
* We also set the LPC mapping to point to the reserved memory region here so
@@ -229,6 +243,7 @@ static int mbox_handle_mbox_info(struct mbox_context *context,
}
if (context->version >= API_VERSION_2) {
resp->args[5] = context->block_size_shift;
+ put_u16(&resp->args[6], get_suggested_timeout(context));
}
return 0;
diff --git a/mboxd_msg.h b/mboxd_msg.h
index 44a2f91..7d81d7a 100644
--- a/mboxd_msg.h
+++ b/mboxd_msg.h
@@ -18,8 +18,13 @@
#ifndef MBOXD_MSG_H
#define MBOXD_MSG_H
-#define NO_BMC_EVENT false
-#define SET_BMC_EVENT true
+#include "common.h"
+
+/* Estimate as to how long (milliseconds) it takes to access a MB from flash */
+#define FLASH_ACCESS_MS_PER_MB 8000
+
+#define NO_BMC_EVENT false
+#define SET_BMC_EVENT true
struct mbox_msg {
uint8_t command;
diff --git a/mboxd_windows.c b/mboxd_windows.c
index c64d19b..f02b0d7 100644
--- a/mboxd_windows.c
+++ b/mboxd_windows.c
@@ -479,6 +479,30 @@ struct window_context *find_oldest_window(struct mbox_context *context)
}
/*
+ * find_largest_window() - Find the largest window in the window cache
+ * @context: The mbox context pointer
+ *
+ * Return: The largest window
+ */
+struct window_context *find_largest_window(struct mbox_context *context)
+{
+ struct window_context *largest = NULL, *cur;
+ uint32_t max_size = 0;
+ int i;
+
+ for (i = 0; i < context->windows.num; i++) {
+ cur = &context->windows.window[i];
+
+ if (cur->size > max_size) {
+ max_size = cur->size;
+ largest = cur;
+ }
+ }
+
+ return largest;
+}
+
+/*
* search_windows() - Search the window cache for a window containing offset
* @context: The mbox context pointer
* @offset: Absolute flash offset to search for (bytes)
diff --git a/mboxd_windows.h b/mboxd_windows.h
index 3625521..925697c 100644
--- a/mboxd_windows.h
+++ b/mboxd_windows.h
@@ -40,6 +40,7 @@ void close_current_window(struct mbox_context *context, bool set_bmc_event,
void reset_window(struct mbox_context *context, struct window_context *window);
void reset_all_windows(struct mbox_context *context, bool set_bmc_event);
struct window_context *find_oldest_window(struct mbox_context *context);
+struct window_context *find_largest_window(struct mbox_context *context);
struct window_context *search_windows(struct mbox_context *context,
uint32_t offset, bool exact);
int create_map_window(struct mbox_context *context,
OpenPOWER on IntegriCloud