mmu_psram_flash.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @Backgrounds
  8. *
  9. * This file contains 2 parts:
  10. * 1. Feature: Copy Flash content to PSRAM. Related APIs are private:
  11. * - mmu_config_psram_text_segment()
  12. * - mmu_config_psram_rodata_segment()
  13. *
  14. * 2. Private APIs used by `flash_mmap.c` and `cache_utils.c`
  15. * APIs in 2 are due to lack of MMU driver. There will be an MMU driver to maintain vaddr range.
  16. * APIs in 2 will be refactored when MMU driver is ready
  17. */
  18. #pragma once
  19. #include <sys/param.h>
  20. #include "esp_err.h"
  21. #include "sdkconfig.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if CONFIG_IDF_TARGET_ESP32
  26. #define MMU_PAGE_SIZE 0x8000
  27. #else
  28. #define MMU_PAGE_SIZE 0x10000
  29. #define MMU_PAGE_TO_BYTES(page_id) ((page_id) * MMU_PAGE_SIZE)
  30. #define BYTES_TO_MMU_PAGE(bytes) ((bytes) / MMU_PAGE_SIZE)
  31. #endif
  32. /*----------------------------------------------------------------------------
  33. Part 1 APIs (See @Backgrounds on top of this file)
  34. -------------------------------------------------------------------------------*/
  35. #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  36. /**
  37. * @brief Copy Flash texts to PSRAM
  38. *
  39. * @param[in] start_page PSRAM physical start page
  40. * @param[in] psram_size PSRAM available size
  41. * @param[out] out_page Used pages
  42. */
  43. esp_err_t mmu_config_psram_text_segment(uint32_t start_page, uint32_t psram_size, uint32_t *out_page);
  44. #endif //#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  45. #if CONFIG_SPIRAM_RODATA
  46. /**
  47. * @brief Copy Flash rodata to PSRAM
  48. *
  49. * @param[in] start_page PSRAM physical start page
  50. * @param[in] psram_size PSRAM available size
  51. * @param[out] out_page Used pages
  52. */
  53. esp_err_t mmu_config_psram_rodata_segment(uint32_t start_page, uint32_t psram_size, uint32_t *out_page);
  54. #endif //#if CONFIG_SPIRAM_RODATA
  55. /*----------------------------------------------------------------------------
  56. Part 2 APIs (See @Backgrounds on top of this file)
  57. -------------------------------------------------------------------------------*/
  58. #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  59. /**
  60. * @brief Init other file requested MMU variables
  61. *
  62. * - These logics are abstracted from the PSRAM driver
  63. * - These functions are only required by `flash_mmap.c` for converting paddr to vaddr, and vice versa
  64. * - The `flash_mmpa.c` will be rewritten into MMU driver
  65. *
  66. * Therefore, keep the APIs here for now
  67. */
  68. void instruction_flash_page_info_init(uint32_t psram_start_physical_page);
  69. /**
  70. * @brief Get the start page number of the instruction in SPI flash
  71. *
  72. * @return start page number
  73. */
  74. uint32_t instruction_flash_start_page_get(void);
  75. /**
  76. * @brief Get the end page number of the instruction in SPI flash
  77. *
  78. * @return end page number
  79. */
  80. uint32_t instruction_flash_end_page_get(void);
  81. /**
  82. * @brief Get the offset of instruction from SPI flash to SPI RAM
  83. *
  84. * @return instruction offset
  85. */
  86. int instruction_flash2spiram_offset(void);
  87. #endif // #if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
  88. #if CONFIG_SPIRAM_RODATA
  89. /**
  90. * @brief Init other file requested MMU variables
  91. *
  92. * - These logics are abstracted from the PSRAM driver
  93. * - These functions are only required by `flash_mmap.c` for converting paddr to vaddr, and vice versa
  94. * - The `flash_mmpa.c` will be rewritten into MMU driver
  95. *
  96. * Therefore, keep the APIs here for now
  97. */
  98. void rodata_flash_page_info_init(uint32_t psram_start_physical_page);
  99. /**
  100. * @brief Get the start page number of the rodata in SPI flash
  101. *
  102. * @return start page number
  103. */
  104. uint32_t rodata_flash_start_page_get(void);
  105. /**
  106. * @brief Get the end page number of the rodata in SPI flash
  107. *
  108. * @return end page number
  109. */
  110. uint32_t rodata_flash_end_page_get(void);
  111. /**
  112. * @brief Get the offset number of rodata from SPI flash to SPI RAM
  113. *
  114. * @return rodata offset
  115. */
  116. int rodata_flash2spiram_offset(void);
  117. #endif // #if CONFIG_SPIRAM_RODATA
  118. #ifdef __cplusplus
  119. }
  120. #endif