1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15#include <autoconf.h> 16#include <sel4utils/gen_config.h> 17#include <utils/util.h> 18#include <sel4/sel4.h> 19 20#include <vka/vka.h> 21#include <vka/object.h> 22 23/* Map a page to a virtual address, allocating a page table if necessary. 24* 25* 26* @param vka a vka compliant allocator 27* @param pd page directory to map the page into 28* @param page capability to the page to map in 29* @param vaddr unmapped virtual address to map the page into 30* @param rights permissions to map the page with 31* @param cacheable 1 if the page should be cached (0 if it is for DMA) 32* @param objects array of vka_object_t structure to be populated with paging structures 33* info any one are allocated 34* @param num_objects Pointer to both the size of the objects array, and the number of 35* objects that get allocated 36* 37* @return error sel4 error code or -1 if allocation failed. 38*/ 39int sel4utils_map_page(vka_t *vka, seL4_CPtr pd, seL4_CPtr frame, void *vaddr, 40 seL4_CapRights_t rights, int cacheable, vka_object_t *objects, int *num_objects); 41 42/** convenient wrapper this if you don't want to track allocated page tables */ 43static inline int sel4utils_map_page_leaky(vka_t *vka, seL4_CPtr pd, seL4_CPtr frame, void *vaddr, 44 seL4_CapRights_t rights, int cacheable) 45{ 46 vka_object_t objects[3]; 47 int num = 3; 48 return sel4utils_map_page(vka, pd, frame, vaddr, rights, cacheable, objects, &num); 49} 50 51#include <vspace/vspace.h> 52 53/* Duplicate a page cap and map it into a vspace 54 * 55 * @param vka Allocator for resources 56 * @param vspace vspace to map into 57 * @param page cptr to duplicate and map 58 * @param size_bits size of the page to map 59 * 60 * @return virtual address of mapping 61 */ 62void *sel4utils_dup_and_map(vka_t *vka, vspace_t *vspace, seL4_CPtr page, size_t size_bits); 63 64/* Unmap a duplicated page cap and free any resources. Is the opposite 65 * of sel4utils_dup_and_map 66 * 67 * @param vka Allocator used to allocated resources 68 * @param vspace vspace that frame was mapped into 69 * @param mapping virtual address of mapping to remove 70 * @param size_bits size of the page to unmap 71 * 72 * @return none 73 */ 74void sel4utils_unmap_dup(vka_t *vka, vspace_t *vspace, void *mapping, size_t size_bits); 75 76#if defined(CONFIG_IOMMU) || defined(CONFIG_TK1_SMMU) 77int sel4utils_map_iospace_page(vka_t *vka, seL4_CPtr iospace, seL4_CPtr frame, seL4_Word vaddr, 78 seL4_CapRights_t rights, int cacheable, seL4_Word size_bits, 79 vka_object_t *pts, int *num_pts); 80#endif /* defined(CONFIG_IOMMU) || defined(CONFIG_TK1_SMMU) */ 81 82#ifdef CONFIG_VTX 83int sel4utils_map_ept_page(vka_t *vka, seL4_CPtr pd, seL4_CPtr frame, seL4_Word vaddr, 84 seL4_CapRights_t rights, int cacheable, seL4_Word size_bits, vka_object_t *pagetable, vka_object_t *pagedir, 85 vka_object_t *pdpt); 86 87#endif /* CONFIG_VTX */ 88 89