1
0

mm_private.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-14 WangXiaoyao the first version
  9. */
  10. #ifndef __MM_PRIVATE_H__
  11. #define __MM_PRIVATE_H__
  12. #include "mm_aspace.h"
  13. #include "mm_fault.h"
  14. #include "mm_flag.h"
  15. #include "mm_page.h"
  16. #include <rtdef.h>
  17. #include <stddef.h>
  18. /**
  19. * @brief DATA STRUCTURE & API USED INTERNALLY
  20. *
  21. * This is mainly a wrapper layer to actual data structure.
  22. * In this way, we can switch to any BST we like by adding new
  23. * wrapper code.
  24. * Every BST must satisfy the API to support MM
  25. *
  26. * *INFO: varea range convention
  27. * For API, a range is specified by a base and its length.
  28. * This provides a clear interface without ambiguity.
  29. * For implementation, a range is specified by [start, end] tuple
  30. * where both start and end are inclusive.
  31. */
  32. #define VAREA_NOT_STATIC(varea) (!((varea)->flag & MMF_STATIC_ALLOC))
  33. #define VAREA_NAME(varea) \
  34. ((!varea->mem_obj || !varea->mem_obj->get_name) \
  35. ? "unknow" \
  36. : varea->mem_obj->get_name(varea))
  37. /* only user address use COW technique, so user permission is always checked */
  38. #define VAREA_IS_WRITABLE(varea) \
  39. (rt_hw_mmu_attr_test_perm(varea->attr, \
  40. RT_HW_MMU_PROT_USER | RT_HW_MMU_PROT_WRITE))
  41. #define VAREA_VA_TO_OFFSET(varea, va) \
  42. ((varea)->offset + MM_PA_TO_OFF((long)(va) - (long)(varea)->start))
  43. struct _mm_range
  44. {
  45. void *start;
  46. void *end;
  47. };
  48. /**
  49. * @brief
  50. *
  51. * @param aspace
  52. * @return rt_err_t
  53. */
  54. rt_err_t _aspace_bst_init(struct rt_aspace *aspace);
  55. /**
  56. * @brief Retrieve any varea if start in [varea->start, varea->end]
  57. *
  58. * @param aspace
  59. * @param start
  60. * @return struct rt_varea*
  61. */
  62. struct rt_varea *_aspace_bst_search(struct rt_aspace *aspace, void *start);
  63. /**
  64. * @brief Retrieve lowest varea satisfies (varea->start >= start)
  65. *
  66. * @param aspace
  67. * @param length
  68. * @param struct _mm_range
  69. * @return struct rt_varea*
  70. */
  71. struct rt_varea *_aspace_bst_search_exceed(struct rt_aspace *aspace,
  72. void *start);
  73. /**
  74. * @brief Retrieve any varea overlaps a specified address range
  75. *
  76. * @param aspace
  77. * @param start
  78. * @param length
  79. * @return struct rt_varea*
  80. */
  81. struct rt_varea *_aspace_bst_search_overlap(struct rt_aspace *aspace,
  82. struct _mm_range range);
  83. /**
  84. * @brief Insert a varea into the bst
  85. *
  86. * @param aspace
  87. * @param varea
  88. */
  89. void _aspace_bst_insert(struct rt_aspace *aspace, struct rt_varea *varea);
  90. /**
  91. * @brief Remove a varea from the bst
  92. *
  93. * @param aspace
  94. * @param varea
  95. */
  96. void _aspace_bst_remove(struct rt_aspace *aspace, struct rt_varea *varea);
  97. int rt_varea_fix_private_locked(rt_varea_t ex_varea, void *pa,
  98. struct rt_aspace_fault_msg *msg,
  99. rt_bool_t dont_copy);
  100. int rt_varea_map_with_msg(rt_varea_t varea, struct rt_aspace_fault_msg *msg);
  101. void _varea_uninstall_locked(rt_varea_t varea);
  102. int _mm_aspace_map(rt_aspace_t aspace, rt_varea_t *pvarea, void **addr,
  103. rt_size_t length, rt_size_t attr, mm_flag_t flags,
  104. rt_mem_obj_t mem_obj, rt_size_t offset);
  105. rt_inline rt_bool_t rt_varea_is_private_locked(rt_varea_t varea)
  106. {
  107. rt_base_t flags = varea->flag;
  108. return !!(
  109. (flags & (MMF_MAP_PRIVATE | MMF_MAP_PRIVATE_DONT_SYNC))
  110. && (varea->aspace->private_object != varea->mem_obj)
  111. );
  112. }
  113. rt_err_t rt_aspace_anon_ref_dec(rt_mem_obj_t aobj);
  114. rt_err_t rt_aspace_page_get_phy(rt_aspace_t aspace, void *page_va, void *buffer);
  115. rt_err_t rt_aspace_page_put_phy(rt_aspace_t aspace, void *page_va, void *buffer);
  116. #endif /* __MM_PRIVATE_H__ */