mm_flag.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-23 WangXiaoyao the first version
  9. */
  10. #ifndef __MM_FLAG_H__
  11. #define __MM_FLAG_H__
  12. /**
  13. * @brief mm_flag_t
  14. * |max ------- 7|6 ----- 0|
  15. * | control | align |
  16. *
  17. * there should be no more than 25 flags
  18. */
  19. typedef unsigned long mm_flag_t;
  20. #define _MMF_CNTL_SHIFT 7
  21. #define _MMF_ALIGN_MASK 0x7f
  22. #define _MMF_CNTL_MASK (~((1 << _MMF_CNTL_SHIFT) - 1))
  23. #define _DEF_FLAG(index) (1 << (_MMF_CNTL_SHIFT + (index)))
  24. enum mm_flag_cntl
  25. {
  26. /**
  27. * @brief Indicate a possible COW mapping
  28. */
  29. MMF_MAP_PRIVATE = _DEF_FLAG(0),
  30. MMF_COW = _DEF_FLAG(1),
  31. /**
  32. * @brief [POSIX MAP_FIXED] When MAP_FIXED is set in the flags argument, the
  33. * implementation is informed that the value of pa shall be addr, exactly.
  34. * If a MAP_FIXED request is successful, the mapping established
  35. * by mmap() replaces any previous mappings for the pages in the range
  36. * [pa,pa+len) of the process.
  37. */
  38. MMF_MAP_FIXED = _DEF_FLAG(2),
  39. /**
  40. * @brief The backup page frame is allocated and setted only until it is
  41. * truly necessary by the user
  42. */
  43. MMF_PREFETCH = _DEF_FLAG(3),
  44. MMF_HUGEPAGE = _DEF_FLAG(4),
  45. MMF_TEXT = _DEF_FLAG(5),
  46. /**
  47. * @brief a non-locked memory can be swapped out when required, this is
  48. * reserved for future
  49. */
  50. MMF_NONLOCKED = _DEF_FLAG(20),
  51. /**
  52. * @brief An alignment is specified in flags that the mapping must admit
  53. */
  54. MMF_REQUEST_ALIGN = _DEF_FLAG(21),
  55. };
  56. #define MMF_GET_ALIGN(src) ((src & _MMF_ALIGN_MASK))
  57. #define MMF_SET_ALIGN(src, align) \
  58. ((src & ~_MMF_ALIGN_MASK) | (__builtin_ffsl(align) - 1))
  59. #define MMF_GET_CNTL(src) (src & _MMF_CNTL_MASK)
  60. #define MMF_TEST_CNTL(src, flag) (src & flag)
  61. #define MMF_SET_CNTL(src, flag) ((src) | (flag))
  62. #define MMF_CLEAR_CNTL(src, flag) ((src) & ~(flag))
  63. /**
  64. * @brief Create Flags
  65. *
  66. * example: MMF_CREATE(0, 0)
  67. * MMF_CREATE(MM_MAP_FIXED, 0x2000)
  68. *
  69. * Direct use of flag is also acceptable: (MMF_MAP_FIXED | MMF_PREFETCH)
  70. */
  71. #define MMF_CREATE(cntl, align) \
  72. (align ? (MMF_SET_CNTL((mm_flag_t)0, (cntl) | MMF_REQUEST_ALIGN) | \
  73. MMF_SET_ALIGN((mm_flag_t)0, align)) \
  74. : (MMF_SET_CNTL((mm_flag_t)0, (cntl) & ~MMF_REQUEST_ALIGN)))
  75. #undef _DEF_FLAG
  76. #endif /* __MM_FLAG_H__ */