mm_private.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <rtdef.h>
  14. #include <stddef.h>
  15. /**
  16. * @brief DATA STRUCTURE & API USED INTERNALLY
  17. *
  18. * This is mainly a wrapper layer to actual data structure.
  19. * In this way, we can switch to any BST we like by adding new
  20. * wrapper code.
  21. * Every BST must satisfy the API to support MM
  22. *
  23. * *INFO: varea range convention
  24. * For API, a range is specified by a base and its length.
  25. * This provides a clear interface without ambiguity.
  26. * For implementation, a range is specified by [start, end] tuple
  27. * where both start and end are inclusive.
  28. */
  29. struct _mm_range
  30. {
  31. void *start;
  32. void *end;
  33. };
  34. /**
  35. * @brief
  36. *
  37. * @param aspace
  38. * @return rt_err_t
  39. */
  40. rt_err_t _aspace_bst_init(struct rt_aspace *aspace);
  41. /**
  42. * @brief Retrieve any varea if start in [varea->start, varea->end]
  43. *
  44. * @param aspace
  45. * @param start
  46. * @return struct rt_varea*
  47. */
  48. struct rt_varea *_aspace_bst_search(struct rt_aspace *aspace, void *start);
  49. /**
  50. * @brief Retrieve lowest varea satisfies (varea->start >= start)
  51. *
  52. * @param aspace
  53. * @param length
  54. * @param struct _mm_range
  55. * @return struct rt_varea*
  56. */
  57. struct rt_varea *_aspace_bst_search_exceed(struct rt_aspace *aspace,
  58. void *start);
  59. /**
  60. * @brief Retrieve any varea overlaps a specified address range
  61. *
  62. * @param aspace
  63. * @param start
  64. * @param length
  65. * @return struct rt_varea*
  66. */
  67. struct rt_varea *_aspace_bst_search_overlap(struct rt_aspace *aspace,
  68. struct _mm_range range);
  69. /**
  70. * @brief Insert a varea into the bst
  71. *
  72. * @param aspace
  73. * @param varea
  74. */
  75. void _aspace_bst_insert(struct rt_aspace *aspace, struct rt_varea *varea);
  76. /**
  77. * @brief Remove a varea from the bst
  78. *
  79. * @param aspace
  80. * @param varea
  81. */
  82. void _aspace_bst_remove(struct rt_aspace *aspace, struct rt_varea *varea);
  83. void rt_varea_pgmgr_pop(rt_varea_t varea, void *vaddr, rt_size_t size);
  84. void rt_varea_pgmgr_pop_all(rt_varea_t varea);
  85. int _varea_map_with_msg(rt_varea_t varea, struct rt_aspace_fault_msg *msg);
  86. #endif /* __MM_PRIVATE_H__ */