From ed8d8055547da5f577931325d62aae9a66a52ecc Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 11 Jan 2024 17:27:24 +0800 Subject: [PATCH] fix(dw_gdma): write back the link list items after creation --- components/esp_hw_support/CMakeLists.txt | 2 +- components/esp_hw_support/dma/dw_gdma.c | 20 +++++++++++++++++-- .../{ => dma}/include/esp_dma_utils.h | 2 +- .../{ => dma}/include/esp_private/dw_gdma.h | 0 .../{ => dma}/include/esp_private/gdma.h | 2 +- .../test_apps/.build-test-rules.yml | 2 ++ .../test_apps/dma/sdkconfig.defaults | 1 + .../test_apps/dma/sdkconfig.defaults.esp32p4 | 2 +- docs/doxygen/Doxyfile | 2 +- 9 files changed, 26 insertions(+), 7 deletions(-) rename components/esp_hw_support/{ => dma}/include/esp_dma_utils.h (97%) rename components/esp_hw_support/{ => dma}/include/esp_private/dw_gdma.h (100%) rename components/esp_hw_support/{ => dma}/include/esp_private/gdma.h (99%) diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 672b7b44f1..919c7d25a6 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -180,7 +180,7 @@ else() endif() idf_component_register(SRCS ${srcs} - INCLUDE_DIRS include include/soc include/soc/${target} + INCLUDE_DIRS include include/soc include/soc/${target} dma/include PRIV_INCLUDE_DIRS port/include include/esp_private REQUIRES ${requires} PRIV_REQUIRES "${priv_requires}" diff --git a/components/esp_hw_support/dma/dw_gdma.c b/components/esp_hw_support/dma/dw_gdma.c index 7f6cdb43cd..c7f0e6e582 100644 --- a/components/esp_hw_support/dma/dw_gdma.c +++ b/components/esp_hw_support/dma/dw_gdma.c @@ -29,6 +29,7 @@ #include "hal/dw_gdma_ll.h" #include "hal/cache_hal.h" #include "hal/cache_ll.h" +#include "esp_cache.h" static const char *TAG = "dw-gdma"; @@ -59,6 +60,8 @@ static const char *TAG = "dw-gdma"; #define DW_GDMA_ALLOW_INTR_PRIORITY_MASK ESP_INTR_FLAG_LOWMED +#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) + typedef struct dw_gdma_group_t dw_gdma_group_t; typedef struct dw_gdma_channel_t dw_gdma_channel_t; @@ -387,10 +390,23 @@ esp_err_t dw_gdma_new_link_list(const dw_gdma_link_list_config_t *config, dw_gdm // also we should respect the data cache line size uint32_t data_cache_line_size = cache_hal_get_cache_line_size(CACHE_LL_LEVEL_INT_MEM, CACHE_TYPE_DATA); uint32_t alignment = MAX(DW_GDMA_LL_LINK_LIST_ALIGNMENT, data_cache_line_size); - items = heap_caps_aligned_calloc(alignment, num_items, sizeof(dw_gdma_link_list_item_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA); - ESP_RETURN_ON_FALSE(items, ESP_ERR_NO_MEM, TAG, "no mem for link list items"); + // because we want to access the link list items via non-cache address, so the memory size should also align to the cache line size + uint32_t lli_size = num_items * sizeof(dw_gdma_link_list_item_t); + if (data_cache_line_size) { + lli_size = ALIGN_UP(lli_size, data_cache_line_size); + } + items = heap_caps_aligned_calloc(alignment, 1, lli_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA); + ESP_GOTO_ON_FALSE(items, ESP_ERR_NO_MEM, err, TAG, "no mem for link list items"); + if (data_cache_line_size) { // do memory sync only when the cache exists + // write back and then invalidate the cache, we won't use the cache to operate the link list items afterwards + // even the cache auto-write back happens, there's no risk the link list items will be overwritten + ESP_GOTO_ON_ERROR(esp_cache_msync(items, lli_size, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_INVALIDATE), + err, TAG, "cache sync failed"); + } + list->num_items = num_items; list->items = items; + // want to use non-cached address to operate the link list items list->items_nc = (dw_gdma_link_list_item_t *)DW_GDMA_GET_NON_CACHE_ADDR(items); // set up the link list diff --git a/components/esp_hw_support/include/esp_dma_utils.h b/components/esp_hw_support/dma/include/esp_dma_utils.h similarity index 97% rename from components/esp_hw_support/include/esp_dma_utils.h rename to components/esp_hw_support/dma/include/esp_dma_utils.h index 747cd1b31b..c0b613495c 100644 --- a/components/esp_hw_support/include/esp_dma_utils.h +++ b/components/esp_hw_support/dma/include/esp_dma_utils.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_hw_support/include/esp_private/dw_gdma.h b/components/esp_hw_support/dma/include/esp_private/dw_gdma.h similarity index 100% rename from components/esp_hw_support/include/esp_private/dw_gdma.h rename to components/esp_hw_support/dma/include/esp_private/dw_gdma.h diff --git a/components/esp_hw_support/include/esp_private/gdma.h b/components/esp_hw_support/dma/include/esp_private/gdma.h similarity index 99% rename from components/esp_hw_support/include/esp_private/gdma.h rename to components/esp_hw_support/dma/include/esp_private/gdma.h index fc04a92a51..2d61d531be 100644 --- a/components/esp_hw_support/include/esp_private/gdma.h +++ b/components/esp_hw_support/dma/include/esp_private/gdma.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_hw_support/test_apps/.build-test-rules.yml b/components/esp_hw_support/test_apps/.build-test-rules.yml index b8118048f0..8a57eebe4a 100644 --- a/components/esp_hw_support/test_apps/.build-test-rules.yml +++ b/components/esp_hw_support/test_apps/.build-test-rules.yml @@ -5,6 +5,8 @@ components/esp_hw_support/test_apps/dma: - if: IDF_TARGET in ["esp32"] temporary: false reason: No general DMA controller on ESP32 + depends_filepatterns: + - components/esp_hw_support/dma/**/* components/esp_hw_support/test_apps/esp_hw_support_unity_tests: disable: diff --git a/components/esp_hw_support/test_apps/dma/sdkconfig.defaults b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults index fa8ac618b9..1ee5d718bc 100644 --- a/components/esp_hw_support/test_apps/dma/sdkconfig.defaults +++ b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults @@ -1,2 +1,3 @@ CONFIG_FREERTOS_HZ=1000 CONFIG_ESP_TASK_WDT_EN=n +CONFIG_IDF_EXPERIMENTAL_FEATURES=y diff --git a/components/esp_hw_support/test_apps/dma/sdkconfig.defaults.esp32p4 b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults.esp32p4 index 9a2c70b27e..702fac3342 100644 --- a/components/esp_hw_support/test_apps/dma/sdkconfig.defaults.esp32p4 +++ b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults.esp32p4 @@ -1,3 +1,3 @@ CONFIG_SPIRAM=y CONFIG_SPIRAM_MODE_HEX=y -CONFIG_SPIRAM_SPEED_20M=y +CONFIG_SPIRAM_SPEED_200M=y diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index 73bb406747..d60e0ec0c5 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -158,13 +158,13 @@ INPUT = \ $(PROJECT_PATH)/components/esp_http_server/include/esp_http_server.h \ $(PROJECT_PATH)/components/esp_https_ota/include/esp_https_ota.h \ $(PROJECT_PATH)/components/esp_https_server/include/esp_https_server.h \ + $(PROJECT_PATH)/components/esp_hw_support/dma/include/esp_dma_utils.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_clk_tree.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_async_memcpy.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_chip_info.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_cpu.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_crc.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_etm.h \ - $(PROJECT_PATH)/components/esp_hw_support/include/esp_dma_utils.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_ds.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_hmac.h \ $(PROJECT_PATH)/components/esp_hw_support/include/esp_intr_alloc.h \