1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/mm/physical/pmm.h"
6
7#include <mos/types.h>
8
9/**
10 * @brief Dump the state of the buddy allocator.
11 *
12 */
13void buddy_dump_all();
14
15/**
16 * @brief Initialize the buddy allocator with the given maximum number of frames.
17 *
18 * @param max_nframes The maximum number of frames that are addressable on the system.
19 */
20void buddy_init(size_t max_nframes);
21
22/**
23 * @brief Reserve several frames at the given physical frame number.
24 *
25 * @param pfn The physical frame number to reserve.
26 * @param nframes The number of frames to reserve.
27 */
28void buddy_reserve_n(pfn_t pfn, size_t nframes);
29
30/**
31 * @brief Allocate nframes of contiguous physical memory.
32 *
33 * @param nframes The number of frames to allocate.
34 * @return phyframe_t * The first frame in the contiguous block.
35 *
36 * @note nframes will be allocated exactly, and each frame can be freed individually.
37 * (unlike buddy_alloc_n_compound)
38 */
39phyframe_t *buddy_alloc_n_exact(size_t nframes);
40
41/**
42 * @brief Free nframes of contiguous physical memory.
43 *
44 * @param pfn The physical frame number of the first frame in the contiguous block.
45 * @param nframes The number of frames to free.
46 *
47 * @note // !! The number of frames freed must be the same as the number of frames allocated. // TODO
48 */
49void buddy_free_n(pfn_t pfn, size_t nframes);
50