Просмотр исходного кода

Merge branch 'refactor/move_soc_memory_types_helper_functions_to_esp_hw_support' into 'master'

hw_support: move soc_memory_types.h helper functions into esp_hw_support (G1)

Closes IDF-4858

See merge request espressif/esp-idf!17657
Armando (Dou Yiwen) 3 лет назад
Родитель
Сommit
5e8db9669d
28 измененных файлов с 506 добавлено и 307 удалено
  1. 152 0
      components/bootloader_support/include/bootloader_memory_utils.h
  2. 0 1
      components/bootloader_support/src/bootloader_common_loader.c
  3. 1 1
      components/bootloader_support/src/esp_image_format.c
  4. 1 1
      components/driver/gdma.c
  5. 1 1
      components/driver/gptimer.c
  6. 3 3
      components/esp_hw_support/CMakeLists.txt
  7. 63 0
      components/esp_hw_support/esp_memory_utils.c
  8. 1 1
      components/esp_hw_support/include/compare_set.h
  9. 182 0
      components/esp_hw_support/include/esp_memory_utils.h
  10. 9 0
      components/esp_hw_support/include/soc/soc_memory_types.h
  11. 1 0
      components/esp_hw_support/linker.lf
  12. 1 1
      components/esp_lcd/src/esp_lcd_panel_io_i80.c
  13. 1 1
      components/freertos/FreeRTOS-Kernel/portable/port_common.c
  14. 5 14
      components/hal/include/hal/spi_flash_hal.h
  15. 15 15
      components/hal/include/hal/spi_flash_types.h
  16. 10 21
      components/hal/spi_flash_hal.c
  17. 6 14
      components/heap/include/soc/soc_memory_layout.h
  18. 1 1
      components/heap/test/test_malloc_caps.c
  19. 1 1
      components/log/CMakeLists.txt
  20. 1 1
      components/log/log_buffers.c
  21. 1 1
      components/lwip/test_afl_host/Makefile
  22. 14 2
      components/mbedtls/port/aes/dma/esp_aes.c
  23. 14 2
      components/mbedtls/port/sha/dma/sha.c
  24. 0 204
      components/soc/include/soc/soc_memory_types.h
  25. 11 2
      components/spi_flash/esp_flash_api.c
  26. 10 13
      components/spi_flash/memspi_host_driver.c
  27. 1 1
      docs/en/migration-guides/system.rst
  28. 0 5
      tools/ci/check_copyright_ignore.txt

+ 152 - 0
components/bootloader_support/include/bootloader_memory_utils.h

@@ -0,0 +1,152 @@
+/*
+ * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "soc/soc.h"
+#include "soc/soc_caps.h"
+#include "sdkconfig.h"
+#include "esp_attr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Check if the pointer is in iram
+ *
+ * @param p pointer
+ *
+ * @return true: is in iram; false: not in iram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_iram(const void *p) {
+#if CONFIG_IDF_TARGET_ESP32 && CONFIG_FREERTOS_UNICORE
+    return ((intptr_t)p >= SOC_CACHE_APP_LOW && (intptr_t)p < SOC_IRAM_HIGH);
+#else
+    return ((intptr_t)p >= SOC_IRAM_LOW && (intptr_t)p < SOC_IRAM_HIGH);
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in dram
+ *
+ * @param p pointer
+ *
+ * @return true: is in dram; false: not in dram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_dram(const void *p) {
+    return ((intptr_t)p >= SOC_DRAM_LOW && (intptr_t)p < SOC_DRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in diram_dram
+ *
+ * @param p pointer
+ *
+ * @return true: is in diram_dram; false: not in diram_dram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_diram_dram(const void *p) {
+    return ((intptr_t)p >= SOC_DIRAM_DRAM_LOW && (intptr_t)p < SOC_DIRAM_DRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in diram_iram
+ *
+ * @param p pointer
+ *
+ * @return true: is in diram_iram; false: not in diram_iram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_diram_iram(const void *p) {
+    return ((intptr_t)p >= SOC_DIRAM_IRAM_LOW && (intptr_t)p < SOC_DIRAM_IRAM_HIGH);
+}
+
+/**
+ * @brief Check if the pointer is in rtc_iram_fast
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_iram_fast; false: not in rtc_iram_fast
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_iram_fast(const void *p) {
+#if SOC_RTC_FAST_MEM_SUPPORTED
+    return ((intptr_t)p >= SOC_RTC_IRAM_LOW && (intptr_t)p < SOC_RTC_IRAM_HIGH);
+#else
+    return false;
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in rtc_dram_fast
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_dram_fast; false: not in rtc_dram_fast
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_dram_fast(const void *p) {
+#if SOC_RTC_FAST_MEM_SUPPORTED
+    return ((intptr_t)p >= SOC_RTC_DRAM_LOW && (intptr_t)p < SOC_RTC_DRAM_HIGH);
+#else
+    return false;
+#endif
+}
+
+/**
+ * @brief Check if the pointer is in rtc_slow
+ *
+ * @param p pointer
+ *
+ * @return true: is in rtc_slow; false: not in rtc_slow
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_rtc_slow(const void *p) {
+#if SOC_RTC_SLOW_MEM_SUPPORTED
+    return ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
+#else
+    return false;
+#endif
+}
+
+
+/* Convert a D/IRAM DRAM pointer to equivalent word address in IRAM
+
+   - Address must be word aligned
+   - Address must pass esp_ptr_in_diram_dram() test, or result will be invalid pointer
+*/
+__attribute__((always_inline))
+inline static void * esp_ptr_diram_dram_to_iram(const void *p) {
+#if SOC_DIRAM_INVERTED
+    return (void *) ( SOC_DIRAM_IRAM_LOW + (SOC_DIRAM_DRAM_HIGH - (intptr_t)p) - 4);
+#else
+    return (void *) ( SOC_DIRAM_IRAM_LOW + ((intptr_t)p - SOC_DIRAM_DRAM_LOW) );
+#endif
+}
+
+/* Convert a D/IRAM IRAM pointer to equivalent word address in DRAM
+
+   - Address must be word aligned
+   - Address must pass esp_ptr_in_diram_iram() test, or result will be invalid pointer
+*/
+__attribute__((always_inline))
+inline static void * esp_ptr_diram_iram_to_dram(const void *p) {
+#if SOC_DIRAM_INVERTED
+    return (void *) ( SOC_DIRAM_DRAM_LOW + (SOC_DIRAM_IRAM_HIGH - (intptr_t)p) - 4);
+#else
+    return (void *) ( SOC_DIRAM_DRAM_LOW + ((intptr_t)p - SOC_DIRAM_IRAM_LOW) );
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif

+ 0 - 1
components/bootloader_support/src/bootloader_common_loader.c

@@ -17,7 +17,6 @@
 #include "soc/gpio_periph.h"
 #include "soc/rtc.h"
 #include "soc/efuse_reg.h"
-#include "soc/soc_memory_types.h"
 #include "hal/gpio_ll.h"
 #include "esp_image_format.h"
 #include "bootloader_sha.h"

+ 1 - 1
components/bootloader_support/src/esp_image_format.c

@@ -18,7 +18,7 @@
 #include "bootloader_util.h"
 #include "bootloader_common.h"
 #include "esp_rom_sys.h"
-#include "soc/soc_memory_types.h"
+#include "bootloader_memory_utils.h"
 #include "soc/soc_caps.h"
 #if CONFIG_IDF_TARGET_ESP32
 #include "esp32/rom/secure_boot.h"

+ 1 - 1
components/driver/gdma.c

@@ -20,7 +20,7 @@
 #include "hal/gdma_hal.h"
 #include "hal/gdma_ll.h"
 #include "soc/gdma_periph.h"
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 #include "esp_private/periph_ctrl.h"
 #include "esp_private/gdma.h"
 

+ 1 - 1
components/driver/gptimer.c

@@ -25,7 +25,7 @@
 #include "hal/timer_hal.h"
 #include "hal/timer_ll.h"
 #include "soc/timer_periph.h"
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 #include "esp_private/periph_ctrl.h"
 #include "esp_private/esp_clk.h"
 

+ 3 - 3
components/esp_hw_support/CMakeLists.txt

@@ -1,9 +1,9 @@
 idf_build_get_property(target IDF_TARGET)
 
-set(requires soc)
-set(priv_requires efuse bootloader_support spi_flash)
+set(requires soc bootloader_support)
+set(priv_requires efuse spi_flash)
 
-set(srcs "compare_set.c" "cpu_util.c")
+set(srcs "compare_set.c" "cpu_util.c" "esp_memory_utils.c")
 if(NOT BOOTLOADER_BUILD)
     list(APPEND srcs "esp_async_memcpy.c"
                      "esp_clk.c"

+ 63 - 0
components/esp_hw_support/esp_memory_utils.c

@@ -0,0 +1,63 @@
+/*
+ * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "sdkconfig.h"
+#include "soc/soc.h"
+#include "soc/soc_caps.h"
+#include "esp_attr.h"
+#include "esp_memory_utils.h"
+
+
+//TODO: IDF-4855, replace PSRAM related address region into PSRAM private APIs
+
+bool esp_ptr_dma_ext_capable(const void *p)
+{
+#ifdef SOC_PSRAM_DMA_CAPABLE
+    return (intptr_t)p >= SOC_DMA_EXT_LOW && (intptr_t)p < SOC_DMA_EXT_HIGH;
+#else
+    return false;
+#endif
+}
+
+bool esp_ptr_byte_accessible(const void *p)
+{
+    intptr_t ip = (intptr_t) p;
+    bool r;
+    r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH);
+#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
+    /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
+     * for single core configuration (where it gets added to system heap) following
+     * additional check is required */
+    r |= (ip >= SOC_RTC_DRAM_LOW && ip < SOC_RTC_DRAM_HIGH);
+#endif
+#if CONFIG_SPIRAM
+#if CONFIG_SPIRAM_SIZE != -1 // Fixed size, can be more accurate
+    r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_LOW + CONFIG_SPIRAM_SIZE));
+#else
+    r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_HIGH));
+#endif
+#endif
+    return r;
+}
+
+bool esp_ptr_external_ram(const void *p) {
+#if SOC_SPIRAM_SUPPORTED
+    return ((intptr_t)p >= SOC_EXTRAM_DATA_LOW && (intptr_t)p < SOC_EXTRAM_DATA_HIGH);
+#else
+    return false; // SoC has no external RAM
+#endif
+}
+
+#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
+bool esp_stack_ptr_in_extram(uint32_t sp)
+{
+    //Check if stack ptr is in between SOC_EXTRAM_DATA_LOW and SOC_EXTRAM_DATA_HIGH, and 16 byte aligned.
+    return !(sp < SOC_EXTRAM_DATA_LOW + 0x10 || sp > SOC_EXTRAM_DATA_HIGH - 0x10 || ((sp & 0xF) != 0));
+}
+#endif

+ 1 - 1
components/esp_hw_support/include/compare_set.h

