mmu_defs.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*!
  2. *****************************************************************************
  3. *
  4. * @File mmu_defs.h
  5. * @Description Internal MMU library header used to define MMU information at
  6. * compilation time and have access to the error printing functions
  7. * ---------------------------------------------------------------------------
  8. *
  9. * Copyright (c) Imagination Technologies Ltd.
  10. *
  11. * The contents of this file are subject to the MIT license as set out below.
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in
  21. * all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. * THE SOFTWARE.
  30. *
  31. * Alternatively, the contents of this file may be used under the terms of the
  32. * GNU General Public License Version 2 ("GPL")in which case the provisions of
  33. * GPL are applicable instead of those above.
  34. *
  35. * If you wish to allow use of your version of this file only under the terms
  36. * of GPL, and not to allow others to use your version of this file under the
  37. * terms of the MIT license, indicate your decision by deleting the provisions
  38. * above and replace them with the notice and other provisions required by GPL
  39. * as set out in the file called "GPLHEADER" included in this distribution. If
  40. * you do not delete the provisions above, a recipient may use your version of
  41. * this file under the terms of either the MIT license or GPL.
  42. *
  43. * This License is also included in this distribution in the file called
  44. * "MIT_COPYING".
  45. *
  46. *****************************************************************************/
  47. #ifndef MMU_DEFS_H
  48. #define MMU_DEFS_H
  49. #include <stdarg.h>
  50. /**
  51. * @addtogroup IMGMMU_lib
  52. * @{
  53. */
  54. /*-------------------------------------------------------------------------
  55. * Following elements are in the IMGMMU_int documentation module
  56. *------------------------------------------------------------------------*/
  57. #ifndef IMGMMU_PHYS_SIZE
  58. /** @brief MMU physical address size in bits */
  59. #define IMGMMU_PHYS_SIZE 40
  60. #endif
  61. #ifndef IMGMMU_VIRT_SIZE
  62. /** @brief MMU virtual address size in bits */
  63. #define IMGMMU_VIRT_SIZE 40
  64. #endif
  65. /** @brief Page size in bytes used at PC & PD (always 4k),
  66. * PT may use variable page size */
  67. #define IMGMMU_PAGE_SIZE 4096u
  68. /** should be log2(IMGMMU_PAGE_SIZE)*3-6 */
  69. #define IMGMMU_CAT_SHIFT 30
  70. /** should be log2(IMGMMU_PAGE_SIZE)*2-3 */
  71. #define IMGMMU_DIR_SHIFT 21
  72. /** should be log2(IMGMMU_PAGE_SIZE) */
  73. #define IMGMMU_PAGE_SHIFT 12
  74. #if IMGMMU_VIRT_SIZE == 40
  75. /**
  76. * @brief maximum number of directories that
  77. * can be stored in the catalogue entry
  78. */
  79. #define IMGMMU_N_DIR (IMGMMU_PAGE_SIZE/4u)
  80. /**
  81. * @brief maximum number of pagetables that
  82. * can be stored in the directory entry
  83. */
  84. #define IMGMMU_N_TABLE (IMGMMU_PAGE_SIZE/8u)
  85. /**
  86. * @brief maximum number of page mappings in the pagetable
  87. * for variable page size
  88. */
  89. #define IMGMMU_N_PAGE (IMGMMU_PAGE_SIZE/ \
  90. ((imgmmu_get_page_size()/IMGMMU_PAGE_SIZE)*8u))
  91. #else
  92. /* it is unlikely to change anyway */
  93. #error "need an update for the new virtual address size"
  94. #endif
  95. /** @brief Memory flag used to mark a page mapping as invalid */
  96. #define MMU_FLAG_VALID 0x1
  97. #define MMU_FLAG_INVALID 0x0
  98. /** @brief Other memory flags */
  99. #define MMU_FLAG_READ_ONLY 0x2
  100. /** @brief PTE entry cache bits mask */
  101. #define MMU_PTE_AXCACHE_MASK 0x3C00000000000000UL
  102. /** @brief PTE entry cache bits shift */
  103. #define MMU_PTE_AXCACHE_SHIFT 58
  104. /** @brief PTE entry parity bit shift */
  105. #define MMU_PTE_PARITY_SHIFT 62
  106. /*
  107. * internal printing functions
  108. */
  109. __printf(4, 5)
  110. void _mmu_log(int err, const char *function, uint32_t line, const char *format, ...);
  111. #define mmu_log_err(...) _mmu_log(1, __func__, __LINE__, __VA_ARGS__)
  112. #define mmu_log_dbg(...)
  113. /*
  114. * #define mmu_log_dbg(...) _mmu_log(0, __func__, __LINE__, __VA_ARGS__)
  115. */
  116. /**
  117. * @}
  118. */
  119. /*-------------------------------------------------------------------------
  120. * End of the IMGMMU_int documentation module
  121. *------------------------------------------------------------------------*/
  122. #endif /* MMU_DEFS_H */