Changeset 6645a14 in mainline for kernel/generic/src/mm/page.c


Ignore:
Timestamp:
2011-12-16T21:09:29Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2718e1
Parents:
01e39cbe
Message:

improve sys_page_find_mapping to calculate the physical address including the offset

File:
1 edited

Legend:

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

    r01e39cbe r6645a14  
    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.
     
    7474#include <syscall/copy.h>
    7575#include <errno.h>
     76#include <align.h>
    7677
    7778/** Virtual operations for page subsystem. */
     
    176177}
    177178
     179int 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;
     187        }
     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}
     196
    178197/** Syscall wrapper for getting mapping of a virtual page.
    179  *
    180  * @retval EOK Everything went find, @p uspace_frame and @p uspace_node
    181  *             contains correct values.
    182  * @retval ENOENT Virtual address has no mapping.
    183  */
    184 sysarg_t sys_page_find_mapping(uintptr_t virt_address,
    185     uintptr_t *uspace_frame)
    186 {
    187         mutex_lock(&AS->lock);
    188        
    189         pte_t *pte = page_mapping_find(AS, virt_address, false);
    190         if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) {
    191                 mutex_unlock(&AS->lock);
    192                
    193                 return (sysarg_t) ENOENT;
    194         }
    195        
    196         uintptr_t phys_address = PTE_GET_FRAME(pte);
    197        
    198         mutex_unlock(&AS->lock);
    199        
    200         int rc = copy_to_uspace(uspace_frame,
    201             &phys_address, sizeof(phys_address));
    202         if (rc != EOK) {
    203                 return (sysarg_t) rc;
    204         }
    205        
    206         return EOK;
     198 *
     199 * @return EOK on success.
     200 * @return ENOENT if no virtual address mapping found.
     201 *
     202 */
     203sysarg_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;
    207212}
    208213
Note: See TracChangeset for help on using the changeset viewer.