summaryrefslogtreecommitdiff
path: root/common/shared_mem.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-08-09 13:47:26 -0700
committerGerrit <chrome-bot@google.com>2012-08-09 17:40:37 -0700
commit371d06bbfdf56fad142539c9a72759e53d5bc26a (patch)
tree0fe36ffa1485b319a7b0d3e59db9c722f97ce020 /common/shared_mem.c
parent019f50590e5c0d49baaf9dbe980c22f8e1e19df1 (diff)
downloadchrome-ec-371d06bbfdf56fad142539c9a72759e53d5bc26a.tar.gz
Tidy shared memory module
Adds shmem command to print amount of shared memory. This is also a useful indicator of how much IRAM is left, since shared memory will expand to fill all unused IRAM. Removes never-implemented wait param to shared_mem_acquire(). BUG=none TEST=shmem Change-Id: I798ff644d701dcba52219b70bec99c06a23d03ec Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/29809 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/shared_mem.c')
-rw-r--r--common/shared_mem.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/common/shared_mem.c b/common/shared_mem.c
index 63edd7e755..7ccf18c4b7 100644
--- a/common/shared_mem.c
+++ b/common/shared_mem.c
@@ -5,45 +5,61 @@
/* Shared memory module for Chrome EC */
-#include "config.h"
+#include "common.h"
+#include "console.h"
#include "link_defs.h"
#include "shared_mem.h"
#include "system.h"
+#include "util.h"
static int buf_in_use;
-
+static int max_used;
int shared_mem_size(void)
{
- /* Use all the RAM we can. The shared memory buffer is the
- * last thing allocated from the start of RAM, so we can use
- * everything up to the jump data at the end of RAM. */
+ /*
+ * Use all the RAM we can. The shared memory buffer is the last thing
+ * allocated from the start of RAM, so we can use everything up to the
+ * jump data at the end of RAM.
+ */
return system_usable_ram_end() - (uint32_t)__shared_mem_buf;
}
-
-int shared_mem_acquire(int size, int wait, char **dest_ptr)
+int shared_mem_acquire(int size, char **dest_ptr)
{
if (size > shared_mem_size() || size <= 0)
return EC_ERROR_INVAL;
- /* TODO: if task_start() hasn't been called, fail immediately
- * if not available. */
-
- /* TODO: wait if requested; for now, we fail immediately if
- * not available. */
if (buf_in_use)
return EC_ERROR_BUSY;
- /* TODO: atomically acquire buf_in_use. */
- buf_in_use = 1;
+ /*
+ * We could guard buf_in_use with a mutex, but since shared memory is
+ * currently only used by debug commands, that's overkill.
+ */
+
+ buf_in_use = size;
*dest_ptr = __shared_mem_buf;
+
+ if (max_used < size)
+ max_used = size;
+
return EC_SUCCESS;
}
-
void shared_mem_release(void *ptr)
{
- /* TODO: use event to wake up a previously-blocking acquire */
buf_in_use = 0;
}
+
+static int command_shmem(int argc, char **argv)
+{
+ ccprintf("Size:%6d\n", shared_mem_size());
+ ccprintf("Used:%6d\n", buf_in_use);
+ ccprintf("Max: %6d\n", max_used);
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(shmem, command_shmem,
+ NULL,
+ "Print shared memory stats",
+ NULL);