From e9163992cfdc24d1ac07d5535230e7480e6bf89d Mon Sep 17 00:00:00 2001 From: Dawid Niedzwiecki Date: Fri, 22 Nov 2024 16:50:02 +0100 Subject: [PATCH] mgmt: ec_host_cmd: add support for nocache buffers Some backends use DMA. Usually, DMA doesn't work correctly, when memory to transfer is cached. Add a config to place the common buffers in the nocache section. Signed-off-by: Dawid Niedzwiecki --- subsys/mgmt/ec_host_cmd/Kconfig | 9 +++++++++ subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c | 15 +++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/subsys/mgmt/ec_host_cmd/Kconfig b/subsys/mgmt/ec_host_cmd/Kconfig index 3e46dc9ce4f..1cd5c8acba3 100644 --- a/subsys/mgmt/ec_host_cmd/Kconfig +++ b/subsys/mgmt/ec_host_cmd/Kconfig @@ -76,6 +76,15 @@ config EC_HOST_CMD_HANDLER_RX_BUFFER_DEF help The handler defines common rx buffer +config EC_HOST_CMD_NOCACHE_BUFFERS + bool "Place RX and TX buffers in __nocache section" + default y if DCACHE && DMA + depends on EC_HOST_CMD_HANDLER_TX_BUFFER_DEF || EC_HOST_CMD_HANDLER_RX_BUFFER_DEF + help + DMA is often use for communication, however it usually requires + uncached memory. Add possibility to place the RX and TX buffers in the + __nocache section. + config EC_HOST_CMD_INITIALIZE_AT_BOOT bool "Initialize the host command subsystem automacitlly" default y diff --git a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c index 265c5bc854c..0e8df2316b8 100644 --- a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c +++ b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -32,12 +33,18 @@ BUILD_ASSERT(NUMBER_OF_CHOSEN_BACKENDS < 2, "Number of chosen backends > 1"); #define RX_HEADER_SIZE (sizeof(struct ec_host_cmd_request_header)) #define TX_HEADER_SIZE (sizeof(struct ec_host_cmd_response_header)) +#ifdef CONFIG_EC_HOST_CMD_NOCACHE_BUFFERS +#define BUFFERS_CACHE_ATTR __nocache +#else +#define BUFFERS_CACHE_ATTR +#endif + COND_CODE_1(CONFIG_EC_HOST_CMD_HANDLER_RX_BUFFER_DEF, - (static uint8_t hc_rx_buffer[CONFIG_EC_HOST_CMD_HANDLER_RX_BUFFER_SIZE] __aligned(4);), - ()) + (static uint8_t hc_rx_buffer[CONFIG_EC_HOST_CMD_HANDLER_RX_BUFFER_SIZE] __aligned(4) + BUFFERS_CACHE_ATTR;), ()) COND_CODE_1(CONFIG_EC_HOST_CMD_HANDLER_TX_BUFFER_DEF, - (static uint8_t hc_tx_buffer[CONFIG_EC_HOST_CMD_HANDLER_TX_BUFFER_SIZE] __aligned(4);), - ()) + (static uint8_t hc_tx_buffer[CONFIG_EC_HOST_CMD_HANDLER_TX_BUFFER_SIZE] __aligned(4) + BUFFERS_CACHE_ATTR;), ()) #ifdef CONFIG_EC_HOST_CMD_DEDICATED_THREAD static K_KERNEL_STACK_DEFINE(hc_stack, CONFIG_EC_HOST_CMD_HANDLER_STACK_SIZE);