AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
pmap.h File Reference

Go to the source code of this file.

Functions

void pmap_init (void)
 Takes over the boot page tables as the kernel's, at boot, and makes the page tables of the kernel's half, which every address space shares.
struct pmap * pmap_switch (struct pmap *pmap)
 Switches this CPU to an address space's page tables.
struct pmap * pmap_create (void)
 Makes the page tables of a new address space: an empty user half, and the kernel's half, which every address space shares.
void pmap_incref (struct pmap *pmap)
 Adds a reference to an address space's page tables.
void pmap_decref (struct pmap *pmap)
 Drops a reference to an address space's page tables, freeing them with the last one.
int pmap_add (struct pmap *pmap, vaddr_t va, paddr_t pa, uint32_t flags)
 Maps a page in an address space, replacing what was mapped there.
void pmap_remove (struct pmap *pmap, vaddr_t sva, vaddr_t eva)
 Unmaps the pages of a range of an address space, and flushes them from the TLBs that may have them.
void pmap_protect (struct pmap *pmap, vaddr_t sva, vaddr_t eva, uint32_t prot)
 Changes the permissions of the mapped pages of a range of an address space.
void pmap_page_copy (paddr_t src, paddr_t dst)
 Copies a page of physical memory to another.
void pmap_remove_all (struct pmap *pmap)
 Unmaps the whole user half of an address space, and frees its page tables.
int pmap_page_read (paddr_t paddr, off_t off, size_t size, void *buf)
 Reads from a page of physical memory, through the kernel's mapping.
int pmap_page_write (paddr_t paddr, off_t off, size_t size, void *buf)
 Writes to a page of physical memory, through the kernel's mapping.

Function Documentation

◆ pmap_add()

int pmap_add ( struct pmap * pmap,
vaddr_t va,
paddr_t pa,
uint32_t flags )

Maps a page in an address space, replacing what was mapped there.

Parameters
pmapthe page tables (an address in the kernel's half is mapped in every address space)
vathe virtual address, page-aligned
pathe page's physical address, page-aligned
flagsthe mapping's permissions and caching (VM_*)
Returns
0, -EINVAL for an address that isn't page-aligned (or that can't be mapped page by page, in the direct map), or -ENOMEM if there was no memory for a page table

Definition at line 307 of file pmap.c.

References ARCH_DMAP_BASE, D_VALID, dmap_end, k_pmap, KERNEL_HALF, PAGE_MASK, PAGE_SIZE, PG_PRESENT, pmap_add(), pte_flags(), pte_get(), and tlb_shootdown().

Referenced by kvmem_alloc(), mm_page_map(), phys_window_map(), pmap_add(), slab_page_alloc(), window_map(), and window_map().

◆ pmap_create()

struct pmap * pmap_create ( void )

Makes the page tables of a new address space: an empty user half, and the kernel's half, which every address space shares.

Returns
the new page tables, or NULL if there was no memory for them

Definition at line 242 of file pmap.c.

References k_pmap, KERNEL_PDE, KERNEL_PML4E, kfree(), kmalloc(), M_ZERO, pmap::map, memset(), NULL, pmap_alloc(), pmap_create(), pmap::ref, table(), and table_alloc().

Referenced by pmap_create(), and proc_new().

◆ pmap_decref()

void pmap_decref ( struct pmap * pmap)

Drops a reference to an address space's page tables, freeing them with the last one.

Parameters
pmapthe page tables

Definition at line 271 of file pmap.c.

References pmap_decref(), pmap_release(), and pmap::ref.

Referenced by pmap_decref(), proc_fork(), proc_kill(), and proc_new().

◆ pmap_incref()

void pmap_incref ( struct pmap * pmap)

Adds a reference to an address space's page tables.

Parameters
pmapthe page tables

Definition at line 263 of file pmap.c.

References pmap_incref(), and pmap::ref.

Referenced by pmap_incref().

◆ pmap_init()

void pmap_init ( void )

Takes over the boot page tables as the kernel's, at boot, and makes the page tables of the kernel's half, which every address space shares.

Definition at line 195 of file pmap.c.

References ARCH_BOOT_MAPPED, ARCH_DMAP_BASE, cur_pmap, D_AF, D_ATTR, D_SH_INNER, D_VALID, dmap_end, IDX, k_pmap, k_root, KERNEL_PDE, KERNEL_PML4E, kvm_space, LARGE_SIZE, LMA, pmap::map, MAX, NULL, PAGE_MASK, panic, PG_ADDR, PG_GLOBAL, PG_LARGE, PG_PRESENT, PG_WRITE, vm_space::pmap, pmap_init(), pmap_loaded(), pmap_switch(), printk(), ram_end(), read_cr3(), pmap::ref, table(), table_alloc(), table_alloc_boot(), and tlb_flush().