@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "esp_cpu.h"
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 
 #ifdef __cplusplus
 extern "C" {

+ 182 - 0
components/esp_hw_support/include/esp_memory_utils.h

@@ -0,0 +1,182 @@
+/*
+ * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "soc/soc.h"
+#include "soc/soc_caps.h"
+#include "sdkconfig.h"
+#include "esp_attr.h"
+#include "bootloader_memory_utils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Check if the pointer is dma capable
+ *
+ * @param p pointer
+ *
+ * @return true: capable; false: not capable
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_dma_capable(const void *p)
+{
+    return (intptr_t)p >= SOC_DMA_LOW && (intptr_t)p < SOC_DMA_HIGH;
+}
+
+/**
+ * @brief Check if the pointer is in external ram dma capable region
+ *
+ * @param p pointer
+ *
+ * @return true: capable; false: not capable
+ */
+bool esp_ptr_dma_ext_capable(const void *p);
+
+/**
+ * @brief Check if the pointer is word aligned
+ *
+ * @param p pointer
+ *
+ * @return true: aligned; false: not aligned
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_word_aligned(const void *p)
+{
+    return ((intptr_t)p) % 4 == 0;
+}
+
+/**
+ * @brief Check if the pointer is executable
+ *
+ * @param p pointer
+ *
+ * @return true: is executable; false: not executable
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_executable(const void *p)
+{
+    intptr_t ip = (intptr_t) p;
+    return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH)
+        || (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH)
+        || (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH)
+#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_FREERTOS_UNICORE)
+        || (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH)
+#endif
+#if SOC_RTC_FAST_MEM_SUPPORTED
+        || (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH)
+#endif
+    ;
+}
+
+/**
+ * @brief Check if the pointer is byte accessible
+ *
+ * @param p pointer
+ *
+ * @return true: is byte accessible; false: not byte accessible
+ */
+bool esp_ptr_byte_accessible(const void *p);
+
+/**
+ * @brief Check if the pointer is in internal ram
+ *
+ * @param p pointer
+ *
+ * @return true: is in internal ram; false: not in internal ram
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_internal(const void *p) {
+    bool r;
+    r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH);
+
+#if SOC_RTC_SLOW_MEM_SUPPORTED
+    r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
+#endif
+
+#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
+    /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
+     * for single core configuration (where it gets added to system heap) following
+     * additional check is required */
+    r |= ((intptr_t)p >= SOC_RTC_DRAM_LOW && (intptr_t)p < SOC_RTC_DRAM_HIGH);
+#endif
+    return r;
+}
+
+/**
+ * @brief Check if the pointer is in external ram
+ *
+ * @param p pointer
+ *
+ * @return true: is in external ram; false: not in external ram
+ */
+bool esp_ptr_external_ram(const void *p);
+
+/**
+ * @brief Check if the pointer is in drom
+ *
+ * @param p pointer
+ *
+ * @return true: is in drom; false: not in drom
+ */
+__attribute__((always_inline))
+inline static bool esp_ptr_in_drom(const void *p) {
+    return ((intptr_t)p >= SOC_DROM_LOW && (intptr_t)p < SOC_DROM_HIGH);
+}
+
+/**
+ * @brief Check if the stack pointer is in dram
+ *
+ * @param sp stack pointer
+ *
+ * @return true: is in dram; false: not in dram
+ */
+__attribute__((always_inline))
+inline static bool esp_stack_ptr_in_dram(uint32_t sp)
+{
+    //Check if stack ptr is in between SOC_DRAM_LOW and SOC_DRAM_HIGH, and 16 byte aligned.
+    return !(sp < SOC_DRAM_LOW + 0x10 || sp > SOC_DRAM_HIGH - 0x10 || ((sp & 0xF) != 0));
+}
+
+#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
+/**
+ * @brief Check if the stack pointer is in external ram
+ *
+ * @param sp stack pointer
+ *
+ * @return true: is in external ram; false: not in external ram
+ */
+bool esp_stack_ptr_in_extram(uint32_t sp);
+#endif
+
+/**
+ * @brief Check if the stack pointer is sane
+ *
+ * @param sp stack pointer
+ *
+ * @return true: is in sane; false: not in sane
+ */
+__attribute__((always_inline))
+inline static bool esp_stack_ptr_is_sane(uint32_t sp)
+{
+    return esp_stack_ptr_in_dram(sp)
+#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
+        || esp_stack_ptr_in_extram(sp)
+#endif
+#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
+        || esp_ptr_in_rtc_dram_fast((void*) sp)
+#endif
+        ;
+}
+
+#ifdef __cplusplus
+}
+#endif

+ 9 - 0
components/esp_hw_support/include/soc/soc_memory_types.h

