My Kernel v0.1.0
mmu.h
Go to the documentation of this file.
1
26#ifndef KERNEL_MMU_H
27#define KERNEL_MMU_H
28
29#include <kernel/error.h>
30#include <kernel/types.h>
31
32#include <utils/bits.h>
33
34#include <stdbool.h>
35
40typedef enum mmu_prot {
41 PROT_NONE = 0x0,
42 PROT_EXEC = 0x1,
43 PROT_READ = 0x2,
44 // TODO: NX bit for PROT_EXEC
45 PROT_WRITE = 0x4,
47} mmu_prot;
48
52typedef enum mmu_caching_policy {
57} mmu_policy_t;
58
71bool mmu_init(void);
72
76paddr_t mmu_new(void);
77
82void mmu_destroy(paddr_t mmu);
83
85void mmu_clone(paddr_t destination);
86
88error_t mmu_copy_on_write(vaddr_t);
89
94void mmu_load(paddr_t mmu);
95
106bool mmu_map(vaddr_t virt, paddr_t physical, int prot);
107
119bool mmu_map_range(vaddr_t virt, paddr_t physical, size_t size, int prot);
120
131paddr_t mmu_unmap(vaddr_t virt);
132
138void mmu_unmap_range(vaddr_t start, vaddr_t end);
139
153void mmu_identity_map(paddr_t start, paddr_t end, int prot);
154
158paddr_t mmu_find_physical(vaddr_t);
159
161static inline bool mmu_is_mapped(vaddr_t addr)
162{
163 return !IS_ERR(mmu_find_physical(addr));
164}
165
172error_t mmu_set_policy(vaddr_t, mmu_policy_t policy);
173
181error_t mmu_set_policy_range(vaddr_t range_start, size_t range_size,
182 mmu_policy_t policy);
183
184#endif /* KERNEL_MMU_H */
#define IS_ERR(_x)
Check if an integer can be interpreted as an error.
Definition: error.h:87
paddr_t mmu_find_physical(vaddr_t)
Find the physical mapping of a virtual address.
Definition: mmu.c:526
void mmu_clone(paddr_t destination)
Clone the current MMU inside another one.
Definition: mmu.c:333
mmu_prot
Protection flags passed to the mmu's functions.
Definition: mmu.h:40
bool mmu_map(vaddr_t virt, paddr_t physical, int prot)
Map a virtual address to a physical one.
Definition: mmu.c:376
mmu_caching_policy
Caching policies.
Definition: mmu.h:52
void mmu_unmap_range(vaddr_t start, vaddr_t end)
Unmap a range of virtual addresses.
Definition: mmu.c:507
void mmu_destroy(paddr_t mmu)
Release the MMU's page_directory.
Definition: mmu.c:224
paddr_t mmu_unmap(vaddr_t virt)
Unmap a virtual address.
Definition: mmu.c:473
error_t mmu_copy_on_write(vaddr_t)
Try to remap a potential copy-on-write mapping.
Definition: mmu.c:540
void mmu_identity_map(paddr_t start, paddr_t end, int prot)
Perform identity mapping inside a given virtual address range.
Definition: mmu.c:521
paddr_t mmu_new(void)
Allocate and initialize a new page directory.
Definition: mmu.c:198
error_t mmu_set_policy_range(vaddr_t range_start, size_t range_size, mmu_policy_t policy)
Configure the caching policy in effect when accessing a range of pages.
Definition: mmu.c:312
bool mmu_init(void)
Initialize the MMU's paging system.
Definition: mmu.c:693
bool mmu_map_range(vaddr_t virt, paddr_t physical, size_t size, int prot)
Map a range of virtual addresses to physical ones.
Definition: mmu.c:429
error_t mmu_set_policy(vaddr_t, mmu_policy_t policy)
Configure the caching policy in effect when accessing a page.
Definition: mmu.c:295
static bool mmu_is_mapped(vaddr_t addr)
Definition: mmu.h:161
void mmu_load(paddr_t mmu)
Replace the current page directory.
Definition: mmu.c:180
@ PROT_READ
Definition: mmu.h:43
@ PROT_WRITE
Definition: mmu.h:45
@ PROT_EXEC
Definition: mmu.h:42
@ PROT_NONE
Definition: mmu.h:41
@ PROT_KERNEL
Definition: mmu.h:46
@ POLICY_UC
Definition: mmu.h:53
@ POLICY_WB
Definition: mmu.h:56
@ POLICY_WT
Definition: mmu.h:55
@ POLICY_WC
Definition: mmu.h:54
#define BIT(_n)
Generate the nth power of 2 (nth bit set)
Definition: bits.h:20