From 2cd87223a87a8bbb7f28974d1ec46f9e059e9c53 Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 26 Feb 2025 11:30:50 +0800 Subject: [PATCH] feat(l2mem): enable buffer mode for ahb burst access --- components/esp_system/port/cpu_start.c | 6 ++++ components/hal/esp32p4/include/hal/l2mem_ll.h | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 components/hal/esp32p4/include/hal/l2mem_ll.h diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c index dce7177fff..82d635e757 100644 --- a/components/esp_system/port/cpu_start.c +++ b/components/esp_system/port/cpu_start.c @@ -58,6 +58,7 @@ #include "esp32c2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32P4 #include "soc/hp_sys_clkrst_reg.h" +#include "hal/l2mem_ll.h" #elif CONFIG_IDF_TARGET_ESP32H21 #include "esp_memprot.h" #endif @@ -403,6 +404,11 @@ void IRAM_ATTR call_start_cpu0(void) ); #endif +#if CONFIG_IDF_TARGET_ESP32P4 + // enable the buffer mode before any AHB burst happens, that's why we do it here + l2mem_ll_enable_ahb_burst_buffer(true, true); +#endif + #if SOC_BRANCH_PREDICTOR_SUPPORTED esp_cpu_branch_prediction_enable(); #endif diff --git a/components/hal/esp32p4/include/hal/l2mem_ll.h b/components/hal/esp32p4/include/hal/l2mem_ll.h new file mode 100644 index 0000000000..6275051d59 --- /dev/null +++ b/components/hal/esp32p4/include/hal/l2mem_ll.h @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include +#include +#include "soc/hp_system_struct.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enable the burst buffer for L2 memory + * + * @note During AHB burst access to the L2MEM, in order to reduce the AHB request to the L2MEM arbiter, + * enabling the buffer mode can improve the performance. + * @note This function must be called before any AHB burst access to the L2MEM. + */ +static inline void l2mem_ll_enable_ahb_burst_buffer(bool en_read, bool en_write) +{ + HP_SYSTEM.l2_mem_ahb_buffer_ctrl.l2_mem_ahb_rdbuffer_en = en_read; + HP_SYSTEM.l2_mem_ahb_buffer_ctrl.l2_mem_ahb_wrbuffer_en = en_write; +} + +#ifdef __cplusplus +} +#endif