mm_private.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_INTERN_H__
  11. #define __MM_INTERN_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
  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
  51. * ((varea->start >= start) || (varea->end >= start))
  52. *
  53. * @param aspace
  54. * @param length
  55. * @param struct _mm_range
  56. * @return struct rt_varea*
  57. */
  58. struct rt_varea *_aspace_bst_search_exceed(struct rt_aspace *aspace,
  59. void *start);
  60. /**
  61. * @brief Retrieve any varea overlaps a specified address range
  62. *
  63. * @param aspace
  64. * @param start
  65. * @param length
  66. * @return struct rt_varea*
  67. */
  68. struct rt_varea *_aspace_bst_search_overlap(struct rt_aspace *aspace,
  69. struct _mm_range range);
  70. /**
  71. * @brief Insert a varea into the bst
  72. *
  73. * @param aspace
  74. * @param varea
  75. */
  76. void _aspace_bst_insert(struct rt_aspace *aspace, struct rt_varea *varea);
  77. /**
  78. * @brief Remove a varea from the bst
  79. *
  80. * @param aspace
  81. * @param varea
  82. */
  83. void _aspace_bst_remove(struct rt_aspace *aspace, struct rt_varea *varea);
  84. #endif /* __MM_INTERN_H__ */