diff options
author | Wealian Liao <whliao@nuvoton.corp-partner.google.com> | 2020-12-16 17:52:30 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-31 04:05:18 +0000 |
commit | 200b09a3e5de25997eab6c19adf503cee5fa9b8e (patch) | |
tree | 8a1d79576779007be4fa87a78a9a4dd94fc59533 | |
parent | 886fe45d23905f4eaa32fe54e003a2dea8e07a21 (diff) | |
download | chrome-ec-200b09a3e5de25997eab6c19adf503cee5fa9b8e.tar.gz |
zephyr: add host command handler
The CL include the following:
1. Add host command handler. For the Zephyr shim, the host command
handler is invoked by ESPI_PERIPHERAL_EC_HOST_CMD event in
ESPI_BUS_PERIPHERAL_NOTIFICATION eSPI event.
2. Add system_reset() empty function for host command build pass in
shim/ship/npcx/system.c
BRANCH=none
BUG=b:175217186
TEST=Get the host command & show on the console for volteer.
e.g.
[HC 0x0d]
[HC 0x0d err 1]
Cq-Depend: chromium:2603204
Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com>
Change-Id: Ifd70b9a73c3a2404530182cfc4ce5f3ce4038b49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2594756
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
-rw-r--r-- | zephyr/shim/chip/npcx/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/shim/chip/npcx/system.c | 18 | ||||
-rw-r--r-- | zephyr/shim/src/espi.c | 56 |
3 files changed, 75 insertions, 0 deletions
diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt index 06725d3e89..35aba349ba 100644 --- a/zephyr/shim/chip/npcx/CMakeLists.txt +++ b/zephyr/shim/chip/npcx/CMakeLists.txt @@ -4,3 +4,4 @@ zephyr_sources(clock.c) zephyr_sources(keyboard_raw.c) +zephyr_sources_ifdef(CONFIG_CROS_EC system.c) diff --git a/zephyr/shim/chip/npcx/system.c b/zephyr/shim/chip/npcx/system.c new file mode 100644 index 0000000000..e86d77a7fd --- /dev/null +++ b/zephyr/shim/chip/npcx/system.c @@ -0,0 +1,18 @@ +/* Copyright 2020 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. + */ + +#include "system.h" + +void system_reset(int flags) +{ + /* + * TODO(b/176523207): Reset the system. NPCX uses Watchdog & BBRAM for + * system reset & reset flag saving. The function could be implemented + * after Watchdog & BBRAM land the zephyr repository. + */ + + while (1) + ; +} diff --git a/zephyr/shim/src/espi.c b/zephyr/shim/src/espi.c index 8f36e1ad50..ee469ab38d 100644 --- a/zephyr/shim/src/espi.c +++ b/zephyr/shim/src/espi.c @@ -25,6 +25,13 @@ LOG_MODULE_REGISTER(espi_shim, CONFIG_ESPI_LOG_LEVEL); +/* host command packet handler structure */ +static struct host_packet lpc_packet; +/* + * For the eSPI host command, request & response use the same share memory. + * This is for input request temp buffer. + */ +static uint8_t params_copy[EC_LPC_HOST_PACKET_SIZE] __aligned(4); static bool init_done; /* @@ -124,6 +131,8 @@ static void espi_vwire_handler(const struct device *dev, } } +static void handle_host_write(uint32_t data); + static void espi_peripheral_handler(const struct device *dev, struct espi_callback *cb, struct espi_event event) @@ -134,6 +143,11 @@ static void espi_peripheral_handler(const struct device *dev, event_type == ESPI_PERIPHERAL_DEBUG_PORT80) { port_80_write(event.evt_data); } + + if (IS_ENABLED(CONFIG_PLATFORM_EC_HOSTCMD) && + event_type == ESPI_PERIPHERAL_EC_HOST_CMD) { + handle_host_write(event.evt_data); + } } #define ESPI_DEV DT_LABEL(DT_NODELABEL(espi0)) @@ -343,3 +357,45 @@ static void host_command_init(void) } DECLARE_HOOK(HOOK_INIT, host_command_init, HOOK_PRIO_INIT_LPC); + +static void lpc_send_response_packet(struct host_packet *pkt) +{ + uint32_t data; + + /* TODO(b/176523211): check whether add EC_RES_IN_PROGRESS handle */ + + /* Write result to the data byte. This sets the TOH status bit. */ + data = pkt->driver_result; + espi_write_lpc_request(espi_dev, ECUSTOM_HOST_CMD_SEND_RESULT, &data); +} + +static void handle_host_write(uint32_t data) +{ + uint32_t shm_mem_host_cmd; + + if (EC_COMMAND_PROTOCOL_3 != (data & 0xff)) { + LOG_ERR("Don't support this version of the host command"); + /* TODO:(b/175217186): error response for other versions */ + return; + } + + espi_read_lpc_request(espi_dev, ECUSTOM_HOST_CMD_GET_PARAM_MEMORY, + &shm_mem_host_cmd); + + lpc_packet.send_response = lpc_send_response_packet; + + lpc_packet.request = (const void *)shm_mem_host_cmd; + lpc_packet.request_temp = params_copy; + lpc_packet.request_max = sizeof(params_copy); + /* Don't know the request size so pass in the entire buffer */ + lpc_packet.request_size = EC_LPC_HOST_PACKET_SIZE; + + lpc_packet.response = (void *)shm_mem_host_cmd; + lpc_packet.response_max = EC_LPC_HOST_PACKET_SIZE; + lpc_packet.response_size = 0; + + lpc_packet.driver_result = EC_RES_SUCCESS; + + host_packet_receive(&lpc_packet); + return; +} |