From 9e2cd9733029130e26446e8e38670578918170ce Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 9 Sep 2026 23:09:47 +0800 Subject: [PATCH] refactor(cache): move cache profile counter support to hal Move the cache profile counter type definitions to hal/cache_types.h so that esp_cache_cnt.h can use them without depending on the public soc header soc/cache_periph.h (which CI rejects as non-public). The remaining cache_periph.h header and its per-target cache_periph.c sources are moved from the soc component into the hal component, with the sources organized per target directory as usual for the hal component. Removes the soc/cache_periph.h dependency from esp_cache_cnt.h and hal/cache_ll.h by using hal/cache_periph.h instead. --- components/esp_hw_support/esp_cache_cnt.c | 2 +- .../esp_hw_support/include/esp_cache_cnt.h | 2 +- components/hal/CMakeLists.txt | 4 +++ .../{soc => hal}/esp32c5/cache_periph.c | 4 +-- components/hal/esp32c5/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32c6/cache_periph.c | 4 +-- components/hal/esp32c6/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32c61/cache_periph.c | 4 +-- .../hal/esp32c61/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32h2/cache_periph.c | 4 +-- components/hal/esp32h2/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32h21/cache_periph.c | 4 +-- .../hal/esp32h21/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32h4/cache_periph.c | 4 +-- components/hal/esp32h4/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32p4/cache_periph.c | 4 +-- components/hal/esp32p4/include/hal/cache_ll.h | 2 +- .../{soc => hal}/esp32s31/cache_periph.c | 4 +-- .../hal/esp32s31/include/hal/cache_ll.h | 2 +- .../soc => hal/include/hal}/cache_periph.h | 26 +++---------------- components/hal/include/hal/cache_types.h | 22 ++++++++++++++++ components/soc/CMakeLists.txt | 4 --- 22 files changed, 55 insertions(+), 53 deletions(-) rename components/{soc => hal}/esp32c5/cache_periph.c (95%) rename components/{soc => hal}/esp32c6/cache_periph.c (95%) rename components/{soc => hal}/esp32c61/cache_periph.c (95%) rename components/{soc => hal}/esp32h2/cache_periph.c (95%) rename components/{soc => hal}/esp32h21/cache_periph.c (95%) rename components/{soc => hal}/esp32h4/cache_periph.c (97%) rename components/{soc => hal}/esp32p4/cache_periph.c (97%) rename components/{soc => hal}/esp32s31/cache_periph.c (97%) rename components/{soc/include/soc => hal/include/hal}/cache_periph.h (53%) diff --git a/components/esp_hw_support/esp_cache_cnt.c b/components/esp_hw_support/esp_cache_cnt.c index b868887a7d7..7ccbab0c368 100644 --- a/components/esp_hw_support/esp_cache_cnt.c +++ b/components/esp_hw_support/esp_cache_cnt.c @@ -7,7 +7,7 @@ /* * Chip-agnostic implementation of the cache access counter API, built on * top of the cache profile counter functions of hal/cache_ll.h and the - * unit descriptor table in soc/cache_periph.h. + * unit descriptor table in hal/cache_periph.h. */ #include diff --git a/components/esp_hw_support/include/esp_cache_cnt.h b/components/esp_hw_support/include/esp_cache_cnt.h index 1623c4810dd..3505d290a1f 100644 --- a/components/esp_hw_support/include/esp_cache_cnt.h +++ b/components/esp_hw_support/include/esp_cache_cnt.h @@ -9,7 +9,7 @@ #include #include #include "esp_err.h" -#include "soc/cache_periph.h" +#include "hal/cache_types.h" #ifdef __cplusplus extern "C" { diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 35021204d28..dbb3cbbbf52 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -46,6 +46,10 @@ else() endif() endif() +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/cache_periph.c") + list(APPEND srcs "${target}/cache_periph.c") +endif() + if(NOT esp_tee_build AND NOT BOOTLOADER_BUILD) list(APPEND srcs "color_hal.c") diff --git a/components/soc/esp32c5/cache_periph.c b/components/hal/esp32c5/cache_periph.c similarity index 95% rename from components/soc/esp32c5/cache_periph.c rename to components/hal/esp32c5/cache_periph.c index 390a51ee509..1355b411a87 100644 --- a/components/soc/esp32c5/cache_periph.c +++ b/components/hal/esp32c5/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-C5 cache profile counter units. diff --git a/components/hal/esp32c5/include/hal/cache_ll.h b/components/hal/esp32c5/include/hal/cache_ll.h index 35e4a9dc2e3..9c05922cae3 100644 --- a/components/hal/esp32c5/include/hal/cache_ll.h +++ b/components/hal/esp32c5/include/hal/cache_ll.h @@ -13,7 +13,7 @@ #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" #include "rom/cache.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "esp32c5/rom/cache.h" diff --git a/components/soc/esp32c6/cache_periph.c b/components/hal/esp32c6/cache_periph.c similarity index 95% rename from components/soc/esp32c6/cache_periph.c rename to components/hal/esp32c6/cache_periph.c index d5354be3f57..aa694047ab0 100644 --- a/components/soc/esp32c6/cache_periph.c +++ b/components/hal/esp32c6/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/extmem_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-C6 cache profile counter units. diff --git a/components/hal/esp32c6/include/hal/cache_ll.h b/components/hal/esp32c6/include/hal/cache_ll.h index fe5f3001dc9..154a5ec385f 100644 --- a/components/hal/esp32c6/include/hal/cache_ll.h +++ b/components/hal/esp32c6/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include #include "soc/extmem_reg.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "esp32c6/rom/cache.h" diff --git a/components/soc/esp32c61/cache_periph.c b/components/hal/esp32c61/cache_periph.c similarity index 95% rename from components/soc/esp32c61/cache_periph.c rename to components/hal/esp32c61/cache_periph.c index 78fcfa15cb5..56332e07f05 100644 --- a/components/soc/esp32c61/cache_periph.c +++ b/components/hal/esp32c61/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-C61 cache profile counter units. diff --git a/components/hal/esp32c61/include/hal/cache_ll.h b/components/hal/esp32c61/include/hal/cache_ll.h index 2fe20d26d6c..ae06a908171 100644 --- a/components/hal/esp32c61/include/hal/cache_ll.h +++ b/components/hal/esp32c61/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include "soc/cache_reg.h" #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "esp32c61/rom/cache.h" diff --git a/components/soc/esp32h2/cache_periph.c b/components/hal/esp32h2/cache_periph.c similarity index 95% rename from components/soc/esp32h2/cache_periph.c rename to components/hal/esp32h2/cache_periph.c index 441a75b46ba..fa12cabf752 100644 --- a/components/soc/esp32h2/cache_periph.c +++ b/components/hal/esp32h2/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-H2 cache profile counter units. diff --git a/components/hal/esp32h2/include/hal/cache_ll.h b/components/hal/esp32h2/include/hal/cache_ll.h index d635288ce1d..3765ea6354d 100644 --- a/components/hal/esp32h2/include/hal/cache_ll.h +++ b/components/hal/esp32h2/include/hal/cache_ll.h @@ -11,7 +11,7 @@ #include #include "soc/extmem_reg.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "esp32h2/rom/cache.h" diff --git a/components/soc/esp32h21/cache_periph.c b/components/hal/esp32h21/cache_periph.c similarity index 95% rename from components/soc/esp32h21/cache_periph.c rename to components/hal/esp32h21/cache_periph.c index 70d992fe033..e3806c0853b 100644 --- a/components/soc/esp32h21/cache_periph.c +++ b/components/hal/esp32h21/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-H21 cache profile counter units. diff --git a/components/hal/esp32h21/include/hal/cache_ll.h b/components/hal/esp32h21/include/hal/cache_ll.h index d8b0755c7cf..9b3d5b72c01 100644 --- a/components/hal/esp32h21/include/hal/cache_ll.h +++ b/components/hal/esp32h21/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include "soc/cache_reg.h" #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "rom/cache.h" diff --git a/components/soc/esp32h4/cache_periph.c b/components/hal/esp32h4/cache_periph.c similarity index 97% rename from components/soc/esp32h4/cache_periph.c rename to components/hal/esp32h4/cache_periph.c index 81da83e3b1b..aca99794a5a 100644 --- a/components/soc/esp32h4/cache_periph.c +++ b/components/hal/esp32h4/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-H4 cache profile counter units. diff --git a/components/hal/esp32h4/include/hal/cache_ll.h b/components/hal/esp32h4/include/hal/cache_ll.h index 6da385d3bd9..1511834bcbe 100644 --- a/components/hal/esp32h4/include/hal/cache_ll.h +++ b/components/hal/esp32h4/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include "soc/cache_reg.h" #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "rom/cache.h" diff --git a/components/soc/esp32p4/cache_periph.c b/components/hal/esp32p4/cache_periph.c similarity index 97% rename from components/soc/esp32p4/cache_periph.c rename to components/hal/esp32p4/cache_periph.c index 7f51fcaf48b..f3110ef8c3e 100644 --- a/components/soc/esp32p4/cache_periph.c +++ b/components/hal/esp32p4/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-P4 cache profile counter units. diff --git a/components/hal/esp32p4/include/hal/cache_ll.h b/components/hal/esp32p4/include/hal/cache_ll.h index e59482bc748..45c45cf0c61 100644 --- a/components/hal/esp32p4/include/hal/cache_ll.h +++ b/components/hal/esp32p4/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include "soc/cache_reg.h" #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/config.h" #include "hal/assert.h" diff --git a/components/soc/esp32s31/cache_periph.c b/components/hal/esp32s31/cache_periph.c similarity index 97% rename from components/soc/esp32s31/cache_periph.c rename to components/hal/esp32s31/cache_periph.c index 5aa5c35443a..b51e2e4c433 100644 --- a/components/soc/esp32s31/cache_periph.c +++ b/components/hal/esp32s31/cache_periph.c @@ -1,11 +1,11 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include "soc/cache_reg.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" /* * ESP32-S31 cache profile counter units. diff --git a/components/hal/esp32s31/include/hal/cache_ll.h b/components/hal/esp32s31/include/hal/cache_ll.h index ddc50f67153..1e4286777c7 100644 --- a/components/hal/esp32s31/include/hal/cache_ll.h +++ b/components/hal/esp32s31/include/hal/cache_ll.h @@ -12,7 +12,7 @@ #include "soc/cache_reg.h" #include "soc/cache_struct.h" #include "soc/ext_mem_defs.h" -#include "soc/cache_periph.h" +#include "hal/cache_periph.h" #include "hal/cache_types.h" #include "hal/assert.h" #include "esp32s31/rom/cache.h" diff --git a/components/soc/include/soc/cache_periph.h b/components/hal/include/hal/cache_periph.h similarity index 53% rename from components/soc/include/soc/cache_periph.h rename to components/hal/include/hal/cache_periph.h index 1b810e9f192..a411753a0b3 100644 --- a/components/soc/include/soc/cache_periph.h +++ b/components/hal/include/hal/cache_periph.h @@ -1,39 +1,20 @@ /* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include #include "soc/soc_caps.h" +#include "hal/cache_types.h" #ifdef __cplusplus extern "C" { #endif -/** - * @brief Kind of traffic observed by a cache profile counter unit - */ -typedef enum { - CACHE_PROFILE_TRAFFIC_INST, /*!< Instruction fetches */ - CACHE_PROFILE_TRAFFIC_DATA, /*!< Data accesses */ - CACHE_PROFILE_TRAFFIC_UNIFIED, /*!< Mixed/unknown (unified request bus) */ -} cache_profile_traffic_t; - -/** - * @brief One of the counters of a cache profile counter unit - */ -typedef enum { - CACHE_PROFILE_COUNTER_HIT, /*!< Completed accesses ("hit" counter) */ - CACHE_PROFILE_COUNTER_MISS, /*!< Miss stall events ("miss" counter) */ - CACHE_PROFILE_COUNTER_CONFLICT, /*!< Requester conflicts */ - CACHE_PROFILE_COUNTER_NXTLVL_RD, /*!< Line fills from the next level */ - CACHE_PROFILE_COUNTER_NXTLVL_WR, /*!< Write-backs to the next level */ - CACHE_PROFILE_COUNTER_MAX, -} cache_profile_counter_t; - +#if SOC_CACHE_CNT_SUPPORTED /** * @brief Description of one cache profile counter unit * @@ -49,7 +30,6 @@ typedef struct { does not have that counter */ } cache_profile_counter_unit_t; -#if SOC_CACHE_CNT_SUPPORTED extern const cache_profile_counter_unit_t cache_periph_profile_counter_units[SOC_CACHE_CNT_UNITS_NUM]; #endif diff --git a/components/hal/include/hal/cache_types.h b/components/hal/include/hal/cache_types.h index 679a6750771..561b2b39fc2 100644 --- a/components/hal/include/hal/cache_types.h +++ b/components/hal/include/hal/cache_types.h @@ -6,12 +6,34 @@ #pragma once +#include #include "esp_bit_defs.h" #ifdef __cplusplus extern "C" { #endif +/** + * @brief Kind of traffic observed by a cache profile counter unit + */ +typedef enum { + CACHE_PROFILE_TRAFFIC_INST, /*!< Instruction fetches */ + CACHE_PROFILE_TRAFFIC_DATA, /*!< Data accesses */ + CACHE_PROFILE_TRAFFIC_UNIFIED, /*!< Mixed/unknown (unified request bus) */ +} cache_profile_traffic_t; + +/** + * @brief One of the counters of a cache profile counter unit + */ +typedef enum { + CACHE_PROFILE_COUNTER_HIT, /*!< Completed accesses ("hit" counter) */ + CACHE_PROFILE_COUNTER_MISS, /*!< Miss stall events ("miss" counter) */ + CACHE_PROFILE_COUNTER_CONFLICT, /*!< Requester conflicts */ + CACHE_PROFILE_COUNTER_NXTLVL_RD, /*!< Line fills from the next level */ + CACHE_PROFILE_COUNTER_NXTLVL_WR, /*!< Write-backs to the next level */ + CACHE_PROFILE_COUNTER_MAX, +} cache_profile_counter_t; + typedef enum { CACHE_TYPE_DATA, CACHE_TYPE_INSTRUCTION, diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt index 45489e2110c..d3bc737c720 100644 --- a/components/soc/CMakeLists.txt +++ b/components/soc/CMakeLists.txt @@ -66,10 +66,6 @@ if(CONFIG_SOC_DEBUG_PROBE_SUPPORTED) list(APPEND srcs "${target_folder}/debug_probe_periph.c") endif() -if(CONFIG_SOC_CACHE_CNT_SUPPORTED) - list(APPEND srcs "${target_folder}/cache_periph.c") -endif() - if(CONFIG_SOC_MPI_SUPPORTED) list(APPEND srcs "${target_folder}/mpi_periph.c") endif()