mmu.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2008-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. //! @addtogroup diag_mmu
  31. //! @{
  32. /*!
  33. * @file mmu.h
  34. * @brief System memory arrangement.
  35. */
  36. #ifndef _MMU_H_
  37. #define _MMU_H_
  38. #include "sdk.h"
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // Definitions
  41. ////////////////////////////////////////////////////////////////////////////////
  42. //! @brief Memory region attributes.
  43. typedef enum _mmu_memory_type
  44. {
  45. kStronglyOrdered,
  46. kDevice,
  47. kOuterInner_WB_WA,
  48. kOuterInner_WT,
  49. kNoncacheable,
  50. } mmu_memory_type_t;
  51. //! @brief Memory region shareability options.
  52. typedef enum _mmu_shareability
  53. {
  54. kShareable = 1,
  55. kNonshareable = 0
  56. } mmu_shareability_t;
  57. //! @brief Access permissions for a memory region.
  58. typedef enum _mmu_access
  59. {
  60. kNoAccess,
  61. kROAccess,
  62. kRWAccess
  63. } mmu_access_t;
  64. ////////////////////////////////////////////////////////////////////////////////
  65. // Prototypes
  66. ////////////////////////////////////////////////////////////////////////////////
  67. #if defined(__cplusplus)
  68. extern "C" {
  69. #endif
  70. /*!
  71. * @brief Enable the MMU.
  72. *
  73. * The L1 page tables and MMU settings must have already been configured by
  74. * calling mmu_init() before the MMU is enabled.
  75. */
  76. void mmu_enable();
  77. /*!
  78. * @brief Disable the MMU.
  79. */
  80. void mmu_disable();
  81. /*!
  82. * @brief Set up the default first-level page table.
  83. *
  84. * Initializes the L1 page table with the following regions:
  85. * - 0x00000000...0x00900000 : ROM and peripherals, strongly-ordered
  86. * - 0x00900000...0x00a00000 : OCRAM, strongly-ordered
  87. * - For MX6DQ or MX6SDL: 0x10000000...0x90000000 : DDR, normal, outer inner, write-back, write-allocate
  88. * - For MX6SL: 0x80000000...0xc0000000 : DDR, normal, outer inner, write-back, write-allocate
  89. *
  90. * If the CPU is participating in SMP, then the DDR regions are made shareable. Otherwise they
  91. * are marked as non-shareable.
  92. *
  93. * The TTBR0 register is set to the base of the L1 table.
  94. *
  95. * All memory domains are configured to allow client access. However, note that only domain 0 is
  96. * used by mmu_map_l1_range().
  97. */
  98. void mmu_init();
  99. /*!
  100. * @brief Maps a range of memory in the first-level page table.
  101. *
  102. * Entries in the first-level page table are filled in for the range of virtual addresses
  103. * starting at @a va and continuing for @a length bytes. These virtual addreses are mapped
  104. * to the physical addresses starting at @a pa and continuing for @a length bytes. All table
  105. * entries for the range of mapped memory have the same attributes, which are selected with
  106. * the @a memoryType, @a isShareable, and @a access parameters.
  107. *
  108. * @param pa The base physical address of the range to which the virtual address will be mapped.
  109. * @param va The base virtual address of the range.
  110. * @param length The size of the range to be mapped, in bytes. This value must be divisible by 1MB.
  111. * @param memoryType The type of the memory region. This controls caching, buffering, ordering of
  112. * memory accesses, and other attributes of the region.
  113. * @param isShareable The shareability of the physical memory. Ignored for strongly-ordered memory.
  114. * @param access Access permissions.
  115. */
  116. void mmu_map_l1_range(uint32_t pa, uint32_t va, uint32_t length, mmu_memory_type_t memoryType, mmu_shareability_t isShareable, mmu_access_t access);
  117. /*!
  118. * @brief Convert virtual address to physical.
  119. *
  120. * First attempts a priviledged read translation for the current security mode. If that fails,
  121. * a priviledged write translation, also for the current security mode, is attempted. If this
  122. * second attempt at translation fails, then false will be returned.
  123. *
  124. * @param virtualAddress Virtual address to convert to a physical address.
  125. * @param[out] physicalAddress This parameter is filled in with the physical address corresponding
  126. * to the virtual address passed in @a virtualAddress.
  127. * @retval true The address returned through @a physicalAddress is valid.
  128. * @retval false The conversion failed for some reason.
  129. */
  130. bool mmu_virtual_to_physical(uint32_t virtualAddress, uint32_t * physicalAddress);
  131. #if defined(__cplusplus)
  132. }
  133. #endif
  134. //! @}
  135. #endif // _MMU_H_
  136. ////////////////////////////////////////////////////////////////////////////////
  137. // EOF
  138. ////////////////////////////////////////////////////////////////////////////////