summaryrefslogtreecommitdiffstats
path: root/mem/zone.h
blob: c0b0f52b5cd8b4501aa64fbfea797b6d8a466f74 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#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;

    struct BuddyMap freemap;
};

/**Return the zone index for the given address
 * @param addr address to look up
 * @return zone index*/
int mem_zone_for(uintptr_t addr);

/**Return the lower bound for the given zone index.
 * @param zone index into zones.
 * @return lower bound.*/
uintptr_t mem_zone_bound_lower(size_t zone);

/**Return the upper bound for the given zone index.
 * @param zone index into zones.
 * @return upper bound.*/
uintptr_t mem_zone_bound_upper(size_t zone);

/**Return the number of pages free in the given zone.
 * @param zone index into zones.
 * @return number of free pages.*/
size_t mem_zone_pages_free(size_t zone);

/** 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
 * @return error code or 0 if success */
int 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
 * @return error code or 0 if success*/
int 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