Changes in kernel/generic/src/mm/page.c [404be7c:6645a14] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/page.c
r404be7c r6645a14 53 53 * We assume that the other processors are either not using the mapping yet 54 54 * (i.e. during the bootstrap) or are executing the TLB shootdown code. While 55 * we don't care much about the former case, the processors in the latter case 55 * we don't care much about the former case, the processors in the latter case 56 56 * will do an implicit serialization by virtue of running the TLB shootdown 57 57 * interrupt handler. … … 65 65 #include <arch/mm/asid.h> 66 66 #include <mm/as.h> 67 #include <mm/km.h>68 67 #include <mm/frame.h> 69 68 #include <arch/barrier.h> … … 178 177 } 179 178 180 uintptr_t hw_map(uintptr_t physaddr, size_t size) 181 { 182 uintptr_t virtaddr; 183 size_t asize; 184 pfn_t i; 185 186 asize = ALIGN_UP(size, PAGE_SIZE); 187 virtaddr = km_page_alloc(asize, PAGE_SIZE); 188 189 page_table_lock(AS_KERNEL, true); 190 for (i = 0; i < ADDR2PFN(asize); i++) { 191 uintptr_t addr = PFN2ADDR(i); 192 page_mapping_insert(AS_KERNEL, virtaddr + addr, physaddr + addr, 193 PAGE_NOT_CACHEABLE | PAGE_WRITE); 179 int page_find_mapping(uintptr_t virt, void **phys) 180 { 181 mutex_lock(&AS->lock); 182 183 pte_t *pte = page_mapping_find(AS, virt, false); 184 if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) { 185 mutex_unlock(&AS->lock); 186 return ENOENT; 194 187 } 195 page_table_unlock(AS_KERNEL, true); 196 197 return virtaddr; 198 } 199 188 189 *phys = (void *) PTE_GET_FRAME(pte) + 190 (virt - ALIGN_DOWN(virt, PAGE_SIZE)); 191 192 mutex_unlock(&AS->lock); 193 194 return EOK; 195 } 200 196 201 197 /** Syscall wrapper for getting mapping of a virtual page. 202 * 203 * @retval EOK Everything went find, @p uspace_frame and @p uspace_node 204 * contains correct values. 205 * @retval ENOENT Virtual address has no mapping. 206 */ 207 sysarg_t sys_page_find_mapping(uintptr_t virt_address, 208 uintptr_t *uspace_frame) 209 { 210 mutex_lock(&AS->lock); 211 212 pte_t *pte = page_mapping_find(AS, virt_address, false); 213 if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) { 214 mutex_unlock(&AS->lock); 215 216 return (sysarg_t) ENOENT; 217 } 218 219 uintptr_t phys_address = PTE_GET_FRAME(pte); 220 221 mutex_unlock(&AS->lock); 222 223 int rc = copy_to_uspace(uspace_frame, 224 &phys_address, sizeof(phys_address)); 225 if (rc != EOK) { 226 return (sysarg_t) rc; 227 } 228 229 return EOK; 198 * 199 * @return EOK on success. 200 * @return ENOENT if no virtual address mapping found. 201 * 202 */ 203 sysarg_t sys_page_find_mapping(uintptr_t virt, void *phys_ptr) 204 { 205 void *phys; 206 int rc = page_find_mapping(virt, &phys); 207 if (rc != EOK) 208 return rc; 209 210 rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys)); 211 return (sysarg_t) rc; 230 212 } 231 213
Note:
See TracChangeset
for help on using the changeset viewer.