Referenced by arch_mm_setup(), and pmap_init().

◆ pmap_page_copy()

void pmap_page_copy ( paddr_t src,
paddr_t dst )

Copies a page of physical memory to another.

Parameters
srcthe physical address of the page to copy
dstthe physical address of the page to copy it to

Definition at line 423 of file pmap.c.

References memcpy(), PAGE_SIZE, PHYS2VIRT, and pmap_page_copy().

Referenced by pf_anon(), pf_object(), pf_present(), and pmap_page_copy().

◆ pmap_page_read()

int pmap_page_read ( paddr_t paddr,
off_t off,
size_t size,
void * buf )

Reads from a page of physical memory, through the kernel's mapping.

Parameters
paddrthe page's physical address
offthe offset to read from, in the page
sizehow much to read, at most what's left of the page
bufwhere to put it
Returns
0, or -EINVAL if off isn't in the page

Definition at line 440 of file pmap.c.

References memcpy(), MIN, PAGE_SIZE, PHYS2VIRT, and pmap_page_read().

Referenced by pmap_page_read().

◆ pmap_page_write()

int pmap_page_write ( paddr_t paddr,
off_t off,
size_t size,
void * buf )

Writes to a page of physical memory, through the kernel's mapping.

Parameters
paddrthe page's physical address
offthe offset to write at, in the page
sizehow much to write, at most what's left of the page
bufwhat to write
Returns
0, or -EINVAL if off isn't in the page

Definition at line 452 of file pmap.c.

References memcpy(), MIN, PAGE_SIZE, PHYS2VIRT, and pmap_page_write().

Referenced by pmap_page_write(), sigcode_in(), vnode_page_in(), and vnode_pages_update().

◆ pmap_protect()

void pmap_protect ( struct pmap * pmap,
vaddr_t sva,
vaddr_t eva,
uint32_t prot )

Changes the permissions of the mapped pages of a range of an address space.

Pages that aren't mapped stay unmapped.

Parameters
pmapthe page tables
svathe range's start, page-aligned
evaits end
protthe new permissions (VM_*)

Definition at line 399 of file pmap.c.

References D_ADDR, D_VALID, k_pmap, KERNEL_HALF, MIN, PAGE_MASK, PAGE_SIZE, PG_ADDR, PG_PRESENT, pmap_protect(), pte_flags(), pte_get(), and tlb_shootdown().

Referenced by pf_present(), pf_zero(), pmap_protect(), and vm_space_fork().

◆ pmap_remove()

void pmap_remove ( struct pmap * pmap,
vaddr_t sva,
vaddr_t eva )

Unmaps the pages of a range of an address space, and flushes them from the TLBs that may have them.

The pages lose no references.

Parameters
pmapthe page tables
svathe range's start, page-aligned
evaits end, page-aligned

Definition at line 337 of file pmap.c.

References D_VALID, k_pmap, KERNEL_HALF, MIN, PAGE_MASK, PAGE_SIZE, PG_PRESENT, pmap_remove(), pte_get(), and tlb_shootdown().

Referenced by arch_page_unmap(), kvmem_unmap(), mm_page_unmap(), pf_zero(), phys_window_map(), pmap_remove(), slab_page_free(), window_map(), and window_map().

◆ pmap_remove_all()

void pmap_remove_all ( struct pmap * pmap)

Unmaps the whole user half of an address space, and frees its page tables.

The pages it mapped lose the reference that the page fault handler gave them (mm_page_incref()).

Parameters
pmapthe page tables

Definition at line 382 of file pmap.c.

References D_ADDR, D_VALID, KERNEL_PDE, KERNEL_PML4E, pmap::map, mm_page_decref(), PG_ADDR, PG_PRESENT, pmap_remove_all(), table(), table_free(), tables_free(), tlb_shootdown(), and USER_STACK.

Referenced by pmap_remove_all(), and vm_space_destroy().

◆ pmap_switch()

struct pmap * pmap_switch ( struct pmap * pmap)

Switches this CPU to an address space's page tables.

Parameters
pmapthe page tables to switch to
Returns
the page tables the CPU had before

Definition at line 164 of file pmap.c.

References cur_pmap, isb, pmap::map, panic, pmap_loaded(), pmap_switch(), tlb_flush(), and write_sysreg.

Referenced by arch_thread_spawn(), arch_thread_switch(), init_execve(), kmain(), pmap_init(), pmap_switch(), request_do(), tlb_shootdown(), and x86_ap_start().