summaryrefslogtreecommitdiffstats
path: root/mem/zone.h
blob: 7e863bfc6281f9c45e673307dc977c68fc47e980 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef JOVE_MEM_ZONE_H
#define JOVE_MEM_ZONE_H 1

#include <stdint.h>
#include "lib/buddymap.h"

enum {
    MEM_ZONE_STANDARD = 0, /* First GiB of physical memory. */
    MEM_ZONE_HIGHER,
    MEM_ZONE_COUNT
};

#define MEM_ZONE_STANDARD_BASE 0
#define MEM_ZONE_STANDARD_LIMIT (1 * GiB)
#define MEM_ZONE_HIGHER_BASE MEM_ZONE_STANDARD_LIMIT

#define MEM_BUDDY_ORDERS 12
struct PhysicalMemoryZone
{
    const char *name;

    uintptr_t base;
    uintptr_t limit;

    size_t npages_total;
    size_t npages_free;

    struct BuddyMap freemap;
};

/** Using a given zone, reserve a range of physical addresses
 * @param zone identifier of zone to modify
 * @param base starting address to reserve
 * @param limit ending address to reserve*/
void mem_zone_resv(size_t zone, uintptr_t base, uintptr_t limit);

/** Using a given zone, free a range of physical addresses
 * @param zone identifier of zone to modify
 * @param base starting address to free
 * @param limit ending address to free*/
void mem_zone_free(size_t zone, uintptr_t base, uintptr_t limit);

/** Allocate a number of pages from the given zone
 * @param zone identifier of the zone to modify
 * @param pages number of pages to allocate
 * @return physical memory address of allocation
 *         zero if allocation failed*/
uintptr_t mem_zone_alloc(size_t zone, size_t pages);

void mem_zone_setup_standard(void);

#endif