Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/page.c

    r6645a14 r404be7c  
    5353 * We assume that the other processors are either not using the mapping yet
    5454 * (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 
    5656 * will do an implicit serialization by virtue of running the TLB shootdown
    5757 * interrupt handler.
     
    6565#include <arch/mm/asid.h>
    6666#include <mm/as.h>
     67#include <mm/km.h>
    6768#include <mm/frame.h>
    6869#include <arch/barrier.h>
     
    177178}
    178179
    179 int page_find_mapping(uintptr_t virt, void **phys)
     180uintptr_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);
     194        }
     195        page_table_unlock(AS_KERNEL, true);
     196       
     197        return virtaddr;
     198}
     199
     200
     201/** 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 */
     207sysarg_t sys_page_find_mapping(uintptr_t virt_address,
     208    uintptr_t *uspace_frame)
    180209{
    181210        mutex_lock(&AS->lock);
    182211       
    183         pte_t *pte = page_mapping_find(AS, virt, false);
    184         if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) {
     212        pte_t *pte = page_mapping_find(AS, virt_address, false);
     213        if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) {
    185214                mutex_unlock(&AS->lock);
    186                 return ENOENT;
     215               
     216                return (sysarg_t) ENOENT;
    187217        }
    188218       
    189         *phys = (void *) PTE_GET_FRAME(pte) +
    190             (virt - ALIGN_DOWN(virt, PAGE_SIZE));
     219        uintptr_t phys_address = PTE_GET_FRAME(pte);
    191220       
    192221        mutex_unlock(&AS->lock);
    193222       
     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       
    194229        return EOK;
    195230}
    196231
    197 /** Syscall wrapper for getting mapping of a virtual page.
    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;
    212 }
    213 
    214232/** @}
    215233 */
Note: See TracChangeset for help on using the changeset viewer.