mm_memblock.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-09-07 zmshahaha the first version
  9. */
  10. #ifndef __MM_MEMBLOCK_H__
  11. #define __MM_MEMBLOCK_H__
  12. #include "mm_page.h"
  13. #include <rtdef.h>
  14. enum mmblk_flag
  15. {
  16. MEMBLOCK_NONE = 0x0, /**< normal region */
  17. MEMBLOCK_HOTPLUG = 0x1, /**< hotpluggable region */
  18. MEMBLOCK_NOMAP = 0x2, /**< don't add to kernel direct mapping */
  19. };
  20. typedef rt_uint32_t mmblk_flag_t;
  21. /**
  22. * @struct rt_mmblk_reg
  23. *
  24. * @brief A structure representing a region in rt_memblock
  25. */
  26. struct rt_mmblk_reg
  27. {
  28. rt_region_t memreg; /**< used to indicate the extent of this area */
  29. mmblk_flag_t flags; /**< the flag of the region */
  30. rt_bool_t alloc; /**< is the node allocated */
  31. rt_slist_t node; /**< hook on rt_memblock */
  32. };
  33. /**
  34. * @struct rt_memblock
  35. *
  36. * @brief A structure representing physical memory block
  37. */
  38. struct rt_memblock
  39. {
  40. rt_slist_t reg_list; /**< store the regions of the memory block */
  41. };
  42. /**
  43. * @brief Add a physical address range to the overall memory region
  44. *
  45. * @note The newly added region is strictly prohibited from overlapping with existing regions.
  46. *
  47. * @param name the name of the region
  48. * @param start the beginning of the physical address range
  49. * @param end the size of the physical address range
  50. * @param flags the flags of the region
  51. */
  52. rt_err_t rt_memblock_add_memory(char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags);
  53. /**
  54. * @brief Add a physical address range to the reserved memory region
  55. *
  56. * @note The newly added region is strictly prohibited from overlapping with existing regions.
  57. *
  58. * @param name the name of the reseved region
  59. * @param start the beginning of the physical address range
  60. * @param end the size of the physical address range
  61. * @param flags the flags of the region
  62. */
  63. rt_err_t rt_memblock_reserve_memory(char *name, rt_size_t start, rt_size_t end, mmblk_flag_t flags);
  64. /**
  65. * @brief To conclude the management of memory by the memblock.
  66. *
  67. * @note This function will free all usable to buddy system and map all memory without
  68. * specified MEMBLOCK_NOMAP.
  69. */
  70. void rt_memblock_setup_memory_environment(void);
  71. /**
  72. * @brief Get the memory memblock.
  73. *
  74. * @return Overall memory memblock.
  75. */
  76. struct rt_memblock *rt_memblock_get_memory(void);
  77. /**
  78. * @brief Get the reserved memory memblock.
  79. *
  80. * @return Reserved memory memblock.
  81. */
  82. struct rt_memblock *rt_memblock_get_reserved(void);
  83. #endif /* __MM_MEMBLOCK_H__ */