Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 03cdd2b in mainline


Ignore:
Timestamp:
2012-01-31T22:44:35Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
b860f9e
Parents:
bf3dd35
Message:

Add km_unmap() and km_unmap_aligned().

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/mm/km.h

    rbf3dd35 r03cdd2b  
    5050
    5151extern uintptr_t km_map(uintptr_t, size_t, unsigned int);
     52extern void km_unmap(uintptr_t, size_t);
    5253
    5354extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t);
  • kernel/generic/src/mm/km.c

    rbf3dd35 r03cdd2b  
    128128{
    129129        uintptr_t vaddr;
    130         size_t asize;
    131130        size_t align;
    132131        uintptr_t offs;
    133132
    134         asize = ALIGN_UP(size, PAGE_SIZE);
     133        ASSERT(ALIGN_DOWN(paddr, FRAME_SIZE) == paddr);
     134        ASSERT(ALIGN_UP(size, FRAME_SIZE) == size);
     135
    135136        align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
    136         vaddr = km_page_alloc(asize, max(PAGE_SIZE, align));
     137        vaddr = km_page_alloc(size, max(PAGE_SIZE, align));
    137138
    138139        page_table_lock(AS_KERNEL, true);
    139         for (offs = 0; offs < asize; offs += PAGE_SIZE) {
     140        for (offs = 0; offs < size; offs += PAGE_SIZE) {
    140141                page_mapping_insert(AS_KERNEL, vaddr + offs, paddr + offs,
    141142                    flags);
     
    146147}
    147148
     149static void km_unmap_aligned(uintptr_t vaddr, size_t size)
     150{
     151        uintptr_t offs;
     152        ipl_t ipl;
     153
     154        ASSERT(ALIGN_DOWN(vaddr, PAGE_SIZE) == vaddr);
     155        ASSERT(ALIGN_UP(size, PAGE_SIZE) == size);
     156
     157        page_table_lock(AS_KERNEL, true);
     158
     159        ipl = tlb_shootdown_start(TLB_INVL_ASID, ASID_KERNEL, 0, 0);
     160
     161        for (offs = 0; offs < size; offs += PAGE_SIZE)
     162                page_mapping_remove(AS_KERNEL, vaddr + offs);
     163
     164        tlb_invalidate_asid(ASID_KERNEL);
     165
     166        as_invalidate_translation_cache(AS_KERNEL, 0, -1);
     167        tlb_shootdown_finalize(ipl);
     168        page_table_unlock(AS_KERNEL, true);
     169
     170        km_page_free(vaddr, size);
     171}
     172
     173/** Map a piece of physical address space into the virtual address space.
     174 *
     175 * @param paddr         Physical address to be mapped. May be unaligned.
     176 * @param size          Size of area starting at paddr to be mapped.
     177 * @param flags         Protection flags to be used for the mapping.
     178 *
     179 * @return New virtual address mapped to paddr.
     180 */
    148181uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags)
    149182{
    150         size_t offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE);
    151183        uintptr_t page;
    152 
    153         page = km_map_aligned(ALIGN_DOWN(paddr, FRAME_SIZE), size + offs,
    154             flags);
     184        size_t offs;
     185
     186        offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE);
     187        page = km_map_aligned(ALIGN_DOWN(paddr, FRAME_SIZE),
     188            ALIGN_UP(size + offs, FRAME_SIZE), flags);
     189
    155190        return page + offs;
    156191}
    157192
    158 /** Unmap kernen non-identity page.
     193/** Unmap a piece of virtual address space.
     194 *
     195 * @param vaddr         Virtual address to be unmapped. May be unaligned, but
     196 *                      it must a value previously returned by km_map().
     197 * @param size          Size of area starting at vaddr to be unmapped.
     198 */
     199void km_unmap(uintptr_t vaddr, size_t size)
     200{
     201        size_t offs;
     202
     203        offs = vaddr - ALIGN_DOWN(vaddr, PAGE_SIZE);
     204        km_unmap_aligned(ALIGN_DOWN(vaddr, PAGE_SIZE),
     205            ALIGN_UP(size + offs, PAGE_SIZE));
     206}
     207
     208/** Unmap kernel non-identity page.
    159209 *
    160210 * @param[in] page      Non-identity page to be unmapped.
Note: See TracChangeset for help on using the changeset viewer.