35#include <kernel/types.h>
37#include <utils/bits.h>
43#define PMM_INVALID_PAGEFRAME (0xFFFFFFFFUL)
58#define TOTAL_PAGEFRAMES_COUNT (ADDRESS_SPACE_SIZE / PAGE_SIZE)
82 struct kmem_cache *cache;
97#define TO_PFN(_pageframe) (((native_t)(_pageframe)) >> PAGE_SHIFT)
99#define FROM_PFN(_pageframe) ((_pageframe) << PAGE_SHIFT)
146bool pmm_init(
struct multiboot_info *);
169#define pmm_allocate() pmm_allocate_pages(PAGE_SIZE)
171#define pmm_free(pageframe) pmm_free_pages(pageframe, PAGE_SIZE)
static bool page_is_cow(struct page *page)
Definition: pmm.h:126
struct page pmm_pageframes[TOTAL_PAGEFRAMES_COUNT]
The array of all existing pageframes.
Definition: pmm.c:35
static struct page * address_to_page(paddr_t addr)
Definition: pmm.h:114
#define TOTAL_PAGEFRAMES_COUNT
Total number of pageframes.
Definition: pmm.h:58
static paddr_t page_address(const struct page *page)
Definition: pmm.h:102
void page_put(struct page *page)
Decrease the page's refcount.
Definition: pmm.c:215
paddr_t pmm_allocate_pages(size_t size)
Allocate previously unused pageframes.
Definition: pmm.c:243
page_flags
Flags used for struct page 'flags' field.
Definition: pmm.h:63
void pmm_free_pages(paddr_t pageframe, size_t size)
Release previously allocated contiguous pageframes.
Definition: pmm.c:290
#define FROM_PFN(_pageframe)
Convert pageframe number to pageframe address.
Definition: pmm.h:99
struct page * page_get(struct page *page)
Increase the page's refcount.
Definition: pmm.c:209
#define TO_PFN(_pageframe)
Convert pageframe address to page frame number.
Definition: pmm.h:97
static struct page * pfn_to_page(unsigned int pfn)
Definition: pmm.h:108
bool pmm_init(struct multiboot_info *)
Initialize the Physical Memory Mapper.
Definition: pmm.c:226
@ PAGE_COW
Currently used in a CoW mapping.
Definition: pmm.h:65
@ PAGE_SLAB
Page allocated by the slab allocator.
Definition: pmm.h:66
@ PAGE_LARGE_ALLOC
Page allocated by kmalloc_large()
Definition: pmm.h:67
@ PAGE_AVAILABLE
This page has not been allocated.
Definition: pmm.h:64
#define BIT(_n)
Generate the nth power of 2 (nth bit set)
Definition: bits.h:20
Represents a physical pageframe.
Definition: pmm.h:73
uint8_t flags
Combination of page_flags.
Definition: pmm.h:74
uint8_t refcount
How many processes reference that page.
Definition: pmm.h:75