@@ -0,0 +1,9 @@
+/*
+ * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+#include "esp_memory_utils.h"
+#warning "soc_memory_types.h is deprecated, please migrate to esp_memory_utils.h"

+ 1 - 0
components/esp_hw_support/linker.lf

@@ -2,6 +2,7 @@
 archive: libesp_hw_support.a
 entries:
     cpu_util (noflash_text)
+    esp_memory_utils (noflash)
     rtc_clk (noflash)
     rtc_init:rtc_vddsdio_set_config (noflash)
     rtc_pm (noflash_text)

+ 1 - 1
components/esp_lcd/src/esp_lcd_panel_io_i80.c

@@ -26,7 +26,7 @@
 #include "esp_rom_gpio.h"
 #include "soc/soc_caps.h"
 #include "soc/rtc.h" // for `rtc_clk_xtal_freq_get()`
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 #include "hal/dma_types.h"
 #include "hal/gpio_hal.h"
 #include "esp_private/gdma.h"

+ 1 - 1
components/freertos/FreeRTOS-Kernel/portable/port_common.c

@@ -16,7 +16,7 @@
 #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 "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 #include "soc/dport_access.h"
 #include "sdkconfig.h"
 

+ 5 - 14
components/hal/include/hal/spi_flash_hal.h

@@ -1,16 +1,8 @@
-// Copyright 2010-2019 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: 2010-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 /*******************************************************************************
  * NOTICE
@@ -25,7 +17,6 @@
 #include "hal/spi_flash_ll.h"
 #include "hal/spi_types.h"
 #include "hal/spi_flash_types.h"
-#include "soc/soc_memory_types.h"
 
 /* Hardware host-specific constants */
 #define SPI_FLASH_HAL_MAX_WRITE_BYTES 64

+ 15 - 15
components/hal/include/hal/spi_flash_types.h

@@ -1,16 +1,8 @@
-// Copyright 2010-2019 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: 2010-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #pragma once
 
