mmu.h 3.3 KB

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