hal_mmu.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HAL_MMU_H_
  13. #define _HAL_MMU_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "hal_config.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. // MMU table uses a simple model
  22. // * Use L1 if possible
  23. // * L2 is used for SRAM, pages used by CP can be set to RO
  24. // * L2 page is used for ONE L1 entry. Shared memory pages can be set to RW
  25. // and others can be set to RO
  26. // * AP memory should be started at L1 (1MB) boundary.
  27. enum
  28. {
  29. HAL_MMU_ACCESS_CACHE_RWX,
  30. HAL_MMU_ACCESS_CACHE_RX,
  31. HAL_MMU_ACCESS_CACHE_R,
  32. HAL_MMU_ACCESS_UNCACHE_RWX,
  33. HAL_MMU_ACCESS_UNCACHE_RX,
  34. HAL_MMU_ACCESS_UNCACHE_R,
  35. HAL_MMU_ACCESS_DEVICE_RW,
  36. HAL_MMU_ACCESS_DEVICE_R
  37. };
  38. /**
  39. * \brief create initial MMU table
  40. *
  41. * For 8910, the initial MMU table is:
  42. * - ROM (1M) uses 4K page
  43. * - SRAM (1M) uses 4K page
  44. * - RAM (CONFIG_RAM_SIZE) uses 4K page
  45. * - Others uses 1M section
  46. *
  47. * Section or page properties:
  48. * - ROM: The first page is NO_ACCESS to detect NULL access, other pages
  49. * are NORMAL_RX.
  50. * - SRAM: (CONFIG_APP_SRAM_SHMEM_OFFSET, CONFIG_APP_SRAM_SHMEM_SIZE) is NC_RW,
  51. * other pages are NORMAL_RWX. After memory list is loaded, it will
  52. * be changed later.
  53. * - RAM: NORMAL_RWX
  54. * - FLASH: (0x60000000, 0x20000000) is NORMAL_RX
  55. * - (0x880000, 0x80000): DEVICE_RW
  56. * - (0x900000, ): DEVICE_RW
  57. */
  58. void halMmuCreateTable(void);
  59. /**
  60. * \brief set range MMU properties
  61. *
  62. * For 8910, the implicit rules for section and pages will be applied.
  63. *
  64. * When the region uses 4K page, \p start will be *aligned down*,
  65. * \p (start + size) will be *aligned up*. That is, when \p start and
  66. * \p size are not 4K aligned, the actual changed range will be no less
  67. * than the specified range. However, it is recommended to set \p start
  68. * and \p size as 4K aligned.
  69. *
  70. * When the region uses 1M section, and \p start or \p size is not 1MB
  71. * aligned, system will panic.
  72. *
  73. * Note: this is designed for batch set. So, cache coherence isn't called
  74. * inside. Caller should take care of cache coherence. An example:
  75. *
  76. * \code{.cpp}
  77. * L1C_CleanDCacheAll();
  78. * halMmuSetAccess(...);
  79. * halMmuSetAccess(...);
  80. * ......
  81. * L1C_CleanDCacheAll();
  82. * MMU_InvalidateTLB();
  83. * \endcode
  84. *
  85. * \param start range start
  86. * \param size range size
  87. * \param access range MMU property
  88. */
  89. void halMmuSetAccess(uintptr_t start, size_t size, uint32_t access);
  90. /**
  91. * \brief enable or disable NULL pointer protection
  92. *
  93. * When enabled, the first page at address 0 is set as inaccessible. It can
  94. * detect NULL pointer access (usually illegal) earlier.
  95. *
  96. * However, ROM is located at address 0. To enable ROM access, this
  97. * protection should be disabled.
  98. *
  99. * Unlike \p halMmuSetAccess, cache and tlb coherence will be handled inside.
  100. *
  101. * \param enable true for enable address 0 protection, inaccessible
  102. */
  103. void halMmuSetNullProtection(bool enable);
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif