summaryrefslogtreecommitdiff
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
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>
-rw-r--r--common/flash_common.c2
-rw-r--r--common/keyboard.c2
-rw-r--r--common/shared_mem.c48
-rw-r--r--include/shared_mem.h49
4 files changed, 64 insertions, 37 deletions
diff --git a/common/flash_common.c b/common/flash_common.c
index 84a2a2d55a..6e2587e652 100644
--- a/common/flash_common.c
+++ b/common/flash_common.c
@@ -158,7 +158,7 @@ static int command_flash_write(int argc, char **argv)
size = shared_mem_size();
/* Acquire the shared memory buffer */
- rv = shared_mem_acquire(size, 0, &data);
+ rv = shared_mem_acquire(size, &data);
if (rv) {
ccputs("Can't get shared mem\n");
return rv;
diff --git a/common/keyboard.c b/common/keyboard.c
index 16b7ad3bc8..e446b1c5aa 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -849,7 +849,7 @@ static int command_keyboard_log(int argc, char **argv)
} else if (argc == 2 && !strcasecmp("on", argv[1])) {
if (!kblog) {
int rv = shared_mem_acquire(sizeof(*kblog) * MAX_KBLOG,
- 1, (char **)&kblog);
+ (char **)&kblog);
if (rv != EC_SUCCESS)
kblog = NULL;
kblog_len = 0;
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);
diff --git a/include/shared_mem.h b/include/shared_mem.h
index 14b6613a9a..f7b8bcbccb 100644
--- a/include/shared_mem.h
+++ b/include/shared_mem.h
@@ -3,37 +3,48 @@
* found in the LICENSE file.
*/
-/* Shared memory interface for Chrome EC.
+/*
+ * Shared memory interface for Chrome EC.
*
- * This is intended to supply a relatively large block of memory for
- * use by a task for a relatively short amount of time. For example,
- * verified boot may need a buffer to hold signature data during a
- * verification operation. It is NOT intended for allocating
- * long-term buffers; those should in general be static variables
- * allocated at compile-time. It is NOT a full-featured replacement
- * for malloc() / free(). */
+ * This is intended to supply a relatively large block of memory for use by a
+ * task for a relatively short amount of time. For example, verified boot may
+ * need a buffer to hold signature data during a verification operation. It is
+ * NOT intended for allocating long-term buffers; those should in general be
+ * static variables allocated at compile-time. It is NOT a full-featured
+ * replacement for malloc() / free().
+ */
#ifndef __CROS_EC_SHARED_MEM_H
#define __CROS_EC_SHARED_MEM_H
#include "common.h"
-/* Initializes the module. */
+/**
+ * Initializes the module.
+ */
int shared_mem_init(void);
-/* Returns the maximum amount of shared memory which can be acquired,
- * in bytes. */
+/**
+ * Returns the maximum amount of shared memory which can be acquired, in
+ * bytes.
+ */
int shared_mem_size(void);
-/* Acquires a shared memory area of the requested size in bytes. If
- * wait != 0, will wait for the area to be available; if wait == 0,
- * will fail with EC_ERROR_BUSY if the request cannot be fulfilled
- * immediately. On success, sets *dest_ptr to the start of the memory
- * area and returns EC_SUCCESS. */
-int shared_mem_acquire(int size, int wait, char **dest_ptr);
+/**
+ * Acquires a shared memory area of the requested size in bytes.
+ *
+ * @param size Number of bytes requested
+ * @param dest_ptr If successful, set on return to the start of the
+ * granted memory buffer.
+ *
+ * @return EC_SUCCESS if successful, EC_ERROR_BUSY if buffer in use, or
+ * other non-zero error code.
+ */
+int shared_mem_acquire(int size, char **dest_ptr);
-/* Releases a shared memory area previously allocated via
- * shared_mem_acquire(). */
+/**
+ * Releases a shared memory area previously allocated via shared_mem_acquire().
+ */
void shared_mem_release(void *ptr);
#endif /* __CROS_EC_SHARED_MEM_H */