diff options
author | Jes B. Klinke <jbk@chromium.org> | 2023-04-26 10:40:42 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-26 22:09:20 +0000 |
commit | 1c3cd9b9c4ef130322c643a146683c4fa0faa9dc (patch) | |
tree | ebc506894054cbd889c0abedcd96cc9a58d9ba02 | |
parent | 852f363e248a4759b621ac6aff729be39ac285bf (diff) | |
download | chrome-ec-1c3cd9b9c4ef130322c643a146683c4fa0faa9dc.tar.gz |
board/hyperdebug: Use dedicated memory buffer for gpio monitoring
HyperDebug can be instructed to capture edge events on a subset of GPIO
pins. The current use of `common/shared_mem.h` conflicts with its use
by e.g. SPI.
This CL introduces a dedicated memory area in `hyperdebug/gpio.c`. For
now, only a single allocation of that area is implemented. We may want
to allow the called to request a certain buffer size, and split the
available are between buffer for disjoint subsets of GPIO pins being
monitored.
BUG=b:279752946
TEST=opentitantool spi tpm read register, while gpio monitoring
Change-Id: I9cc9b016b964b4db1cb31a048126deeacfef9b99
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4481050
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jes Klinke <jbk@chromium.org>
Tested-by: Jes Klinke <jbk@chromium.org>
-rw-r--r-- | board/hyperdebug/gpio.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/board/hyperdebug/gpio.c b/board/hyperdebug/gpio.c index 53a4929b3c..fff62ee233 100644 --- a/board/hyperdebug/gpio.c +++ b/board/hyperdebug/gpio.c @@ -12,7 +12,6 @@ #include "gpio.h" #include "hooks.h" #include "registers.h" -#include "shared_mem.h" #include "task.h" #include "timer.h" #include "util.h" @@ -101,6 +100,36 @@ struct monitoring_slot_t { struct monitoring_slot_t monitoring_slots[16]; /* + * Memory area used for allocation of cyclic buffers. (Currently the + * implementation supports only a single allocation.) + */ +uint8_t buffer_area[sizeof(struct cyclic_buffer_header_t) + 8192]; +bool buffer_area_in_use = false; + +static struct cyclic_buffer_header_t *allocate_cyclic_buffer(size_t size) +{ + struct cyclic_buffer_header_t *res = + (struct cyclic_buffer_header_t *)buffer_area; + if (buffer_area_in_use) { + /* No support for multiple smaller allocations, yet. */ + return 0; + } + if (sizeof(struct cyclic_buffer_header_t) + size > + sizeof(buffer_area)) { + /* Requested size exceeds the capacity of the area. */ + return 0; + } + buffer_area_in_use = true; + res->size = size; + return res; +} + +static void free_cyclic_buffer(struct cyclic_buffer_header_t *buf) +{ + buffer_area_in_use = false; +} + +/* * Counts unacknowledged buffer overflows. Whenever non-zero, the red LED * will flash. */ @@ -251,7 +280,7 @@ static void stop_all_gpio_monitoring(void) num_cur_monitoring--; if (buffer_header->overflow) atomic_sub(&num_cur_error_conditions, 1); - shared_mem_release((char *)buffer_header); + free_cyclic_buffer(buffer_header); } } @@ -521,14 +550,13 @@ static int command_gpio_monitoring_start(int argc, const char **argv) * All the requested signals were available for monitoring, and their * slots have been marked as reserved for the respective signal. */ - rv = shared_mem_acquire(sizeof(struct cyclic_buffer_header_t) + - cyclic_buffer_size, - (char **)&buf); - if (rv != EC_SUCCESS) + buf = allocate_cyclic_buffer(cyclic_buffer_size); + if (!buf) { + rv = EC_ERROR_BUSY; goto out_cleanup; + } buf->head = buf->tail = 0; - buf->size = cyclic_buffer_size; buf->overflow = 0; buf->num_signals = gpio_num; buf->signal_bits = 0; @@ -790,7 +818,7 @@ static int command_gpio_monitoring_stop(int argc, const char **argv) if (buf->overflow) atomic_sub(&num_cur_error_conditions, 1); - shared_mem_release((char *)buf); + free_cyclic_buffer(buf); return EC_SUCCESS; } |