From cdad8a02fe6bd9dc36447fdbd23aa831e8546708 Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 26 May 2022 22:48:49 +0800 Subject: [PATCH] esp_psram: remove g_spiram_ok --- .../esp_hw_support/port/esp32s2/mmu_psram.c | 0 .../esp_psram/esp32/esp_psram_extram_cache.c | 1 + components/esp_psram/mmu_psram.c | 2 ++ .../include/esp_private/startup_internal.h | 19 +++++-------------- components/esp_system/port/cpu_start.c | 6 +----- components/esp_system/startup.c | 5 +++-- .../portable/xtensa/port.c | 7 ++++--- .../FreeRTOS-Kernel/portable/port_common.c | 4 ++-- tools/ci/check_copyright_ignore.txt | 1 - 9 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 components/esp_hw_support/port/esp32s2/mmu_psram.c diff --git a/components/esp_hw_support/port/esp32s2/mmu_psram.c b/components/esp_hw_support/port/esp32s2/mmu_psram.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/components/esp_psram/esp32/esp_psram_extram_cache.c b/components/esp_psram/esp32/esp_psram_extram_cache.c index 764c23b514..b21bbb7456 100644 --- a/components/esp_psram/esp32/esp_psram_extram_cache.c +++ b/components/esp_psram/esp32/esp_psram_extram_cache.c @@ -5,6 +5,7 @@ */ #include "soc/dport_reg.h" +#include "esp_attr.h" #include "esp_psram.h" #include "esp_private/esp_psram_extram.h" diff --git a/components/esp_psram/mmu_psram.c b/components/esp_psram/mmu_psram.c index 00c16283b8..3f690bf68c 100644 --- a/components/esp_psram/mmu_psram.c +++ b/components/esp_psram/mmu_psram.c @@ -31,6 +31,8 @@ #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA +//page_size - 1, where page_size on s2 and s3 is always 0x10000. To be refactored by MMU driver +#define INVALID_PHY_PAGE 0xffff const static char *TAG = "mmu_psram"; //TODO IDF-4387 static uint32_t page0_mapped = 0; diff --git a/components/esp_system/include/esp_private/startup_internal.h b/components/esp_system/include/esp_private/startup_internal.h index 52ec6e09b3..3e59429c2a 100644 --- a/components/esp_system/include/esp_private/startup_internal.h +++ b/components/esp_system/include/esp_private/startup_internal.h @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -25,7 +17,6 @@ extern "C" { #endif -extern bool g_spiram_ok; // [refactor-todo] better way to communicate this from port layer to common startup code // Port layer defines the entry point. It then transfer control to a `sys_startup_fn_t`, stored in this // array, one per core. diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c index f93159162a..b85aa8f10a 100644 --- a/components/esp_system/port/cpu_start.c +++ b/components/esp_system/port/cpu_start.c @@ -128,9 +128,6 @@ static volatile bool s_cpu_inited[SOC_CPU_CORES_NUM] = { false }; static volatile bool s_resume_cores; #endif -// If CONFIG_SPIRAM_IGNORE_NOTFOUND is set and external RAM is not found or errors out on testing, this is set to false. -bool g_spiram_ok = true; - static void core_intr_matrix_clear(void) { uint32_t core_id = cpu_hal_get_core_id(); @@ -394,7 +391,6 @@ void IRAM_ATTR call_start_cpu0(void) #if CONFIG_SPIRAM_IGNORE_NOTFOUND ESP_EARLY_LOGI(TAG, "Failed to init external RAM; continuing without it."); - g_spiram_ok = false; #else ESP_EARLY_LOGE(TAG, "Failed to init external RAM!"); abort(); @@ -428,7 +424,7 @@ void IRAM_ATTR call_start_cpu0(void) #endif // SOC_CPU_CORES_NUM > 1 #if CONFIG_SPIRAM_MEMTEST - if (g_spiram_ok) { + if (esp_psram_is_initialized()) { bool ext_ram_ok = esp_psram_extram_test(); if (!ext_ram_ok) { ESP_EARLY_LOGE(TAG, "External RAM failed memory test!"); diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index eabb0d8c6f..5c46dee56f 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -72,6 +72,7 @@ #include "esp_rom_sys.h" #if CONFIG_SPIRAM +#include "esp_psram.h" #include "esp_private/esp_psram_extram.h" #endif /***********************************************/ @@ -246,8 +247,8 @@ static void do_core_init(void) esp_timer_early_init(); esp_newlib_init(); - if (g_spiram_ok) { #if CONFIG_SPIRAM_BOOT_INIT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC) + if (esp_psram_is_initialized()) { esp_err_t r=esp_psram_extram_add_to_heap_allocator(); if (r != ESP_OK) { ESP_EARLY_LOGE(TAG, "External RAM could not be added to heap!"); @@ -255,9 +256,9 @@ static void do_core_init(void) } #if CONFIG_SPIRAM_USE_MALLOC heap_caps_malloc_extmem_enable(CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL); -#endif #endif } +#endif #if CONFIG_ESP_BROWNOUT_DET // [refactor-todo] leads to call chain rtc_is_register (driver) -> esp_intr_alloc (esp32/esp32s2) -> diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index 27860e004d..5a5d338911 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c @@ -17,7 +17,6 @@ #include "xtensa/config/core.h" #include "xtensa/config/core-isa.h" #include "xtensa/xtruntime.h" -#include "esp_private/startup_internal.h" /* Required by g_spiram_ok. [refactor-todo] for g_spiram_ok */ #include "esp_private/esp_int_wdt.h" #include "esp_heap_caps.h" #include "esp_system.h" @@ -29,7 +28,9 @@ #include "esp_heap_caps_init.h" #include "esp_freertos_hooks.h" #if CONFIG_SPIRAM -#include "esp_private/esp_psram_extram.h" /* Required by esp_psram_extram_reserve_dma_pool() */ +/* Required by esp_psram_extram_reserve_dma_pool() */ +#include "esp_psram.h" +#include "esp_private/esp_psram_extram.h" #endif #ifdef CONFIG_APPTRACE_ENABLE #include "esp_app_trace.h" @@ -182,7 +183,7 @@ static void main_task(void* args) // Now we have startup stack RAM available for heap, enable any DMA pool memory #if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL - if (g_spiram_ok) { + if (esp_psram_is_initialized()) { esp_err_t r = esp_psram_extram_reserve_dma_pool(CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL); if (r != ESP_OK) { ESP_EARLY_LOGE(TAG, "Could not reserve internal/DMA pool (error 0x%x)", r); diff --git a/components/freertos/FreeRTOS-Kernel/portable/port_common.c b/components/freertos/FreeRTOS-Kernel/portable/port_common.c index da9fe7883b..864b1d43ca 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/port_common.c +++ b/components/freertos/FreeRTOS-Kernel/portable/port_common.c @@ -14,13 +14,13 @@ #include "esp_task_wdt.h" #include "esp_task.h" #include "esp_private/crosscore_int.h" -#include "esp_private/startup_internal.h" /* Required by g_spiram_ok. [refactor-todo] for g_spiram_ok */ #include "esp_log.h" #include "esp_memory_utils.h" #include "esp_freertos_hooks.h" #include "sdkconfig.h" #if CONFIG_SPIRAM +#include "esp_psram.h" #include "esp_private/esp_psram_extram.h" #endif @@ -89,7 +89,7 @@ static void main_task(void* args) // Now we have startup stack RAM available for heap, enable any DMA pool memory #if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL - if (g_spiram_ok) { + if (esp_psram_is_initialized()) { esp_err_t r = esp_psram_extram_reserve_dma_pool(CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL); if (r != ESP_OK) { ESP_EARLY_LOGE(TAG, "Could not reserve internal/DMA pool (error 0x%x)", r); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index b295f17474..6a18d75149 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -666,7 +666,6 @@ components/esp_system/include/esp_freertos_hooks.h components/esp_system/include/esp_int_wdt.h components/esp_system/include/esp_private/dbg_stubs.h components/esp_system/include/esp_private/panic_internal.h -components/esp_system/include/esp_private/startup_internal.h components/esp_system/include/esp_private/system_internal.h components/esp_system/include/esp_private/usb_console.h components/esp_system/include/esp_task.h