45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
// physical memory allocator
|
|
|
|
#ifndef KARLOS_RAM_H
|
|
#define KARLOS_RAM_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <address.h>
|
|
|
|
#define PAGE_SIZE 4096
|
|
#define PAGE_BASE(ptr) (void *)((intptr_t)(ptr) & ~(intptr_t)0xfff)
|
|
|
|
enum frame_size {
|
|
RAM_PAGE_NORMAL = 0,
|
|
RAM_PAGE_LARGE = 1,
|
|
RAM_PAGE_HUGE = 2,
|
|
};
|
|
|
|
size_t frame_size_to_num_bytes(enum frame_size size);
|
|
|
|
struct ram_buffer_requirements {
|
|
uint64_t size;
|
|
uint64_t align;
|
|
bool limit4gb;
|
|
};
|
|
|
|
// This can be used before the allocator itself is initialized (and ONLY then! early BSP code.)
|
|
// Used for static allocations that are never freed (alternative to global variables)
|
|
bool ram_steal(struct pa *out, size_t size, size_t align);
|
|
|
|
void ram_init(void);
|
|
bool ram_alloc_frame(struct ppn *ppn_out, enum frame_size size);
|
|
bool ram_alloc_frame_zeroed(struct ppn *ppn_out, enum frame_size size);
|
|
bool ram_alloc_buffer(struct ppn *ppn_out, struct ram_buffer_requirements req);
|
|
bool ram_alloc_buffer_zeroed(struct ppn *ppn_out, struct ram_buffer_requirements req);
|
|
void ram_free(struct ppn ppn);
|
|
|
|
struct ram_info {
|
|
uint64_t bytes_total;
|
|
uint64_t bytes_free;
|
|
};
|
|
|
|
struct ram_info ram_get_info(void);
|
|
|
|
#endif
|