Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Functions | |
void | arch_mem_map (void *virt, uintptr_t phys, size_t size, uint32_t flags) |
void | arch_mem_unmap (void *addr, size_t size) |
int | arch_page_phys_get (void *virt, uintptr_t *phys) |
#include <kernel/include/kernel_arch_interface.h>
Map physical memory into the virtual address space
This is a low-level interface to mapping pages into the address space. Behavior when providing unaligned addresses/sizes is undefined, these are assumed to be aligned to CONFIG_MMU_PAGE_SIZE.
The core kernel handles all management of the virtual address space; by the time we invoke this function, we know exactly where this mapping will be established. If the page tables already had mappings installed for the virtual memory region, these will be overwritten.
If the target architecture supports multiple page sizes, currently only the smallest page size will be used.
The memory range itself is never accessed by this operation.
This API must be safe to call in ISRs or exception handlers. Calls to this API are assumed to be serialized, and indeed all usage will originate from kernel/mm.c which handles virtual memory management.
Architectures are expected to pre-allocate page tables for the entire address space, as defined by CONFIG_KERNEL_VM_BASE and CONFIG_KERNEL_VM_SIZE. This operation should never require any kind of allocation for paging structures.
Validation of arguments should be done via assertions.
This API is part of infrastructure still under development and may change.
virt | Page-aligned Destination virtual address to map |
phys | Page-aligned Source physical address to map |
size | Page-aligned size of the mapped memory region in bytes |
flags | Caching, access and control flags, see K_MAP_* macros |
#include <kernel/include/kernel_arch_interface.h>
Remove mappings for a provided virtual address range
This is a low-level interface for un-mapping pages from the address space. When this completes, the relevant page table entries will be updated as if no mapping was ever made for that memory range. No previous context needs to be preserved. This function must update mappings in all active page tables.
Behavior when providing unaligned addresses/sizes is undefined, these are assumed to be aligned to CONFIG_MMU_PAGE_SIZE.
Behavior when providing an address range that is not already mapped is undefined.
This function should never require memory allocations for paging structures, and it is not necessary to free any paging structures. Empty page tables due to all contained entries being un-mapped may remain in place.
Implementations must invalidate TLBs as necessary.
This API is part of infrastructure still under development and may change.
addr | Page-aligned base virtual address to un-map |
size | Page-aligned region size |
#include <kernel/include/kernel_arch_interface.h>
Get the mapped physical memory address from virtual address.
The function only needs to query the current set of page tables as the information it reports must be common to all of them if multiple page tables are in use. If multiple page tables are active it is unnecessary to iterate over all of them.
Unless otherwise specified, virtual pages have the same mappings across all page tables. Calling this function on data pages that are exceptions to this rule (such as the scratch page) is undefined behavior. Just check the currently installed page tables and return the information in that.
virt | Page-aligned virtual address | |
[out] | phys | Mapped physical address (can be NULL if only checking if virtual address is mapped) |
0 | if mapping is found and valid |
-EFAULT | if virtual address is not mapped |