From eb606a8e7d52fd3bb80743df5648929825805d63 Mon Sep 17 00:00:00 2001 From: Raffael Rostagno Date: Fri, 21 Feb 2025 15:34:31 -0300 Subject: [PATCH] soc: esp32: Update IRQ config for shared allocator Update IRQ handling related files to unify interrupt controller between Xtensa and RISCV devices. Signed-off-by: Raffael Rostagno Signed-off-by: Sylvio Alves --- soc/espressif/common/loader.c | 4 +- soc/espressif/esp32/soc.c | 4 -- soc/espressif/esp32/soc_appcpu.c | 2 - soc/espressif/esp32c2/CMakeLists.txt | 1 - soc/espressif/esp32c2/Kconfig.defconfig | 6 +- soc/espressif/esp32c2/soc.c | 6 +- soc/espressif/esp32c2/soc_irq.S | 11 +--- soc/espressif/esp32c2/soc_irq.c | 69 -------------------- soc/espressif/esp32c2/vectors.S | 8 +-- soc/espressif/esp32c3/CMakeLists.txt | 1 - soc/espressif/esp32c3/Kconfig.defconfig | 4 +- soc/espressif/esp32c3/soc.c | 6 +- soc/espressif/esp32c3/soc_irq.S | 11 +--- soc/espressif/esp32c3/soc_irq.c | 69 -------------------- soc/espressif/esp32c3/vectors.S | 12 ++-- soc/espressif/esp32c6/CMakeLists.txt | 1 - soc/espressif/esp32c6/Kconfig.defconfig | 6 +- soc/espressif/esp32c6/soc.c | 6 +- soc/espressif/esp32c6/soc_irq.S | 19 ++---- soc/espressif/esp32c6/soc_irq.c | 86 ------------------------- soc/espressif/esp32c6/vectors.S | 8 +-- soc/espressif/esp32s2/soc.c | 4 -- soc/espressif/esp32s3/soc.c | 4 -- soc/espressif/esp32s3/soc_appcpu.c | 2 - 24 files changed, 35 insertions(+), 315 deletions(-) delete mode 100644 soc/espressif/esp32c2/soc_irq.c delete mode 100644 soc/espressif/esp32c3/soc_irq.c delete mode 100644 soc/espressif/esp32c6/soc_irq.c diff --git a/soc/espressif/common/loader.c b/soc/espressif/common/loader.c index b3cea053290..624fa987542 100644 --- a/soc/espressif/common/loader.c +++ b/soc/espressif/common/loader.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. + * Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd. * * SPDX-License-Identifier: Apache-2.0 */ @@ -252,7 +252,7 @@ void __start(void) { #ifdef CONFIG_RISCV_GP - __asm__ __volatile__("la t0, _esp_vector_table\n" + __asm__ __volatile__("la t0, _vector_table\n" "csrw mtvec, t0\n"); /* Disable normal interrupts. */ diff --git a/soc/espressif/esp32/soc.c b/soc/espressif/esp32/soc.c index e0f307a2d8e..d7cf1315da2 100644 --- a/soc/espressif/esp32/soc.c +++ b/soc/espressif/esp32/soc.c @@ -26,8 +26,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - #if CONFIG_ESP_SPIRAM esp_init_psram(); @@ -47,8 +45,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_prep_c(); diff --git a/soc/espressif/esp32/soc_appcpu.c b/soc/espressif/esp32/soc_appcpu.c index 82c8ef1ad65..40903ffc321 100644 --- a/soc/espressif/esp32/soc_appcpu.c +++ b/soc/espressif/esp32/soc_appcpu.c @@ -87,8 +87,6 @@ void IRAM_ATTR __appcpu_start(void) core_intr_matrix_clear(); - esp_intr_initialize(); - /* Start Zephyr */ z_prep_c(); diff --git a/soc/espressif/esp32c2/CMakeLists.txt b/soc/espressif/esp32c2/CMakeLists.txt index bd1b0474de6..0248ccef51e 100644 --- a/soc/espressif/esp32c2/CMakeLists.txt +++ b/soc/espressif/esp32c2/CMakeLists.txt @@ -3,7 +3,6 @@ zephyr_sources( vectors.S soc_irq.S - soc_irq.c soc.c ../common/loader.c ) diff --git a/soc/espressif/esp32c2/Kconfig.defconfig b/soc/espressif/esp32c2/Kconfig.defconfig index 21877a186a9..59ec24263c5 100644 --- a/soc/espressif/esp32c2/Kconfig.defconfig +++ b/soc/espressif/esp32c2/Kconfig.defconfig @@ -1,12 +1,10 @@ -# ESP32C2 SoC configuration - -# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. +# Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 if SOC_SERIES_ESP32C2 config NUM_IRQS - default 43 + default 32 config FLASH_SIZE default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0) diff --git a/soc/espressif/esp32c2/soc.c b/soc/espressif/esp32c2/soc.c index f131f5fbfee..e14ca4d02b0 100644 --- a/soc/espressif/esp32c2/soc.c +++ b/soc/espressif/esp32c2/soc.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -24,8 +24,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); @@ -34,8 +32,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); diff --git a/soc/espressif/esp32c2/soc_irq.S b/soc/espressif/esp32c2/soc_irq.S index b970b84ffa3..7e41a1f961e 100644 --- a/soc/espressif/esp32c2/soc_irq.S +++ b/soc/espressif/esp32c2/soc_irq.S @@ -1,4 +1,4 @@ -/* Copyright 2024 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2021-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,13 +8,8 @@ /* Exports */ GTEXT(__soc_handle_irq) -GTEXT(soc_intr_get_next_source) SECTION_FUNC(exception.other, __soc_handle_irq) - addi sp, sp,-4 - sw ra, 0x00(sp) - la t1, soc_intr_get_next_source - jalr ra, t1, 0 - lw ra, 0x00(sp) - addi sp, sp, 4 + + /* int status clearing is done at ISR */ ret diff --git a/soc/espressif/esp32c2/soc_irq.c b/soc/espressif/esp32c2/soc_irq.c deleted file mode 100644 index 713dfc936eb..00000000000 --- a/soc/espressif/esp32c2/soc_irq.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define ESP32C2_INTSTATUS_SLOT1_THRESHOLD 32 - -void arch_irq_enable(unsigned int irq) -{ - esp_intr_enable(irq); -} - -void arch_irq_disable(unsigned int irq) -{ - esp_intr_disable(irq); -} - -int arch_irq_is_enabled(unsigned int irq) -{ - bool res = false; - uint32_t key = irq_lock(); - - if (irq < 32) { - res = esp_intr_get_enabled_intmask(0) & BIT(irq); - } else { - res = esp_intr_get_enabled_intmask(1) & BIT(irq - 32); - } - - irq_unlock(key); - - return res; -} - -uint32_t soc_intr_get_next_source(void) -{ - uint32_t status; - uint32_t source; - - status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_REG_0_REG) & - esp_intr_get_enabled_intmask(0); - - if (status) { - source = __builtin_ffs(status) - 1; - } else { - status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_REG_1_REG) & - esp_intr_get_enabled_intmask(1); - source = (__builtin_ffs(status) - 1 + ESP32C2_INTSTATUS_SLOT1_THRESHOLD); - } - - return source; -} diff --git a/soc/espressif/esp32c2/vectors.S b/soc/espressif/esp32c2/vectors.S index 9299750a525..272ab653a5f 100644 --- a/soc/espressif/esp32c2/vectors.S +++ b/soc/espressif/esp32c2/vectors.S @@ -1,4 +1,4 @@ -/* Copyright 2024 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2020-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,12 +22,12 @@ GTEXT(_isr_wrapper) * only uses the 24 MSBs of the MTVEC, i.e. (MTVEC & 0xffffff00). */ - .global _esp_vector_table + .global _vector_table .section .exception_vectors.text .balign 0x100 - .type _esp_vector_table, @function + .type _vector_table, @function -_esp_vector_table: +_vector_table: .option push .option norvc .rept (32) diff --git a/soc/espressif/esp32c3/CMakeLists.txt b/soc/espressif/esp32c3/CMakeLists.txt index 186cf17af9b..980863025ef 100644 --- a/soc/espressif/esp32c3/CMakeLists.txt +++ b/soc/espressif/esp32c3/CMakeLists.txt @@ -3,7 +3,6 @@ zephyr_sources( vectors.S soc_irq.S - soc_irq.c soc.c ../common/loader.c ) diff --git a/soc/espressif/esp32c3/Kconfig.defconfig b/soc/espressif/esp32c3/Kconfig.defconfig index 1e9f47ad6a3..dfa777ae547 100644 --- a/soc/espressif/esp32c3/Kconfig.defconfig +++ b/soc/espressif/esp32c3/Kconfig.defconfig @@ -1,10 +1,10 @@ -# Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. +# Copyright (c) 2023-2025 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 if SOC_SERIES_ESP32C3 config NUM_IRQS - default 62 + default 32 config FLASH_SIZE default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0) diff --git a/soc/espressif/esp32c3/soc.c b/soc/espressif/esp32c3/soc.c index 7541530eec0..d5f241f43d5 100644 --- a/soc/espressif/esp32c3/soc.c +++ b/soc/espressif/esp32c3/soc.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -25,8 +25,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); @@ -35,8 +33,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); diff --git a/soc/espressif/esp32c3/soc_irq.S b/soc/espressif/esp32c3/soc_irq.S index 0a9e917f508..7e41a1f961e 100644 --- a/soc/espressif/esp32c3/soc_irq.S +++ b/soc/espressif/esp32c3/soc_irq.S @@ -1,4 +1,4 @@ -/* Copyright 2021 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2021-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,13 +8,8 @@ /* Exports */ GTEXT(__soc_handle_irq) -GTEXT(soc_intr_get_next_source) SECTION_FUNC(exception.other, __soc_handle_irq) - addi sp, sp,-4 - sw ra, 0x00(sp) - la t1, soc_intr_get_next_source - jalr ra, t1, 0 - lw ra, 0x00(sp) - addi sp, sp, 4 + + /* int status clearing is done at ISR */ ret diff --git a/soc/espressif/esp32c3/soc_irq.c b/soc/espressif/esp32c3/soc_irq.c deleted file mode 100644 index 6511901a0d4..00000000000 --- a/soc/espressif/esp32c3/soc_irq.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define ESP32C3_INTSTATUS_SLOT1_THRESHOLD 32 - -void arch_irq_enable(unsigned int irq) -{ - esp_intr_enable(irq); -} - -void arch_irq_disable(unsigned int irq) -{ - esp_intr_disable(irq); -} - -int arch_irq_is_enabled(unsigned int irq) -{ - bool res = false; - uint32_t key = irq_lock(); - - if (irq < 32) { - res = esp_intr_get_enabled_intmask(0) & BIT(irq); - } else { - res = esp_intr_get_enabled_intmask(1) & BIT(irq - 32); - } - - irq_unlock(key); - - return res; -} - -uint32_t soc_intr_get_next_source(void) -{ - uint32_t status; - uint32_t source; - - status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_0_REG) & - esp_intr_get_enabled_intmask(0); - - if (status) { - source = __builtin_ffs(status) - 1; - } else { - status = REG_READ(INTERRUPT_CORE0_INTR_STATUS_1_REG) & - esp_intr_get_enabled_intmask(1); - source = (__builtin_ffs(status) - 1 + ESP32C3_INTSTATUS_SLOT1_THRESHOLD); - } - - return source; -} diff --git a/soc/espressif/esp32c3/vectors.S b/soc/espressif/esp32c3/vectors.S index 629ce21ff0d..272ab653a5f 100644 --- a/soc/espressif/esp32c3/vectors.S +++ b/soc/espressif/esp32c3/vectors.S @@ -1,4 +1,4 @@ -/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2020-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,12 +22,12 @@ GTEXT(_isr_wrapper) * only uses the 24 MSBs of the MTVEC, i.e. (MTVEC & 0xffffff00). */ - .global _esp_vector_table - .section .exception_vectors.text - .balign 0x100 - .type _esp_vector_table, @function + .global _vector_table + .section .exception_vectors.text + .balign 0x100 + .type _vector_table, @function -_esp_vector_table: +_vector_table: .option push .option norvc .rept (32) diff --git a/soc/espressif/esp32c6/CMakeLists.txt b/soc/espressif/esp32c6/CMakeLists.txt index 155134b8654..9101292b406 100644 --- a/soc/espressif/esp32c6/CMakeLists.txt +++ b/soc/espressif/esp32c6/CMakeLists.txt @@ -3,7 +3,6 @@ zephyr_sources_ifdef(CONFIG_SOC_ESP32C6_HPCORE vectors.S soc_irq.S - soc_irq.c soc.c ../common/loader.c ) diff --git a/soc/espressif/esp32c6/Kconfig.defconfig b/soc/espressif/esp32c6/Kconfig.defconfig index 86fc3369d92..ac076779842 100644 --- a/soc/espressif/esp32c6/Kconfig.defconfig +++ b/soc/espressif/esp32c6/Kconfig.defconfig @@ -1,12 +1,10 @@ -# ESP32C6 board configuration - -# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. +# Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd. # SPDX-License-Identifier: Apache-2.0 if SOC_SERIES_ESP32C6 config NUM_IRQS - default 77 + default 32 config FLASH_SIZE default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0) diff --git a/soc/espressif/esp32c6/soc.c b/soc/espressif/esp32c6/soc.c index 8fdd8b71e5f..ba49300a1da 100644 --- a/soc/espressif/esp32c6/soc.c +++ b/soc/espressif/esp32c6/soc.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -24,8 +24,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); @@ -34,8 +32,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_cstart(); diff --git a/soc/espressif/esp32c6/soc_irq.S b/soc/espressif/esp32c6/soc_irq.S index c1ad164c153..7e41a1f961e 100644 --- a/soc/espressif/esp32c6/soc_irq.S +++ b/soc/espressif/esp32c6/soc_irq.S @@ -1,26 +1,15 @@ -/* Copyright 2021 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2021-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include /* Exports */ -GTEXT(__soc_is_irq) GTEXT(__soc_handle_irq) -GTEXT(soc_intr_get_next_source) - -SECTION_FUNC(exception.other, __soc_is_irq) - csrr a0, mcause - srli a0, a0, 31 - ret SECTION_FUNC(exception.other, __soc_handle_irq) - addi sp, sp,-4 - sw ra, 0x00(sp) - la t1, soc_intr_get_next_source - jalr ra, t1, 0 - lw ra, 0x00(sp) - addi sp, sp, 4 + + /* int status clearing is done at ISR */ ret diff --git a/soc/espressif/esp32c6/soc_irq.c b/soc/espressif/esp32c6/soc_irq.c deleted file mode 100644 index b048b5f325a..00000000000 --- a/soc/espressif/esp32c6/soc_irq.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define ESP32C6_INTSTATUS_REG1_THRESHOLD 32 -#define ESP32C6_INTSTATUS_REG2_THRESHOLD 64 - -void arch_irq_enable(unsigned int irq) -{ - esp_intr_enable(irq); -} - -void arch_irq_disable(unsigned int irq) -{ - esp_intr_disable(irq); -} - -int arch_irq_is_enabled(unsigned int irq) -{ - bool res = false; - uint32_t key = irq_lock(); - - if (irq < 32) { - res = esp_intr_get_enabled_intmask(0) & BIT(irq); - } else if (irq < 64) { - res = esp_intr_get_enabled_intmask(1) & BIT(irq - 32); - } else { - res = esp_intr_get_enabled_intmask(2) & BIT(irq - 64); - } - - irq_unlock(key); - - return res; -} - -uint32_t soc_intr_get_next_source(void) -{ - uint32_t status; - uint32_t source = IRQ_NA; - - /* Status register for interrupt sources 0 ~ 31 */ - status = REG_READ(INTMTX_CORE0_INT_STATUS_REG_0_REG) & - esp_intr_get_enabled_intmask(0); - - if (status) { - source = __builtin_ffs(status) - 1; - goto ret; - } - - /* Status register for interrupt sources 32 ~ 63 */ - status = REG_READ(INTMTX_CORE0_INT_STATUS_REG_1_REG) & - esp_intr_get_enabled_intmask(1); - - if (status) { - source = (__builtin_ffs(status) - 1 + ESP32C6_INTSTATUS_REG1_THRESHOLD); - goto ret; - } - - /* Status register for interrupt sources 64 ~ 76 */ - status = REG_READ(INTMTX_CORE0_INT_STATUS_REG_2_REG) & - esp_intr_get_enabled_intmask(2); - - if (status) { - source = (__builtin_ffs(status) - 1 + ESP32C6_INTSTATUS_REG2_THRESHOLD); - } - -ret: - return source; -} diff --git a/soc/espressif/esp32c6/vectors.S b/soc/espressif/esp32c6/vectors.S index 3ad3ae6d790..272ab653a5f 100644 --- a/soc/espressif/esp32c6/vectors.S +++ b/soc/espressif/esp32c6/vectors.S @@ -1,4 +1,4 @@ -/* Copyright 2023 Espressif Systems (Shanghai) PTE LTD +/* Copyright 2020-2025 Espressif Systems (Shanghai) PTE LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,12 +22,12 @@ GTEXT(_isr_wrapper) * only uses the 24 MSBs of the MTVEC, i.e. (MTVEC & 0xffffff00). */ - .global _esp_vector_table + .global _vector_table .section .exception_vectors.text .balign 0x100 - .type _esp_vector_table, @function + .type _vector_table, @function -_esp_vector_table: +_vector_table: .option push .option norvc .rept (32) diff --git a/soc/espressif/esp32s2/soc.c b/soc/espressif/esp32s2/soc.c index 286bbe2469a..9d8258a23ab 100644 --- a/soc/espressif/esp32s2/soc.c +++ b/soc/espressif/esp32s2/soc.c @@ -41,8 +41,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - #if CONFIG_ESP_SPIRAM esp_init_psram(); @@ -62,8 +60,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_prep_c(); diff --git a/soc/espressif/esp32s3/soc.c b/soc/espressif/esp32s3/soc.c index 881d709d7a0..08865b19151 100644 --- a/soc/espressif/esp32s3/soc.c +++ b/soc/espressif/esp32s3/soc.c @@ -54,8 +54,6 @@ void IRAM_ATTR __esp_platform_app_start(void) esp_flash_config(); - esp_intr_initialize(); - #if CONFIG_ESP_SPIRAM esp_init_psram(); @@ -74,8 +72,6 @@ void IRAM_ATTR __esp_platform_app_start(void) void IRAM_ATTR __esp_platform_mcuboot_start(void) { - esp_intr_initialize(); - /* Start Zephyr */ z_prep_c(); diff --git a/soc/espressif/esp32s3/soc_appcpu.c b/soc/espressif/esp32s3/soc_appcpu.c index a03304c8751..5e6eca88f0b 100644 --- a/soc/espressif/esp32s3/soc_appcpu.c +++ b/soc/espressif/esp32s3/soc_appcpu.c @@ -72,8 +72,6 @@ void IRAM_ATTR __appcpu_start(void) core_intr_matrix_clear(); - esp_intr_initialize(); - /* Start Zephyr */ z_prep_c();