summaryrefslogtreecommitdiff
path: root/loader/memory_efi.c
blob: b2d38ee7dce93b39049ecd02295027d4757f3e66 (plain)
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
#include "loader_efi.h"

#include <loader/data_efi.h>
#include <kernel/memory/paging.h>

struct memory_range system_allocate(size_t size)
{
    EFI_STATUS status;
    struct memory_range buffer;

    buffer.type = SYSTEM_MEMORY;
    buffer.size = size;

    status = e_bs->AllocatePages(AllocateAnyPages,
                                 SystemMemoryType,
                                 page_count(buffer.size, 1),
                                 &buffer.base);

    if (EFI_ERROR(status))
    {
        e_last_error = status;
        buffer.type = UNUSABLE_MEMORY;
    }

    return buffer;
}

void *efi_allocate(size_t size)
{
    EFI_STATUS status;
    void *buffer;

    status = e_bs->AllocatePool(EfiLoaderData, size, &buffer);

    if (EFI_ERROR(status))
    {
        e_last_error = status;
        buffer = NULL;
    }

    return buffer;
}

void efi_free(void *buffer)
{
    EFI_STATUS status;
    
    status = e_bs->FreePool(buffer);
    
    if (EFI_ERROR(status))
    {
        e_last_error = status;
    }
}