@@ -180,7 +172,11 @@ struct spi_flash_host_driver_s {
      * Program a page of the flash. Check ``max_write_bytes`` for the maximum allowed writing length.
      */
     void (*program_page)(spi_flash_host_inst_t *host, const void *buffer, uint32_t address, uint32_t length);
-    /** Check whether given buffer can be directly used to write */
+    /**
+     * @brief Check whether the SPI host supports direct write
+     *
+     * When cache is disabled, SPI1 doesn't support directly write when buffer isn't internal.
+     */
     bool (*supports_direct_write)(spi_flash_host_inst_t *host, const void *p);
     /**
      * Slicer for write data. The `program_page` should be called iteratively with the return value
@@ -198,7 +194,11 @@ struct spi_flash_host_driver_s {
      * Read data from the flash. Check ``max_read_bytes`` for the maximum allowed reading length.
      */
     esp_err_t (*read)(spi_flash_host_inst_t *host, void *buffer, uint32_t address, uint32_t read_len);
-    /** Check whether given buffer can be directly used to read */
+    /**
+     * @brief Check whether the SPI host supports direct read
+     *
+     * When cache is disabled, SPI1 doesn't support directly read when the given buffer isn't internal.
+     */
     bool (*supports_direct_read)(spi_flash_host_inst_t *host, const void *p);
     /**
      * Slicer for read data. The `read` should be called iteratively with the return value

+ 10 - 21
components/hal/spi_flash_hal.c

@@ -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
+ */
 
 // HAL for SPI Flash (non-IRAM part)
 // The IRAM part is in spi_flash_hal_iram.c, spi_flash_hal_gpspi.c, spi_flash_hal_common.inc.
@@ -93,9 +85,6 @@ static inline int extra_dummy_under_timing_tuning(const spi_flash_hal_config_t *
 
 esp_err_t spi_flash_hal_init(spi_flash_hal_context_t *data_out, const spi_flash_hal_config_t *cfg)
 {
-    if (!esp_ptr_internal(data_out) && cfg->host_id == SPI1_HOST) {
-        return ESP_ERR_INVALID_ARG;
-    }
     if (cfg->cs_num >= SOC_SPI_PERIPH_CS_NUM(cfg->host_id)) {
         return ESP_ERR_INVALID_ARG;
     }
@@ -144,16 +133,16 @@ esp_err_t spi_flash_hal_init(spi_flash_hal_context_t *data_out, const spi_flash_
 
 bool spi_flash_hal_supports_direct_write(spi_flash_host_inst_t *host, const void *p)
 {
-    bool direct_write = ( ((spi_flash_hal_context_t *)host)->spi != spi_flash_ll_get_hw(SPI1_HOST)
-                          || esp_ptr_in_dram(p) );
+    (void)p;
+    bool direct_write = (((spi_flash_hal_context_t *)host)->spi != spi_flash_ll_get_hw(SPI1_HOST));
     return direct_write;
 }
 
 
 bool spi_flash_hal_supports_direct_read(spi_flash_host_inst_t *host, const void *p)
 {
-  //currently the host doesn't support to read through dma, no word-aligned requirements
-    bool direct_read = ( ((spi_flash_hal_context_t *)host)->spi != spi_flash_ll_get_hw(SPI1_HOST)
-                         || esp_ptr_in_dram(p) );
+    (void)p;
+    //currently the host doesn't support to read through dma, no word-aligned requirements
+    bool direct_read = ( ((spi_flash_hal_context_t *)host)->spi != spi_flash_ll_get_hw(SPI1_HOST));
     return direct_read;
 }

+ 6 - 14
components/heap/include/soc/soc_memory_layout.h

@@ -1,16 +1,8 @@
-// Copyright 2010-2016 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: 2010-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 /**
  * Compatibility header file.
@@ -18,4 +10,4 @@
 #pragma once
 
 #include "heap_memory_layout.h"
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"

+ 1 - 1
components/heap/test/test_malloc_caps.c

@@ -8,7 +8,7 @@
 #include "esp_attr.h"
 #include "esp_heap_caps.h"
 #include "esp_spi_flash.h"
-#include "soc/soc_memory_types.h"
+#include "esp_memory_utils.h"
 #include <stdlib.h>
 #include <sys/param.h>
 

+ 1 - 1
components/log/CMakeLists.txt

@@ -7,7 +7,7 @@ if(${target} STREQUAL "linux")
     list(APPEND srcs "log_linux.c")
 else()
     list(APPEND srcs "log_buffers.c")
-    list(APPEND priv_requires soc hal)
+    list(APPEND priv_requires soc hal esp_hw_support)
 endif()
 
 idf_component_register(SRCS ${srcs}

+ 1 - 1
components/log/log_buffers.c

@@ -8,7 +8,7 @@
 #include <ctype.h>
 #include <string.h>
 #include "esp_log.h"
-#include "soc/soc_memory_types.h"  // for esp_ptr_byte_accessible
+#include "esp_memory_utils.h"  // for esp_ptr_byte_accessible
 
 
 //print number of bytes per line for esp_log_buffer_char and esp_log_buffer_hex

+ 1 - 1
components/lwip/test_afl_host/Makefile

@@ -2,7 +2,7 @@ COMPONENTS_DIR=../..
 COMPILER_ICLUDE_DIR=$(shell echo `which xtensa-esp32-elf-gcc | xargs dirname | xargs dirname`/xtensa-esp32-elf)
 CFLAGS=-std=gnu99 -Og -ggdb -ffunction-sections -fdata-sections -nostdlib -Wall  -Werror=all -Wno-int-to-pointer-cast -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-macro-redefined -Wno-constant-conversion -Wno-incompatible-pointer-types-discards-qualifiers -Wno-typedef-redefinition -Wno-incompatible-pointer-types  -Wextra \
 -Wno-unused-parameter -Wno-sign-compare -Wno-address   -Wno-unused-variable -DESP_PLATFORM -D IDF_VER=\"v3.1\" -MMD -MP -DWITH_POSIX -DLWIP_NO_CTYPE_H=1
-INC_DIRS=-I . -I ./build/config -I $(COMPONENTS_DIR)/newlib/platform_include -I $(COMPONENTS_DIR)/newlib/include -I $(COMPONENTS_DIR)/driver/include -I $(COMPONENTS_DIR)/esp32/include -I $(COMPONENTS_DIR)/ethernet/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include/freertos -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/include -I $(COMPONENTS_DIR)/heap/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include  -I $(COMPONENTS_DIR)/lwip/include/apps -I $(COMPONENTS_DIR)/lwip/lwip/src/include/netif -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/port/esp32/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/include/apps/ping -I $(COMPONENTS_DIR)/lwip/include/apps/sntp  -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/esp_rom/include  -I $(COMPONENTS_DIR)/esp_common/include -I $(COMPONENTS_DIR)/esp_hw_support/include -I $(COMPONENTS_DIR)/xtensa/include -I $(COMPONENTS_DIR)/xtensa/esp32/include -I $(COMPONENTS_DIR)/esp_wifi/include -I $(COMPONENTS_DIR)/esp_event/include -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/portable/xtensa/include  -I $(COMPONENTS_DIR)/esp_system/include -I $(COMPONENTS_DIR)/esp_timer/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/src/esp32/include -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/esp_netif/include -I $(COMPONENTS_DIR)/esp_eth/include -I $(COMPONENTS_DIR)/esp_netif/lwip -I $(COMPONENTS_DIR)/hal/include -I $(COMPONENTS_DIR)/hal/esp32/include -I $(COMPILER_ICLUDE_DIR)/include
+INC_DIRS=-I . -I ./build/config -I $(COMPONENTS_DIR)/newlib/platform_include -I $(COMPONENTS_DIR)/newlib/include -I $(COMPONENTS_DIR)/driver/include -I $(COMPONENTS_DIR)/esp32/include -I $(COMPONENTS_DIR)/ethernet/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include -I $(COMPONENTS_DIR)/freertos/esp_additions/include/freertos -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/include -I $(COMPONENTS_DIR)/heap/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include  -I $(COMPONENTS_DIR)/lwip/include/apps -I $(COMPONENTS_DIR)/lwip/lwip/src/include/netif -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/port/esp32/include -I $(COMPONENTS_DIR)/lwip/lwip/src/include/posix -I $(COMPONENTS_DIR)/lwip/include/apps/ping -I $(COMPONENTS_DIR)/lwip/include/apps/sntp  -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/esp_rom/include  -I $(COMPONENTS_DIR)/esp_common/include -I $(COMPONENTS_DIR)/esp_hw_support/include -I $(COMPONENTS_DIR)/xtensa/include -I $(COMPONENTS_DIR)/xtensa/esp32/include -I $(COMPONENTS_DIR)/esp_wifi/include -I $(COMPONENTS_DIR)/esp_event/include -I $(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/portable/xtensa/include  -I $(COMPONENTS_DIR)/esp_system/include -I $(COMPONENTS_DIR)/esp_timer/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/include -I $(COMPONENTS_DIR)/soc/src/esp32/include -I $(COMPONENTS_DIR)/soc/esp32/include -I $(COMPONENTS_DIR)/esp_netif/include -I $(COMPONENTS_DIR)/esp_eth/include -I $(COMPONENTS_DIR)/esp_netif/lwip -I $(COMPONENTS_DIR)/hal/include -I $(COMPONENTS_DIR)/hal/esp32/include -I $(COMPILER_ICLUDE_DIR)/include -I $(COMPONENTS_DIR)/bootloader_support/include
 TEST_NAME=test
 FUZZ=afl-fuzz
 GEN_CFG=generate_config

+ 14 - 2
components/mbedtls/port/aes/dma/esp_aes.c

@@ -93,6 +93,7 @@ static esp_pm_lock_handle_t s_pm_sleep_lock;
 #endif //SOC_PSRAM_DMA_CAPABLE
 
 static const char *TAG = "esp-aes";
+static bool s_check_dma_capable(const void *p);
 
 /* These are static due to:
  *  * Must be in DMA capable memory, so stack is not a safe place to put them
@@ -349,11 +350,11 @@ static int esp_aes_process_dma(esp_aes_context *ctx, const unsigned char *input,
         }
 #endif
         /* DMA cannot access memory in the iCache range, copy input to internal ram */
-        if (!esp_ptr_dma_ext_capable(input) && !esp_ptr_dma_capable(input)) {
+        if (!s_check_dma_capable(input)) {
             input_needs_realloc = true;
         }
 
-        if (!esp_ptr_dma_ext_capable(output) && !esp_ptr_dma_capable(output)) {
+        if (!s_check_dma_capable(output)) {
             output_needs_realloc = true;
         }
 
@@ -1040,3 +1041,14 @@ int esp_aes_crypt_ctr(esp_aes_context *ctx,
 
     return r;
 }
+
+static bool s_check_dma_capable(const void *p)
+{
+    bool is_capable = false;
+#if CONFIG_SPIRAM
+    is_capable |= esp_ptr_dma_ext_capable(p);
+#endif
+    is_capable |= esp_ptr_dma_capable(p);
+
+    return is_capable;
+}

+ 14 - 2
components/mbedtls/port/sha/dma/sha.c

@@ -68,6 +68,7 @@
 #endif
 
 const static char *TAG = "esp-sha";
+static bool s_check_dma_capable(const void *p);
 
 /* These are static due to:
  *  * Must be in DMA capable memory, so stack is not a safe place to put them
@@ -225,7 +226,7 @@ int esp_sha_dma(esp_sha_type sha_type, const void *input, uint32_t ilen,
     }
 
     /* DMA cannot access memory in flash, hash block by block instead of using DMA */
-    if (!esp_ptr_dma_ext_capable(input) && !esp_ptr_dma_capable(input) && (ilen != 0)) {
+    if (!s_check_dma_capable(input) && (ilen != 0)) {
         esp_sha_block_mode(sha_type, input, ilen, buf, buf_len, is_first_block);
         return 0;
     }
@@ -240,7 +241,7 @@ int esp_sha_dma(esp_sha_type sha_type, const void *input, uint32_t ilen,
 #endif
 
     /* Copy to internal buf if buf is in non DMA capable memory */
-    if (!esp_ptr_dma_ext_capable(buf) && !esp_ptr_dma_capable(buf) && (buf_len != 0)) {
+    if (!s_check_dma_capable(buf) && (buf_len != 0)) {
         dma_cap_buf = heap_caps_malloc(sizeof(unsigned char) * buf_len, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
         if (dma_cap_buf == NULL) {
             ESP_LOGE(TAG, "Failed to allocate buf memory");
@@ -326,3 +327,14 @@ static esp_err_t esp_sha_dma_process(esp_sha_type sha_type, const void *input, u
 
     return ret;
 }
+
+static bool s_check_dma_capable(const void *p)
+{
+    bool is_capable = false;
+#if CONFIG_SPIRAM
+    is_capable |= esp_ptr_dma_ext_capable(p);
+#endif
+    is_capable |= esp_ptr_dma_capable(p);
+
+    return is_capable;
+}

+ 0 - 204
components/soc/include/soc/soc_memory_types.h

@@ -1,204 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-
-#pragma once
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "soc/soc.h"
-#include "soc/soc_caps.h"
-#include "sdkconfig.h"
-#include "esp_attr.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-inline static bool IRAM_ATTR esp_ptr_dma_capable(const void *p)
-{
-    return (intptr_t)p >= SOC_DMA_LOW && (intptr_t)p < SOC_DMA_HIGH;
-}
-
-inline static bool IRAM_ATTR esp_ptr_dma_ext_capable(const void *p)
-{
-#ifdef SOC_PSRAM_DMA_CAPABLE
-    return (intptr_t)p >= SOC_DMA_EXT_LOW && (intptr_t)p < SOC_DMA_EXT_HIGH;
-#else
-    return false;
-#endif
-}
-
-inline static bool IRAM_ATTR esp_ptr_word_aligned(const void *p)
-{
-    return ((intptr_t)p) % 4 == 0;
-}
-
-inline static bool IRAM_ATTR esp_ptr_executable(const void *p)
-{
-    intptr_t ip = (intptr_t) p;
-    return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH)
-        || (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH)
-        || (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH)
-#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_FREERTOS_UNICORE)
-        || (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH)
-#endif
-#if SOC_RTC_FAST_MEM_SUPPORTED
-        || (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH)
-#endif
-    ;
-}
-
-inline static bool IRAM_ATTR esp_ptr_byte_accessible(const void *p)
-{
-    intptr_t ip = (intptr_t) p;
-    bool r;
-    r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH);
-#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
-    /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
-     * for single core configuration (where it gets added to system heap) following
-     * additional check is required */
-    r |= (ip >= SOC_RTC_DRAM_LOW && ip < SOC_RTC_DRAM_HIGH);
-#endif
-#if CONFIG_SPIRAM
-#if CONFIG_SPIRAM_SIZE != -1 // Fixed size, can be more accurate
-    r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_LOW + CONFIG_SPIRAM_SIZE));
-#else
-    r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_HIGH));
-#endif
-#endif
-    return r;
-}
-
-inline static bool IRAM_ATTR esp_ptr_internal(const void *p) {
-    bool r;
-    r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH);
-
-#if SOC_RTC_SLOW_MEM_SUPPORTED
-    r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
-#endif
-
-#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
-    /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
-     * for single core configuration (where it gets added to system heap) following
-     * additional check is required */
-    r |= ((intptr_t)p >= SOC_RTC_DRAM_LOW && (intptr_t)p < SOC_RTC_DRAM_HIGH);
-#endif
-    return r;
-}
-
-
-inline static bool IRAM_ATTR esp_ptr_external_ram(const void *p) {
-#if SOC_SPIRAM_SUPPORTED
-    return ((intptr_t)p >= SOC_EXTRAM_DATA_LOW && (intptr_t)p < SOC_EXTRAM_DATA_HIGH);
-#else
-    return false; // SoC has no external RAM
-#endif
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_iram(const void *p) {
-#if CONFIG_IDF_TARGET_ESP32 && CONFIG_FREERTOS_UNICORE
-    return ((intptr_t)p >= SOC_CACHE_APP_LOW && (intptr_t)p < SOC_IRAM_HIGH);
-#else
-    return ((intptr_t)p >= SOC_IRAM_LOW && (intptr_t)p < SOC_IRAM_HIGH);
-#endif
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_drom(const void *p) {
-    return ((intptr_t)p >= SOC_DROM_LOW && (intptr_t)p < SOC_DROM_HIGH);
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_dram(const void *p) {
-    return ((intptr_t)p >= SOC_DRAM_LOW && (intptr_t)p < SOC_DRAM_HIGH);
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_diram_dram(const void *p) {
-    return ((intptr_t)p >= SOC_DIRAM_DRAM_LOW && (intptr_t)p < SOC_DIRAM_DRAM_HIGH);
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_diram_iram(const void *p) {
-    return ((intptr_t)p >= SOC_DIRAM_IRAM_LOW && (intptr_t)p < SOC_DIRAM_IRAM_HIGH);
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_rtc_iram_fast(const void *p) {
-#if SOC_RTC_FAST_MEM_SUPPORTED
-    return ((intptr_t)p >= SOC_RTC_IRAM_LOW && (intptr_t)p < SOC_RTC_IRAM_HIGH);
-#else
-    return false;
-#endif
-}
-inline static bool IRAM_ATTR esp_ptr_in_rtc_dram_fast(const void *p) {
-#if SOC_RTC_FAST_MEM_SUPPORTED
-    return ((intptr_t)p >= SOC_RTC_DRAM_LOW && (intptr_t)p < SOC_RTC_DRAM_HIGH);
-#else
-    return false;
-#endif
-}
-
-inline static bool IRAM_ATTR esp_ptr_in_rtc_slow(const void *p) {
-#if SOC_RTC_SLOW_MEM_SUPPORTED
-    return ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
-#else
-    return false;
-#endif
-}
-
-
-/* Convert a D/IRAM DRAM pointer to equivalent word address in IRAM
-
-   - Address must be word aligned
-   - Address must pass esp_ptr_in_diram_dram() test, or result will be invalid pointer
-*/
-inline static void * IRAM_ATTR esp_ptr_diram_dram_to_iram(const void *p) {
-#if SOC_DIRAM_INVERTED
-    return (void *) ( SOC_DIRAM_IRAM_LOW + (SOC_DIRAM_DRAM_HIGH - (intptr_t)p) - 4);
-#else
-    return (void *) ( SOC_DIRAM_IRAM_LOW + ((intptr_t)p - SOC_DIRAM_DRAM_LOW) );
-#endif
-}
-
-/* Convert a D/IRAM IRAM pointer to equivalent word address in DRAM
-
-   - Address must be word aligned
-   - Address must pass esp_ptr_in_diram_iram() test, or result will be invalid pointer
-*/
-inline static void * IRAM_ATTR esp_ptr_diram_iram_to_dram(const void *p) {
-#if SOC_DIRAM_INVERTED
-    return (void *) ( SOC_DIRAM_DRAM_LOW + (SOC_DIRAM_IRAM_HIGH - (intptr_t)p) - 4);
-#else
-    return (void *) ( SOC_DIRAM_DRAM_LOW + ((intptr_t)p - SOC_DIRAM_IRAM_LOW) );
-#endif
-}
-
-inline static bool IRAM_ATTR esp_stack_ptr_in_dram(uint32_t sp)
-{
-    //Check if stack ptr is in between SOC_DRAM_LOW and SOC_DRAM_HIGH, and 16 byte aligned.
-    return !(sp < SOC_DRAM_LOW + 0x10 || sp > SOC_DRAM_HIGH - 0x10 || ((sp & 0xF) != 0));
-}
-
-#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
-inline static bool IRAM_ATTR esp_stack_ptr_in_extram(uint32_t sp)
-{
-    //Check if stack ptr is in between SOC_EXTRAM_DATA_LOW and SOC_EXTRAM_DATA_HIGH, and 16 byte aligned.
-    return !(sp < SOC_EXTRAM_DATA_LOW + 0x10 || sp > SOC_EXTRAM_DATA_HIGH - 0x10 || ((sp & 0xF) != 0));
-}
-#endif
-
-inline static bool IRAM_ATTR esp_stack_ptr_is_sane(uint32_t sp)
-{
-    return esp_stack_ptr_in_dram(sp)
-#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
-        || esp_stack_ptr_in_extram(sp)
-#endif
-#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
-        || esp_ptr_in_rtc_dram_fast((void*) sp)
-#endif
-        ;
-}
-
-#ifdef __cplusplus
-}
-#endif

+ 11 - 2
components/spi_flash/esp_flash_api.c

@@ -9,6 +9,7 @@
 #include <sys/param.h>
 #include <string.h>
 
+#include "esp_memory_utils.h"
 #include "spi_flash_chip_driver.h"
 #include "memspi_host_driver.h"
 #include "esp_log.h"
@@ -782,7 +783,11 @@ esp_err_t IRAM_ATTR esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t add
     }
 
     //when the cache is disabled, only the DRAM can be read, check whether we need to receive in another buffer in DRAM.
-    bool direct_read = chip->host->driver->supports_direct_read(chip->host, buffer);
+    bool direct_read = false;
+    //If the buffer is internal already, it's ok to use it directly
+    direct_read |= esp_ptr_in_dram(buffer);
+    //If not, we need to check if the HW support direct write
+    direct_read |= chip->host->driver->supports_direct_read(chip->host, buffer);
     uint8_t* temp_buffer = NULL;
 
     //each time, we at most read this length
@@ -850,7 +855,11 @@ esp_err_t IRAM_ATTR esp_flash_write(esp_flash_t *chip, const void *buffer, uint3
     }
 
     //when the cache is disabled, only the DRAM can be read, check whether we need to copy the data first
-    bool direct_write = chip->host->driver->supports_direct_write(chip->host, buffer);
+    bool direct_write = false;
+    //If the buffer is internal already, it's ok to write it directly
+    direct_write |= esp_ptr_in_dram(buffer);
+    //If not, we need to check if the HW support direct write
+    direct_write |= chip->host->driver->supports_direct_write(chip->host, buffer);
 
     // Indicate whether the bus is acquired by the driver, needs to be released before return
     bool bus_acquired = false;

+ 10 - 13
components/spi_flash/memspi_host_driver.c

@@ -1,16 +1,8 @@
-// Copyright 2015-2019 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
+ */
 
 #include "soc/soc_caps.h"
 #include "spi_flash_defs.h"
@@ -19,6 +11,7 @@
 #include "esp_log.h"
 #include "cache_utils.h"
 #include "esp_flash_partitions.h"
+#include "esp_memory_utils.h"
 
 
 #define SPI_FLASH_HAL_MAX_WRITE_BYTES 64
@@ -69,6 +62,10 @@ static const spi_flash_host_driver_t esp_flash_gpspi_host = {
 
 esp_err_t memspi_host_init_pointers(memspi_host_inst_t *host, const memspi_host_config_t *cfg)
 {
+    if (!esp_ptr_internal(host) && cfg->host_id == SPI1_HOST) {
+        return ESP_ERR_INVALID_ARG;
+    }
+
 #if SOC_MEMSPI_IS_INDEPENDENT
     if (cfg->host_id == SPI1_HOST)
         host->inst.driver = &esp_flash_default_host;

+ 1 - 1
docs/en/migration-guides/system.rst

@@ -55,6 +55,7 @@ SOC dependency
 
 - Public API headers who are listed in the Doxyfiles won't expose unstable and unnecessary soc header files like ``soc/soc.h``, ``soc/rtc.h``. That means, the user has to explicitly include them in their code if these "missing" header files are still wanted.
 - Kconfig option ``LEGACY_INCLUDE_COMMON_HEADERS`` is also removed.
+- The header file ``soc/soc_memory_types.h`` has been deprecated. Users should use the ``esp_memory_utils.h`` instead. Including `soc/soc_memory_types.h` will bring a build warning like `soc_memory_types.h is deprecated, please migrate to esp_memory_utils.h`
 
 APP Trace
 ---------
@@ -65,4 +66,3 @@ ESP Timer
 ---------
 
 Removed the FRC2 based legacy implementation of esp_timer available on ESP32. The simpler and more efficient implementation based on the LAC timer is now the only option.
-

+ 0 - 5
tools/ci/check_copyright_ignore.txt

@@ -926,8 +926,6 @@ components/hal/include/hal/sha_hal.h
 components/hal/include/hal/sigmadelta_hal.h
 components/hal/include/hal/soc_hal.h
 components/hal/include/hal/spi_flash_encrypt_hal.h
-components/hal/include/hal/spi_flash_hal.h
-components/hal/include/hal/spi_flash_types.h
 components/hal/include/hal/spi_slave_hal.h
 components/hal/include/hal/spi_slave_hd_hal.h
 components/hal/include/hal/systimer_hal.h
@@ -955,7 +953,6 @@ components/hal/sha_hal.c
 components/hal/sigmadelta_hal.c
 components/hal/soc_hal.c
 components/hal/spi_flash_encrypt_hal_iram.c
-components/hal/spi_flash_hal.c
 components/hal/spi_flash_hal_gpspi.c
 components/hal/spi_slave_hal.c
 components/hal/spi_slave_hal_iram.c
@@ -977,7 +974,6 @@ components/heap/heap_trace_standalone.c
 components/heap/include/esp_heap_task_info.h
 components/heap/include/esp_heap_trace.h
 components/heap/include/heap_memory_layout.h
-components/heap/include/soc/soc_memory_layout.h
 components/heap/multi_heap_config.h
 components/heap/multi_heap_internal.h
 components/heap/multi_heap_poisoning.c
@@ -1631,7 +1627,6 @@ components/spi_flash/include/spi_flash_chip_generic.h
 components/spi_flash/include/spi_flash_chip_issi.h
 components/spi_flash/include/spi_flash_chip_mxic.h
 components/spi_flash/include/spi_flash_chip_winbond.h
-components/spi_flash/memspi_host_driver.c
 components/spi_flash/sim/SpiFlash.cpp
 components/spi_flash/sim/flash_mock.cpp
 components/spi_flash/sim/flash_mock_util.c