summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Mittelberg <bmbm@google.com>2021-03-29 23:35:03 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-06-15 00:14:58 +0000
commita02fbd4cf6bcb6c9bb395c7304390ef8973e7dcb (patch)
treee2fbc6ffab7682bdc1562e8ffb334396c715599f
parente5f09dc23a0d31dee317b744168d28cf3574a61d (diff)
downloadchrome-ec-a02fbd4cf6bcb6c9bb395c7304390ef8973e7dcb.tar.gz
mkbp: Separate FIFO from the keyboard driver
Move protocol-related functionality out from the keyboard driver. This change is required to allow passing button events via MKBP on devices with non-MKBP keyboards. It reorganizes the code without changing the logic. BUG=b:170966461 BRANCH=main,firmware-dedede-13606.B,firmware-volteer-13672.B-main TEST=None Signed-off-by: Boris Mittelberg <bmbm@google.com> Change-Id: Ifb5b9d8e605f491313ee1dfe2c9950eb52152aa8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2669355 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3700696 Tested-by: Shelley Chen <shchen@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Commit-Queue: Shelley Chen <shchen@chromium.org>
-rw-r--r--common/build.mk2
-rw-r--r--common/keyboard_mkbp.c208
-rw-r--r--common/keyboard_scan.c2
-rw-r--r--common/mkbp_event.c4
-rw-r--r--common/mkbp_fifo.c241
-rw-r--r--include/keyboard_mkbp.h16
-rw-r--r--include/mkbp_fifo.h54
-rw-r--r--test/kb_mkbp.c2
-rw-r--r--test/kb_scan.c2
9 files changed, 317 insertions, 214 deletions
diff --git a/common/build.mk b/common/build.mk
index 428d65b1cc..3c2068edb7 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -92,7 +92,7 @@ common-$(CONFIG_I2C_VIRTUAL_BATTERY)+=virtual_battery.o
common-$(CONFIG_INDUCTIVE_CHARGING)+=inductive_charging.o
common-$(CONFIG_KEYBOARD_PROTOCOL_8042)+=keyboard_8042.o \
keyboard_8042_sharedlib.o
-common-$(CONFIG_KEYBOARD_PROTOCOL_MKBP)+=keyboard_mkbp.o
+common-$(CONFIG_KEYBOARD_PROTOCOL_MKBP)+=keyboard_mkbp.o mkbp_fifo.o
common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o
common-$(CONFIG_KEYBOARD_VIVALDI)+=keyboard_vivaldi.o
common-$(CONFIG_LED_COMMON)+=led_common.o
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c
index ff7ddc4d5c..b3b11cf13e 100644
--- a/common/keyboard_mkbp.c
+++ b/common/keyboard_mkbp.c
@@ -23,6 +23,7 @@
#include "keyboard_test.h"
#include "lid_switch.h"
#include "mkbp_event.h"
+#include "mkbp_fifo.h"
#include "power_button.h"
#include "system.h"
#include "tablet_mode.h"
@@ -34,17 +35,6 @@
#define CPUTS(outstr) cputs(CC_KEYBOARD, outstr)
#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
-/*
- * Common FIFO depth. This needs to be big enough not to overflow if a
- * series of keys is pressed in rapid succession and the kernel is too busy
- * to read them out right away.
- *
- * RAM usage is (depth * #cols); A 16-entry FIFO will consume 16x13=208 bytes,
- * which is non-trivial but not horrible.
- */
-
-#define FIFO_DEPTH 16
-
/* Changes to col,row here need to also be reflected in kernel.
* drivers/input/mkbp.c ... see KEY_BATTERY.
*/
@@ -52,21 +42,6 @@
#define BATTERY_KEY_ROW 7
#define BATTERY_KEY_ROW_MASK BIT(BATTERY_KEY_ROW)
-static uint32_t fifo_start; /* first entry */
-static uint32_t fifo_end; /* last entry */
-static uint32_t fifo_entries; /* number of existing entries */
-static struct ec_response_get_next_event fifo[FIFO_DEPTH];
-/*
- * Mutex for critical sections of mkbp_fifo_add(), which is called
- * from various tasks.
- */
-static struct mutex fifo_add_mutex;
-/*
- * Mutex for critical sections of fifo_remove(), which is called from the
- * hostcmd task and from keyboard_clear_buffer().
- */
-static struct mutex fifo_remove_mutex;
-
/* Button and switch state. */
static uint32_t mkbp_button_state;
static uint32_t mkbp_switch_state;
@@ -96,143 +71,24 @@ static struct ec_mkbp_protocol_config config = {
.fifo_max_depth = FIFO_DEPTH,
};
-static int get_data_size(enum ec_mkbp_event e)
-{
- switch (e) {
- case EC_MKBP_EVENT_KEY_MATRIX:
- return keyboard_cols;
-
-#ifdef CONFIG_HOST_EVENT64
- case EC_MKBP_EVENT_HOST_EVENT64:
- return sizeof(uint64_t);
-#endif
-
- case EC_MKBP_EVENT_HOST_EVENT:
- case EC_MKBP_EVENT_BUTTON:
- case EC_MKBP_EVENT_SWITCH:
- case EC_MKBP_EVENT_SYSRQ:
- return sizeof(uint32_t);
- default:
- /* For unknown types, say it's 0. */
- return 0;
- }
-}
-
-/**
- * Pop MKBP event data from FIFO
- *
- * @return EC_SUCCESS if entry popped, EC_ERROR_UNKNOWN if FIFO is empty
- */
-static int fifo_remove(uint8_t *buffp)
-{
- int size;
-
- mutex_lock(&fifo_remove_mutex);
- if (!fifo_entries) {
- /* no entry remaining in FIFO : return last known state */
- int last = (fifo_start + FIFO_DEPTH - 1) % FIFO_DEPTH;
-
- size = get_data_size(fifo[last].event_type);
-
- memcpy(buffp, &fifo[last].data, size);
- mutex_unlock(&fifo_remove_mutex);
-
- /*
- * Bail out without changing any FIFO indices and let the
- * caller know something strange happened. The buffer will
- * will contain the last known state of the keyboard.
- */
- return EC_ERROR_UNKNOWN;
- }
-
- /* Return just the event data. */
- if (buffp) {
- size = get_data_size(fifo[fifo_start].event_type);
- /* skip over event_type. */
- memcpy(buffp, &fifo[fifo_start].data, size);
- }
-
- fifo_start = (fifo_start + 1) % FIFO_DEPTH;
- atomic_sub(&fifo_entries, 1);
- mutex_unlock(&fifo_remove_mutex);
-
- return EC_SUCCESS;
-}
-
/*****************************************************************************/
/* Interface */
void keyboard_clear_buffer(void)
{
- mkbp_clear_fifo();
+ mkbp_fifo_clear_keyboard();
}
-void mkbp_clear_fifo(void)
+test_mockable int mkbp_keyboard_add(const uint8_t *buffp)
{
- int i;
-
- CPRINTS("clear MKBP fifo");
-
/*
- * Order of these locks is important to prevent deadlock since
- * mkbp_fifo_add() may call fifo_remove().
+ * If the keyboard protocol is not enabled, don't save the state to
+ * the FIFO or trigger an interrupt.
*/
- mutex_lock(&fifo_add_mutex);
- mutex_lock(&fifo_remove_mutex);
-
- fifo_start = 0;
- fifo_end = 0;
- /* This assignment is safe since both mutexes are held. */
- fifo_entries = 0;
- for (i = 0; i < FIFO_DEPTH; i++)
- memset(&fifo[i], 0, sizeof(struct ec_response_get_next_event));
-
- mutex_unlock(&fifo_remove_mutex);
- mutex_unlock(&fifo_add_mutex);
-}
-
-test_mockable int keyboard_fifo_add(const uint8_t *buffp)
-{
- return mkbp_fifo_add((uint8_t)EC_MKBP_EVENT_KEY_MATRIX, buffp);
-}
-
-test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
-{
- uint8_t size;
-
- /*
- * If the data is a keyboard matrix and the keyboard protocol is not
- * enabled, don't save the state to the FIFO or trigger an interrupt.
- */
- if (!(config.flags & EC_MKBP_FLAGS_ENABLE) &&
- (event_type == EC_MKBP_EVENT_KEY_MATRIX))
+ if (!(config.flags & EC_MKBP_FLAGS_ENABLE))
return EC_SUCCESS;
- mutex_lock(&fifo_add_mutex);
- if (fifo_entries >= config.fifo_max_depth) {
- mutex_unlock(&fifo_add_mutex);
- CPRINTS("MKBP common FIFO depth %d reached",
- config.fifo_max_depth);
-
- return EC_ERROR_OVERFLOW;
- }
-
- size = get_data_size(event_type);
- fifo[fifo_end].event_type = event_type;
- memcpy(&fifo[fifo_end].data, buffp, size);
- fifo_end = (fifo_end + 1) % FIFO_DEPTH;
- atomic_add(&fifo_entries, 1);
-
- /*
- * If our event didn't generate an interrupt then the host is still
- * asleep. In this case, we don't want to queue our event, except if
- * another event just woke the host (and wake is already in progress).
- */
- if (!mkbp_send_event(event_type) && fifo_entries == 1)
- fifo_remove(NULL);
-
- mutex_unlock(&fifo_add_mutex);
- return EC_SUCCESS;
+ return mkbp_fifo_add((uint8_t)EC_MKBP_EVENT_KEY_MATRIX, buffp);
}
void mkbp_update_switches(uint32_t sw, int state)
@@ -333,64 +189,28 @@ DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, keyboard_power_button,
HOOK_PRIO_DEFAULT);
#endif /* defined(CONFIG_POWER_BUTTON) */
-static int get_next_event(uint8_t *out, enum ec_mkbp_event evt)
-{
- uint8_t t = fifo[fifo_start].event_type;
- uint8_t size;
-
- if (!fifo_entries)
- return -1;
-
- /*
- * We need to peek at the next event to check that we were called with
- * the correct event.
- */
- if (t != (uint8_t)evt) {
- /*
- * We were called with the wrong event. The next element in the
- * FIFO's event type doesn't match with what we were called
- * with. Return an error that we're busy. The caller will need
- * to call us with the correct event first.
- */
- return -EC_ERROR_BUSY;
- }
-
- fifo_remove(out);
-
- /* Keep sending events if FIFO is not empty */
- if (fifo_entries)
- mkbp_send_event(fifo[fifo_start].event_type);
-
- /* Return the correct size of the data. */
- size = get_data_size(t);
- if (size)
- return size;
- else
- return -EC_ERROR_UNKNOWN;
-}
-
static int keyboard_get_next_event(uint8_t *out)
{
- return get_next_event(out, EC_MKBP_EVENT_KEY_MATRIX);
+ return mkbp_fifo_get_next_event(out, EC_MKBP_EVENT_KEY_MATRIX);
}
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_KEY_MATRIX, keyboard_get_next_event);
static int button_get_next_event(uint8_t *out)
{
- return get_next_event(out, EC_MKBP_EVENT_BUTTON);
+ return mkbp_fifo_get_next_event(out, EC_MKBP_EVENT_BUTTON);
}
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_BUTTON, button_get_next_event);
static int switch_get_next_event(uint8_t *out)
{
- return get_next_event(out, EC_MKBP_EVENT_SWITCH);
+ return mkbp_fifo_get_next_event(out, EC_MKBP_EVENT_SWITCH);
}
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SWITCH, switch_get_next_event);
#ifdef CONFIG_EMULATED_SYSRQ
static int sysrq_get_next_event(uint8_t *out)
{
- return get_next_event(out, EC_MKBP_EVENT_SYSRQ);
+ return mkbp_fifo_get_next_event(out, EC_MKBP_EVENT_SYSRQ);
}
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SYSRQ, sysrq_get_next_event);
#endif
@@ -405,7 +225,7 @@ void keyboard_send_battery_key(void)
/* Add to FIFO only if AP is on or else it will wake from suspend */
if (chipset_in_state(CHIPSET_STATE_ON))
- keyboard_fifo_add(state);
+ mkbp_keyboard_add(state);
}
void clear_typematic_key(void)
@@ -543,7 +363,7 @@ static void simulate_key(int row, int col, int pressed)
if (pressed)
simulated_key[col] |= BIT(row);
- keyboard_fifo_add(simulated_key);
+ mkbp_keyboard_add(simulated_key);
}
static int command_mkbp_keyboard_press(int argc, char **argv)
@@ -688,6 +508,8 @@ host_command_mkbp_set_config(struct host_cmd_handler_args *args)
config.valid_mask & req->config.valid_mask,
config.valid_flags & req->config.valid_flags);
+ mkbp_fifo_depth_update(config.fifo_max_depth);
+
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_MKBP_SET_CONFIG,
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c
index 183c2cd8b5..04c0a946dc 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -589,7 +589,7 @@ static int check_keys_changed(uint8_t *state)
#endif
#ifdef CONFIG_KEYBOARD_PROTOCOL_MKBP
- keyboard_fifo_add(state);
+ mkbp_keyboard_add(state);
#endif
}
diff --git a/common/mkbp_event.c b/common/mkbp_event.c
index 1b37bf78de..b0d03ae673 100644
--- a/common/mkbp_event.c
+++ b/common/mkbp_event.c
@@ -184,7 +184,7 @@ static inline int host_is_sleeping(void)
/*
* This is the deferred function that ensures that we attempt to set the MKBP
* interrupt again if there was a failure in the system (EC or AP) and the AP
- * never called get_next_event.
+ * never called mkbp_fifo_get_next_event.
*/
static void force_mkbp_if_events(void);
DECLARE_DEFERRED(force_mkbp_if_events);
@@ -259,7 +259,7 @@ static void activate_mkbp_with_events(uint32_t events_to_add)
/*
* This is the deferred function that ensures that we attempt to set the MKBP
* interrupt again if there was a failure in the system (EC or AP) and the AP
- * never called get_next_event.
+ * never called mkbp_fifo_get_next_event.
*/
static void force_mkbp_if_events(void)
{
diff --git a/common/mkbp_fifo.c b/common/mkbp_fifo.c
new file mode 100644
index 0000000000..428d6412fc
--- /dev/null
+++ b/common/mkbp_fifo.c
@@ -0,0 +1,241 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Matrix KeyBoard Protocol FIFO buffer implementation
+ */
+
+#include "atomic.h"
+#include "common.h"
+#include "keyboard_config.h"
+#include "mkbp_event.h"
+#include "mkbp_fifo.h"
+#include "system.h"
+#include "task.h"
+#include "util.h"
+
+/* Console output macros */
+#define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)
+
+/*
+ * Common FIFO depth. This needs to be big enough not to overflow if a
+ * series of keys is pressed in rapid succession and the kernel is too busy
+ * to read them out right away.
+ *
+ * RAM usage is (depth * #cols); A 16-entry FIFO will consume 16x13=208 bytes,
+ * which is non-trivial but not horrible.
+ */
+
+static uint32_t fifo_start; /* first entry */
+static uint32_t fifo_end; /* last entry */
+static uint32_t fifo_entries; /* number of existing entries */
+static uint8_t fifo_max_depth = FIFO_DEPTH;
+static struct ec_response_get_next_event fifo[FIFO_DEPTH];
+
+/*
+ * Mutex for critical sections of mkbp_fifo_add(), which is called
+ * from various tasks.
+ */
+K_MUTEX_DEFINE(fifo_add_mutex);
+/*
+ * Mutex for critical sections of fifo_remove(), which is called from the
+ * hostcmd task and from keyboard_clear_buffer().
+ */
+K_MUTEX_DEFINE(fifo_remove_mutex);
+
+static int get_data_size(enum ec_mkbp_event e)
+{
+ switch (e) {
+ case EC_MKBP_EVENT_KEY_MATRIX:
+ return KEYBOARD_COLS_MAX;
+
+#ifdef CONFIG_HOST_EVENT64
+ case EC_MKBP_EVENT_HOST_EVENT64:
+ return sizeof(uint64_t);
+#endif
+
+ case EC_MKBP_EVENT_HOST_EVENT:
+ case EC_MKBP_EVENT_BUTTON:
+ case EC_MKBP_EVENT_SWITCH:
+ case EC_MKBP_EVENT_SYSRQ:
+ return sizeof(uint32_t);
+ default:
+ /* For unknown types, say it's 0. */
+ return 0;
+ }
+}
+
+/**
+ * Pop MKBP event data from FIFO
+ *
+ * @return EC_SUCCESS if entry popped, EC_ERROR_UNKNOWN if FIFO is empty
+ */
+static int fifo_remove(uint8_t *buffp)
+{
+ int size;
+
+ mutex_lock(&fifo_remove_mutex);
+ if (!fifo_entries) {
+ /* no entry remaining in FIFO : return last known state */
+ int last = (fifo_start + FIFO_DEPTH - 1) % FIFO_DEPTH;
+
+ size = get_data_size(fifo[last].event_type);
+
+ memcpy(buffp, &fifo[last].data, size);
+ mutex_unlock(&fifo_remove_mutex);
+
+ /*
+ * Bail out without changing any FIFO indices and let the
+ * caller know something strange happened. The buffer will
+ * will contain the last known state of the keyboard.
+ */
+ return EC_ERROR_UNKNOWN;
+ }
+
+ /* Return just the event data. */
+ if (buffp) {
+ size = get_data_size(fifo[fifo_start].event_type);
+ /* skip over event_type. */
+ memcpy(buffp, &fifo[fifo_start].data, size);
+ }
+
+ fifo_start = (fifo_start + 1) % FIFO_DEPTH;
+ atomic_sub(&fifo_entries, 1);
+ mutex_unlock(&fifo_remove_mutex);
+
+ return EC_SUCCESS;
+}
+
+/*****************************************************************************/
+/* Interface */
+
+void mkbp_fifo_depth_update(uint8_t new_max_depth)
+{
+ fifo_max_depth = new_max_depth;
+}
+
+
+void mkbp_fifo_clear_keyboard(void)
+{
+ int i, new_fifo_entries = 0;
+
+ CPRINTS("clear keyboard MKBP fifo");
+
+ /*
+ * Order of these locks is important to prevent deadlock since
+ * mkbp_fifo_add() may call fifo_remove().
+ */
+ mutex_lock(&fifo_add_mutex);
+ mutex_lock(&fifo_remove_mutex);
+
+ /* Reset the end position */
+ fifo_end = fifo_start;
+
+ for (i = 0; i < fifo_entries; i++) {
+ int cur = (fifo_start + i) % FIFO_DEPTH;
+
+ /* Drop keyboard events */
+ if (fifo[cur].event_type == EC_MKBP_EVENT_KEY_MATRIX)
+ continue;
+
+ /* And move other events to the front */
+ memmove(&fifo[fifo_end], &fifo[cur], sizeof(fifo[cur]));
+ fifo_end = (fifo_end + 1) % FIFO_DEPTH;
+ ++new_fifo_entries;
+ }
+ fifo_entries = new_fifo_entries;
+
+ mutex_unlock(&fifo_remove_mutex);
+ mutex_unlock(&fifo_add_mutex);
+}
+
+void mkbp_clear_fifo(void)
+{
+ int i;
+
+ CPRINTS("clear MKBP fifo");
+
+ /*
+ * Order of these locks is important to prevent deadlock since
+ * mkbp_fifo_add() may call fifo_remove().
+ */
+ mutex_lock(&fifo_add_mutex);
+ mutex_lock(&fifo_remove_mutex);
+
+ fifo_start = 0;
+ fifo_end = 0;
+ /* This assignment is safe since both mutexes are held. */
+ fifo_entries = 0;
+ for (i = 0; i < FIFO_DEPTH; i++)
+ memset(&fifo[i], 0, sizeof(struct ec_response_get_next_event));
+
+ mutex_unlock(&fifo_remove_mutex);
+ mutex_unlock(&fifo_add_mutex);
+}
+
+test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp)
+{
+ uint8_t size;
+
+ mutex_lock(&fifo_add_mutex);
+ if (fifo_entries >= fifo_max_depth) {
+ mutex_unlock(&fifo_add_mutex);
+ CPRINTS("MKBP common FIFO depth %d reached",
+ fifo_max_depth);
+
+ return EC_ERROR_OVERFLOW;
+ }
+
+ size = get_data_size(event_type);
+ fifo[fifo_end].event_type = event_type;
+ memcpy(&fifo[fifo_end].data, buffp, size);
+ fifo_end = (fifo_end + 1) % FIFO_DEPTH;
+ atomic_add(&fifo_entries, 1);
+
+ /*
+ * If our event didn't generate an interrupt then the host is still
+ * asleep. In this case, we don't want to queue our event, except if
+ * another event just woke the host (and wake is already in progress).
+ */
+ if (!mkbp_send_event(event_type) && fifo_entries == 1)
+ fifo_remove(NULL);
+
+ mutex_unlock(&fifo_add_mutex);
+ return EC_SUCCESS;
+}
+
+int mkbp_fifo_get_next_event(uint8_t *out, enum ec_mkbp_event evt)
+{
+ uint8_t t = fifo[fifo_start].event_type;
+ uint8_t size;
+
+ if (!fifo_entries)
+ return -1;
+
+ /*
+ * We need to peek at the next event to check that we were called with
+ * the correct event.
+ */
+ if (t != (uint8_t)evt) {
+ /*
+ * We were called with the wrong event. The next element in the
+ * FIFO's event type doesn't match with what we were called
+ * with. Return an error that we're busy. The caller will need
+ * to call us with the correct event first.
+ */
+ return -EC_ERROR_BUSY;
+ }
+
+ fifo_remove(out);
+
+ /* Keep sending events if FIFO is not empty */
+ if (fifo_entries)
+ mkbp_send_event(fifo[fifo_start].event_type);
+
+ /* Return the correct size of the data. */
+ size = get_data_size(t);
+ if (size)
+ return size;
+ else
+ return -EC_ERROR_UNKNOWN;
+}
diff --git a/include/keyboard_mkbp.h b/include/keyboard_mkbp.h
index cc1dec04b2..c0fe0a842d 100644
--- a/include/keyboard_mkbp.h
+++ b/include/keyboard_mkbp.h
@@ -16,21 +16,7 @@
*
* @return EC_SUCCESS if entry added, EC_ERROR_OVERFLOW if FIFO is full
*/
-int keyboard_fifo_add(const uint8_t *buffp);
-
-/**
- * Add an element to the common MKBP FIFO.
- *
- * @param event_type The MKBP event type.
- * @param buffp Pointer to the event data to enqueue.
- * @return EC_SUCCESS if entry added, EC_ERROR_OVERFLOW if FIFO is full.
- */
-int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp);
-
-/**
- * Clear the MKBP common FIFO.
- */
-void mkbp_clear_fifo(void);
+int mkbp_keyboard_add(const uint8_t *buffp);
/**
* Send KEY_BATTERY keystroke.
diff --git a/include/mkbp_fifo.h b/include/mkbp_fifo.h
new file mode 100644
index 0000000000..347f94e2a7
--- /dev/null
+++ b/include/mkbp_fifo.h
@@ -0,0 +1,54 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* FIFO buffer of MKBP events for Chrome EC */
+
+#ifndef __CROS_EC_MKBP_FIFO_H
+#define __CROS_EC_MKBP_FIFO_H
+
+#include "common.h"
+#include "ec_commands.h"
+
+
+#define FIFO_DEPTH 16
+
+
+/**
+ * Update the "soft" FIFO depth (size). The new depth should be less or
+ * equal FIFO_DEPTH
+ *
+ * @param new_max_depth New FIFO depth.
+ */
+void mkbp_fifo_depth_update(uint8_t new_max_depth);
+
+/**
+ * Clear all keyboard events from the MKBP common FIFO
+ */
+void mkbp_fifo_clear_keyboard(void);
+
+/**
+ * Clear the entire MKBP common FIFO.
+ */
+void mkbp_clear_fifo(void);
+
+/**
+ * Add an element to the common MKBP FIFO.
+ *
+ * @param event_type The MKBP event type.
+ * @param buffp Pointer to the event data to enqueue.
+ * @return EC_SUCCESS if entry added, EC_ERROR_OVERFLOW if FIFO is full.
+ */
+test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp);
+
+/**
+ * Remove an element from the common MKBP FIFO.
+ *
+ * @param out Pointer to the event data to dequeue.
+ * @param event_type The MKBP event type.
+ * @return size of the returned event, EC_ERROR_BUSY if type mismatch.
+ */
+int mkbp_fifo_get_next_event(uint8_t *out, enum ec_mkbp_event evt);
+
+#endif /* __CROS_EC_MKBP_FIFO_H */
diff --git a/test/kb_mkbp.c b/test/kb_mkbp.c
index 4624896268..a490e1974f 100644
--- a/test/kb_mkbp.c
+++ b/test/kb_mkbp.c
@@ -65,7 +65,7 @@ int press_key(int c, int r, int pressed)
{
ccprintf("Input %s (%d, %d)\n", action[pressed], c, r);
set_state(c, r, pressed);
- return keyboard_fifo_add(state);
+ return mkbp_keyboard_add(state);
}
int verify_key(int c, int r, int pressed)
diff --git a/test/kb_scan.c b/test/kb_scan.c
index 24015758b1..3b0382a3b7 100644
--- a/test/kb_scan.c
+++ b/test/kb_scan.c
@@ -77,7 +77,7 @@ int keyboard_raw_read_rows(void)
}
}
-int keyboard_fifo_add(const uint8_t *buffp)
+int mkbp_keyboard_add(const uint8_t *buffp)
{
fifo_add_count++;
return EC_SUCCESS;