Skip to content

Commit

Permalink
mgmt: ec_host_cmd: add support for nocache buffers
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
niedzwiecki-dawid committed Dec 4, 2024
1 parent 73172e5 commit 9d01dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions subsys/mgmt/ec_host_cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <zephyr/devicetree.h>
#include <zephyr/kernel.h>
#include <zephyr/linker/section_tags.h>
#include <zephyr/logging/log.h>
#include <zephyr/mgmt/ec_host_cmd/ec_host_cmd.h>
#include <zephyr/mgmt/ec_host_cmd/backend.h>
Expand All @@ -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);
Expand Down

0 comments on commit 9d01dda

Please sign in to comment.